Selenium TestNG TestDriven

 

from OpenQA : All Content - Se: Advanced Techniques and Automation by clearspace@openqa.org

Well, some basic Java (relativelly speaking) would help a lot. At work we  use Selenium, TestNG and Ant (we use Eclipse only to write tests, not to run them).

 

Our set up is very similar to this: http://sites.google.com/site/testngantjavaseleniumrc/   In fact this is scaled down version what I use at work.

 

There is one more folder called data (and guess what it holds excel files).   We modify our Selenium tests to read from excel files (http://www.vogella.de/articles/JavaExcel/article.html  we use this one, there is alsohttp://poi.apache.org/). You can create your own helper class that fits your needs. 

 

Excel files can be organized in any way you want.

 

example: http://seleniumhq.org/docs/05_selenium_rc.html#programming-your-test 

 

advantage of doing it this way:

 

      public void testNew() throws Exception {
           selenium.open("/");
           selenium.type("q", "selenium rc");
           selenium.click("btnG");
           selenium.waitForPageToLoad("30000");
           assertTrue(selenium.isTextPresent("Results * for selenium rc"));
           // These are the real test steps
     }


if you look at selenium.type("q", "selenium rc");
your excel file can hold   values, and pseudo code would be something like :

// you will need to specify exact cell in your spreadsheet
   searchString = sheet.getCell(0,row).getContents(); 
   clickOnThis = sheet.getCell(1,row).getContents();
   waitingPeriod =   sheet.getCell(2,row).getContents();
   expectedResult = sheet.getCell(3,row).getContents();
  
     selenium.type("q", searchString);
    selenium.click(clickOnThis );
    selenium.waitForPageToLoad(waitingPeriod );
 assertTrue(selenium.isTextPresent(expectedResult));

if you want to change search string, you just edit spread sheet and enter different string. if Google changes the name for the button,
same story: just edit excel file, etc.  there is no need to change you Java code, plus code is much easier to understand

this way, you write your test once and usualy there is no need to change Java code often.
most of the time you edit your excel files 

when I have time (no promises here) I will try to add excel helper class  to the example posted at  http://sites.google.com/site/testngantjavaseleniumrc/

 

 

http://code.google.com/p/testng-xslt/