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
See Question&Answers more detail:os