Not able to run selenium tests with testng while test are successfull if i run tests one by one

403 views Asked by At

I have written some selenium code to test a web application using Testng + webdriver. I have a hub and one node where I rune firefox+chrome and an android tablet where I run android tests.

I can run android tests one by one but when I run as a part of testng suite I am facing the following problem :

the android browser is not closing after each test even though I am calling driver.quit() in @aftertest annotation.

Here in one of my tests :

public class LanguageCheckEN {

WebDriver driverEN, driverFR;
String BaseURL, winURL, TestURL, andURL;

@BeforeTest
@Parameters({ "browser" })
public void setup(String browser) throws IOException

{
    File file = new File("config.properties");
    FileInputStream fileInput = new FileInputStream(file);
    Properties properties = new Properties();
    properties.load(fileInput);
    fileInput.close();

    TestURL = properties.getProperty("AppURL");
    BaseURL = properties.getProperty("HubURL");
    winURL = properties.getProperty("WinURL");
    andURL = properties.getProperty("AndURL");

    DesiredCapabilities capability = null;

    if (browser.equalsIgnoreCase("firefox")) {
        System.out.println("firefox");
        capability = DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setPlatform(Platform.WINDOWS);
        // capability.setVersion("");
        driverEN = new RemoteWebDriver(new URL(winURL), capability);
    }

    if (browser.equalsIgnoreCase("chrome")) {
        System.out.println("chrome");
        capability = DesiredCapabilities.chrome();
        capability.setBrowserName("chrome");
        capability.setPlatform(Platform.WINDOWS);
        driverEN = new RemoteWebDriver(new URL(winURL), capability);

        // capability.setVersion("");

    }

    if (browser.equalsIgnoreCase("android")) {
        System.out.println("android");
        capability = DesiredCapabilities.android();
        capability.setBrowserName("android");
        capability.setPlatform(Platform.ANDROID);
        driverEN = new RemoteWebDriver(new URL(andURL), capability);

        // capability.setVersion("");

    }

}

@Test
private void checkLanguageEN() {

    driverEN.get(TestURL);
    WebElement input1 = driverEN
            .findElement(By.id("login_form_user_input"));
    input1.sendKeys("guest");
    WebElement input2 = driverEN.findElement(By
            .id("login_form_password_input"));
    input2.sendKeys("guest");
    WebElement btn = driverEN
            .findElement(By.id("login_form_signin_button"));
    btn.click();
    WebElement img = driverEN.findElement(By.id("header_language_button"));
    String lng = img.getText();
    if (lng.equals("en"))

    {

        WebDriverWait wait = new WebDriverWait(driverEN, 20);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By
                .linkText("Calendar Search")));

    }

    else

    {
        img.click();
        WebDriverWait wait = new WebDriverWait(driverEN, 20);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By
                .linkText("Calendar Search")));
    }

}

@AfterTest
private void quitTest() {
    driverEN.close();
}

public void aftertest()

{
    quitTest();
}

}

Here is also my testng.xml file :

<?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
       <suite name="Dollar Universe Explorer E2E Testing" thread-count="3" parallel="tests" >
      <test name="Language English Chrome">
    <parameter name="browser" value="chrome"  />
    <classes>
        <class name="basicWebElements.LanguageCheckEN" />
    </classes>
     </test>
     <test name="Language English firefox">
    <parameter name="browser" value="firefox"  />
    <classes>
        <class name="basicWebElements.LanguageCheckEN" />
    </classes>
    </test>
    <test name="Language English android">
    <parameter name="browser" value="android"  />
    <classes>
        <class name="basicWebElements.LanguageCheckEN" />
    </classes>
   </test>
</suite>

Because of this issue when I run the whole suite i get this error :

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

Thanks for your help.

1

There are 1 answers

0
Ziwdigforbugs On BEST ANSWER

Here the answer :

Android now whinges when you destroy an activity that has view that you

havent disconnected from it

WebView webview = (WebView) findViewById(R.id.webview);
    if (webview != null) 
      {
        webview.removeAllViews();
        webview.destroy();
      }
WebView rssWebView = (WebView) findViewById(R.id.rssWebView);
   if (rssWebView != null)
      {
        rssWebView.removeAllViews();
        rssWebView.destroy();
       }

is needed in onDestroy to make it stop complaining