calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 368 forks source link

It is not possible to input text to a text field in a springboard alert #1420

Open papatr0x opened 4 years ago

papatr0x commented 4 years ago

Currently I am trying to input a password in a textfield placed on a springboard alert. But command keyboard_enter_text() throws with "Keyboard is not visible", however keyboard is present on screen. Auto dismiss springboard alerts is disabled.

I looked into the code and it seems that query for keyboard into docked_keyboard_visible? function fails to get the right value.

The setup used for testing is:

calabash-ios 0.21.10> keyboard_enter_text('password')
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/dismiss-springboard-alerts {:retries=>200, :timeout=>20}
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/dismiss-springboard-alerts {:retries=>200, :timeout=>20}
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/dismiss-springboard-alerts {:retries=>200, :timeout=>20}
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/dismiss-springboard-alerts {:retries=>200, :timeout=>20}
INFO: Embed is not available in this context. Will not embed.
Traceback (most recent call last):
        8: from /Users/ppalma/.rbenv/versions/2.6.3/bin/irb:23:in `<main>'
        7: from /Users/ppalma/.rbenv/versions/2.6.3/bin/irb:23:in `load'
        6: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
        5: from (irb):1
        4: from (irb):2:in `rescue in irb_binding'
        3: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/core.rb:743:in `keyboard_enter_text'
        2: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/keyboard_helpers.rb:89:in `expect_keyboard_visible!'
        1: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/failure_helpers.rb:75:in `screenshot_and_raise'
RuntimeError (Keyboard is not visible)
calabash-ios 0.21.10>
jmoody commented 4 years ago

Try using device_agent.enter_text. Whenever you are interacting with a SpringBoard, use the device_agent APIs.

papatr0x commented 4 years ago

Hi @jmoody, I've tried device_agent.enter_text() , this throws with "RuntimeError (Keyboard must be visible)", however keyboard in on screen.

calabash-ios 0.21.10> device_agent.set_dismiss_springboard_alerts_automatically(false)
DEBUG: HTTP: get http://192.168.102.201:27753/1.0/health {:retries=>1, :timeout=>0.5}
DEBUG: DeviceAgent says, "Calabash is ready and waiting."
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/set-dismiss-springboard-alerts-automatically {:retries=>200, :timeout=>20}
false
calabash-ios 0.21.10> device_agent.enter_text("password")
DEBUG: HTTP: get http://192.168.102.201:27753/1.0/health {:retries=>1, :timeout=>0.5}
DEBUG: DeviceAgent says, "Calabash is ready and waiting."
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/query {:retries=>200, :timeout=>20}
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/dismiss-springboard-alerts {:retries=>200, :timeout=>20}
DEBUG: HTTP: post http://192.168.102.201:27753/1.0/dismiss-springboard-alerts {:retries=>200, :timeout=>20}
INFO: Embed is not available in this context. Will not embed.
Traceback (most recent call last):
        9: from /Users/ppalma/.rbenv/versions/2.6.3/bin/irb:23:in `<main>'
        8: from /Users/ppalma/.rbenv/versions/2.6.3/bin/irb:23:in `load'
        7: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
        6: from (irb):26
        5: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/device_agent.rb:307:in `enter_text'
        4: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/device_agent.rb:467:in `with_screenshot_on_failure'
        3: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/device_agent.rb:471:in `rescue in with_screenshot_on_failure'
        2: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/failure_helpers.rb:88:in `fail'
        1: from /Users/ppalma/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/calabash-cucumber-0.21.10/lib/calabash-cucumber/failure_helpers.rb:75:in `screenshot_and_raise'
RuntimeError (Keyboard must be visible)
calabash-ios 0.21.10>
jmoody commented 4 years ago

Try using the DeviceAgent.iOS http API.

https://github.com/calabash/DeviceAgent.iOS/blob/develop/Server/AutomationActions/Gestures/EnterText.m

POST /1.0/gesture
{
  "gesture" : "enter_text",
  "string" : "<string to type>"
}

Alternatively, use the RunLoop API directly.

I am not allowed to investigate defects in Calabash iOS because it is no longer supported by Microsoft.