2
votes

Just wondering, is there a way that I could tell Capybara to click on an element as soon as it's loaded instead of waiting for the entire page to load? I have a step that alone, adds 40 seconds to each test as it's calling a 3rd party service.

The element I want to click on just to progress to the next step is one of the first elements to load on screen.

Seems a waste of test time to have this 40 second wait for every scenario.

I've trawled the net, but can't find a solution.

2

2 Answers

1
votes

When Capybara will first interact with a page is dependent on the driver you're using and how exactly the extra page data is loaded (asynchronously, triggered from a setTimeout, inline, etc). Since you don't seem to really care about the data returned from the 3rd party service you'd probably be much better off using something like puffing-billy which provides a programmable proxy, that works with Capybara, you could use to fake the responses from the service when wanted, and/or block the connection attempts. Another option is to use the blacklists provided by some drivers (obviously depends on which driver you're using with Capybara) to prevent the connections to the 3rd party service from being made.

-1
votes

As far as I know Capybara should be able to automatically wait for elements, so in this example:

page.find("#foo").should have_content("login failed")

it would automatically wait until #foo element appears with login failed text.

The default waiting time should be configurable through Capybara.default_wait_time setting.