Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Appium:第二次登录后无法在MainActivity上找到元素_Java_Android_Appium_Appium Android - Fatal编程技术网

Java Appium:第二次登录后无法在MainActivity上找到元素

Java Appium:第二次登录后无法在MainActivity上找到元素,java,android,appium,appium-android,Java,Android,Appium,Appium Android,我是阿皮姆的新手。我目前正在测试一个应用程序,当我第二次登录时,试图定位属于MainActivity的移动元素时,遇到了一些问题 我的应用程序(跟踪器)的工作原理如下: 目前,向用户提供pin码以供登录。当用户首次登录时,必须设置应用程序(在主活动页面上)以启用VPN和应用程序使用权限。设置好后,跟踪器将启动并运行,用户将看到一个新页面,可以在其中停止/启动跟踪器(它也属于MainActivity页面)。容易的。用户第二次登录或启动跟踪器时,无需进行任何设置,直接向用户显示停止/启动跟踪器页面(

我是阿皮姆的新手。我目前正在测试一个应用程序,当我第二次登录时,试图定位属于MainActivity的移动元素时,遇到了一些问题

我的应用程序(跟踪器)的工作原理如下:

目前,向用户提供pin码以供登录。当用户首次登录时,必须设置应用程序(在主活动页面上)以启用VPN和应用程序使用权限。设置好后,跟踪器将启动并运行,用户将看到一个新页面,可以在其中停止/启动跟踪器(它也属于MainActivity页面)。容易的。用户第二次登录或启动跟踪器时,无需进行任何设置,直接向用户显示停止/启动跟踪器页面(属于主活动页面)

情景1

如果用户从头开始使用应用程序,我正在进行的测试效果良好: *登录 *启用VPN *启用应用使用权限 *检查是否向用户提供启动/停止跟踪器阶段

@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();

}
场景2

然而,当我第二次登录时,它无法定位属于启动/停止跟踪器阶段的移动元素 *登录 *检查是否向用户提供启动/停止跟踪器阶段

@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();


}
stopTrackerbutton具有唯一的id,它只能位于第一个场景中。 有什么想法吗

错误日志 失败:基本测试

org.openqa.selenium.NoSuchElementException:无法通过找到元素 此策略:定位地图: -本机内容:“By.chained({By.id:toggleStopStart})” -html内容:“通过io.appium.java_client.pagefactory.AppiumElementLocator.FinDelelement(AppiumElementLocator.java:102)上的id或名称“stopTrackerButton” 在 InterceptorOfASingleElement.intercept(InterceptorOfASingleElement.java:61) 在 io.appium.java_client.android.AndroidElement$$enhancerbyglib$$b598166c.isDisplayed() 在Pages.MainActivity.verifyAppIsReady(MainActivity.java:72)中 Tests.TestLaura2.basicTitleTest(TestLaura2.java:69)位于 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机 方法)在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 位于java.base/java.lang.reflect.Method.invoke(Method.java:564) org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) 位于org.testng.internal.Invoker.invokeMethod(Invoker.java:580) org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)位于 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)位于 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 在 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 位于org.testng.TestRunner.privateRun(TestRunner.java:648) org.testng.TestRunner.run(TestRunner.java:505)位于 org.testng.SuiteRunner.runTest(SuiteRunner.java:455)位于 org.testng.SuiteRunner.runsequential(SuiteRunner.java:450)位于 org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)位于 org.testng.SuiteRunner.run(SuiteRunner.java:364)位于 org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)位于 org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)位于 org.testng.testng.runSuitesSequentially(testng.java:1208)位于 org.testng.testng.runSuitesLocal(testng.java:1137)位于 org.testng.testng.runSuites(testng.java:1049)位于 org.testng.testng.run(testng.java:1017)位于 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) 位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) 位于org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)的 发件人:org.openqa.selenium.TimeoutException:预期条件失败: 等待 io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction@4925f4f5 (以500毫秒的间隔尝试10秒) org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:303) 在 org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271) 在 io.appium.java_client.pagefactory.AppiumElementLocator.waitFor(AppiumElementLocator.java:76) 在 io.appium.java_client.pagefactory.AppiumElementLocator.findElement(AppiumElementLocator.java:95) ... 29更多原因:org.openqa.selenium.NoSuchElementException: 无法使用By.chained({By.id:toggleStopStart})查找元素 有关此错误的文档,请访问: 构建信息: 版本:“3.11.0”,修订版:“e59cfb3”,时间: “2018-03-11T20:26:55.152Z”系统信息:主机: “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.version:AndroidDriver位于 io.appium.java_client.pagefactory.bys.builder.ByChained.findElement(ByChained.java:72) 在 org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:311) 在 io.appium.java_client.DefaultGenericMobileDriver.findelelement(DefaultGenericMobileDriver.java:58) 在 io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) 在 io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1) 在 io.appium.java_client.pagefactory.bys.ContentMappedBy.findElement(ContentMappedBy.java:36) 在 org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:311) 在 io.appium.java_client.DefaultGenericMobileDriver.findelelement(DefaultGenericMobileDriver.java:58) 在 io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) 在 io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1) 在 io.appium.java_client.pagefactory.AppiumElementLocator.lambda$0(AppiumElementLocator.j
public void verifyAppIsReady ()  throws InterruptedException { 

    TimeUnit.SECONDS.sleep(2);
    assertTrue(stopTrackerButton.isDisplayed());

    }