0

I am trying to run 2 different tests on 2 different emulators parallelly. But my execution halts on 1 device as soon as the test on other device is complete. I am using the below driver setup code

capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("VERSION", platformVersion);
capabilities.setCapability("udid", deviceName);
capabilities.setCapability("app", "app.apk");
capabilities.setCapability("appPackage", "xxx");
capabilities.setCapability("appActivitiy", "xxx.HomeActivity");
capabilities.setCapability("systemPort", systemPort);
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

And below is my testNG.xml file

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Parallel Tests" parallel="tests" thread-count="2">
    <test name="Android native app test on Android 12">
        <parameter name="platformVersion" value="12"/>
        <parameter name="deviceName" value="emulator-5554"/>
        <parameter name="systemPort" value="6666"/>
        <classes>
            <class name="LoginTest" />
        </classes>
    </test>
    <test name="Android native app test on Android 10">
        <parameter name="platformVersion" value="10"/>
        <parameter name="deviceName" value="emulator-5556"/>
        <parameter name="systemPort" value="8666"/>
        <classes>
            <class name="SignUpTest" />
        </classes>
    </test>
</suite>

I get the following exception

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?

And sometimes this exception as well

org.openqa.selenium.NoSuchSessionException: A session is either terminated or not started

1 Answer 1

0

@Sanjay,

What is the problem & why its happening?

  • Your test on 1 device gets halted because, I can see how you have initialise your driver static using port 4723
    driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

Solution :

  • When you want to execute tests in parallel you should :
    • Create no. of driver instances equal to the same no. of devices to perform tests
    • You should have different port for each driver instance
    • Example :
      1. If I want to run tests on 2 devices
      2. Driver should be initialise separately with separate port number
  // Driver 1: 
  driver1 = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

  //Driver 2
  driver2 = new AndroidDriver(new URL("http://0.0.0.0:4733/wd/hub"), capabilities);

Note - To run tests in parallel, you do not need to run two separate instances of appium server. Parallel support has been implemented after version 1.5 onwards

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.