run test scripts on three different browsers one after another?

100 views
Skip to first unread message

Ankita@Adslot

unread,
Sep 18, 2013, 11:57:44 PM9/18/13
to watir-...@googlegroups.com
Hi

Just wondering if there is a way I could automate my script to run on three different browsers one after another...

wanted something like

Open Browser1 - firefox
Run script
Close Browser
<output>
Open Browser2 - ie
Run script
Close Browser
<output>
OpenBrowser3- phantomjs
Run script
Close Browser
 <output>


I know we could initiate browser of our choice through command prompt and then run the script but just wondering if there is something which could automate the process rather then running the test manually 3 times with three different browsers?

Dan

unread,
Sep 19, 2013, 9:07:48 AM9/19/13
to watir-...@googlegroups.com
Not sure what framework you're using or whatever, but you can do this pretty easy with a loop.  Below is the basic concept.

require 'watir-webdriver'
browsers = [:firefox,:chrome,:safari].each do |br|
b = Watir::Browser.new br
b.goto("google.com")
puts b.title
b.close
end

Ankita@Adslot

unread,
Sep 19, 2013, 6:47:54 PM9/19/13
to watir-...@googlegroups.com
Hi Dan 

Thanks for your reply. This does work if the script runs without any failure, but, in case any failure happens script stops and does not execute on other browsers.

I wanted something where even if script fails on one browser, it still runs on others to complete the test.

Your help is much appreciated!

Dan

unread,
Sep 20, 2013, 9:08:38 AM9/20/13
to watir-...@googlegroups.com
Not sure what you're considering a failure, but you'll want to use some exception handling in that case.  See below for an example.  :none is not a valid browser so, it'll fail to initialize it, but keep going with some exception handling.

require 'watir-webdriver'
browsers = [:none,:firefox,:chrome,:safari].each do |br|
begin
b = Watir::Browser.new br
b.goto("google.com")
puts b.title
b.close
rescue => e
puts e.message
next
end
end

Oscar Rieken

unread,
Sep 20, 2013, 9:52:33 AM9/20/13
to watir-...@googlegroups.com
To me this doesn't sound like a good test I would probably do something more like


before do
   b = (ENV['BROWSER'] ||= 'firefox').downcase
  @browser = Watir::Browser.new b.to_sym
end

it "has the correct title" do
  @browser.goto "place"
  expect(@browser.title).to eql "something"
end

then just run it with
rspec BROWSER=chrome
rspec BROWSER=ie
rspec 

to me this makes more sense because , sorry if the code doesn't actually work did this from memory 


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dan Franko

unread,
Sep 20, 2013, 9:57:22 AM9/20/13
to watir-...@googlegroups.com
Yeah, that's why I stated I wasn't sure what they were considering a failure.


You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/C9ufcIGfIPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.

Ragavan Ambighananthan

unread,
Sep 20, 2013, 1:34:30 PM9/20/13
to watir-...@googlegroups.com
Ankita

currently i am trying https://github.com/90kts/watirgrid , this is originally developed for the same purpose as yours.

Regards
Ragavan

Dan

unread,
Sep 20, 2013, 2:16:58 PM9/20/13
to watir-...@googlegroups.com
I'm pretty sure watirgrid is dead.  Your'e going to want to look at Grid2 from Selenium.  You don't need the grid just to run across different browsers though.

Mihir Dhandhusaria

unread,
Sep 20, 2013, 4:16:48 PM9/20/13
to watir-...@googlegroups.com
I have a same problem. Please help me to correct it. I have put following code in my hook 

Before do
  browser = [:firefox,:chrome,:safari]
  browser.each do |browser|
  $browser = Watir::Browser.new browser
end
end

When i execute my code it opens all 3 browsers but it never executes my features. 
Is there anything i should be putting in to my hook file to execute my features in each browser one by one


Thanks
Mihir
Mihir Dhandhusaria
516-776-6534


Reply all
Reply to author
Forward
0 new messages