How do I prevent Watir from auto closing firefox?
Asked Answered
W

2

-2

I am automating test cases using Ruby and Watir. One of my methods opens the web browser, but as soon as my script leaves the "open browser" method and goes to the next method (filling out forms within the browser), the browser auto closes. When I automate using the IE browser it will not close until it hits the IE.close statement, but with firefox it closes automatically. Is there any way to avoid this?

Code:

require 'rubygems'
require 'watir-webdriver'
require 'rexml/document'

def openbrowser
  $user = "user"
  $pass = "password"

  ff = Watir::Browser.new :firefox
  ff.goto "http://<some website>"
  ff.text_field(:name, "username").set($user)
  ff.text_field(:name, "password").set($pass)
  ff.button(:value,"Sign In").click
  ff.link(:xpath => "html/body/div[1]/div[2]/a[1]").click
  ff.text_field(:name,"userID").set($ID)
  ff.button(:value,"View User").click
  ff.link(:xpath => "html/body/div[1]/ul[1]/li[2]/a").click

  sleep 20
end

# Run Program
openbrowser
Wilburwilburn answered 20/5, 2011 at 14:42 Comment(6)
Mind reading does not work. Show us the code.Chita
I find actually reading the post to be a lot easier than mind reading ;-)Wilburwilburn
I have read your post. You did not provide enough information, and said what information you should provide.Chita
Sorry, newbie mistake, the code has now been added.Wilburwilburn
You learn fast. :) The code you have provided would not close the browser. Please provide more relevant code. Probably anothermethod code.Chita
All code included. This time I attempted to just run the one method with a sleep, and it completely ignores the sleep and shuts down :-(Wilburwilburn
W
2

I was attempting to run this code in NetBeans, so this behavior may just be specific to that editor.

There were two causes I have found for it shutting down, first is when there is an error in the code, the browser will shut down as soon as an exception is thrown. Second, the browser shuts down at the end of the program if there is no sleep established.

Wilburwilburn answered 26/5, 2011 at 19:31 Comment(1)
Does that also happen when you run it from the command line? I'm unable to reproduce that behavior - the browser is left running for me.Naught
T
1

I use the Test Unit class, I open the browser in the setup method and generally close it down in the teardown method, this works for me in IE & Firefox.

More information here, http://wiki.openqa.org/display/WTR/Test+Unit

Teneshatenesmus answered 23/5, 2011 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.