singularity
singularity

Reputation: 593

Cancel page load in Capybara

I am testing a page which contains a pesky iframe which takes a long time to load; however, I'm not testing the iframe itself. If possible, I'd like to be able to run my tests without having to wait for this iframe each time.

One of the following potential solutions should do the trick, but I'm having difficulty either finding documentation or getting any of them to work:

a) Cancel the page load shortly after the request is placed.

b) Simulate an Escape press while the page is loading using send_keys method.

c) Use javascript - page.execute_script("return window.stop();") while the page is loading.

d) Cancel loading of a specific element

How would one send a cancellation request to a loading page or element using Capybara?

Upvotes: 4

Views: 668

Answers (2)

samjewell
samjewell

Reputation: 1178

We were having problems with outstanding network requests (both Ajax and assets) at the end of our integration tests, when all the assertions had been met and the test was over and getting torn down.

So we added execute_script("window.stop();") to our integration_test_helper.rb file, in the teardown block, and it worked very well.

So I'd suggest adding an assertion that can be met before your iframe is fully loaded, and running window.stop() in the teardown of the test.

Upvotes: 1

Thomas R. Koll
Thomas R. Koll

Reputation: 3139

Altnerative here, you could use puffing-billy gem to stub that iframe request.

Upvotes: 0

Related Questions