1

My test needs to open and close the notifications panel and go back to the app from an Android device (Moto G4 Android 7 - AWS device farm). So I'm calling the following method in my test

androidActivity.openAndCloseNotifications();

where

public void openAndCloseNotifications() throws InterruptedException{ 
    TimeUnit.SECONDS.sleep(3);
    driver.openNotifications();
    TimeUnit.SECONDS.sleep(3);
    driver.pressKeyCode(AndroidKeyCode.BACK);          
} 

The test passes locally with the device but when I run it on AWS device farm I can see that the notifications panel is never open therefore the test fails. At this point does AWS device farm allow to interact with notifications panel? if not, how could I deal with it? Because this would be a problem for most of our tests. Thanks in advance!

This is the test that it's failing, failing at line androidActivity.openAndCloseNotifications(); :

    public boolean run() throws Exception {
    MainActivity mainActivity = new MainActivity(driver);
    AndroidActivity androidActivity = new AndroidActivity(driver);
    LoginActivity loginActivity = new LoginActivity(driver);



    try {
    if(device.getCapability("manufacturer")=="Huawei")
    { 
        driver.closeApp();
        driver.launchApp();
        loginActivity.registerApp("whateverhere");
        androidActivity.openAndCloseNotifications();
        mainActivity.verifyAppIsReady();
        assertTrue(mainActivity.check());
        return true;

    }

    else {

        driver.closeApp();
        driver.launchApp();
        loginActivity.registerApp("whateverhere");
        androidActivity.openAndCloseNotifications();
        mainActivity.verifyAppIsReady();
        System.out.println("Verified Stop button is displayed");
        assertTrue(mainActivity.check());
        System.out.println("Verified title is displayed");
        return true;
        }
    }

    catch(Exception e) {
        System.out.println(e);
        return false;
    }

}

Logs From AWS Device farm (there are no failures locally) java.lang.AssertionError: expected [true] but found [false]\n\tat org.testng.Assert.fail(Assert.java:94)\n\tat org.testng.Assert.failNotEquals(Assert.java:494)\n\tat org.testng.Assert.assertTrue(Assert.java:42)\n\tat org.testng.Assert.assertTrue(Assert.java:52)\n\tat com.OneMeter.Robirdo.TestSequence1.test1(TestSequence1.java:48)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)\n\tat org.testng.internal.Invoker.invokeMethod(Invoker.java:714)\n\tat org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)\n\tat org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)\n\tat org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)\n\tat org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)\n\tat org.testng.TestRunner.privateRun(TestRunner.java:767)\n\tat org.testng.TestRunner.run(TestRunner.java:617)\n\tat org.testng.SuiteRunner.runTest(SuiteRunner.java:348)\n\tat org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)\n\tat org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)\n\tat org.testng.SuiteRunner.run(SuiteRunner.java:254)\n\tat org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)\n\tat org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)\n\tat org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)\n\tat org.testng.TestNG.runSuitesLocally(TestNG.java:1149)\n\tat org.testng.TestNG.run(TestNG.java:1057)\n\tat org.testng.TestNG.privateMain(TestNG.java:1364)\n\tat org.testng.TestNG.main(TestNG.java:1333)\n\n

  • The log points to the assertTrue() failing, not your previous method call. Which is likely due to openAndCloseNotifications() not throwing an exception or it is being swallowed in your try/catch. The assert fails, because openAndCloseNotifications() didn't leave the app in the expected state. – kirbycope May 7 '18 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.