Reputation: 8446
I'm using calabash-android-java to test a hybrid application built with Xamarin. As you can see below, I'm able to query for the DOM element, and even log some information to console, however when I execute the touch command, for whatever reason, the element can no longer be found.
I took a look at at the point of failure in the calabash-android-java source code, however it just seems to pass my query off to a scripting engine, which is as far as I can take it.
Am I simply misunderstanding the use of the touch command? I would assume it should be able to "touch" an anchor tag, but perhaps not?
At any rate, any assistance would be greatly appreciated...my Google fu has failed me this day.
HTML
<div style="width: 100px">
<a data-role="button" ng-click="submit()" id="loginButton">Log In</a>
</div>
Java
@When("^user \"(.*?)\" logs in with valid credentials$")
public void user_logs_in_with_valid_credentials(String username) throws Throwable {
UIElement login = app.query("webView css:'#loginButton'").first();
System.out.println("Element_Id=" + login.getId());
System.out.println("Element_Class=" + login.getElementClass());
System.out.println("Element_Query=" + login.getQuery());
System.out.println("Element_Text=" + login.getText());
System.out.println("Element_Enabled=" + login.isEnabled());
Rect rect = login.getRect();
System.out.println("Center_X=" + rect.getCenter_x());
System.out.println("Center_Y=" + rect.getCenter_y());
login.touch();
}
Console output
Element_Id=loginButton
Element_Class=ui-btn ui-btn-up-c ui-shadow ui-btn-corner-all
Element_Query=webView css:'#loginButton' index:0
Element_Text=
Element_Enabled=false
Center_X=91.98979
Center_Y=308.5714
com.thoughtworks.calabash.android.CalabashException: Failed to touch on: webView css:'#loginButton' index:0. (RuntimeError) No elements found. Query: webView css:'#loginButton' index:0
at com.thoughtworks.calabash.android.CalabashWrapper.touch(CalabashWrapper.java:293)
at com.thoughtworks.calabash.android.UIElement.touch(UIElement.java:196)
at com.mycompany.calabash.LoginStepDefs.user_logs_in_with_valid_credentials(LoginStepDefs.java:41)
at ?.When user "xxx@xx" logs in with valid credentials(C:/_Workspace/calabash-android-java/calabash-android-java/src/test/resources/features/login.feature:13)
UPDATE: It's worth noting that I'm able to touch the element using the same query when in console mode, and the device responds accordingly:
irb(main):023:0> touch("webView css:'#loginButton'")
{
"bonusInformation" => [],
"message" => "",
"success" => true
}
Upvotes: 1
Views: 776
Reputation: 4677
I updated to clabash android 0.5.1 which helps to handle better touch and set text on webelements. Web views are now handled better(consistent with calabash android).
https://github.com/vishnukarthikl/calabash-android-java/issues/3
Upvotes: 0
Reputation: 8446
After speaking with Vishnu via GitHub, I was able to alter the source code to work around the bug:
Note, one must truncate the String "index:N" that is appended to the query variable, which is subsequently passed to the Ruby script:
CalabashWrapper.java
public void touch(String query) throws CalabashException {
try {
info("Touching - %s", query);
query = query.substring(0, query.indexOf("index:"));
container.put(QUERY_STRING, query);
container.runScriptlet(String.format("touch(%s)", QUERY_STRING));
pause();
} catch (Exception e) {
error("Failed to touch on: %s", e, query);
throw new CalabashException(String.format("Failed to touch on: %s. %s", query, e.getMessage()));
}
}
Upvotes: 0