IOSElement size crashes, index out of bounds.
When I'm trying to loop through some code to click on some buttons with the the same ID, and do it by index, eventually the element info crashes the program. See StackTrace, Declaration of element, Code Snippet and
STACKTRACE:
Session ID: ff5552c8-0fb4-43d9-b105-4dc61c67dbb2
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:164)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:863)
at io.appium.java_client.pagefactory.AppiumElementLocator.changeImplicitlyWaitTimeOut(AppiumElementLocator.java:115)
at io.appium.java_client.pagefactory.AppiumElementLocator.waitFor(AppiumElementLocator.java:133)
at io.appium.java_client.pagefactory.AppiumElementLocator.findElements(AppiumElementLocator.java:167)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements.intercept(InterceptorOfAListOfElements.java:44)
at $java.util.ArrayList$$EnhancerByCGLIB$$17343041.size(
DECLARATION OF ELEMENT
@iOSFindAll({
@iOSFindBy(id = "Hide Account")
})
public List
SNIPPET OF CODE
int startSize = AccountMapping.findAllHideButton.size();
for (int x = 1; x < startSize; x++) {
//as the second account(1) is hidden the next account becomes index 1...loops through until all 7 have been closed.
System.out.println("Clicking number [" + x + "]");
**This loops for a while then eventually the next statement bombs.
System.out.println("At this time the size is [" + AccountMapping.findAllHideButton.size() + "]");
AccountMapping.findAllHideButton.get(1).click();
Utils.sleep(1000);
}
DEBUG SHOWING CODE WORKING Clicking number [1] At this time the size is [8] Clicking number [2] At this time the size is [7] Clicking number [3] At this time the size is [6] Clicking number [4] At this time the size is [5] Clicking number [5] At this time the size is [5] Clicking number [6] THEN IT BOMBS ON THE OUTPUT OF System.out.println("At this time the size is [" + AccountMapping.findAllHideButton.size() + "]");
It is weird. It looks like something happens when it tries to add whole found collection to the resulted list. https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/interceptors/InterceptorOfAListOfElements.java#L44
Here is the appium debug output.
https://gist.github.com/nuggit32/b3aefe7adaf89b695693
One thing in my research and can be seen in the log is this: info: [debug] [INST] 2016-01-22 14:57:17 +0000 Fail: The target application appears to have died
The code crashed in the For loop on this line System.out.println("At this time the size is [" + AccountMapping.findAllHideButton.size() + "]");
It is interesting...
I'm still trying to figure out what happens. But now I think that it is most like not the problem of page object tool. It may be the server-side problem or .. the bug of your application.
int startSize = AccountMapping.findAllHideButton.size();
for (int x = 1; x < startSize; x++) {
it looks like the starting size has been 9 or 8. Ok. But each time after the clicking the actual element count decreases:
Clicking number [1]
At this time the size is [8]
Clicking number [2]
At this time the size is [7]
Clicking number [3]
At this time the size is [6]
Clicking number [4]
At this time the size is [5]
Clicking number [5]
At this time the size is [5]
Clicking number [6]
- Here were about 8 elements
- still 8
- and now here are 8 elements
- but now here are 7 elements
- and 7 elements again
- 6
- 5
and so on...
- and now it finds nothing (!!!) the searching has been started
the searching has been finished
So the
AccountMapping.findAllHideButton.get(1).click()
crashes with ListIndexOfBoundsException.
The invocation of a method of a List instance doesn't mean that you are working with the real list. It is proxy which intercepts the method. It was designed to simplify work with elements. Otherwise you have to do the same thing the following way:
int startSize = driver.findElements(By.id("Hide Account"));
for (int x = 1; x < startSize; x++) {
System.out.println("At this time the size is [" + driver.findElements(By.id("Hide Account")).size() + "]");
driver.findElements(By.id("Hide Account")).get(1).click(); //after this clicking
//element count could be decreased
}
So you can see that element count can be different for each iteration.
Why does it happen? I don't know. Maybe it is the feature/bug of the app. It may be the bug of Appium server-side.
Also this stacktrace is very interesting
org.openqa.selenium.remote.SessionNotFoundException:
Command duration or timeout: 3 milliseconds
Build info: version: '2.49.0', revision: '365eeb44deba2067b1761c8862ef21d55250e063', time: '2016-01-13 11:57:39'
System info: host: 'herberts-MacBook-Pro.local', ip: '10.40.112.81', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.2', java.version: '1.8.0_65'
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{networkConnectionEnabled=false, warnings={}, bundleId=FNB.QA-FNB-Kansas, databaseEnabled=false, deviceName=CRi iPhone 6, platform=MAC, desired={bundleId=FNB.QA-FNB-Kansas, platformName=iOS, udid=auto, deviceName=CRi iPhone 6}, webStorageEnabled=false, locationContextEnabled=false, browserName=iOS, takesScreenshot=true, javascriptEnabled=true, platformName=iOS, udid=auto}]
Session ID: 4ff4dfaf-3ecc-4d9a-905d-7228142c8d16
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:164)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:863)
at io.appium.java_client.pagefactory.AppiumElementLocator.changeImplicitlyWaitTimeOut(AppiumElementLocator.java:115)
at io.appium.java_client.pagefactory.AppiumElementLocator.waitFor(AppiumElementLocator.java:133)
at io.appium.java_client.pagefactory.AppiumElementLocator.findElements(AppiumElementLocator.java:167)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements.intercept(InterceptorOfAListOfElements.java:44)
at $java.util.ArrayList$$EnhancerByCGLIB$$e3e8e026.size(<generated>)
at com.cri.fnbo.ios.accounts.HideAllAccountsExceptOne.hideAccounts(HideAllAccountsExceptOne.java:100)
Is it possible that some clicking crashes your app?
@nuggit32 I'm waiting for your response.
PS: Also I could make an assumption that your code has a mistake.
AccountMapping.findAllHideButton.get(1).click()
If your test checks that at end of the cycle there should be only one element (the test name HideAllAccountsExceptOne gives a clue) so I think that it is correct
AccountMapping.findAllHideButton.get(0).click()
This is not a coding error. It happened again today when trying to click a SAVE button.
info: [debug] Pushing command to appium work queue: "au.getElementsByName('Save')"
info: [debug] Sending command to instruments: au.getElementsByName('Save')
info: [debug] [INST] 2016-01-25 20:27:27 +0000 Debug: evaluation finished
info: [debug] [INST] 2016-01-25 20:27:27 +0000 Debug: responding with:
info: [debug] [INST] 2016-01-25 20:27:27 +0000 Debug: Running system command #61: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] [INST] 2016-01-25 20:27:28 +0000 Debug: Got new command 61 from instruments: au.getElementsByName('Save')
info: [debug] [INST] 2016-01-25 20:27:28 +0000 Debug: evaluating au.getElementsByName('Save')
info: [debug] [INST] 2016-01-25 20:27:28 +0000 Fail: The target application appears to have died
info: [debug] [INST STDERR] 2016-01-25 14:27:28.537 instruments[6945:790060] Attempting to change event horizon while disengage
info: [debug] Socket data received (41 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":[{"ELEMENT":"80"}]}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"80"}],"sessionId":"89b703d4-4cea-42e6-9868-73d6dadc96e9"}
info: <-- POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/elements 200 1244.299 ms - 90 {"status":0,"value":[{"ELEMENT":"80"}],"sessionId":"89b703d4-4cea-42e6-9868-73d6dadc96e9"}
info: --> POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/timeouts {"type":"implicit","ms":1000}
info: [debug] Set iOS implicit wait to 1000ms
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"89b703d4-4cea-42e6-9868-73d6dadc96e9"}
info: <-- POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/timeouts 200 1.422 ms - 76 {"status":0,"value":null,"sessionId":"89b703d4-4cea-42e6-9868-73d6dadc96e9"}
info: --> POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/element/80/click {"id":"80"}
info: [debug] Pushing command to appium work queue: "au.tapById('80')"
info: [debug] Sending command to instruments: au.tapById('80')
info: [debug] [INST] 2016-01-25 20:27:28 +0000 Debug: evaluation finished
info: [debug] [INST] 2016-01-25 20:27:28 +0000 Debug: responding with:
2016-01-25 20:27:28 +0000 Debug: Running system command #62: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":[{"ELEMENT":"80"}]}...
info: [debug] [INST] Instruments Trace Complete (Duration : 78.318398s; Output : /tmp/appium-instruments/instrumentscli0.trace)
info: [debug] [INSTSERVER] Instruments exited with code 0
info: [debug] Cleaning up after instruments exit
info: [debug] Instruments exited unexpectedly
info: [debug] Shutting down command proxy and ignoring any errors
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Stopping iOS log capture
info: [debug] Reset not set, not ending sim or cleaning up app state
info: [debug] We were in the middle of processing a command when instruments died; responding with a generic error
info: [debug] Cleaning up appium session
info: [debug] Responding to client with error: {"status":13,"value":{"message":"Instruments died while responding to command, please check appium logs","name":"UnknownError","origValue":"Instruments died while responding to command, please check appium logs"},"sessionId":null}
info: <-- POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/element/80/click 500 225.872 ms - 230
info: --> POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/timeouts {"type":"implicit","ms":0}
info: <-- POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/timeouts 404 0.804 ms - 40
info: --> POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/timeouts {"type":"implicit","ms":1000}
info: <-- POST /wd/hub/session/89b703d4-4cea-42e6-9868-73d6dadc96e9/timeouts 404 1.496 ms - 40
Tests run: 5, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 86.094 sec <<< FAILURE! - in TestSuite
verifyAccountTotalsChangeWhenHidingDepositAndCCLoans(com.cri.fnbo.ios.accounts.VerifyAccountTotals) Time elapsed: 15.026 sec <<< FAILURE!
org.openqa.selenium.WebDriverException: Instruments died while responding to command, please check appium logs (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 229 milliseconds
Build info: version: '2.49.0', revision: '365eeb44deba2067b1761c8862ef21d55250e063', time: '2016-01-13 11:57:39'
System info: host: 'herberts-MacBook-Pro.local', ip: '10.40.112.81', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.2', java.version: '1.8.0_65'
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{networkConnectionEnabled=false, warnings={}, bundleId=FNB.QA-FNB-Kansas, databaseEnabled=false, deviceName=CRi iPhone 6, platform=MAC, desired={bundleId=FNB.QA-FNB-Kansas, platformName=iOS, udid=auto, deviceName=CRi iPhone 6}, webStorageEnabled=false, locationContextEnabled=false, browserName=iOS, takesScreenshot=true, javascriptEnabled=true, platformName=iOS, udid=auto}]
Session ID: 89b703d4-4cea-42e6-9868-73d6dadc96e9
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:44)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.ios.IOSElement.execute(IOSElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
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:497)
at io.appium.java_client.pagefactory.ElementInterceptor.getObject(ElementInterceptor.java:39)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.intercept(InterceptorOfASingleElement.java:52)
at io.appium.java_client.ios.IOSElement$$EnhancerByCGLIB$$3b949a7d.click(
This is the same issue as https://github.com/appium/appium/issues/6285.
Hello! Are there any updates on this issue?
Btw, I don't believe it is related to java-client. I faced the same app crash both in tests and in Appium GUI app when trying to launch the inspector (after au.mainApp().getTreeForXML() command has been called). The app crashes in random places when click() or isDisplayed() methods are called in my tests. Here is a fragment from application crash log.
Here is a fragment from Appium logs when the app crashes when I click on Inspector button in Appium GUI app: https://gist.github.com/grumpyNika/ce26bf9544b409fe0c5a2e7ac7ede0f9
Here is a fragment from Appium logs when the app crashes when isDisplayed() method is called in my tests: https://gist.github.com/grumpyNika/9d1d18c38af22f1d075c37e016e8f5b9
The app does not crash if to install it on the simulator not using Appium and test it manually. And some actions are performed in automated tests but the app crashes randomly in each test.
The issue occurs for me from the latest delivered from the developers build, and the tests on the previous build have been working fine. So there is a chance that it's not Appium issue...
@nuggit32 Have you found any workaround for this?
Thank you.
@grumpyNika no I have not found a workaround. I have opened up an internal bug for my developers to look at the crash logs to see if they have any idea.
Our developer found out that the issue has appeared when he upgraded this library to 2.0.0 version: TTTAttributedLabel to place the images near UIALink elements. Seems that now, when images are added to the links, some error happens when trying to add accessibility to these elements. We can see this library in the stack trace of application crash log.
I don't know if it's Appium or Instruments or this library bug and how to workaround this.
Probably similar problem is in your application as well...