Ricardonacif / touch_action

Ruby gem to add touch gestures (swipe, pinch...) simulation to Watir-Webdriver, Selenium and Capybara.
MIT License
21 stars 6 forks source link

Error while trying to tap. #1

Closed PushkarPahare closed 9 years ago

PushkarPahare commented 9 years ago

Hi There,

I am getting below error while I tried to use the API on Andorid phone thru Appium on Mac box.

/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/response.rb:52:in assert_ok': unknown error: 'script' must be a string (Selenium::WebDriver::Error::UnknownError) (Session info: chrome=41.0.2272.96) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.9.5 x86_64) from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/response.rb:15:ininitialize' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/common.rb:59:in new' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/common.rb:59:increate_response' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/default.rb:66:in request' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/common.rb:40:incall' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:640:in raw_execute' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:618:inexecute' from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:339:in executeScript' from /Library/Ruby/Gems/2.0.0/gems/touch_action-1.2.1/lib/touch_action/selenium-webdriver.rb:20:inwait_for_page_ready_state' from /Library/Ruby/Gems/2.0.0/gems/touch_action-1.2.1/lib/touch_action/selenium-webdriver.rb:12:in `touch_action'

Let me know if I am doing something wrong.

Thanks, Pushkar Pahare

blago commented 9 years ago

I recently used this gem (for Android Chrome browser) after reading an appium issue. https://github.com/appium/appium/issues/3896

Also encountered the 'script' must be a string error. Here's the error in IRB console:

@element.touch_action :swipe Selenium::WebDriver::Error::UnknownError: unknown error: 'script' must be a stri ng (Session info: chrome=41.0.2272.96) (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/response.rb:52:in assert_ok' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/response.rb:15:ininitialize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/common.rb:59:in new' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/common.rb:59:increate_response' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/default.rb:66:in request' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/common.rb:40:incall' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/bridge.rb:640:in raw_execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/bridge.rb:618:inexecute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/bridge.rb:339:in executeScript' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/touch_action-1.2.1/lib/touch_ac tion/selenium-webdriver.rb:20:inwait_for_page_ready_state' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/touch_action-1.2.1/lib/touch_ac tion/selenium-webdriver.rb:12:in touch_action' from (irb):43 from C:/Ruby193/bin/irb:12:in

'

Here's the appium console log:

info: --> POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute_async {"script":"(function( touch_action, $, undefined ) {\n\n touch_action.perform_gesture = function(selenium_finalized_callback) {\n\n YUI().use('node-event-simulate', function(Y) {\n \n var node = Y.one(touch_action.element);\n node.simulateGesture(touch_action.gesture, touch_action.options);\n \n }); \n\n selenium_finalized_callback();\n };\n\n\n}( window.touch_action = window.touch_action || {} ));\n\ntouch_action.element = arguments[0];\n\ntouch_action.gesture = \"flick\";\n\ntouch_action.options = {\"axis\":\"x\",\"distance\":100,\"duration\":500};\n\ntouch_action.perform_gesture(arguments[arguments.length - 1]);","args":[{"ELEMENT":"0.3137048671487719-1"}]} info: [debug] Proxying command to 127.0.0.1:9515 info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute_async","method":"POST","json":{"script":"(function( touch_action, $, undefined ) {\n\n touch_action.perform_gesture = function(selenium_finalized_callback) {\n\n YUI().use('node-event-simulate', function(Y) {\n \n var node = Y.one(touch_action.element);\n node.simulateGesture(touch_action.gesture, touch_action.options);\n \n }); \n\n selenium_finalized_callback();\n };\n\n\n}( window.touch_action = window.touch_action || {} ));\n\ntouch_action.element = arguments[0];\n\ntouch_action.gesture = \"flick\";\n\ntouch_action.options = {\"axis\":\"x\",\"distance\":100,\"duration\":500};\n\ntouch_action.perform_gesture(arguments[arguments.length - 1]);","args":[{"ELEMENT":"0.3137048671487719-1"}]}} info: [debug] Proxied response received with status 200: {"sessionId":"94f11abb2bce64a2565f5f1357b5c3dc","status":0,"value":null} info: <-- POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute_async 200 221.898 ms - 72 info: --> POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute {"script":true,"args":[]} info: [debug] Proxying command to 127.0.0.1:9515 info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute","method":"POST","json":{"script":true,"args":[]}} info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"unknown error: 'script' must be a string\n (Session info: chrome=41.0.2272.96)\n (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64)"},"sessionId":"94f11abb2bce64a2565f5f1357b5c3dc"} info: <-- POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute 500 2.288 ms - 322

Ricardonacif commented 9 years ago

I'm traveling right now so I can't take a closer look, but can you try using Version 1.1.0 or even 1.0.0 and see if the error persists? I might know why this is happening. Let me know if either worked or not please.

On Tuesday, April 7, 2015, Bernard Lago notifications@github.com wrote:

I recently used this gem (for Android Chrome browser) after reading an appium issue. appium/appium#3896 https://github.com/appium/appium/issues/3896

Also encountered the 'script' must be a string error. Here's the error in IRB console:

@element.touch_action :swipe Selenium::WebDriver::Error::UnknownError: unknown error: 'script' must be a stri ng (Session info: chrome=41.0.2272.96) (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/response.rb:52:in assert_ok' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/response.rb:15:ininitialize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/common.rb:59:in new' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/common.rb:59:increate_response' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/default.rb:66:in request' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/http/common.rb:40:incall' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/bridge.rb:640:in raw_execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/bridge.rb:618:inexecute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.45.0/lib/s elenium/webdriver/remote/bridge.rb:339:in executeScript' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/touch_action-1.2.1/lib/touch_ac tion/selenium-webdriver.rb:20:inwait_for_page_ready_state' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/touch_action-1.2.1/lib/touch_ac tion/selenium-webdriver.rb:12:in touch_action' from (irb):43 from C:/Ruby193/bin/irb:12:in'

Here's the appium console log:

info: --> POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute_async {"script":"(function( touch_action, $, undefined ) {\n\n touch_action.perform_gesture = function(selenium_finalized_callback) {\n\n YUI().use('node-event-simulate', function(Y) {\n \n var node = Y.one(touch_action.element);\n node.simulateGesture(touch_action.gesture, touch_action.options);\n \n }); \n\n selenium_finalized_callback();\n };\n\n\n}( window.touch_action = window.touch_action || {} ));\n\ntouch_action.element = arguments[0];\n\ntouch_action.gesture = \"flick\";\n\ntouch_action.options = {\"axis\":\"x\",\"distance\":100,\"duration\":500};\n\ntouch_action.perform_gesture(arguments[arguments.length

  • 1]);","args":[{"ELEMENT":"0.3137048671487719-1"}]} info: [debug] Proxying command to 127.0.0.1:9515 info: [debug] Making http request with opts: {"url":" http://127.0.0.1:9515/wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute_async","method":"POST","json":{"script":"(function( touch_action, $, undefined ) {\n\n touch_action.perform_gesture = function(selenium_finalized_callback) {\n\n YUI().use('node-event-simulate', function(Y) {\n \n var node = Y.one(touch_action.element);\n node.simulateGesture(touch_action.gesture, touch_action.options);\n \n }); \n\n selenium_finalized_callback();\n };\n\n\n}( window.touch_action = window.touch_action || {} ));\n\ntouch_action.element = arguments[0];\n\ntouch_action.gesture = \"flick\";\n\ntouch_action.options = {\"axis\":\"x\",\"distance\":100,\"duration\":500};\n\ntouch_action.perform_gesture(arguments[arguments.length
  • 1]);","args":[{" ELEMENT":"0.3137048671487719-1"}]}} info: [debug] Proxied response received with status 200: {"sessionId":"94f11abb2bce64a2565f5f1357b5c3dc","status":0,"value":null} info: <-- POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute_async 200 221.898 ms - 72 info: --> POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute {"script":true,"args":[]} info: [debug] Proxying command to 127.0.0.1:9515 info: [debug] Making http request with opts: {"url":" http://127.0.0.1:9515/wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute","method":"POST","json":{"script":true,"args":[]} } info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"unknown error: 'script' must be a string\n (Session info: chrome=41.0.2272.96)\n (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64)"},"sessionId":"94f11abb2bce64a2565f5f1357b5c3dc"} info: <-- POST /wd/hub/session/94f11abb2bce64a2565f5f1357b5c3dc/execute 500 2.288 ms - 322

    — Reply to this email directly or view it on GitHub https://github.com/Ricardonacif/touch_action/issues/1#issuecomment-90503274 .

blago commented 9 years ago

It's working with touch_action -v 1.1.0. The element was tapped and page responded.

IRB

=> # element = driver.find_element(:xpath, '//html/body/div/div[3]/ul/li[1]/a') => # element.touch_action(:tap) => nil

APPIUM LOG

info: --> POST /wd/hub/session/09fdfb814c09734b5e90934d39be81d4/element {"using":"xpath","value":"//html/body/div/div[3]/ul/li[1]/a"} info: [debug] Proxying command to 127.0.0.1:9515 info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/09fdfb814c09734b5e90934d39be81d4/element","method":"POST","json":{"using":"xpath","value":"//html/body/div/div[3]/ul/li[1]/a"}} info: [debug] Proxied response received with status 200: {"sessionId":"09fdfb814c09734b5e90934d39be81d4","status":0,"value":{"ELEMENT":"0.402474069269374-10"}} info: <-- POST /wd/hub/session/09fdfb814c09734b5e90934d39be81d4/element 200 49.066 ms - 102 info: --> POST /wd/hub/session/09fdfb814c09734b5e90934d39be81d4/execute {"script":"(function( touch_action, $, undefined ) {\n\n // private property\n var execute_gesture = function() {\n YUI().use('node-event-simulate', function(Y) {\n \n var node = Y.one(touch_action.element);\n node.simulateGesture(touch_action.gesture, touch_action.options);\n \n });\n };\n\n // private method\n function loadYui() { \n\n var head = document.getElementsByTagName('head')[0];\n var script = document.createElement('script');\n script.type = 'text/javascript';\n script.src = \"//yui.yahooapis.com/3.18.1/build/yui/yui-min.js\";\n\n script.onreadystatechange = execute_gesture;\n script.onload = execute_gesture;\n\n head.appendChild(script);\n \n };\n // public method\n touch_action.perform = function() {\n \n if (typeof YUI == 'undefined') {\n loadYui();\n } else {\n execute_gesture();\n };\n\n };\n\n\n}( window.touch_action = window.touch_action || {} ));\n\ntouch_action.element = arguments[0];\n info: [debug] Proxying command to 127.0.0.1:9515 info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/09fdfb814c09734b5e90934d39be81d4/execute","method":"POST","json":{"script":"(function( touch_action, $, undefined ) {\n\n // private property\n var execute_gesture = function() {\n YUI().use('node-event-simulate', function(Y) {\n \n var node = Y.one(touch_action.element);\n node.simulateGesture(touch_action.gesture, touch_action.options);\n \n });\n };\n\n // private method\n function loadYui() { \n\n var head = document.getElementsByTagName('head')[0];\n var script = document.createElement('script');\n script.type = 'text/javascript';\n script.src = \"//yui.yahooapis.com/3.18.1/build/yui/yui-min.js\";\n\n script.onreadystatechange = execute_gesture;\n script.onload = execute_gesture;\n\n head.appendChild(script);\n \n };\n // public method\n touch_action.perform = function() {\n \n if (typeof YUI == 'undefined') {\n loadYui();\n } else {\n execute_gesture();\n };\n\n };\n\n\n}( window.touch_action = window.touch_action || {} ));\n\ntouch_action.element = arguments[0];\n\ntouch_action.gesture = \"tap\";\n\ntouch_action.options = {};\n\ntouch_action.perform();","args":[{"ELEMENT":"0.402474069269374-10"}]}} info: [debug] Proxied response received with status 200: {"sessionId":"09fdfb814c09734b5e90934d39be81d4","status":0,"value":null} info: <-- POST /wd/hub/session/09fdfb814c09734b5e90934d39be81d4/execute 200 93.464 ms - 72

Tried other gestures as well, doubletap worked.

I'm aware that the filed issue relates to 'TAP', but other gestures seems to be not working. i.e. swipe down using element.touch_action(:flick, axis: 'y', distance: 100, duration: 60) did not do anything against the mobile web page. (http://coenraets.org/apps/angular-directory/#/employees)

element = driver.find_element(:xpath, '//html/body/div/div[3]/ul/li[1]/a') => # element.touch_action(:flick, axis: 'y', distance: 500, duration: 60) => nil Am I missing something in this :flick action?

I was able to go to the bottom of the page using: driver.execute_script("arguments[0].scrollIntoView(true);", element_at_the_bottom_of_the_page)

Ricardonacif commented 9 years ago

The flick action won't work as a mobile scroller. It will only work for swiping elements that are specifically listening for touch events. Like this one: http://hammerjs.github.io/

blago commented 9 years ago

Makes sense. Thanks for explaining that.

Tried the available touch_action gestures against this element on that page. element = driver.find_element(:id, 'hitarea')

They all worked with -v 1.1.0 on Android's Chrome browser.

Ricardonacif commented 9 years ago

Awesome, I think I'll rollback the to that version. I did somethings on the code in a hurry to accomplish one other thing, and looks like I messed up.

Ricardonacif commented 9 years ago

Rolledback the code (use 1.3.0). @PushkarPahare can you update the gem now to 1.3.0 and see if it is working?

Ricardonacif commented 9 years ago

@PushkarPahare did it work?