"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

June 19, 2010

Learning Selenium – Part I


Please find Selenium example Walkthru. (Win 7- 64 bit)

2. Download Testng from http://testng.org/doc/download.html

3. Run Command Prompt in administrator mode. Start Selenium Server. Command is - java -jar selenium-server.jar. To Run in Single Window, you need to specify java -jar selenium-server.jar -singleWindow

4. Second very good walkthrough is available in http://epyramid.wordpress.com/2008/11/26/setting-up-selenium-rc-testng-using-eclipse/. This link does not seem to exist now, You need to download Eclipse IDE for Java Developers. (Check Links - Link1)

5. Run Eclipse program as Administrator

6. Got Error ‘Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path! Please add the directory containing firefox.exe to your PATH environment’

7. Fix is below line of code
selenium = new DefaultSelenium("localhost", 4444, "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",http://yahoo.com/);

8. Modified code as per example in below page - http://seleniumhq.org/docs/05_selenium_rc.html

9. Code Example
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
public class GoogleTest
{
public Selenium selenium;
public void setup()
{
    selenium = new DefaultSelenium("localhost", 4444, "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe","http://google.com");
    selenium.start();
}
public void search()
{
    selenium.open("http://www.Google.com/");
    selenium.type("q", "selenium rc");
    selenium.click("btnG");
    selenium.waitForPageToLoad("30000");
    assertTrue(selenium.isTextPresent("seleniumhq.org"));
}
public static void main(String arg[])
{
    GoogleTest g = new GoogleTest();
    g.setup();
    g.search();
}
}

Snapshot of Example
















10. Export it as Ant Files. Select Export Option by right click on the Project node. Choose ANT build files from below window


11. Choose the Project to create ANT build file

Reference Link. Build file created with all the contents of the project.
TestNG makes Java unit testing a breeze
Cedric Beust - Test NG
Data Driven Testing using Selenium & TestNG Part 1 of 4
Selenium Remote Control and TestNG

More Reads
Login Scenario - Providing Login Detail from Excel Sheet
Data Driven Testing Using Selenium RC with TestNG
WebDriver with Excelsheet


Happy Reading!!

No comments: