Selenium Grid parallel execution only run few test cases on the docker chrome nodes

577 Views Asked by At

Right now i have 80 test method (@Test) using data provider I am running my test case and its almost 400 test cases. When I run it in selenium grid parallel then it only run few test case. Some times 40 some time 50 randomly its running Here is my Base class

public class BaseTest {
private static final String OS = System.getProperty("os.name").toLowerCase();
public static boolean IS_WINDOWS = (OS.indexOf("win") >= 0);
public WebDriver driver;
String report = null;

public WebDriver getDriver() {
    return driver;
}
@BeforeClass(alwaysRun = true)
public void classLevelSetup() throws InterruptedException {
   //Did nothing
}

@BeforeMethod(alwaysRun = true)
public void methodLevelSetup() throws ParseException, MalformedURLException {
       Log.info("Tests are starting!");
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--disable-gpu");
        chromeOptions.addArguments("--disable-extensions");
        chromeOptions.addArguments("disable-infobars");
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.addArguments("ignore-certificate-errors");
        chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        chromeOptions.addArguments("--start-maximized");
        driver=new RemoteWebDriver(new 
        URL("http://localhost:4444/wd/hub"),chromeOptions);
    

    // Added Browser

}

@AfterMethod(alwaysRun = true)
public void AfterMethod(ITestResult result, ITestContext ctx)
{
        getTest().fail(result.getThrowable());

    

    driver.quit();
}

@AfterClass(alwaysRun = true)
public void teardown() {
    //Did nothing
}

Here is my test class

public class DashboardTest extends BaseTest {
    @DataProvider(name = "CreateProperty")
    public Object[][] getData() {
        Object[][] data = SiteConfig.CreateProperty;
        return data;
    }

@Test(priority = 0, alwaysRun = true, dataProvider = "CreateProperty", description = "Add new property from Management > Properties")
public void Add_new_Property_from_management_Properties(String url, String username, String password, Method method, ITestContext ctx) throws Exception {
    SignupPage sp = new SignupPage(driver);
       sp.Open_login_Page(url);
     
}

}

Here is my testng.xml file

<?xml version="1.0" encoding="UTF-8"?>
<test name="CultBooking">
    <classes>
        <class name="tests.RoomTypeTest"></class>
        <class name="tests.RoomTypeTest_1"></class>
        <class name="tests.RoomTypeTest_2"></class>
        <class name="tests.RoomTypeTest_3"></class>
        <class name="tests.RoomValidatyApiResponseTest"></class>
        <class name="tests.MealPlanTest"></class>
        <class name="tests.MealPlanTest_1"></class>
        <class name="tests.MasterdataTest"></class>
        <class name="tests.DescriptionsTest"></class>
        <class name="tests.SignupTest"></class>
        <class name="tests.Reservation_processTest"></class>
        <class name="tests.SignInTest"></class>
        <class name="tests.DashboardTest"></class>
        <class name="tests.ForgotPasswordTest"></class>

    </classes>
</test>
**I am running everything in jenkins and here is the error I getting sometimes**
Command: [54f8c566912260f004c50d969fb3fbb8, screenshot {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome,
browserVersion: 96.0.4664.45, chrome: {chromedriverVersion:
96.0.4664.45 (76e4c1bb2ab46..., userDataDir: /tmp/.com.google.Chrome.DIPhAl}, goog:chromeOptions: {debuggerAddress:
 localhost:36179}, javascriptEnabled: true, networkConnectionEnabled:
 false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX,
 proxy: Proxy(), se:cdp: ws://172.19.0.4:4444/sessio..., se:cdpVersion:
 96.0.4664.45, se:vnc: ws://172.19.0.4:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.19.0.4:7900, setWindowRect: true,
 strictFileInteractability: false, timeouts: {implicit: 0, pageLoad:
 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify,
 webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true,
 webauthn:virtualAuthenticators: true} Session ID:
 54f8c566912260f004c50d969fb3fbb8   at
 jdk.internal.reflect.GeneratedConstructorAccessor27.newInstance(Unknown
 Source)    at
 java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at
 java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at
 org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
    at
 org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
    at
 org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
    at
 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
    at
 org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:50)
    at
 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559)
    at
 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:614)
    at
 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
    at
 org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:349)
    at
 utils.listeners.TestListener.saveScreenshotPNG(TestListener.java:39)
    at utils.listeners.TestListener.onTestFailure(TestListener.java:78)
    at
 org.testng.internal.TestListenerHelper.runTestListeners(TestListenerHelper.java:96)
    at
 org.testng.internal.TestInvoker.runTestResultListener(TestInvoker.java:219)
    at
 org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:834)
    at
 org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at
 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at
 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at
 java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at
 java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

Can anyone help me to solve this problem?

1

There are 1 best solutions below

0
On

If the total test-cases count does not match the expected, it could be because of an exception in some testNG-lifecycle code.

First of all, I'm talking about listeners.

I see utils.listeners.TestListener in stacktrace.

saveScreenshotPNG produces some exception.

Make sure, all of its methods will not throw any exception. Surround all the code in try-catch, since TestNG is not able to handle exceptions in listeners accurately.

Another question, why sometimes the exception happens in saveScreenshotPNG. But anyway, try to make fail-safe utils.listeners.TestListener first.