自动化 Firefox 和 Chrome 浏览器 [英] Automating Firefox and Chrome browsers

查看:35
本文介绍了自动化 Firefox 和 Chrome 浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从外部应用程序/进程自动化几个浏览器的方法...... Firefox 和 Chrome(目前仅在 Windows 上).

有没有办法按照这些方式做事:

  1. 使用 URL 启动浏览器
  2. 让浏览器加载页面、运行脚本等
  3. 检查 DOM

作为参考,IE 可以使用 InternetExplorer.Application 对象自动化,该对象可以使用以下 javascript 在 shell 脚本中创建,然后我可以遍历 DOM API:

var ie = new ActiveXObject('InternetExplorer.Application');

这里的激励场景是自动化测试.我想加载包含测试代码的页面,并在测试运行后收集结果.

解决方案

http://watin.sourceforge.net/

WatiN 正是这样做的,我相信他们最近添加了 Chrome 支持

2011 年 6 月 22 日更新:目前,WatiN 仅适用于 Firefox 2 和 3,不适用于 Firefiox 4(几乎可以肯定不适用于今天发布的 Firefox 5).此外,在这个答案的时候,据说已经添加了 Chrome 支持,但看起来它从未完全成熟,现在没有在他们的主页上列为支持的平台.

另外值得注意的是,根据我的经验,当我升级到 IE9 时,WatiN 变慢了很多.我在两台不同的机器上看到了这个,降级到 IE8 加速了两台机器上的测试.

我仍然大量使用 WatiN,但现在主要用于行为驱动设计和功能回归测试,这通常不是特定于浏览器的.然后,在 FF 和 Chrome 中手动测试所有进程测试.

2015 年 9 月 22 日更新:Elmue 是对的,看起来 WatiN 不再被开发.我们现在正在研究 Selenium 以进行自动化验收测试:http://www.seleniumhq.org

I am looking for a way to automate couple of browsers... Firefox and Chrome (for now on just Windows) from an external application/process.

Is there a way to do things along these lines:

  1. Start the browser with a URL
  2. Have the browser load up the page, run script etc.
  3. Inspect the DOM

For reference, IE can be automated using the InternetExplorer.Application object which can be created in a shell script using the following javascript, and then I can walk the DOM API:

var ie = new ActiveXObject('InternetExplorer.Application');

The motivating scenario here is automated testing. I'd like to load up the page containing the test code, and gather results after the test has run.

解决方案

http://watin.sourceforge.net/

WatiN does exactly that, and I believe they recently added Chrome support

Update 6/22/2011: Currrently WatiN only works on Firefox 2 and 3, not in Firefiox 4 (and almost certainly not in Firefox 5, which was released today). Also, the time of this answer, Chrome support was supposedly being added, but it looks like that never got fully baked and now is not listed as a suported platform on their home page.

Also worth noting, in my experience WatiN got a lot slower when I upgraded to IE9. I saw this on two different machines, and downgrading to IE8 sped the tests back up on both machines.

I still use WatiN heavily, but now mostly for behavior driven design and functional regression testing, which generally are not browser-specific. Then, manually test in FF and Chrome for all progression testing.

Update 9/22/2015: Elmue is right, it looks like WatiN is no longer being worked on. We've looking into Selenium for our automated acceptance tests now: http://www.seleniumhq.org

这篇关于自动化 Firefox 和 Chrome 浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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