Pages

Search This Blog

Monday, May 17, 2010

How to pass parameters in selenium RC using TestNG

We can parametrize our test cases using TestNG in Selenium RC.


import org.openqa.selenium.server.RemoteControlConfiguration;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;

import java.io.*;
import java.sql.*;



public class TestExcel extends SeleneseTestBase {

@DataProvider(name="DP1")
public Object[][] createData(){
Object[][] retObjArr = {{"testuser1","password1"},
{"testuser2","password2"},
{"testuser3","password3"},
{"testuser4","password4"},
{"testuser5","password5"},
};
return(retObjArr);
}


private SeleniumServer seleniumServer;
Selenium selenium;

@BeforeClass
public void setUp()throws Exception{

RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.trustAllSSLCertificates();
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost",4444,"*iexplore","http://www.yahoo.com");
seleniumServer.start();
selenium.start();
}

@Test (dataProvider = "DP1")
public void testEmployeeData(String username, String password){
selenium.open("https://login.yahoo.com/config/mail?.src=ym&.intl=us/");
selenium.type("username", username);
selenium.type("passwd",password);
selenium.click(".save");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("Hi,"+username));
selenium.click("_test_sign_out");
selenium.waitForPageToLoad("30000");

}
@AfterTest
public void tearDown() throws InterruptedException{
selenium.stop();
seleniumServer.stop();

}


3 comments: