0

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;
}
}
Moni
  • 1
  • 3
  • 1
    Please provide enough code so others can better understand or reproduce the problem. – Community May 29 '23 at 06:30
  • if your tests run sequentially then having no thread-local should not be an issue. If you run tests in parallel, then webdriver might not be the only thing that is shared across threads so wrapping it with `ThreadLocal` won't be probably enough.. So we need your representative test code and `testng.xml` – Alexey R. May 29 '23 at 10:43
  • @AlexeyR. Thank you for your response. Yes, I am running test scripts sequentially and Thread Local is not creating any problem. My test scripts run fine individually but fails when run in suit using testNg.xml file – Moni May 31 '23 at 11:58
  • @AlexeyR. Please check and provide some help as I have provided the related code – Moni May 31 '23 at 12:21

0 Answers0