醉里乾坤大,壶中日月长

Use Python to Drive Selenium RC(转)

上一篇 / 下一篇  2010-02-25 10:13:35 / 个人分类:应用配置

转自:http://www.cnblogs.com/oscarxie/archive/2008/07/20/1247004.html

Selenium RC支持多种编程语言驱动客户端浏览器,这里主要介绍使用Python在Windows下驱动Selenium RC。Python是一种面向对象的解释性的计算机程序设计语言。

1、准备工作

下载Java:目前是1.6 update7,下载地址:http://www.java.com/zh_CN/

下载Python:目前稳定版本为2.5.2,下载地址:http://www.python.org/download/,Python的相关信息参见:http://www.python.org/

下载Selenium RC:目前是1.0 Beta1版本,下载地址:http://selenium-rc.openqa.org/download.html,Selenium RC相关信息参见:http://selenium-rc.openqa.org/

2、开始运行

  • 首先启动Selenium Server,把下载的Selenium RC解压后,会有一个selenium-server-1.0-beta-1的文件夹,就是Selenium Server的存放目录,通过命令行Java -jar selenium-server.jar来启动Selenium Server端的服务,

  • 以在Google上搜索Hello World为例,Python的脚本如下:

"*firefox"是指支持的浏览器或是通过Selenium RC调用的浏览器,Selenium支持以下的浏览器类型,

Supported browsers include:
*iexplore
*konqueror
*firefox
*mock
*pifirefox
*piiexplore
*chrome
*safari
*opera
*iehta
*custom

在这里,仅使用*iexplore或*firefox则表示浏览器安装在默认的路径,即IE安装在"C:\Program Files\Internet Explorer\iexplore.exe",Firefox安装在"C:\Program Files\Mozilla Firefox\firefox.exe"。如果不是安装在默认的路径,需要指明浏览器安装的地址,如:"*firefox D:\Program Files\Mozilla Firefox\\firefox.exe"。

"def tearDown(self):
   self.selenium.stop()"

这段表示浏览器运行结束后直接关闭浏览器,这里可以注释掉。

  • 首先,使用IE为浏览器运行一次,代码如下:

 点击Python IDE上的Run菜单下拉中的Run Module或是快捷键F5,开始运行Python代码。通过Selenium直接调用IE浏览器进行客户端运行。

同时命令行窗口显示Selenium Server进行的每个步骤操作

 

  • 接下来使用Firefox作为浏览器进行访问

修改代码,*iexplore"修改为"*custom D:\Program Files\Mozilla Firefox\\firefox.exe",因为我电脑上的Firefox为3.0版本,目前Selenium RC不支持此版本,不管是使用"*chrome"还是"*firefox",都无法把Firefox调出;但是如果你机器上使用的Firefox是低于 3.0版本,那么可以直接使用"*chrome"这个参数。

在运行之前,需要将Firefox中的代理设置成和Selenium Server一致,Localhost,端口为4444。

 

对于其他的浏览器只需要相应的修改参数为如*safari或*opera等,就能调用访问,实现一个多浏览器的兼容性测试

其他相关文章

Running Selenium in Python Driven Mode

http://agiletesting.blogspot.com/2006/01/running-s...

Web app testing with Python part 1: MaxQ

http://agiletesting.blogspot.com/2005/02/web-app-testing-with-python-part-1.html

Web app testing with Python part 2: Selenium and Twisted

http://agiletesting.blogspot.com/2005/03/web-app-testing-with-python-part-2.html

OscarXie.net

关注质量与体验——电子商务与自动化测试
http://www.cnblogs.com/oscarxie/


TAG:

 

评分:0

我来说两句

日历

« 2024-03-25  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 72660
  • 日志数: 106
  • 建立时间: 2009-06-05
  • 更新时间: 2011-09-09

RSS订阅

Open Toolbar