1

I have 5 to 6 methods in a class and want to run methods in parallel on different nodes. I have grid 2 setup with 4 nodes in it.

Find below my testng.xml

<suite name="Test" parallel="methods"  thread-count="2">

    <test name="Test1">
        <classes>
             <class name="test.LoginTest"/>
        </classes>
    </test>

</suite>

I have a test harness, which intilizes login, common and utils class

Public class TestHarness{
public WebDriver driver = null;
public DesiredCapabilities cap = null;

public Login login;
public Common common;
    public void initilize(){
        cap = DesiredCapabilities.firefox();
                cap.setBrowserName("firefox");
                cap.setPlatform(Platform.ANY);
        driver = new RemoteWebDriver(new URL(CONFIG.getProperty("hub")),cap);

        common = new Common(driver);
        login = new Login(driver);
        utils = new Utils(driver);

    }

}

In my test class I extend the test harness and in @BeforeMethod I call the intilize method

public class LoginTest extends TestHarness{

    @BeforeMethod
    public void startTest() {

        initilize();
        login.loginAsAdmin();
    }

    @Test
    public void testLoginWithCorrectPassword(){
        common.goToAdminSettings();
    }

    @Test
    public void testLoginwithInCorrectPassword(){
        utils.getMessage();
    }
}

If I run the testing, I see the following problem

Two browsers are opening one in each node but only one browser launches the application and the other doesn't.

Let me know if I am missing anything?

Thank You

1

2 Answers 2

1

1) are you sure you are running right test class?

<class name="test.LoginTest"/>

your tests are in:

public class Testing123 extends TestHarness{

2) Your code does not show declaration of driver. Make sure this field is not static

3) Also, check what the grid is actually configured to handle: http://localhost:4444/grid/admin/AllNodes

4) Raise the thread count in your testing config to 4.

Sign up to request clarification or add additional context in comments.

2 Comments

1,The actual test name is LoginTest. It was just a typo.
2, I have excluded the decaration for simplicity. Updated the question now.
1

even the driver is non static it is shared between test methods because they are invoked from the same class instance

let's put the test methods to separate classes

a) move @BeforeMethod to TestHarness class

b) create

public class LoginTest2 exteds TestHarness 

and move second @Test method there

c) modify suite:

<suite name="Test" parallel="classes"  thread-count="2">

<test name="Test1">
    <classes>
         <class name="test.LoginTest"/>
         <class name="test.LoginTest2"/>
    </classes>
</test>

If this will help the ultimate solution can be ThreadLocal as here:

parallel-webdriver-executions-using-testng

1 Comment

Thanks for your comment. Since there are lots of test methods, I can't create classes for each test method. Also I will try to use ThreadLocal and let you know.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.