Search code examples
rubycapybaraappium

Appium-Capybara-ruby running automation on Physical device and some of the capybara function not working


I have setup Appium - Capybara and was able to run automation suites on physical device, but facing issue with few methods

I was able to successfully run Capybara methods like

fill_in field, :with => text
click_button button_text
expect(page).to have_content(text)

But facing issues with below method ( it works on regular chrome on laptop but not on mobile )

page.first(:link, link_text).click

can you please help me to understand if appium capybara supports all the capybara methods or only few of them.

Below is the error message

undefined method `click' for nil:NilClass (NoMethodError)

Solution

  • In the above code, first the link with link_text is being searched on the page. If no link is found then nil is returned. Thus, to make this code work, we need to wait for the link with the link text to appear on the page and then click it. So you can use any one of the below mentioned code before clicking the fink

    1. page.should have_content(link_text)

    2. page.find_link(link_text)

    If the above code doesn't works then you can also try increasing the default wait time as shown below:

    Capybara.default_wait_time = 30
    page.should have_content(link_text)
    page.first(:link, link_text).click
    Capybara.default_wait_time = DEFAULT_WAIT_TIME
    

    DEFAULT_WAIT_TIME for Capybara tests is set in your environment file.

    Hope this helps :)