Tuesday, February 11, 2014

Using of the WebDriver (Selenium). Some additional techniques

Before using web-driver you need to configure it. Please, make sure that all that you did corresponds to the following list of links:

  1. Using Web Driver
  2. FireFox Driver
  3. Internet Explorer Driver
It was found out (I suppose no one would need any additional checks) that controls in web-application can have different location in hierarchy tree in different browsers. It means that some checks in your code need depend on a type of a web-driver. In my case, I actually did not find differences, so I did not write any checks on that.

What I've found useful is ExpectedConditionsA good example for using such capability can be found here and here.


Monday, February 3, 2014

How I automate testing of one web-application

I would like to share my experience with tests’ integration and preparation for a web-application, using Eclipse, Selenium and testNG.

A few words about the web-application that I need to automate. This is a 7-screen application. The screens have all kind of controls such as our custom control, edit boxes, labels, buttons, radio buttons, combo boxes, menu control and so on. I cannot provide any hard copies of screens or anything else about this tool because this information is confidential.

No doubt, you may find a lot of information on how to do it on the Internet. But I personally have failed to find a link that would contain all necessary information on one page, that’s why I would like to share my own experience.

Let me introduce the task. I have a rich web application developed with GWT. I have a specification, a list of test cases that I've prepared during the previous month and a requirement for additional automatization. I suggest that we have the same environment as our developers have. So I used Eclipse as IDE for development. After that I was trying out different test automatization. Based on my previous experience, the list was as follows:
  1.  UIAutomation - Microsoft Visual Studio is required for development (no such IDE here). When I've looked through on the components tree of the application, I found out a huge hierarchy without any chance to identify required web-control.
  2. AutoIT - Did not 'see' any controls on the web-application
  3. WatIN - Microsoft Visual Studio is required for development (no such IDE here).

The first search sends me to Selenium project, so I read additional forums and articles, and decided to use it. 
The next step is test framework selection. Selenium gives an opportunity to generate the source code for Java and JUnit or testNG. According to this article, I decided to use testNG 
First of all I tried to use Selenium for automatization, just to check if all significant cases can be covered by the Selenium IDE.


It took me a few days to make sure that it is possible to automate the main functionality of the web-application. 
However, I faced some troubles during my investigation.
1.   The name of test case will be converted to class name in Java during the test launch, so in the first place I suggest to avoid test names which contain special symbols like: 'Wheel: Speed 100 km/h', 'Wheel: Speed 200 km/h'
2.   Our application has a complex logic with many events, so I frequently needed to call operations with the “pause” command after it. First, I decided to use '*AndWait' versions of the required commands but it was not applicable for me according to this article (in details: Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”. This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.)

3.   I had a lot of troubles with our custom control, because the 'sendKeys' function call was required to enter the text correctly. Function 'type' does not allow sanding the entered value correctly.
I probably should have been aware about these troubles but I was a beginner in Selenium.
Moreover, you can find information about how to create your first Selenium script by following this link
After that I decided to convert the existing Selenium tests from 'html' to 'java' and configure environment to work with these tests like from IDE.
If you want to learn how to configure a project in Eclipse you may follow this link (or this one and this one ). I used it for my project, but I had to make some changes at the last stage.
I decided to leave the functions generated by Selenium IDE as they are, I added them as separate functions, not as part of the main function. So, my main function looks like:

@Test
public void main() {
    try {
        ConvertedTestFunction();
    }
    catch(Exception e){
        System.out.print("Exception occurs: " + e.getMessage());
        Assert.fail(e.getMessage());
    }

}

'Assert' prefix was  added after I had converted my project to TestNG. (step #8 from link above)
After that I launched Selenium server using this command java -jar selenium-server-standalone-2.39.0.jar like has it was described in section 'Running Standalone Selenium Server for use with RemoteDrivers' of this page.  Afterwards I chose the menu item 'Run As -> TestNG Suite' in menu for testing.xml file (more information can be found in section 'Launching your tests in Eclipse' on this page)

Now all works fine!
Only one case in under investigation. function 'sendKeys' does not exist in realization on java.
Workaround in my case was in using both functions 'type("field", "text to type")' and 'typeKeys("field", "\\13")
I created the required ticket about this issue on official site.

As you can see using of Selenium RC is depricated. All test code should be updated from selenium to webdriver.