Installing tools for Selenium Eclipse Java Maven Webdriver on Windows

20120107

Summary of tools installation:

 

  • Eclipse JEE Juno
  • Selenium Java Client .jar
  • Selenium server .jar
  • Add above to project build path
  • Add selenium javadoc path
  • Thats it!

 

 


20121220

I have a complex browser based application to test.

The UI component I am responsible for testing has a large set of record fields, with complex navigation & edit options including:

  • paginated summary data records as rows
  • user can sort
  • user can select which columns to see in the summary view
  • user can select rows for subsequent operations (filter / fill / custom action)
  • user can build queries to select / apply a filter to work with a subset of rows
  • user can expand a row inplace to view the tabbed full details
  • user can select a row to open the tabed full details edit view (bottom of page)

In my mind I intuitively see a data driven approach but how to implement it.

My initial focus is the select (search) functionality for a single field

In Excel I have identified my test records to create with the relevant test data, and the set of search operations to perform.

I have started using Selenium IDE 1.9.0 and have successfully abstracted some of the required Xpath using UI-Elements. (works well).  Additionally I have used sideflow.js to allow conditional loops.

This example finds a row across the paginated rows:

<tr>
	<td>echo</td>
	<td>Start: Common-ItemGroupFindItem</td>
	<td></td>
</tr>
<!---------------------------->
<!--Finds first occurance of an item across pagination by column in the current filtered view-->
<!--Column needs to be a column as recognised by ui=itemGroup_page::gridItemSummary-->
<!---------------------------->
<!--Start page: Item group: any paginated page-->
<!--End page: Item group paginated page with target item on it-->
<!---------------------------->
<!--Required input variables:-->
<tr>
	<td>store</td>
	<td>code</td>
	<td>targetItemColumn</td>
</tr>
<tr>
	<td>store</td>
	<td>R30002162</td>
	<td>targetItemColumnValue</td>
</tr>
<!---------------------------->
<tr>
	<td>echo</td>
	<td>${targetItemColumn}</td>
	<td>target item summary column</td>
</tr>
<tr>
	<td>echo</td>
	<td>${targetItemColumnValue}</td>
	<td>target value to search for</td>
</tr>
<tr>
	<td>echo</td>
	<td>${ItemGroupCount_filtered}</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>${ItemGroupCount_pages}</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>${ItemGroupCount_activePage}</td>
	<td></td>
</tr>
<!---------------------------->
<tr>
	<td>echo</td>
	<td>*** set defaults assume not found ***</td>
	<td></td>
</tr>
<tr>
	<td>store</td>
	<td>0</td>
	<td>ItemGroupFindItem</td>
</tr>
<tr>
	<td>store</td>
	<td>0</td>
	<td>ItemGroupFindItem_page</td>
</tr>
<tr>
	<td>store</td>
	<td>0</td>
	<td>ItemGroupFindItem_row</td>
</tr>
<!---------------------------->
<tr>
	<td>echo</td>
	<td>*** Do we have any items displayed? ***</td>
	<td></td>
</tr>
<tr>
	<td>gotoIf</td>
	<td>${ItemGroupCount_filtered}==0</td>
	<td>END</td>
</tr>
<tr>
	<td>store</td>
	<td>1</td>
	<td>currentItemIndex</td>
</tr>
<tr>
	<td>store</td>
	<td>1</td>
	<td>searchPage</td>
</tr>
<tr>
	<td>echo</td>
	<td>*** Start looking ***</td>
	<td></td>
</tr>
<tr>
	<td>while</td>
	<td>${searchPage} &lt;= ${ItemGroupCount_pages}</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>*** Per page while start ***</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>*** Get to page ***</td>
	<td></td>
</tr>
<tr>
	<td>gotoIf</td>
	<td>${searchPage} == ${ItemGroupCount_activePage}</td>
	<td>ONPAGE</td>
</tr>
<tr>
	<td>click</td>
	<td>ui=itemGroup_page::paginationPageLink(page=${searchPage})</td>
	<td></td>
</tr>
<tr>
	<td>waitForText</td>
	<td>ui=itemGroup_page::paginationActiveLink()</td>
	<td>${searchPage}</td>
</tr>
<tr>
	<td>store</td>
	<td>${searchPage}</td>
	<td>ItemGroupCount_activePage</td>
</tr>
<tr>
	<td>label</td>
	<td>ONPAGE</td>
	<td></td>
</tr>
<tr>
	<td>store</td>
	<td>1</td>
	<td>currentRow</td>
</tr>
<tr>
	<td>while</td>
	<td>${currentRow} &lt;= ${lookupItemGroupItemsPerPage} &amp;&amp; ${currentItemIndex} &lt;= ${ItemGroupCount_filtered}</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>*** Per page row while start***</td>
	<td></td>
</tr>
<tr>
	<td>storeText</td>
	<td>ui=itemGroup_page::gridItemSummary(row=${currentRow}, column=${targetItemColumn})</td>
	<td>retrievedValue</td>
</tr>
<tr>
	<td>gotoIf</td>
	<td>storedVars['retrievedValue'] == storedVars['targetItemColumnValue']</td>
	<td>FOUND</td>
</tr>
<tr>
	<td>storeEval</td>
	<td>${currentRow} + 1</td>
	<td>currentRow</td>
</tr>
<tr>
	<td>storeEval</td>
	<td>${currentItemIndex} + 1</td>
	<td>currentItemIndex</td>
</tr>
<tr>
	<td>echo</td>
	<td>*** Per page row while end ***</td>
	<td></td>
</tr>
<tr>
	<td>endWhile</td>
	<td></td>
	<td></td>
</tr>
<tr>
	<td>storeEval</td>
	<td>${searchPage} + 1</td>
	<td>searchPage</td>
</tr>
<tr>
	<td>echo</td>
	<td>*** Per page while end***</td>
	<td></td>
</tr>
<tr>
	<td>endWhile</td>
	<td></td>
	<td></td>
</tr>
<tr>
	<td>goto</td>
	<td>END</td>
	<td></td>
</tr>
<tr>
	<td>label</td>
	<td>FOUND</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>FOUND</td>
	<td></td>
</tr>
<tr>
	<td>store</td>
	<td>${ItemGroupCount_activePage}</td>
	<td>ItemGroupFindItem_page</td>
</tr>
<tr>
	<td>store</td>
	<td>${currentRow}</td>
	<td>ItemGroupFindItem_row</td>
</tr>
<tr>
	<td>store</td>
	<td>${currentItemIndex}</td>
	<td>ItemGroupFindItem</td>
</tr>
<tr>
	<td>label</td>
	<td>END</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>END</td>
	<td></td>
</tr>
<!---------------------------->
<tr>
	<td>echo</td>
	<td>*** Output variables ***</td>
	<td></td>
</tr>
<tr>
	<td>echo</td>
	<td>${ItemGroupFindItem}</td>
	<td>0 if not found</td>
</tr>
<tr>
	<td>echo</td>
	<td>${ItemGroupFindItem_row}</td>
	<td>0 if not found</td>
</tr>
<tr>
	<td>echo</td>
	<td>${ItemGroupFindItem_page}</td>
	<td>0 if not found</td>
</tr>
<!---------------------------->
<tr>
	<td>echo</td>
	<td>End: Common-ItemGroupFindItem</td>
	<td></td>
</tr>

I was thinking of outputting the test data & operations from Excel as JSON and loading into a js var via user-extensions.js

This approach works but creating complex logic to perform specific tests based on the above data in Selenese results in test cases that are stupid hard to read & hard to maintain.

I also tried to use the UI-Elements rollup functionality but it is difficult to debug.


So now we look at using Selenium WebDriver.  I have no Java experience.. so lets just fumble our way along initially


Attempt 1: Goal: minimum installation configuration to get a script running

Installation:

http://www.silverwareconsulting.com/index.cfm/2010/5/17/Getting-Started-with-WebDriver-a-Browser-Automation-Tool

http://tuventytuventy.wordpress.com/2011/12/06/installing-selenium-2-0-maventestng-and-eclipse/

Downloaded in advance:

  • Eclipse JEE Juno
  • selenium-java-2.25.0
  • Install Eclipse JEE Juno version
  • Start Eclipse
  • Eclipse: Select workspace as prompted
  • Eclipse: File -> New project -> Java project:
    • Project name: GDAP.01 (all others accept defaults)
    • Accept Java aspect
  • Unzip all .jar files from selenium-java-2.25.0 into \GDAP.01\lib\
  • Eclipse: In package explorer refresh & right click on above \lib\ folder and Build path -> Use as source folder
Now to create a simple test script:

All in Eclipse:

  • In Eclipse package explorer right click on src ->  New class
    • name: test1
    • method stubs: public static void main(String[] args) selected
    • Accept
public class test1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

Change to:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test1 {
/**
* @param args
*/
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
        driver.get("http:/xxx.nz");
        WebElement element = driver.findElement(By.xpath("//input[@id='username']"));
        element.sendKeys("testuser");
}
}

 

CTRL-F11 = hey it runs ok

 


20121221 0741

A nugget as to why I am finding some examples starting the selenium server some not:

http://www.qaautomation.net/?p=263: 

Unlike previous versions of Selenium, starting the selenium server is optional. In this case, we are not going to start the selenium server

I really really wanted to use our current UI-Elements.js locators but it looks like to do that I need to run selenium server and that is probably not the recommended approach.

 


20130105

Eclipse:

- Selenium Java Jar, Serve Jar

- TstNG Eclipse extensons

xxxxx

 

public class test1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}