0

I am new to parallel testing with Java and TestNG.

Here is what the syxtax of my testng.xml file looks...

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestNG" parallel="methods" thread-count="2">
    <listeners>
        <listener class-name="framework.adapters.AutomationTestListener"/>
        <listener class-name="framework.adapters.AppiumListener"></listener>
    </listeners>
    <test name="Test Suite">
        <packages>
            <package name="org.abc.tests"/>
        </packages>
    </test>
</suite>

And these are two @Tests I am trying to run, but when they run, the steps of one of the tests invades the other. So, basically, they will pass when run individually, but when I attempt to run them in parallel, they steps from each test will crisscross into the other.

Here are the two tests...

@Test(groups = {"Regression", "TC_111"}, description = "TC_111")
    public void padTestSubmission() {
        SubmissionTestData testData = new SubmissionTestData();
        SummaryScreen summaryScreen = onStartScreen()
                .clickLoginButton()
                .loginWithUser(UserCache.MAIN_USER)
                .clickSkipOnAndroid()
                .clickOnBottomIcon(BottomMenu.NEW_TEST, MaterialTypeScreen.class)
                .clickOnMaterialType("Pad")
                .fillTestInfoAndSubmit(testData)
                .fillClaimInfoAndSubmit(testData, UserCache.MAIN_USER)
                .addPhotoAndVerifyMetaData("Top of Sample")
                .submitWithPeriod(SAME_DAY_PERIOD);
        verifySubmissionSuccessful(summaryScreen, testData.getClaimNumber(), testData.getDamageLocation());
    }

    @Test(groups = {"Regression", "TC_222"}, description = "TC_222")
    public void carpetTestSubmission() {
        SubmissionTestData testData = new SubmissionTestData();
        SummaryScreen summaryScreen = onStartScreen()
                .clickLoginButton()
                .loginWithUser(UserCache.MAIN_USER)
                .addPhotoAndVerifyMetaData("Side 1 of Carpet")
                .addLastPhotoAndGoToReviewScreenAndVerifyMetaData("Side 2 of Carpet")
                .verifyMetaData("Side 3")
                .submitWithPeriod(SAME_DAY_PERIOD);
        verifySubmissionSuccessful(summaryScreen, testData.getClaimNumber(), testData.getDamageLocation());
    }

1 Answers1

0

This only happens when the webdriver is being shared between the two threads. Put each driver in a threadlocal object and it would work out.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
  • Thank you for responding @niharika_neo. However, I am using TestNG and Browserstack and I don't think the ThreadLocal object will work with this. Do you have any thoughts on this? – spartan117 Jun 15 '21 at 18:37