如何防止Watir自动关闭Firefox? [英] How do I prevent Watir from auto closing firefox?

查看:146
本文介绍了如何防止Watir自动关闭Firefox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby和Watir自动化测试用例。我的一个方法是打开Web浏览器,但是一旦我的脚本离开了打开浏览器方法并转到下一个方法(在浏览器中填写表单),浏览器就会自动关闭。当我使用IE浏览器自动运行时,它将不会关闭,直到它碰到IE.close语句,但是随着Firefox的自动关闭。有什么办法可以避免这种情况?



代码:

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

def openbrowser
$ user =user
$ pass = 密码

ff = Watir :: Browser.new:firefox
ff.gotohttp://< some website>
ff.text_field(:name,username)。set($ user)
ff.text_field(:name,password)。set($ pass)
ff.button :value,Sign In)。点击
ff.link(:xpath =>html / body / div [1] / div [2] / a [1]) 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

#运行程序
openbrowser


解决方案

我试图运行这段代码在NetBeans中,所以这种行为可能只是特定于该编辑器。



有两个原因,我发现它关闭,首先是当有一个错误代码,一旦抛出异常,浏览器就会关闭。其次,如果没有建立睡眠,浏览器会在程序结束时关闭。


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

解决方案

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.

这篇关于如何防止Watir自动关闭Firefox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆