1
votes

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
2
Not likely related to your issue, but Watir-Webdriver is deprecated. It has been replaced by Watir v6.0 or greater. - Justin Ko
Welcome to Stack Overflow. Please read "How to Ask" and the linked pages. SO isn't a discussion list, it's a reference site, like a cookbook or encyclopedia. As such concise questions are preferred over verbose ones; A little personality is great but remember, you're creating a new entry in the book to help others, not writing in a message thread so keep it to the point. Also, salutations, valedictions and signatures are not desirable. - the Tin Man
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 - Emjey
@MrityunjeyanS thanks that is help fo my case.But i put not in hooks.rb i put it on env.rb - Dmitriy Andrienko
@DmitriyAndrienko : Cool! on a side note the best practice is to put it in hooks.rb. env.rb usually should consist the desired capabilities plus server environment codes. :) I have updated the answer. Please accept the answer, if it had helped you in resolving your bug :) Thanks - Emjey

2 Answers

0
votes

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. :)

0
votes

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!!