artemave
artemave

Reputation: 6946

Hybrid mobile app: how to use css selectors in cucumber tests?

There is a hybrid app (build with steroids) that I can run cukes against via selenium remote webdriver (remote part is appium server) on IOS simulator.

However, I can’t seem to be able to use css selectors in the cukes, only some kind of “native” ones.

For example, if my app is an html with only <p>TEXT</p>, then driver.find_element(:xpath, '//staticText')[:label] will get me TEXT, but is there a way to use css a selector - p - instead?

Perhaps selenium/appium is the not the best kind of setup?

Upvotes: 0

Views: 769

Answers (2)

zliw
zliw

Reputation: 1096

To all people getting here via search machines. Note, that the usage of window operations to change to web view context is outdated since Appium version 1.0. As Selenium-webdriver currently does not support contexts, you should switch to appium_lib.

Using appium_lib with its promote_appium_methods-Function switching contexts is as easy:

set_context('WEBVIEW_1')

Upvotes: 2

artemave
artemave

Reputation: 6946

To use css selectors, the context needs to be switched to webview. Assuming a single page app, that means to switch to window "1":

[1] pry(#<Cucumber::Rails::World>)> driver.window_handles
=> ["1"]
[2] pry(#<Cucumber::Rails::World>)> driver.switch_to.window "1"
=> ""
[3] pry(#<Cucumber::Rails::World>)> driver.find_elements :css, "div"
=> [#<Selenium::WebDriver::Element:0x..fdcd88f550f201750 id="5000">]

Upvotes: 0

Related Questions