Я определял локаторы для обеих платформ, используя 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, пожалуйста?
Заранее спасибо
Vamc