宁静:WebElementFacade未检测到移动应用上的定位器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了宁静:WebElementFacade未检测到移动应用上的定位器相关的知识,希望对你有一定的参考价值。

我使用WebElementFacade定义了两个平台的定位器,并将定义的WebElementFacade调用到方法中。

在运行脚本时,使用WebElementFacade定义的定位器不会在移动应用程序上检测到两个平台。以下是使用的代码示例:

使用WebElementFacade定义定位器

@androidBy(id = "buttonRed")
@iosFindBy(id = "LogInButton")
private WebElementFacade signInBtn;

使用WebElementFacade的方法

Assert.assertEquals(signInBtn.getText(), "SIGN IN");
System.out.println(signInBtn.getText());

所以目前为了使代码工作,我在方法中直接使用定位器。下面是代码示例:

没有WebElementFacade的方法

if (isPlatformIos()) {
        Assert.assertEquals(find(By.id("LogInButton")).getText(), "SIGN IN");
        System.out.println(find(By.id("LogInButton")).getText());
    } else {
        Assert.assertEquals(find(By.id("buttonRed")).getText(), "SIGN IN");
        System.out.println(find(By.id("buttonRed")).getText());
    }

build.gradle文件:

buildscript {
    repositories {
        maven {
            url 'https://repo.maven.apache.org/maven2'
        }
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'net.serenity-bdd:serenity-gradle-plugin:1.9.26'
    }

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'

dependencies {
    testCompile(
            'net.serenity-bdd:serenity-junit:1.9.27',
            'net.serenity-bdd:serenity-cucumber:1.9.12',
            'org.assertj:assertj-core:3.10.0'
}

在运行脚本时,我没有看到任何特定的错误消息,只有日志中的TimeoutException

错误日志:

TEST FAILED WITH ERROR: Verify user is taken to Home screen
---------------------------------------------------------------------
11:08:05.393 [Test worker] DEBUG net.thucydides.core.steps.ConsoleLoggingListener - RELATED ISSUES: 
11:08:05.532 [Test worker] ERROR net.thucydides.core.steps.ConsoleLoggingListener - TEST FAILED AT STEP Verify first onboarding screen
11:08:05.533 [Test worker] ERROR net.thucydides.core.steps.ConsoleLoggingListener - Expected condition failed: waiting for LoginScreen.welcomeScreenTitle to be displayed (tried for 5 second(s) with 100 milliseconds interval)Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'System info: host: 'Lappy78', ip: '102.18.120.471', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'Driver info: driver.version: unknownBuild info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'System info: host: 'Lappy78', ip: '102.18.120.471', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'Driver info: driver.version: unknown
com.company.qa.RunTests > Login.Verify user is taken to Home screen FAILED
    org.openqa.selenium.NoSuchElementException
        Caused by: org.openqa.selenium.TimeoutException

Expected condition failed: waiting for LoginScreen.welcomeScreenTitle to be displayed (tried for 5 second(s) with 100 milliseconds interval)
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'Lappy78', ip: '102.18.120.471', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: unknown
org.openqa.selenium.NoSuchElementException: Expected condition failed: waiting for LoginScreen.welcomeScreenTitle to be displayed (tried for 5 second(s) with 100 milliseconds interval)
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'Lappy78', ip: '102.18.120.471', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: unknown
    at net.serenitybdd.core.pages.WebElementFacadeImpl.throwNoSuchElementExceptionWithCauseIfPresent(WebElementFacadeImpl.java:888)
    at net.serenitybdd.core.pages.WebElementFacadeImpl.checkPresenceOfWebElement(WebElementFacadeImpl.java:861)
    at net.serenitybdd.core.pages.WebElementFacadeImpl.getText(WebElementFacadeImpl.java:952)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.thucydides.core.annotations.locators.AbstractSingleItemHandler.invoke(AbstractSingleItemHandler.java:45)
    at com.sun.proxy.$Proxy28.getText(Unknown Source)
    at com.company.qa.screens.LoginScreen.welcomeScreenTitle(LoginScreen.java:27)
    at com.company.qa.steplib.LoginUser.verify_first_onboarding_screen(LoginUser.java:17)
    at com.company.qa.steplib.LoginUser$$EnhancerByCGLIB$$722358e7.CGLIB$verify_first_onboarding_screen$0(<generated>)
    at com.company.qa.steplib.LoginUser$$EnhancerByCGLIB$$722358e7$$FastClassByCGLIB$$8b3b74e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:449)
    at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:434)
    at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:409)
    at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:150)
    at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:137)
    at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:68)
    at com.company.qa.steplib.LoginUser$$EnhancerByCGLIB$$722358e7.verify_first_onboarding_screen(<generated>)
    at com.company.qa.steps.LoginSteps.verify_onboarding_screen(LoginSteps.java:23)
    at ✽.I am on first onboarding screen(src/test/resources/features/login.feature:7)
Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for LoginScreen.welcomeScreenTitle to be displayed (tried for 5 second(s) with 100 milliseconds interval)
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'Lappy78', ip: '102.18.120.471', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:303)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
    at net.serenitybdd.core.pages.WebElementFacadeImpl.checkPresenceOfWebElement(WebElementFacadeImpl.java:855)
    at net.serenitybdd.core.pages.WebElementFacadeImpl.getText(WebElementFacadeImpl.java:952)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.thucydides.core.annotations.locators.AbstractSingleItemHandler.invoke(AbstractSingleItemHandler.java:45)
    at com.sun.proxy.$Proxy28.getText(Unknown Source)
    at com.company.qa.screens.LoginScreen.welcomeScreenTitle(LoginScreen.java:27)
    at com.company.qa.steplib.LoginUser.verify_first_onboarding_screen(LoginUser.java:17)
    at com.company.qa.steplib.LoginUser$$EnhancerByCGLIB$$722358e7.CGLIB$verify_first_onboarding_screen$0(<generated>)
    at com.company.qa.steplib.LoginUser$$EnhancerByCGLIB$$722358e7$$FastClassByCGLIB$$8b3b74e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:449)
    at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:434)
    at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:409)
    at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:150)
    at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:137)
    at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:68)
    at com.company.qa.steplib.LoginUser$$EnhancerByCGLIB$$722358e7.verify_first_onboarding_screen(<generated>)
    at com.company.qa.steps.LoginSteps.verify_onboarding_screen(LoginSteps.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:31)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:25)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
    at cucumber.api.TestStep.executeStep(TestStep.java:102)
    at cucumber.api.TestStep.run(TestStep.java:83)
    at cucumber.api.TestCase.run(TestCase.java:58)
    at cucumber.runner.Runner.runPickle(Runner.java:80)
    at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:118)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:56)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:127)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:106)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:748)

由于在方法中直接使用定位器,因此我觉得增加了代码行,并且使用WebElementFacade减少两个平台的编码行是最佳实践。

有人可以帮我找出导致问题的原因是没有使用WebElementFacade检测定位器吗?

提前致谢

种子

答案

它现在正在工作,如下面的代码是使用的示例。

@FindAll({
         @FindBy(id = "buttonRed")      //Android Identifier
         @FindBy(id = "LogInButton")   //IOS Identifier
)}
private WebElementFacade signInBtn;

由于@AndroidFindBy@iOSFindBy不能与WebElementFacade一起工作所以我们需要使用@FindBy用于具有不同id的两个平台,如上例所示。问候

种子

以上是关于宁静:WebElementFacade未检测到移动应用上的定位器的主要内容,如果未能解决你的问题,请参考以下文章

HTML unicode ☰ 在 android chrome 浏览器的移动 Web 应用程序菜单中未检测到

代号一 - “未检测到连接”时的 ToastBar

为啥 docker build 中的 COPY 未检测到更新

keyListener未检测到按键

在动画移动对象(UIView)上未检测到点击手势

未检测到 SDL2 iOS 多点触控第二个手指向下