 That's fine. This is the last talk of the day. I'm Anisha and I've been working with NetApp for nearly two years now. I mostly do test automation for web applications. So today I'm going to talk about the testing of web applications. Which tools we can use to test the web applications? How do we go about testing the web applications? How do we start with it? Application testing. Web application testing is about validating the user flow and checking the functionality of the application. Some of the cases might that whether the links on the page redirect to the correct page or if there are forms do they behave correctly or the content present on the page is correct or not also we verify some of the end-to-end user flows. Also including some of the negative scenarios that if a user inputs some invalid data of correct error should be misplaced which notifies the user to input the valid data. Such as the test cases we covered while we were doing web application testing. Automation versus manual. Test automation is nothing but the use of a testing tool to control the execution of tests. Now suppose today you have web application which is pretty small and you think that you can just test it manually. But what if your application increases in size tomorrow and there are so many features in edge case scenarios where you may be required to test your manually. Now this could involve a lot of time. It will increase your regression time as well. So these are the places where test automation comes into the picture. Open source as well as commercial tools which are available with which we can do automation. But we need to make sure that do not automate just for the sake of automating or you are automating because you can automate or the other way that you are doing manual test continuously because you do not want to write any code. We need to decide and plan depending on our project and test cases which are the ones that we need to automate which help us do web application testing. There are a couple of tools like Selenium, Water, Sahi which help us automate browsers and interact with the web elements present on the page. Also there are a couple of commercial tools available with which we can do the web application testing. The most widely used is Selenium. And how many of you have heard of the tool Selenium? Selenium is an open source tool which automates browsers. It tests pages by loading them and forming certain actions on them just as it's a person. It will simulate the actions of that of a user on a web application. It will perform certain clicks, fill up certain applications forms available on the web page, it will do some assertions and it will help you automate your process, save you on regression time. So one of the advantages with Selenium to get started is that Selenium IDE is a recording plane tool which allows you to record lots of test clips. So you make, I can do some interaction on the web browser and then you can record that interaction and come right into a script. Yes, absolutely. So Selenium IDE is a recording plane tool which helps you record your test clips. So whatever transactions you perform on the page, it gets recorded. Now what you can do is you just need to wait. It is available as a Firefox plugin, you install the plugin and you go ahead doing some user flows on your web page and it gets recorded as a script. The Selenium IDE also allows you to get started by converting your test clip to any language with just a click of a button. You can convert the HTML script which is getting recorded in a Python format or in a Ruby format depending upon which language you want to get started with. What is, what is that form web application testing in Ruby? It is a Ruby jet. The water API is built as a wrapper around the Selenium IDE to the Adobe API. It is based on Selenium. It has a web-friendly API. It says it is a Ruby jet you need to use Ruby as a programming language to use water web drive. Selenium is one tool which can be controlled by many programming languages and testing frameworks. Advantages I find with Selenium water is that I do not have to worry about element locators like XPAR or CSS detectors. I can, we will be going forward and seeing how the water, what is the comparison between the codes for work with them. Capubara is another Ruby gem. It has a very intuitive API that mimics the language a human would use. Something like, if there is an email, then there is the method provided like fill that email with password which helps you to write code easier. Easier. Another tool which uses image recognition to identify elements on the page. This is programming language to use. You can choose a programming language if you are comfortable with Python. You can go ahead and use Python as your language and write your test scripts or Ruby or Java, whichever language you are comfortable with. Now before we go, see some code. I just want to, and how do we start writing a test script? I'm sure all of you might have used a paste bin some or the other time. Some sort of paste bin. So this is the Fedora paste bin. So the basic functionality of this application is that we input some texture, we click on the paste button and our paste bin gets created. So this is the basic functionality. Now we'll see how can we automate and write code for this for testing this functionality. So the first step is to interact with the elements. The first step is to input some text box. So how do we know which element on the page we need to interact with? What we do is we go here, we use some inspector element and we see that this text area has an id which is paste data. You know all of you see that? So now we know that this text area available on this page is associated with an id which is unique on the page. The next step should be to click on this button. We go here, we click on this button and again we see that this button also has an id which is paste button. So now we're done with two steps interacting with the elements. We go here, now here our action is to assert. What we do is we go here again on this text, we do a right click and we do an inspector element. But here we see that I do not find any substantial element named with which I can interact. It's contained in the div which has a style it does not have to do name or class or anything like that. So what I do is I go a level above I scroll up and I find that this div is contained apart of the div parent div which has a class text. So now I will interact with this element using the parent div element. Now we go here and we see some code. So on the left you see the Selenium Web Driver writing code and on the right we have written the same script using the water web driver in Ruby part and this is the part. So what we do, the first line says from Selenium import web driver which will import all the web driver implementations and we import the keys class which are there on the keyboard so that the web driver can import the keys on behalf of the user. Finally we see that when we require Ruby gems we require the water web driver gem which we are using. Archspec API provides us to have to master expected outcomes. Next line simulates a real user opening a Firefox browser with the panel sides here. The next step is to open the URL of the application. So on the other side we have used the get method to open the URL which is f-paste.varg and here it's the go-to method. So the concept remains the same for the syntax and the API interpreters, the DSM. Now we have now to interact with the elements once we open the browser. We use finders by ID, face, data we just saw that the text area had an ID and we send the keys sample text here. On the battle side we use the text area ID, face, data So here in the battle, this is the key value here where the key is the name of the attribute and the value is the value of the attribute which was ID. So there we used method like findElementByID, Selenium, findSendFindEx provide us with a lot of findElementBy notators with which we can find elements present on the web page and here this API we find the name of the element like if it's a text area, if it's a button if it's a text box if it's a link and we again send the keys. Now our next action is to click on the button we perform a click on the button similarly we findElementBy classNameNow This one is for ID, face button and we perform a click action which is to make an assertion for the text for the text that we have entered should be same as what we will put We find the element by class name which was text as we saw and here so here you see that we mentioned the type of the element which is like live here so we say live, call it class text, we mention the key value pair as specified should equal to the sample text here Yes, so we do an assertion here that the text that we have got should be equal to the text that I have entered. If there is a failure my test case would fail if it matches my test case would pass and here we use the assertEqual method to match the text enter if that we contain the text in our variable and then we are matching the text enter should equal to the sample text here if it does not matches it will give an error saying text mismatch and the last we close the browser so this is a very small script we have written to test the basic functionality of FBase and you have seen how we can write the code using any of the languages choose your element locators wisely. It is very important to choose the element locators wisely. The safest option is to choose an ID because you know that an ID is unique on the range. Next you can interact with the element using a class name or using a time name link text partial link text but I would say that do not use the text as the element locator suppose a particular link with the name ok or a button the text ok changes to continue to work there is a possibility that your text might fail you will need to modify the text once there is a the new iteration is released if you add a number so it is always advisable to use the elements which can be interacted with or there is very less probability for them to get changed now you saw the application you just saw the sample code for the application the one script it was what if your application is big you cannot just go on writing 100 scripts or you know 50 scripts and manage them you need to have a testing framework to manage all the tests. A testing framework helps you to control the execution of tests it allows you to organize your text better you can maintain consistency help you to generate reports in a server format you would like to see the test reports these are some of the testing frameworks that you can use the natural art VDD frameworks which is talked about to one of them Python test is a Python testing framework unit test is unit test the unit test module as available in Python knows is again a Python testing framework test unit is a testing framework available for Ruby test and GJ unit are similarly Python 2 for Java cucumber is a behavior driven development tool it's a Ruby's jam so cucumber we can use with respect to testing for behavior driven testing behavior driven testing is a companion to VDD the development says that you write your code test first and the application code afterwards but what if you can just describe the behavior of your application in plain text so how about that you are able to write the test that we just performed in plain English saying when I go to phpace.org and I input some text then I should see the same text it's more readable let's see using the tools you can map your code to Python it is a similar tool to cucumber using jvhate you can map your code to Java this is again a similarly VDD tool to remember try do not repeat yourself make proper methods proper libraries modules so that a particular step does not get repeated every time a login function you can create a method and keep it in a separate file and you can reuse that code again and again so that there is no code to use are you putting your code to sleep so this is one of the very commonly done things by most of the people who write tests for web applications the elements always take time to appear on the page because of the network latency so all the elements like web drive, water drive they provide an implicit time out for 30 seconds but the elements to appear on the page so what happens is they put additional sleep time sleep for 10 seconds sleep for 5 seconds so that the tests don't fail that's not a good approach because anything which is taking more to 30 seconds any element which is taking more to 30 seconds to appear on the page is not going to give you a good user experience I hope all of you agree or you would like to wait for more to 30 seconds for any element to appear on the page or any data to appear on the page do not do that choose your element potatoes carefully which is soft organize your code well you need to organize your code into methods and how in the features if you're using cucumber it gets very easy for you to organize your code because you can make subcoulders for your features and use them definitions and things like that with demo of cucumber and water drive how much time do I have you have another 10 minutes 10 minutes maybe see when I say always you don't put the right files in the right folders if you look at the folder structure here you can see a country folder which is there which will contain all the country files so this project this project is using cucumber which is again ruby gem and using the water web drive gem which is a ruby gem so this is the format that we follow there is a features folder where you put all the features of your web application that whatever you want to test so here I have a base.feature inside there is a step definitions folder where you map your features to the actual code how are things working the code that we just saw before we map that code at that right locations we have an environment on rv file where we do all the initialization required like launching of the web browser initial steps that are required to be done gem file just specifies that what all gems are to be mentioned there is a reports folder there is a screenshot folder so screenshot folder is basically for if a test case fails if there is not appropriate code which is being mapped a screenshot is being taken and it's being displayed let's see how the feature files work what you come and looks like we have already written everything that we are doing are in plain text we have to paste the sticker of text so that way successfully my scenario states to verify that I can paste the sticker of text given that I am on the home page when I put text and I click on the paste button then a new paste should be created with the same text and how do we map our code here this is the step definitions file here we map the code exactly given that I am on the home page I specify I navigate to the URL I input the text in the next step I click on the button I verify that whatever text that I have entered should be the same and it should pass the text or else same code that we just saw that we just saw but if you just want to execute the plain script that we have written you can execute like this you can execute like this so the browser is opening the text has been entered and it has been verified it has executed the plain script which did not give us any indication of passing or failing it passed because there is no error so this is what the comparison is how we bring Unity to use and what we see when we just write a simple script there are a couple of other output formats which you can well provide you to generate the reports the format will be html and we specify the output report to be report.html what we got created this is an html report format which will again give you a description then how your tests work what your tests work whether they pass or fail if the test fail then you see your red lines which will give you your indication now comes the integration to Jenkins you can integrate your tests to Jenkins continuous integration and so we do a build now there are a couple of plugins that you need to use when you have to integrate your tests to Jenkins so you can easily integrate your code and if you are using Ruby you can use the rdm environment plugin to manage the Ruby versions so here when you see the reports you see some fancy reports with a clear description of how many people what person of test pass what person of test fail and if you are really interested in knowing about the screenshot thing that I mentioned I will show you that this is one of the test cases which fail so here we go to the reports and we see that there were 25% of the steps which failed and the number of scenarios which failed was 100% because we are just including one scenario here and then we go here we see that the test fail and then the screenshot behind so the test fail because if on fbase if we have a base with a 5 intervals a second the new base does not get created so we see the message here please keep an interval of 5 seconds between your base this is the error that we want and the screenshot if you really want to this is what happens while you are running on this and hence the test case did not pass that's how it works any questions can I also make them dynamically pass if I am writing a test case I can use the same thing for other pages as well can I pass the name of the test box in run time in run time I don't want to hard put the name of the test box because if it is the same file I can use for testing another web page you can parameterize you can mention all the elements that you want to pass at your run time maybe in the environment I am not sure about passing at the run time but please specify them in the environment file because somewhere at the other you will have to mention environment file should be ok because from there you can pass the variables yes so that is the same way the way I was make a config file and you know all the tips this is how the browser variable is being passed and being used everywhere what are support other browsers besides Firefox yes they can support Chrome Firefox you need the download extra stuff but it is actually quite straightforward also whenever you are integrating to Jenkins you mostly use the headless browser and the headless browser that I used for this one was Phantom.js so it simulates the actual real browser and it is faster even as compared to the actual version so it cuts down on the time taken for your build sometimes too fast sometimes too fast you can say that yes it doesn't wait for elements rendered too fast or the page gets dismissed too fast yes why is it crashing for funny reasons so for this if it is going too fast you can always use methods like wait until present if it is taking like 5 seconds it will wait for 5 seconds I suspect the way that it wrote the code because we wrote our own wait until instead of using kebibara's wait until so it is kind of crashing but that wait until present has an implicit time out of 30 seconds so it will not wait for more than 30 seconds yeah it does so sometimes there are times when it crashes but the test code is waiting for the response it is damn lame so can you use this tool to put forth some login page can you use for performance testing I am supposed to do this I have friends who have used kebibara for some e-commerce websites I should not name names you don't have a twitter account so to say that I think a lot of sites these days are nice like a lot so an event like this when you are writing tests on the page you can always use the wait until present which is an implicit time out of 30 seconds I think I have covered it answer the question but since the page can load a lot of things it is only good practical so you can always type down to the page there might be a wizard which might be containing all the elements on the page so you can always type down to the page so that it doesn't run faster than on elements it is very complicated it is not just a vaccine it is present for whichever element you want to write the next one sometimes it is too difficult to do it at interaction level I don't think about writing a unit test I don't know some Ajaxi I don't know if it is like Angular or something sometimes things just doesn't happen the way you want it so you might bring one level over into integration test or the unit test level see you yesterday