androidrubyseleniumappiumgestures

ruby appium driver tap gesture does not work


Setup

Wanted action/step to perform

IRB

require 'appium_lib'
require 'touch_action'
grid_url = "http://localhost:4444/wd/hub" 
capabilities = {
'browserName' => 'chrome',
'platformName' => 'Android',
'deviceName' => 'Nexus5',
'newCommandTimeout' => '15000',
'javascript_enabled' => true 
}
browser = Appium::Driver.new(caps: capabilities, url: grid_url).start_driver
browser.get("https://www.google.nl")
sleep 5
inputfield = browser.find_element(:id, 'lst-ib')
inputfield.click
inputfield.send_keys("appium mobile gestures ruby")
sleep 2
button = browser.find_element(:id, 'tsbb')

So far so good. But when I try to perform a tab action. it fails

irb(main):026:0> button.touch_action(:tap)
NoMethodError: undefined method `executeScript' for #<Selenium::WebDriver::Remote::OSS::Bridge:0x3119b50>
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/touch_action-1.3.3/lib/touch_action/selenium-webdriver.rb:9:in `touch_action'
from (irb):26
from C:/Ruby23/bin/irb.cmd:19:in `<main>'

I have the feeling I miss something small a detail (I'm new to appium), I just don't see the mistake I make here. So if someone can point me in the right direction that would be really helpful. For example scrolling also did not do anything for me (just returned nil) https://appium.readthedocs.io/en/stable/en/writing-running-appium/touch-actions/

I also tried some other commands that I found here: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/appium-bindings.md

For example driver.lock (in my case browser.lock), worked so I can interact with the phone commands. It just looks like I can't do anything with the website besides finding elements, .get and .click (I was also not able to scroll to an element or scroll down).

I even tried this on the https://hammerjs.github.io website to be sure there was an element that tab being suppose to be responding to touch events (the id hitarea), same result.


Solution

  • So maybe my initial question was not really clear, but I really had no clue what I exaclty was looking for either (not that many examples about ruby + appium + touch action in combination with tests on Android + Chrome)

    So I tried the touch_action ruby gem. Unfortunatelly this was not what I was looking for. Maybe I'm doing something basic wrong, but I could not get it to work with the latest watir and selenium-webdriver.

    Then I tried appium_lib which gave me a bit of a headacke since I saw so many examples (even some good ruby ones), but again I did exactly the same and it did not seem to work on my machine. The problem with my setup was that the driver was in the CHROMIUM context and Appium::TouchAction .perform can only be done in the NATIVE_APP context. https://discuss.appium.io/t/ruby-appium-touchaction-perform-returns-error-method-has-not-yet-been-implemented/18308 So keep that in mind when using the appium/android driver and you want to use the TouchAction events.