-2

I have created Project(Page Object Model) in Eclipse like this

Project name Package 1 src bin package 2 src bin

In package 1 contains, element description and method In package 2 contains,

BaseScript.java --------- preconditon

webdriver driver=new FirefoxDriver();

        driver.get("url");
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.manage().window().maximize();
        LoginPage l=new LoginPage(driver);
        l.setusername("");
        l.setpassword("");
        l.LoginBut();

Postconditons

driver.quit();

I have T1.java,T2.java and converted into.xml(testng.xml) and Run using Testng that file(testng.xml)

I want to execute all testcases at a time with one browser but i've got when i execute testcases it's calls BaseScript.java

1 Answers1

1

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>
fabfas
  • 2,200
  • 1
  • 21
  • 21