How to pass parameters in selenium RC using TestNG
We can parametrize our test cases using TestNG in Selenium RC in two ways
Pass the data from testng.xml file...
1. using @parameters
public class first_class {
private Selenium selenium;
public String url = "http://google.com/";
@Parameter ({ "url" })
@Test
public void Test(String url) throws MalformedURLException {
System.out.println("In Test Methos");
selenium.open(url);
System.out.println(selenium.getTitle() + "in in Test Method");
selenium.close();
}
}
2. using @DataProvider
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();
}
No comments:
Post a Comment