How to use same browser window for automated test using selenium-webdriver (ruby)?

后端 未结 3 687
孤城傲影
孤城傲影 2020-12-18 13:46

I am automating test cases for a website using selenium-webdriver and cucumber in ruby. I need each feature to run in a particular order and using the same browser window. A

3条回答
  •  北海茫月
    2020-12-18 14:32

    I had a similar problem in creating a spec_helper file. I did the following (simplified for locally-run firefox) for my purposes and it works very, very reliably. RSpec will use the same browser window for all it blocks in your _spec.rb file.

    Rspec.configure do |config|
      config.before(:all) do
        @driver = Selenium::WebDriver.for :firefox
      end
    
      config.after(:all) do
        @driver.quit
      end
    end
    

    If you switch to :each instead of :all, you can use a separate browser instance for each assertion block... again, with :each RSpec will give a new browser instance for each it. Both are useful depending on the circumstance.

提交回复
热议问题