I have create more than 200 test-scripts in selenium using TestNg. These scripts run fine if executed individually, but if I try to run those multiple test-scripts in Suite using testNg.xml file in sequential manner, some of the test cases fails that were running fine individually.

The reason of failure was element not clickable or not visible or sometimes stale element issue. I used fluent and explicit waits to synchronize the scripts execution. To avoid the issue of web driver being shared between the two threads, I used thread-Local object also. but my problem is still not resolved. How can I make my test script execution result consistent.

Please suggest any solution.

Following is testNg.xml

<!DOCTYPE suite>
<suite name="Suite">
<listeners>
<listener class-name="xyz.report.ExtentListeners" />
</listeners>
<test name="Test">
<classes>
<class name="xyz.TestCases.Module1.Testscenario1"/>
<class name="xyz.TestCases.Module1.Testscenario2"/>
<class name="xyz.TestCases.Module1.Testscenario3"/>
<class name="xyz.TestCases.Module1.Testscenario4"/>
<class name="xyz.TestCases.Module1.Testscenario5"/>
<class name="xyz.TestCases.Module1.Testscenario6"/>
<class name="xyz.TestCases.Module1.Testscenario7"/>
<class name="xyz.TestCases.Module1.Testscenario8"/>
<class name="xyz.TestCases.Module2.Testscenario1"/>
<class name="xyz.TestCases.Module2.Testscenario2"/>
<class name="xyz.TestCases.Module2.Testscenario3"/>
<class name="xyz.TestCases.Module2.Testscenario4"/>
<class name="xyz.TestCases.Module2.Testscenario5"/>
<class name="xyz.TestCases.Module2.Testscenario6"/>
<class name="xyz.TestCases.Module2.Testscenario7"/>
<class name="xyz.TestCases.Module2.Testscenario8"/>  
</classes>
</test> 
</suite>

The fluent wait code used in test scripts is following:

public static WebElement waitForElementToAppear(WebElement element) 
throws Exception {
try {
new FluentWait<WebDriver> 
(DriverManager.getdriver()).withTimeout(Duration.ofSeconds(60))
.pollingEvery(Duration.ofMillis(500)).ignoring(Exception.class)                  
.until(ExpectedConditions.elementToBeClickable(element));
return element;
} catch (Exception e) {throw e;
}
}
0

There are 0 best solutions below