0
votes

I use cucumber framework for testing web application, as i develop my scripts i have to launch the browser again and again every time after adding something to my code. My question is "Is it possible to execute a command on already opened browser from a ruby(.rb ) file" ??. Which will save me a lot of time . My framework is based on cucumber, capybara and selenium webdriver.

Thanks In advance

3

3 Answers

1
votes

It's not possible to use existing browser with Selenium Webdriver.

However, there drivers (Capybara-Webkit, Poltergeist, Webdriver's HtmlUnitDriver) that are faster and have less startup time than browsers. Maybe, they will be good for you.

0
votes

Not sure what you want exactly... if you have to "F5" everytime you change something in the UI-Code, you may consider using the guard gem.

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

0
votes

I've been using a monkey-patched version of Selenium Webdriver, which keeps PhantomJS browser open 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 stub the Selenium::WebDriver::PhantomJS::Service.create_process method and tell the Selenium Driver to use the default port 8910 even though it is reserved.

You can add this piece of code to your 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 in a terminal tab:

phantomjs --webdriver=8910

And when you have PhantomJS running, you can start your Cucumber tests.

Obviously this works only for PhantomJS, but something similar could work with other browsers too.