Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and Selenium: how to stop/pause execution of a test in the browser?

I'm having a hard (but very interesting time) diving into Behavior Driven Development using Cucumber, RSpec, Selenium, and Rails.

I have my setup ready for testing with Selenium, and it's funny to watch Firefox pop up and run automatically through my scenarios. But one thing I'd like to do is pause or stop execution at a certain point, so I can inspect what Selenium sees at a certain point.

I know of the save_and_open_page command, but this only shows me plain HTML without formatting. So maybe there is a stop_execution method or something that stops Selenium without closing the browser?

like image 950
Joshua Muheim Avatar asked Jun 20 '12 07:06

Joshua Muheim


4 Answers

Install pry, then put binding.pry in your test where you want it to pause. When you're done, press Ctrl+D or type exit in the REPL that gets opened to continue execution.

like image 53
Abe Voelker Avatar answered Sep 27 '22 23:09

Abe Voelker


or just:

 visit '/'
 sleep(inspection_time=5)
 visit '/dreamland'
like image 40
ronnie bermejo Avatar answered Sep 28 '22 00:09

ronnie bermejo


All the answers need installing new gems or even setting a sleep which is not the best approach. You can put this line anywhere in you step:

ask "Continue?"

It will stop execution until you enter y (Yes)

So, for example it would look like this:

expect(page).to have_button('Submit')
ask "Continue?"
click_button('Submit')
like image 41
Aleks Avatar answered Sep 27 '22 23:09

Aleks


Use Debugger where you want to stop/pause the execution.

or

In Selenium IDE you can right click on the commands line and you can select Set/Clear Start point to stop/pause the execution.

like image 35
Ranadheer Reddy Avatar answered Sep 28 '22 00:09

Ranadheer Reddy