Hi, I’m new with Appium. I’m currently testing an app and I’m facing issues when trying to locate a mobile element that belongs to MainActivity second time I log in.
How the app works (tracker):
As it stands, a pin code is provided to the user for logging in. When user logs in for first time has to set up the app (on Main activity page) enabling a VPN and app usage permissions. Once this is set up the tracker is up and running and user is presented with a new page where can stop/start the tracker ( it belongs to MainActivity page too). Easy. Second time that user logs in or starts the tracker no set up is required and user is directly presented with stop/start tracker page (belonging to main activity page)
SCENARIO 1
The test I’m doing works fine if user starts from scratch the app:
-
Log in
-
Enable VPN
-
Enable app usage permissions
-
Check user is presented with start/Stop tracker stage
@Test(enabled = true, priority=1)
public void basicTitleTest() throws java.lang.InterruptedException, MalformedURLException {
LoginActivity loginActivity = new LoginActivity(driver);
MainActivity mainActivity = new MainActivity(driver);
AndroidActivity androidActivity = new AndroidActivity(driver);
loginActivity.registerApp("********");
TimeUnit.SECONDS.sleep(5);
String current = driver.currentActivity();
System.out.println(current);
mainActivity.enableVPN();
mainActivity.clickOnOpenSettings();
androidActivity.enableSettings();
androidActivity.navigateBackToWakoopaApp();
mainActivity.verifyAppIsReady();
}
SCENARIO 2
Whereas when I log for second time, it can’t locate the mobile elements belonging to start/Stop tracker stage
-
Log in
-
Check user is presented with start/Stop tracker stage
@Test(enabled = true, priority=1)
public void basicTitleTest() throws java.lang.InterruptedException, MalformedURLException {
LoginActivity loginActivity = new LoginActivity(driver);
MainActivity mainActivity = new MainActivity(driver);
String context = driver.getContext();
System.out.println(context);
loginActivity.registerApp("********");
TimeUnit.SECONDS.sleep(5);
Set<String> contextNames = driver.getContextHandles();
int size = contextNames.size();
System.out.println(size);
mainActivity.verifyAppIsReady();
}
Where:
public void verifyAppIsReady () throws InterruptedException {
TimeUnit.SECONDS.sleep(2);
assertTrue(stopTrackerButton.isDisplayed());
}
stopTrackerbutton has an unique id, it can only be located in the first scenario.
Any ideas?
Error log
FAILED: basicTitleTest
org.openqa.selenium.NoSuchElementException: Can’t locate an element by this strategy: Locator map:
- native content: “By.chained({By. id: toggleStopStart})”
- html content: "by id or name “stopTrackerButton”"
at io.appium.java_client.pagefactory.AppiumElementLocator.findElement(AppiumElementLocator.java:102)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.intercept(InterceptorOfASingleElement.java:61)
at io.appium.java_client.android.AndroidElement$$EnhancerByCGLIB$$b598166c.isDisplayed()
at Pages.MainActivity.verifyAppIsReady(MainActivity.java:72)
at Tests.TestLaura2.basicTitleTest(TestLaura2.java:69)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction@4925f4f5 (tried for 10 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:303)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
at io.appium.java_client.pagefactory.AppiumElementLocator.waitFor(AppiumElementLocator.java:76)
at io.appium.java_client.pagefactory.AppiumElementLocator.findElement(AppiumElementLocator.java:95)
… 29 more
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.chained({By.id: toggleStopStart})
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘3.11.0’, revision: ‘e59cfb3’, time: '2018-03-11T20:26:55.152Z’
System info: host: ‘bcnl-jmeunier.ad.netquest.com’, ip: ‘fe80:0:0:0:1cd6:7fc:4338:52b7%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.13.3’, java.version: '10’
Driver info: driver.version: AndroidDriver
at io.appium.java_client.pagefactory.bys.builder.ByChained.findElement(ByChained.java:72)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:311)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at io.appium.java_client.pagefactory.bys.ContentMappedBy.findElement(ContentMappedBy.java:36)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:311)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at io.appium.java_client.pagefactory.AppiumElementLocator.lambda$0(AppiumElementLocator.java:96)
at io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction.apply(AppiumElementLocator.java:150)
at io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction.apply(AppiumElementLocator.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
… 31 more
**Apium Inspector **