How to execute a command on an already opened browser from a ruby โ€‹โ€‹file

I use the cucumber structure to test the web application, since I am developing my own scripts, I have to start the browser again and again every time after adding something to my code. My question is: "Is it possible to execute a command on an already opened browser from a ruby โ€‹โ€‹file (.rb)" ?. Which will save me a lot of time. My frameworks are based on cucumber, capybara and selenium.

thanks in advance

0
ruby cucumber
source share
3 answers

Cannot use existing browser with Selenium Webdriver.

However, there are drivers (Capybara-Webkit, Poltergeist, Webdriver HtmlUnitDriver) that are faster and have less startup time than browsers. Perhaps they will be useful to you.

+1
source share

Not sure what you want for sure ... if you need "F5" every time you change something in the user interface, you can use a protective stone.

guard + guard-livereload and the rack insert included in your application automatically updates the browser if you edit "views".

0
source share

I am using the monkey version of Selenium Webdriver that opens the PhantomJS browser between test runs. See this blog post: http://blog.sharetribe.com/2014/04/07/faster-cucumber-startup-keep-phantomjs-browser-open-between-tests/

The trick is to Selenium::WebDriver::PhantomJS::Service.create_process method and tell Selenium Driver to use port 8910 by default, even if it is reserved.

You can add this piece of code to the config / test.rb file:

 class Selenium::WebDriver::PortProber def self.free?(port) true end end class Selenium::WebDriver::PhantomJS::Service def create_process(args) puts "Starting monkey-patched PhantomJS Selenium Webdriver" Struct.new("ChildProcessFake") do def start() end def exited?() true end end.new end end 

Now you can start PhantomJS on the terminal tab:

 phantomjs --webdriver=8910 

And when you start PhantomJS, you can start the cucumber tests.

Obviously this only works for PhantomJS, but something like this can work with other browsers as well.

0
source share

All Articles