How can I execute multiple test class 'test1' and 'test2' parallely? Which is using the same function in another class using TestNG.

When I define the parallel option as 'classes' and thread-count as '2' in TestNG XML, the login page is loading two times, but 'sendelement' method is executing in single browser two times simultaneously.

for eg; if my login is 'user1', sendelement function execute two times as 'user1user1' in the username field and shows invalid login.

<?xml version="1.0" encoding="UTF-8"?>
<!--  <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> -->
<suite name="Suite" parallel="classes" thread-count="2">

    <test name="NavigationTest">
            <class name="Test1" />
            <class name="Test2" />

public class Test1 {

    loginToUserPage(strUserName, strPassword);

public class Test2{

    loginToUserPage(strUserName, strPassword);

public class Test3
    public void loginToUserPage(String strUserName,String strPassword) 
        webdriverCommon.sendElement(CommonRepo.userName_Edit, strUserName);
        webdriverCommon.sendElement(CommonRepo.password_Edit, strPassword);

  • Where do your username and password come from? I don't see that data anywhere.
    – FDM
    Commented May 26, 2017 at 9:03
  • strUserName,strPassword are username, password variables.. CommonRepo.userName_Edit and CommonRepo.userName_Edit are the By elements for input fields in UI Commented May 26, 2017 at 12:21
  • Can you show the actual test class where you pass the data?
    – FDM
    Commented May 26, 2017 at 12:34

1 Answer 1


It looks like you are using one webDriver, webdriverCommon. You'll need to setup your framework such that each class or test uses its own driver. I have a TestBase class that each test class inherits from. The following example is using JUnit but the idea is the same.

public class TestBase {

    protected WebDriver driver;
    protected String baseUrl = "http://example.com/";
    protected String hubUrl = "http://localhost:4444/wd/hub";

    public void setUp() throws Exception{
        try {
            DesiredCapabilities capability = DesiredCapabilities.chrome();
            driver = new RemoteWebDriver(new URL(hubUrl), capability);
        catch (Exception e){
            System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
            driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    public void tearDown() throws Exception{

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.