简体   繁体   中英

Why does Watir-webdriver open two browsers?

I'm working on website test automation using Cucumber/Ruby/Selenium-Webdriver/Capybara. I want to switch to Watir-Webdriver in combination with Cucumber and Ruby, but I'm struggling with the following:

Every time I run my cucumber test, Watir opens two browser windows, a blank screen to the site I configurated as default, plus another in which the actual test steps are executed.

My 'Support/env.rb' file has:

require 'allure-cucumber'
require 'rspec'
require 'watir-webdriver'

AllureCucumber.configure do |c|
  c.output_dir = 'D:\Test\result'
  c.clean_dir  = true
  c.tms_prefix      = '@PRACTEST--'
  c.issue_prefix    = '@JIRA++'
  c.severity_prefix = '@URGENCY:'
  c.tms_prefix =  ''
end

My steps file begins with:

require 'watir-webdriver'
require 'cucumber'
require 'rspec'
require_relative 'D:\EntelTest\src\PageObject\home_page.rb'

Before  do
  @test = AbstractPage.new(Watir::Browser.new :ff)
  @test.full_size
end

After  do
  @test.quit
end


home_page = nil


When(/^Go to home page$/) do
  home_page  = @test.goToHomePage

end

Can you put these before do and after do in hooks.rb ? In the steps.rb file, just mention the code for your cucumber steps, and before that declare browser = Watir::Browser.new :ff

The best practice is to put it in hooks.rb. env.rb usually should consist the desired capabilities plus server environment codes. :)

What you have put in step file should go in hooks.rb file.

Please install gem called testnow. It will help you to create most standard and easy to use watir-webdriver framework with all pre-configured browsers.

Steps:

1) gem install testnow   
2) testnow watir_cucumber_now

It will as you to install dependecies, enter Y to set it up completely. It will create robust framework with a sample scenario.

Just run the sample scenario with any of the following commands.

rake testnow BROWSER=firefox
rake testnow BROWSER=chrome
rake testnow BROWSER=opera

This will only work provided you have browsers pre-installed and webdriver present in PATH variable.

Please comment for more information.

Hope it helps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM