Below identifier was working with version 1.7.0 but broken in 1.8.3
@iOSFindBy(xpath="//XCUIElementTypeButton[@name='button-lets-begin']")
private WebElement LetsBeginButton;
exception
Can't locate an element by this strategy: Locator map:
- native content: "By.id: LetsBeginButton"
- html content: "by id or name "LetsBeginButton""
You will have to dig into this to isolate the change and propose a PR, I think. I’m not aware of anything that would have have changed in that area
Sure; I'll try to debug this issue and update back
@wakaleo I tried debugging this issue and stumbled upon another one for which I need your expertise
In this I changed element type from WebElement to MobileElement as we're testing native app controls. This is throwing below error
Caused by: java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field com.serenity.appium.poc.pages.WordPressLoginPage.WPLogInButton to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:117)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at net.thucydides.core.annotations.locators.SmartElementProxyCreator.lambda$new$2(SmartElementProxyCreator.java:32)
at net.thucydides.core.annotations.locators.SmartElementProxyCreator.proxyElements(SmartElementProxyCreator.java:48)
at net.thucydides.core.webdriver.DefaultPageObjectInitialiser.apply(DefaultPageObjectInitialiser.java:21)
at net.serenitybdd.core.pages.PageObject.setDriver(PageObject.java:151)
at net.serenitybdd.core.pages.PageObject.setDriver(PageObject.java:155)
at net.thucydides.core.steps.PageObjectDependencyInjector.updatePageObject(PageObjectDependencyInjector.java:69)
at net.thucydides.core.steps.PageObjectDependencyInjector.injectDependenciesInto(PageObjectDependencyInjector.java:31)
at net.thucydides.core.steps.PageObjectDependencyInjector.instantiatePageObjectIfNotAssigned(PageObjectDependencyInjector.java:56)
at net.thucydides.core.steps.PageObjectDependencyInjector.injectDependenciesInto(PageObjectDependencyInjector.java:33)
at net.thucydides.core.steps.StepFactory.injectOtherDependenciesInto(StepFactory.java:165)
at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:155)
at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:138)
at net.thucydides.core.steps.StepFactory.getNewStepLibraryFor(StepFactory.java:85)
... 25 more
Exception is thrown in method
private static void proxyFields(FieldDecorator decorator, Object page, Class<?> proxyIn) {
Field[] fields = proxyIn.getDeclaredFields();
Field[] var4 = fields;
int var5 = fields.length;
for(int var6 = 0; var6 < var5; ++var6) {
Field field = var4[var6];
Object value = decorator.decorate(page.getClass().getClassLoader(), field);
if (value != null) {
try {
field.setAccessible(true);
field.set(page, value);
} catch (IllegalAccessException var10) {
throw new RuntimeException(var10);
}
}
}
}
That is WebDriver code, I think the issue must be higher up.
I double checked and exception is thrown in above method, can you please try with project https://github.com/serenity-bdd/serenity-core/tree/master/serenity-appium
I wanted to add android to this project but currently blocked.
@ricardorlg @pisarenco92 @livastar @hypery2k @cliviu can you please have a look at this issue as well ? Thanks in advance.
May be because of https://github.com/appium/appium/issues/9780
This started happening from version 1.8.0; till 1.7.5 it is working fine. I'll look into changes went in during 1.8.0 to find root cuase
Thanks Vikram.
@wakaleo below is the output from arc
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//XCUIElementTypeButton[@name='button-lets-begin']","df4db19e-59ad-46d4-8229-9cb642a20809"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/C573423D-5C61-4E77-BFCD-8E68AB49F921/element] with body: {"using":"xpath","value":"//XCUIElementTypeButton[@name='button-lets-begin']"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"2C0343EF-9849-479A-85B2-1D7E833845BA"},"sessionId":"C573423D-5C61-4E77-BFCD-8E68AB49F921","status":0}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"2C0343EF-9849-479A-85B2-1D7E833845BA"}
[HTTP] <-- POST /wd/hub/session/df4db19e-59ad-46d4-8229-9cb642a20809/element 200 238 ms - 122
[HTTP] --> POST /wd/hub/session/df4db19e-59ad-46d4-8229-9cb642a20809/element/2C0343EF-9849-479A-85B2-1D7E833845BA/click {"{}":""}
I'm not understanding what may be going wrong while executing java code ?
appium server output with serenity framework 1.8.0 onwards
[HTTP] <-- POST /wd/hub/session/a4c5e5cb-7adc-42cb-8333-d6f1ebf6af44/timeouts 200 7 ms - 76
[HTTP] --> POST /wd/hub/session/a4c5e5cb-7adc-42cb-8333-d6f1ebf6af44/element {"using":"id","value":"LetsBeginButton"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","LetsBeginButton","a4c5e5cb-7adc-42cb-8333-d6f1ebf6af44"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[debug] [BaseDriver] Waiting up to 18000 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/BDB4FAD6-7818-45D3-B6A9-7AE171052575/element] with body: {"using":"id","value":"LetsBeginButton"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"using":"id","value":"LetsBeginButton","description":"unable to find an element"},"sessionId":"BDB4FAD6-7818-45D3-B6A9-7AE171052575","status":7}
[debug] [BaseDriver] Waited for 123 ms so far
[debug] [BaseDriver] Waited for 16243 ms so far
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/BDB4FAD6-7818-45D3-B6A9-7AE171052575/element] with body: {"using":"name","value":"LetsBeginButton"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"using":"name","value":"LetsBeginButton","description":"unable to find an element"},"sessionId":"BDB4FAD6-7818-45D3-B6A9-7AE171052575","status":7}
[debug] [BaseDriver] Waited for 16844 ms so far
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/BDB4FAD6-7818-45D3-B6A9-7AE171052575/element] with body: {"using":"name","value":"LetsBeginButton"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"using":"name","value":"LetsBeginButton","description":"unable to find an element"},"sessionId":"BDB4FAD6-7818-45D3-B6A9-7AE171052575","status":7}
[debug] [BaseDriver] Waited for 17443 ms so far
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/BDB4FAD6-7818-45D3-B6A9-7AE171052575/element] with body: {"using":"name","value":"LetsBeginButton"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"using":"name","value":"LetsBeginButton","description":"unable to find an element"},"sessionId":"BDB4FAD6-7818-45D3-B6A9-7AE171052575","status":7}
serenity version 1.7.5 appium server log
[debug] [MJSONWP] Calling AppiumDriver.getCurrentContext() with args: ["fb4996ff-1059-42d3-9f21-51c54cb22d38"]
[debug] [XCUITest] Executing command 'getCurrentContext'
[debug] [MJSONWP] Responding to client with driver.getCurrentContext() result: "NATIVE_APP"
[HTTP] <-- GET /wd/hub/session/fb4996ff-1059-42d3-9f21-51c54cb22d38/context 200 4 ms - 84
[HTTP] --> POST /wd/hub/session/fb4996ff-1059-42d3-9f21-51c54cb22d38/element {"using":"xpath","value":"//XCUIElementTypeButton[@name='button-lets-begin']"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//XCUIElementTypeButton[@name='button-lets-begin']","fb4996ff-1059-42d3-9f21-51c54cb22d38"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[debug] [BaseDriver] Waiting up to 18000 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/7295CB35-5908-478E-B0B0-80F0756DE808/element] with body: {"using":"xpath","value":"//XCUIElementTypeButton[@name='button-lets-begin']"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"B3B6D9A2-733B-4C38-9639-DABEB44C1202"},"sessionId":"7295CB35-5908-478E-B0B0-80F0756DE808","status":0}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"B3B6D9A2-733B-4C38-9639-DABEB44C1202"}
[HTTP] <-- POST /wd/hub/session/fb4996ff-1059-42d3-9f21-51c54cb22d38/element 200 520 ms - 122
[HTTP] --> GET /wd/hub/session/fb4996ff-1059-42d3-9f21-51c54cb22d38 {}
```
@iOSFindBy(xpath="//XCUIElementTypeButton[@name='button-lets-begin']")
private WebElement LetsBeginButton;
being called differently in above 2 cases
Before 1.8.0 version
[HTTP] --> POST /wd/hub/session/fb4996ff-1059-42d3-9f21-51c54cb22d38/element {"using":"xpath","value":"//XCUIElementTypeButton[@name='button-lets-begin']"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//XCUIElementTypeButton[@name='button-lets-begin']","fb4996ff-1059-42d3-9f21-51c54cb22d38"]
After 1.8.0 version
[HTTP] --> POST /wd/hub/session/a4c5e5cb-7adc-42cb-8333-d6f1ebf6af44/element {"using":"id","value":"LetsBeginButton"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","LetsBeginButton","a4c5e5cb-7adc-42cb-8333-d6f1ebf6af44"]
```
Please clarify why xpath is treated as id here ?
@wakaleo need your help here please
@vikramvi is this happening in the POC project? so I can take a look.
@ricardorlg please checkout the branch of POC project , https://github.com/vikramvi/AppiumSerenityPOC/tree/joe_winApp_poc
@ricardorlg can you please let me know if you got chance to debug the issue ?
@vikramvi sorry, I have been some busy but I will check this before the end of the week and let you know if I can solve it.
Thanks @ricardorlg
@vikramvi @ricardorlg @wakaleo I was trying serenity version 1.8.3 and serenity cucumber version 1.6.6. appium java client 5.0.4 and 6.0.0-BETA2 . as @vikramvi I tried MobileElement and RemoteWebElement , When I changed the annotation to @FindBy(id = "org.wordpress.android:id/login_button") . it worked. not sure about the root cause but i guess is something related to the annotation @AndroidFindBy and @iOSFindBy . so work around for now use @FindBy with @vikramvi SerenityAppiumPOC . it works perfectly for IOS and Android.
Its related to PageObject factory init of Appium, I'm working on this @vikramvi
for now best option , for supporting both devices. @FindAll({@FindBy(xpath = "//android.widget.Button[@text='Log In']"), @FindBy(xpath = "//XCUIElementTypeButton[@label='Log In']")}) . , you can set both selectors for IOS and Android and it will look for both strategies.
Looks like is ignoring appiumfielddecorator I'm going to try using custom web driver, anyway I think is time to review appium integration.
@CamiloCode what was the element type you used? MobileElement? Because your solution does not work for me even with similar setup. Using serenity 1.8.21, javaclient 6.0.0-BETA2 selenium 3.8.1,
@FindBy(xpath = "//android.widget.EditText[@text='Email Address']")
private MobileElement emailField;
throws
java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field com.****.emailField to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4
@risinek no , I'm not using MobileElement, I also tried WebElementFacade and It didnt work. Im using WebElement . and it should work. we try to avoid using @ annotations from AppiumFieldDecorator AndroidFindBy and iOSFindby as those are broken in the new version. simply using @FindBy from Selenium and WebElement should work. Btw I got that same error you posted above when I used other kind of element.
I will take a look on this issue
@cliviu which one strategies @AndroidFindBy / iOSFindBy or the issue with the mobileWebElement?
Ok find the cause of this - https://github.com/serenity-bdd/serenity-core/pull/1029 ... If I revert this file and make a new build from 1.8.21, it works again..
@risinek I saw this commit and I thought it has to do with the issue. I think we should investigate further. maybe it needs more than fixing that bug.
@risinek, I agree, it looks like this change causes problems
@cliviu could you please check what makes it fail after this bug fix ?
the change will be reverted soon
@CamiloCode sorry, I'm busy right now. I just managed to locate the commit and fix it on my own. I don't understand how those PageFactories work very much, so I would need to spend more time on it to track what makes it fail..
serenity-core 1.8.22-rc.2 is on Bintray, please try it. It should work now by using directly WebElementFacade. The annotations AndroidFindBy and iOSFindby should work.
@cliviu so now I dont need to use AppiumFieldDecorator, just extends from PageObject (serenity-bdd) and declare my elements as WebElementFacade and I should able to use @AndroidBy and @iOSFindBy?
@CamiloCode yes, it should work now
public class LoginPage extends PageObject {
@AndroidFindBy(id = "org.wordpress.android:id/login_button")
@iOSFindBy(xpath = "//XCUIElementTypeButton[@label='Log In']")
private WebElementFacade WPLogInButton;
public void loginPageClick() {
WPLogInButton.click();
}
}
Not working.
ERROR net.serenitybdd.core.Serenity - The following error occurred: Expected enabled element was not enabled
@cliviu
POM
<serenity.version>1.8.22-rc.2</serenity.version> @@ <serenity.cucumber.version>1.6.10</serenity.cucumber.version>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.4</version>
</dependency>
Do you have a stack trace ?
@CamiloCode I guess there will be some differences between WebElementFacade and MobileElement and its methods..
So just rewriting MobileElement to WebElementFacade won't work right away..
@cliviu Stacktrace:
net.serenitybdd.core.exceptions.SerenityManagedException: The following error occurred: Expected enabled element was not enabled
at net.serenitybdd.core.pages.WebElementFacadeImpl.waitUntilEnabled(WebElementFacadeImpl.java:968)
at net.serenitybdd.core.pages.WebElementFacadeImpl.waitUntilElementAvailable(WebElementFacadeImpl.java:807)
at net.serenitybdd.core.pages.WebElementFacadeImpl.click(WebElementFacadeImpl.java:1044)
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.$Proxy25.click(Unknown Source)
at com.colpatria.appium.pages.LoginPage.loginPageClick(LoginPage.java:22)
at com.colpatria.appium.features.steps.login.LoginSteps.test_one(LoginSteps.java:12)
at com.colpatria.appium.features.steps.login.LoginSteps$$EnhancerByCGLIB$$1514a92f.CGLIB$test_one$0(
at com.colpatria.appium.features.steps.login.LoginSteps$$EnhancerByCGLIB$$1514a92f$$FastClassByCGLIB$$1d5970f8.invoke(
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:450)
at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:435)
at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:410)
at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:151)
at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:138)
at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:69)
at com.colpatria.appium.features.steps.login.LoginSteps$$EnhancerByCGLIB$$1514a92f.test_one(
at com.colpatria.appium.features.steps.login.LoginStepDefinition.login_test_one(LoginStepDefinition.java:15)
at ✽.Client wants to log in(src/test/resources/features/valid_login.feature:5)
Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for LoginPage.WPLogInButton to be enabled (tried for 5 second(s) with 100 MILLISECONDS interval)
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:263)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231)
at net.serenitybdd.core.pages.WebElementFacadeImpl.waitUntilEnabled(WebElementFacadeImpl.java:965)
at net.serenitybdd.core.pages.WebElementFacadeImpl.waitUntilElementAvailable(WebElementFacadeImpl.java:807)
at net.serenitybdd.core.pages.WebElementFacadeImpl.click(WebElementFacadeImpl.java:1044)
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.$Proxy25.click(Unknown Source)
at com.colpatria.appium.pages.LoginPage.loginPageClick(LoginPage.java:22)
at com.colpatria.appium.features.steps.login.LoginSteps.test_one(LoginSteps.java:12)
at com.colpatria.appium.features.steps.login.LoginSteps$$EnhancerByCGLIB$$1514a92f.CGLIB$test_one$0(
at com.colpatria.appium.features.steps.login.LoginSteps$$EnhancerByCGLIB$$1514a92f$$FastClassByCGLIB$$1d5970f8.invoke(
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:450)
at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:435)
at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:410)
at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:151)
at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:138)
at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:69)
at com.colpatria.appium.features.steps.login.LoginSteps$$EnhancerByCGLIB$$1514a92f.test_one(
at com.colpatria.appium.features.steps.login.LoginStepDefinition.login_test_one(LoginStepDefinition.java:15)
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:32)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:26)
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:117)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:55)
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:126)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:272)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
Caused by: org.openqa.selenium.NoSuchElementException: Timed out after 2 seconds. Element not found
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'MacBook-Pro-de-helpdesk-3.local', ip: 'fe80:0:0:0:18a4:526c:83b5:25d%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_131'
Driver info: driver.version: unknown
at net.thucydides.core.annotations.locators.SmartAjaxElementLocator.ajaxFindElement(SmartAjaxElementLocator.java:173)
at net.thucydides.core.annotations.locators.SmartAjaxElementLocator.findElement(SmartAjaxElementLocator.java:125)
at net.serenitybdd.core.pages.WebElementResolverByElementLocator.resolveForDriver(WebElementResolverByElementLocator.java:27)
at net.serenitybdd.core.pages.WebElementFacadeImpl.getElement(WebElementFacadeImpl.java:209)
at net.serenitybdd.core.pages.WebElementExpectations$3.apply(WebElementExpectations.java:63)
at net.serenitybdd.core.pages.WebElementExpectations$3.apply(WebElementExpectations.java:55)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
@cliviu forgot to mention that I have a custom driver that implements DriverSource. its just an AndroidDriver. so I guess it doesnt have anything to do with the error.
can it be a timeout issue ? by default WebElementFacade method waits for the element to be available (for up to 5 seconds, or whatever you configure in the webdriver.wait.for.timeout property) when you call the click() method.
@cliviu my implicit wait in the implementation of DriverSource is:
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for LoginPage.WPLogInButton to be enabled (tried for 5 second(s) with 100 MILLISECONDS interval) looks like a test-specific issue.
@wakaleo if I do try this test with AppiumDecorator (@vikramvi sample) . it works perfectly . (serenity version 1.7.5) above 1.8.x tests are broken
@CamiloCode, maybe a small project to help us understand the problem and to debug will help to make progress on this issue.
There is a project here where a hybrid mobile application is tested :
https://github.com/cliviu/serenity-appium-hybrid-poc. It currently works using a plain serenity PageObject containing WebElementFacade elements
serenity-core 1.8.22-rc.2 doesn't solve issue with MobileElement, which worked before https://github.com/serenity-bdd/serenity-core/pull/1029 ... Will you have time to look into it? Or can I somehow help with this?
hmm, Isn't a WebElement Facade enough or do you need a MobileElement ?
yes, at least it should be. so there is no need to solve it for MobileElement? I'm just curious
I'm not sure if there is any need to make it work for MobileElement
@risinek is everything wokring for you with WebElementFacade? I try to adapt my code with cliviu sample and it wont work
@CamiloCode , is it possible to use an "id" locator instead of "xpath" just for testing if it works in this case ? Thanks
in @cliviu sample its using SerenityRunner , IM using CucumberWithSerenity Runner, do you think it has something to do ? , the only difference between my code and your sample is that and also that im using a custom driver . implementing DriverSource
Yes, all tests are green when I replaced all MobileElements with WebElementFacade type.. I'm using
@AndroidFindBy(xpath = "etc")
WebElementFacade email;
(I don't have the source code in front of me right now, just what I remember)
This works good for me. What exactly is not working for you? What error you get or what happens?
@risinek can we follow this in https://serenity-bdd.rocket.chat/channel/general ?
@cliviu I do use Ids instead of xpaths . it isnt working. as I mentioned I dont use SerenityRunner. just CucumberWithSerenity Runner and I do use Pageobjects and I do super(driver) of the page object im working on. as I mentioned is it possible to follow the thread in the rocket chat?
@CamiloCode , no problem , we can discuss this in the rocket chat. I'm not sure what is your id there. Nevertheless, can you try it with a plain AndroidDriver ? Maybe there is something different with your implementation of the DriverSource.
@cliviu my id is hackcode in rocket chat, but ill copy here my implementation of DriverSource:
public class Android implements DriverSource {
@Override
public WebDriver newDriver() {
DesiredCapabilities capabilities = new DesiredCapabilities();
EnvironmentVariables properties = SystemEnvironmentVariables.createEnvironmentVariables();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, properties.getProperty("android.automationName"));
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, properties.getProperty("android.platformVersion"));
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, properties.getProperty("android.deviceName"));
capabilities.setCapability(MobileCapabilityType.APP, properties.getProperty("android.app"));
capabilities.setCapability("appActivity", properties.getProperty("android.appActivity"));
capabilities.setCapability("appPackage", properties.getProperty("android.appPackage"));
try {
AndroidDriver driver = new AndroidDriver(new URL(properties.getProperty("appium.server")), capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
return driver;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public boolean takesScreenshots() {
return true;
}
}
Unable to upgrade to latest Serenity version because of the same issue, any idea when it will be resolved?
hi @csnthsh120 , you have also an own implementation of the DriverSource ?
@CamiloCode, I have tested with your implementation of DriverSource and the https://github.com/cliviu/serenity-appium-hybrid-poc . The tests were ok. I'm not sure where the problem is.
@cliviu yes but i see you arent using cucumber on your tests. I'm just using 1 runner which is cucumber with serenity . and I see you use in your tests SerenityRunner . im not sure if this is related. could you please check your poc with cucumber? please.
@cliviu : I am not using any custom implementation of the DriverSource. Anyone is working on this issue anymore?
hi @ExcessWarriors , can you describe what your problem is ? Have you tried my POC (https://github.com/cliviu/serenity-appium-hybrid-poc)?
hi @cliviu , I am not using your POC project but when I run tests with serenity-core version 1.7.5 the tests are running fine but with 1.8.22-rc.2, I am getting below error :
net.serenitybdd.core.exceptions.StepInitialisationException: Failed to create step library for GenericStepDefinitions:Failed to create step library for Pages:Can not set io.appium.java_client.MobileElement field nl.essent.automation.pages.forgot_login.ForgotPasswordSuccessPage.forgotPasswordSuccess to com.sun.proxy.$Proxy29
Below are more in depth errors :
Caused by: net.serenitybdd.core.exceptions.StepInitialisationException: Failed to create step library for Pages:Can not set io.appium.java_client.MobileElement field nl.essent.automation.pages.forgot_login.ForgotPasswordSuccessPage.forgotPasswordSuccess to com.sun.proxy.$Proxy29
Caused by: java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field nl.essent.automation.pages.forgot_login.ForgotPasswordSuccessPage.forgotPasswordSuccess to com.sun.proxy.$Proxy29
hi @cliviu , Here is the full trace
net.serenitybdd.core.exceptions.StepInitialisationException: Failed to create step library for GenericStepDefinitions:Failed to create step library for Pages:Can not set io.appium.java_client.MobileElement field nl.essent.automation.pages.forgot_login.ForgotPasswordSuccessPage.forgotPasswordSuccess to com.sun.proxy.$Proxy29
at net.thucydides.core.steps.StepFactory.getNewStepLibraryFor(StepFactory.java:101)
at net.thucydides.core.steps.IndividualInstancesByDefaultStepCreationStrategy.initiateStepsFor(IndividualInstancesByDefaultStepCreationStrategy.java:16)
at net.thucydides.core.steps.StepAnnotations.instantiateAnyUnitiaializedSteps(StepAnnotations.java:75)
use WebElementFacade instead of MobileElement . please check the POC. Can you please post some snippets of your PageObject ? How are you declaring the fields ?
hi, @cliviu , WebElementFacade makes no sense. Below is how I am declaring my element]
private final String forgotPasswordSuccessAutomationText = "forgot-password-success-message";
@AndroidFindBy(accessibility = forgotPasswordSuccessAutomationText)
@iOSFindBy(accessibility = forgotPasswordSuccessAutomationText)
private MobileElement forgotPasswordSuccess;
@ExcessWarriors as @cliviu says change MobileElement to WebElementFacade
@ricardorlg & @cliviu : My entire project is with MobileElements, I will create a POC project out of it and try with WebElementFacade. Will let you know the result.
Right now Appium locators only work with WebElementFacde, @cliviu I can take a look to make this works with MobileElements, should I start with the SmartFieldDecorator class?
@ricardorlg @cliviu : Tried WebElementFacade and below is the new error
Failed to instantiate page (java.lang.IllegalArgumentException: Can not set net.serenitybdd.core.pages.WebElementFacade field nl.essent.automation.pages.forgot_login.ForgotPasswordSuccessPage.forgotPasswordSuccess to io.appium.java_client.ios.IOSElement$$EnhancerByCGLIB$$d311658)
Are you using a plain PageObject ? You do not have to use an AppiumFieldDecorator anymore
@cliviu : I think that's the problem, I am using MobilePageObject with AppiumFiledDecorator like below
public MobilePageObject(final WebDriver driver) {
super(driver, page -> {
PageFactory
.initElements(new AppiumFieldDecorator(((WebDriverFacade) page.getDriver()).getProxiedDriver(),
page.getImplicitWaitTimeout().in(TimeUnit.SECONDS), TimeUnit.SECONDS), page);
return true;
});
}
Could you please suggest me how I should modify this?
don't use MobilePageObject, don't need that anymore, extends of PageObject
Yes, exactly as @ricardorlg mentioned. MobilePageObject should not be used anymore. I will make a pull request to remove it
@ricardorlg @cliviu : That helped. Thanks you very much for the help. That was exactly the issue. I needed to remove MobilePageObject and change the definition of all MobileElements to WebElementFacade. It took me 1 hour to override all methods and elements but everything is working fine now.
@CamiloCode @vikramvi : I think we got solution for this issue. I just tested with latest version 1.9.3, after removing MobilePageObject and over riding all MobileElements to WebElementFacade everything is working fine. It is working for native pop ups as well. I think we can close this issue now, unless someone has any extra questions.
@CamiloCode @vikramvi @ExcessWarriors In which cases you guys think is necessary to have appium locators working with MobileElement type.
@ricardorlg : I don't have any case in which we need appium locator. For me, all cases are working fine with WebElementFacade.
@ExcessWarriors @ricardorlg i just wonder if you guys have tested this with cucumber. in my side I couldnt get it to work.
Plenty of people use Serenity with Appium and Cucumber, ask in https://serenity-bdd.rocket.chat
@ricardorlg I don't have any specific needs to use MobileElement for now. Does it recommended to use WebElementFacade instead of WebElement as well ?
@CamiloCode : Hi, what do you mean by cucumber? I use the runner @RunWith(CucumberWithSerenity.class)
@ricardorlg @cliviu I came into a situation, where WebElementFacade is not enough in compare with MobileElement.. Appium's setValue() method on MobileElement is not available on WebElementFacade, so I have to get wrapped element and cast it to Mobile element everytime I want to use this method.. And I guess it's not the only method. ((MobileElement el.getWrappedElement()).setValue("string")
@vikramvi @cliviu @wakaleo
Hi All,
I am having the same broken locator strategy, but with all the latest updates to serenity core, serenity cucumber, and appium.
I am using the SmartFieldDecorator:
[
public class GenericActions extends PageObject {
public GenericActions(WebDriver driver) {
super(driver);
}
...
...
}
]
In my child page of GenericActions, I am using the '@iOSXCUITFindBy(iOSNsPredicate = "name == 'example_locator'")' syntax with WebElementFacade.
However, I am still receiving 'NoSuchElementException' for elements that I have verified through Appium Desktop.
Any help in the right direction would be appreciated! Thanks.
This is my pom file:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<configuration>
<argLine>-Xmx2048m</argLine>
<includes>
<include>**/IOS.java</include>
</includes>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
<executions>
<execution>
<id>cucumber-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!--<dependency>-->
<!--<groupId>io.appium</groupId>-->
<!--<artifactId>java-client</artifactId>-->
<!--<version>${appium-java-client.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>io.appium</groupId>-->
<!--<artifactId>java-client</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber</artifactId>
<version>${serenity-cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>${surefire.version}</version>
</dependency>
@risinek : .setValue("string") will not always work, please use .sendKeys(''string''). SendKeys works perfectly fine for me.
@Warren25 : I am not sure that '@iosxcuitfindby' will work. Please use @iOSFindBy(accessibility='name of the element'). You can use any of the following locator strategies with iOSFindBy
uiAutomator,accessibility,id,className,tagName or xpath
@ExcessWarriors '@ iosxcuitfindby' was working actually for me, except a few locators would "mysteriously" result in a nosuchelementexception even after being recognized in Appium Desktop. When I upgraded from serenity core 1.6.3 and serenity cucumber 1.5.7 to the latest, the location strategy does not work.
Hi, I just wanted to give this page a bump. I am currently on 1.7.5 serenity core, and 1.6.13 serenity cucumber. Using any serenity core release higher 1.7.5 still results in the locator error referenced in this thread. I am currently using the iOSNsPredicate strategy with Appium Java Client 6.0.0-Beta3. This will not work in 1.8.0 or higher. Also, from reading tips provided by @ricardorlg , @cliviu , and @ExcessWarriors , I tried using MobileElement type, WebElementFacade, WebElement (w/ iOSFindby) with both SmartFieldDecorator and AppiumFieldDecorator, a total of 6 permutations all to no avail. If anybody can provide some new context on this, that would be very helpful. I would very much like to upgrade my serenity core and cucumber releases if I can get a working build thanks.
Hello everybody. I ran into a problem, when i updated my serenity to 1.9.17, i can't use appium Widget(it is a custom element https://github.com/appium/java-client/blob/master/docs/Page-objects.md ), because in new version we don't have PageFactory.initElements(new AppiumFieldDecorator... Please help who solve this problem or give advice. Thanks.
Most helpful comment
the change will be reverted soon