Selenium
is a tool which controls the browser/website like a user. It simulates a user clicking through the pages. Knowing the functionality of your web application, you can setup your tests. Now run set of test cases together i.e. Test Suite. TestNG
gives this capability to manage test execution.
I suggest you to read this simple tutorial to setup TestNG suite of tests.
I want to execute all testcases at a time
Selenium Grid is a part of the Selenium Suite to run tests in parallel. You setup the driver in base classs
public class TestBase {
protected ThreadLocal<RemoteWebDriver> threadDriver = null;
@BeforeMethod
public void setUp() throws MalformedURLException {
threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities dc = new DesiredCapabilities();
FirefoxProfile fp = new FirefoxProfile();
dc.setCapability(FirefoxDriver.PROFILE, fp);
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));
}
public WebDriver getDriver() {
return threadDriver.get();
}
@AfterMethod
public void closeBrowser() {
getDriver().quit();
}
}
An example of sample test would be:
public class Test01 extends TestBase {
@Test
public void testLink()throws Exception {
getDriver().get("http://facebook.com");
WebElement textBox = getDriver().findElement(By.xpath("//input[@value='Name']"));
// test goes here
}
}
You can add more tests in similar way as above
public class Test02 extends TestBase {
@Test
public void testLink()throws Exception {
// test goes here
}
}
TestNG Configurations:
testng.xml
<suite name="My Test Suite">
<suite-files>
<suite-file path="./testFiles.xml" />
</suite-files>
testFiles.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test runs" parallel="tests" thread-count="2">
<test name="T_01">
<classes>
<class name="com.package.name.Test01" ></class>
</classes>
</test>
<test name="T_02">
<classes>
<class name="com.package.name.Test02" ></class>
</classes>
</test>
<!-- more tests -->
</suite>