Launching the whole test suite with Appium

884 Views Asked by At

Now I am trying to automate hybrid mobile app using Appium. For now I run test suites on android emulators, using GenyMotion or Android SDK emulators, but I have problems with both.

When I launch my tests one by one, one at a time - everything is OK. Sometimes everything is OK even while launching them 2 or 3 at one time.

But when I try to launch the whole test suite (the whole class with test methods) - problems with Appium sessions occur.

My base settings:

public class BaseAppTest {
    protected AppiumDriver driver;

    @BeforeMethod
    public void before() throws Exception
    {
        File appDir = new File("D:\\Build\\");
        File app = new File(appDir, "2015-06-10_13-09-03_amt-en_Development_234.apk");

        DesiredCapabilities capabilities = new DesiredCapabilities();       
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "192.168.56.101:5555");
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        capabilities.setCapability("autoWebviewTimeout", 5000);
        capabilities.setCapability("app", app.getAbsolutePath());

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);

        Set<String> contextNames = driver.getContextHandles();       
        driver.context(contextNames.toArray()[1].toString()); // set context to WEBVIEW_1
        WebDriverRunner.setWebDriver(driver);


    }

    @AfterMethod
    public void afterMethod()
    {
       driver.quit();
    }
}

Inside tests I use Selenide, also use navigation from URL to URL and LocaleStorage injections:

public class WGCTest extends BaseAppTest {

    @BeforeMethod
    public void before() throws Exception {
        super.before();
        Thread.sleep(2000);
        //driver.navigate().to(BaseSelectors.URL);
        LocalStorageInjector.clearStorage(getWebDriver());
        open(BaseSelectors.URL);
    }

}

And testSuite:

@BeforeMethod
public void before() throws Exception {
        super.before();
        Injections.injectionWeek0(getWebDriver());
        open(WGCSelectors.URL);
        //driver.navigate().to(WGCSelectors.URL);
        //WebDriverRunner.setWebDriver(driver);
    }


    @Test
    @Features(MyFeatures.WGC)
    @Stories("Clicking links")
    public static void clickingHowItWorksLink()
    {
        WGCTestMethods2.clickHowItWorksLink(weight85, weight300, feet5, inches0);
    }

    @Test
    @Features(MyFeatures.WGC)
    @Stories("Checking default structure")
    public static void checkDefaultStructure()
    {
        WGCTestMethods2.defaultStructureChecking();
    }

    @Test
    @Features(MyFeatures.WGC)
    @Stories("Filling fields and checking saving")
    public static void settingPreWeightFieldAndCheckChangesGotSaved() {
        WGCTestMethods2.settingPreWeightField(weight85);
    }

I think something is wrong is settings or annotations, cause each tests is OK separately... But what is wrong?

Please help find my mistakes! Thank you!

Exception:

     org.openqa.selenium.remote.SessionNotFoundException: 
Command duration or timeout: 3 milliseconds
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'KOZLOVA7', ip: '192.168.2.87', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=D:\Build\2015-06-10_13-09-03_amt-en_Development_234.apk, networkConnectionEnabled=true, autoWebviewTimeout=5000, warnings={}, databaseEnabled=false, deviceName=emulator-5554, platform=LINUX, desired={app=D:\Build\2015-06-10_13-09-03_amt-en_Development_234.apk, autoWebviewTimeout=5000, platformVersion=4.4, automationName=Appium, platformName=Android, deviceName=emulator-5554}, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, browserName=Android, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: 69af8a8f-83af-4c46-a7d1-56d6d4d31cf9
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:162)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:508)
    at utils.LocalStorageInjector.LocalStorageInjector.clearStorage(LocalStorageInjector.java:21)
    at AppTests.BaseTests.WGCTest.before(WGCTest.java:17)
    at AppTests.WGCTestSuite02.before(WGCTestSuite02.java:36)
1

There are 1 best solutions below

3
On BEST ANSWER

You are getting this error because already a session exists for the same parameters. Please change your annotation from @BeforeMethod to @BeforeTest and the same for @AfterTest. In this way the before and after steps will be provided once time before/after the whole test suite.