Watir WebDriver对于用户验证的处理

上一篇 / 下一篇  2013-01-27 16:13:53 / 个人分类:测试

有一些网站,在访问的时候,就会先弹出一个验证窗口,要求你输入用户名和密码。

一般来说,常见的网站都是采用默认的验证方式,也就是说,你只需要在URL里附带user/passwod就行,例如:

require 'watir-webdriver'
b = Watir::Browser.new :firefox
b.goto 'http://admin:password@192.168.0.1'

但是,有些网站采用更严格的验证方式,比如NTLM,这时候需要验证的是proxy。

简单的快速解决方法,就是手工的进入该网站一次,这样验证方式就存在当前的profile里了,对于ff来说,就直接使用默认的profile即可:

require 'watir-webdriver'
b = Watir::Browser.new :firefox, :profile => 'default'
b.goto 'http://192.168.0.1'

当然复杂的也不会太复杂,就安装一个addon就可以解决:

profile = Selenium::WebDriver::Firefox::Profile.from_name 'WatirWebDriver'
profile.add_extension 'autoauth-2.1-fx+fn.xpi'
b = Watir::Browser.new :firefox, :profile => profile
b.goto 'http://192.168.0.1'


总之,基本策略就是:

1. 使用ff的profile manager创建一个profile
2. 把需要的验证信息,加入profile
3. 在测试中,指定使用这个profile
4. 添加AutoAuth插件,一劳永逸

这个方法 目前也就对ff和chrome可用,ie的话,手工配置吧

TAG:

 

评分:0

我来说两句

日历

« 2024-04-28  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 151180
  • 日志数: 185
  • 文件数: 6
  • 建立时间: 2007-08-06
  • 更新时间: 2015-01-06

RSS订阅

Open Toolbar