交流:python开发自动化测试群291184506 PythonJava单元白盒测试群144081101

快速入门

Selenium是一个简便的Web应用软件测试框架。Selenium的组件Selenium IDE支持录制/回放。它还支持Python,Java,C#,javascript等语言。支持Windows,Linux和Macintosh。它是 开源软件,根据Apache2.0许可证发布的,并可以下载并无偿使用。

 

历史

Selenium来源于由杰森·哈金斯 (Jason Huggins)在2004年在ThoughtWorks的开发内部工具,后面有ThoughtWorks的其他程序员和测试人员在 ThoughtWorks加入。后来Paul Hammant加入开发了’Selenium Remote Control’ (RC)并开源。

2005年Dan Fabulich和Nelson Sproul在Pat Lightbody的帮助下给Selenium-RC做了一些补丁。同时ThoughtWorks在Huggins和Hammant代表的情况下组建了Selenium委员会。

2007 年哈金斯和Jennifer Bevan等加盟谷歌。他继续Selenium RC的开发和稳定。与此同时,西蒙·斯图尔特(Simon Stewart)在ThoughtWorks开发出了卓越的浏览器自动化工具webdriver。2009年在谷歌测试自动化大会上决定合并两个项目,新 项目叫Selenium WebDriver,即Selenium 2.0。

2008年,ThoughtWorks的Philippe Hanrigou开发了’Selenium Grid’,支持同时在任意数量的本地或远程系统执行多个Selenium测试,从而减少测试执行时间。Selenium Grid提供类似谷歌内部Selenium RC云项目的功能,但是它是开源的。Pat Lightbody也开发了一个类似的私有云:’HostedQA’,并卖给了Gomez公司。

当时有个类似的软件叫Mercury,及汞,哈金斯就取名为硒,可以通过服用硒补充剂治愈汞中毒。

 

组件

支持浏览器: Firefox、Internet        Explorer、Google Chrome、Safari和Opera。

支持操作系统:Linux, Windows和Mac OS X。

  • Selenium IDE

Selenium IDE是Selenium测试完整的集成开发环境(IDE)。它是Firefox插件,并允许录制,编辑和调试。这是以前被称为Selenium Recorder,最初是由Shinya Kasatani开发并于2006年捐赠给Selenium。

脚本会自动录制,可以事后编辑,编辑时可以自动完成并快速移动命令。脚本记录在Selenese的(Selenium特殊的测试脚本语言)。Selenese可以在浏览器中执行操作命令(如点击链接,选择选项),并从网页中检索数据。

  • Selenium client API

目前支持Python, Java,C#,Ruby。

  • Selenium Remote Control(webdriver已经弃用)

Selenium Remote Control (RC)是Java编写的服务,通过HTTP接收浏览器的命令(类似代理服务器)。RC支持多种编程语言对Web应用进行测试,方便集成进语言的单元测试 框架。支持PHP,Python和Ruby,.NET,Perl和Java客户端驱动程序。java驱动通过Rhino engine支持JavaScript。一个端口只支持一个实例,但是Java/PHP中一个端口可以支持多个实例。RC来源于Paul Hammant和Jason。

Selenium Remote Control来源于Paul Hammant的Driven Selenium或Selenium B。最初的版本直接在编程语言中启动进程和浏览器交互,Selenese在各种语言中实现。Dan Fabulich和Nelson Sproul在Pat Lightbody的帮助下改进后,测试脚本和和浏览器之间增加了守护进程,这样就可以驱动远程浏览器,并只需要维护一套Selenese语言。2006 年RC完全替代Driven Selenium。RC和Driven Selenium浏览器模式是响应/请求,即Comet。

Selenium 2发布时,已经建议用webdriver替代RC。

  • Selenium WebDriver:

Selenium WebDriver是RC的替代。它接受命令(Selenese或者API),并发送给浏览器。调用特定浏览器的驱动,发送命令到浏览器,并获取结果。多 数浏览器驱动启动和访问浏览器应用程序(如Firefox或Internet Explorer);另外还有浏览器的HtmlUnit驱动程序,它用模拟使用浏览器。

Selenium WebDrive不需要特殊的服务器来执行测试。webdriver直接启动浏览器实例并控制它。Selenium Grid可以用于的webdriver执行远程测试。

2012 年初,Simon Stewart(webdriver的发明者,当时在google工作,现在在Facebook)和Mozilla的David Burns与W3C协商将WebDriver作为互联网标准。2013年初草案发布,Selenium-Webdriver为参考实现。目前 Selenium-WebDriver在Python和Ruby,Java和C#有完整的支持。

  • Selenium Grid(Selenium standalone server)

Selenium Grid是允许在远程机器上运行的Web浏览器实例的服务。Selenium Grid允许运行测试在多台计算机上并行,以及管理的不同版本的浏览器和浏览器配置。甚至支持移动操作系统:Android和Apple iOS。

 

快速入门

Selenium WebDriver python client可以访问Selenium WebDriver和Selenium standalone server,开发人员:David        Burns,        Adam Goucher, Maik Röder,Jason        Huggins, Luke        Semerau, Miki Tebeka和Eric Allenin。支持python版本2.6, 2.7, 3.2和3.3。

安装:

1 pip install U selenium

  • 文档
    • API文档
    • 官方文档
    • Selenium Wiki

需要选择一个合适IDE,要求如下:

  • 代码完成和智能提示的图形化代码编辑器
  • 函数和类的代码浏览器
  • 语法高亮
  • 项目管理
  • 代码模板
  • 单元测试和调试
  • 源代码控制支持

推荐:WingIDE,PyCharm,PyDev Eclipse plugin,PyScripter。相关下载地址如下:

  • WingIDE
  • pycharm
  • Eclipse
  • PyDev安装教程
  • PyDev官网
  • PyScripter

实例1:在网站python自动化测试上面寻找webdriver相关的页面,并输出相关的网址:

注意:本实例因为http://automationtesting.vipsinaapp.com及http://automationtesting.sinaapp.com已经因为新浪收费原因关闭匿名用户查询,已经不能执行。

12345678910111213141516171819202122232425262728293031323334 #!/usr/bin/env python# encoding: utf-8import time from selenium import webdriver # create a new Firefox sessiondriver = webdriver.Firefox()driver.implicitly_wait(30)driver.maximize_window() # navigate to the application home pagedriver.get(\”http://automationtesting.sinaapp.com/\”) # get the search textboxsearch_field = driver.find_element_by_name(\”q\”)search_field.clear() # enter search keyword and submitsearch_field.send_keys(\”webdriver\”)search_field.submit() time.sleep(6)products = driver.find_elements_by_xpath(\”//a[@class=\’searchable\’]\”)# get the number of anchor elements foundprint \”Found \” + str(len(products)) + \” pages:\” # iterate through each anchor element and# print the text that is name of the productfor product in products:    print product.get_attribute(\’href\’) # close the browser windowdriver.quit()

selenium.webdriver实现了浏览器驱动类,涉及 Firefox, Chrome, Internet Explorer,        Safari等浏览器及用于测试远程机器的类RemoteWebDriver。

driver.implicitly_wait(30)表示最多等待页面打开的时间为30秒。

执行结果:

123 Found 2 pages:http://automationtesting.sinaapp.com/blog/python_selenium1http://automationtesting.sinaapp.com/blog/appium

实例2打开网址,搜索产品,并列出产品名。实例的网站为:magentocommerce,代码下载地址:learnsewithpython。

注意:上面演示的网址可能需要翻墙

1234567891011121314151617181920212223242526272829303132 from selenium import webdriver޶。Selenium的组件Selenium IDE支持录制/回放。它还支持Python,Java,C#,javascript等语言。支持Windows,Linux和Macintosh。它是 开源软件,根据Apache2.0许可证发布的,并可以下载并无偿使用。

 

历史

Selenium来源于由杰森·哈金斯 (Jason Huggins)在2004年在ThoughtWorks的开发内部工具,后面有ThoughtWorks的其他程序员和测试人员在 ThoughtWorks加入。后来Paul Hammant加入开发了’Selenium Remote Control’ (RC)并开源。

2005年Dan Fabulich和Nelson Sproul在Pat Lightbody的帮助下给Selenium-RC做了一些补丁。同时ThoughtWorks在Huggins和Hammant代表的情况下组建了Selenium委员会。

2007 年哈金斯和Jennifer Bevan等加盟谷歌。他继续Selenium RC的开发和稳定。与此同时,西蒙·斯图尔特(Simon Stewart)在ThoughtWorks开发出了卓越的浏览器自动化工具webdriver。2009年在谷歌测试自动化大会上决定合并两个项目,新 项目叫Selenium WebDriver,即Selenium 2.0。

2008年,ThoughtWorks的Philippe Hanrigou开发了’Selenium Grid’,支持同时在任意数量的本地或远程系统执行多个Selenium测试,从而减少测试执行时间。Selenium Grid提供类似谷歌内部Selenium RC云项目的功能,但是它是开源的。Pat Lightbody也开发了一个类似的私有云:’HostedQA’,并卖给了Gomez公司。

当时有个类似的软件叫Mercury,及汞,哈金斯就取名为硒,可以通过服用硒补充剂治愈汞中毒。

 

组件

支持浏览器: Firefox、Internet        Explorer、Google Chrome、Safari和Opera。

支持操作系统:Linux, Windows和Mac OS X。

  • Selenium IDE

Selenium IDE是Selenium测试完整的集成开发环境(IDE)。它是Firefox插件,并允许录制,编辑和调试。这是以前被称为Selenium Recorder,最初是由Shinya Kasatani开发并于2006年捐赠给Selenium。

脚本会自动录制,可以事后编辑,编辑时可以自动完成并快速移动命令。脚本记录在Selenese的(Selenium特殊的测试脚本语言)。Selenese可以在浏览器中执行操作命令(如点击链接,选择选项),并从网页中检索数据。

  • Selenium client API

目前支持Python, Java,C#,Ruby。

  • Selenium Remote Control(webdriver已经弃用)

Selenium Remote Control (RC)是Java编写的服务,通过HTTP接收浏览器的命令(类似代理服务器)。RC支持多种编程语言对Web应用进行测试,方便集成进语言的单元测试 框架。支持PHP,Python和Ruby,.NET,Perl和Java客户端驱动程序。java驱动通过Rhino engine支持JavaScript。一个端口只支持一个实例,但是Java/PHP中一个端口可以支持多个实例。RC来源于Paul Hammant和Jason。

Selenium Remote Control来源于Paul Hammant的Driven Selenium或Selenium B。最初的版本直接在编程语言中启动进程和浏览器交互,Selenese在各种语言中实现。Dan Fabulich和Nelson Sproul在Pat Lightbody的帮助下改进后,测试脚本和和浏览器之间增加了守护进程,这样就可以驱动远程浏览器,并只需要维护一套Selenese语言。2006 年RC完全替代Driven Selenium。RC和Driven Selenium浏览器模式是响应/请求,即Comet。

Selenium 2发布时,已经建议用webdriver替代RC。

  • Selenium WebDriver:

Selenium WebDriver是RC的替代。它接受命令(Selenese或者API),并发送给浏览器。调用特定浏览器的驱动,发送命令到浏览器,并获取结果。多 数浏览器驱动启动和访问浏览器应用程序(如Firefox或Internet Explorer);另外还有浏览器的HtmlUnit驱动程序,它用模拟使用浏览器。

Selenium WebDrive不需要特殊的服务器来执行测试。webdriver直接启动浏览器实例并控制它。Selenium Grid可以用于的webdriver执行远程测试。

2012 年初,Simon Stewart(webdriver的发明者,当时在google工作,现在在Facebook)和Mozilla的David Burns与W3C协商将WebDriver作为互联网标准。2013年初草案发布,Selenium-Webdriver为参考实现。目前 Selenium-WebDriver在Python和Ruby,Java和C#有完整的支持。

  • Selenium Grid(Selenium standalone server)

Selenium Grid是允许在远程机器上运行的Web浏览器实例的服务。Selenium Grid允许运行测试在多台计算机上并行,以及管理的不同版本的浏览器和浏览器配置。甚至支持移动操作系统:Android和Apple iOS。

 

快速入门

Selenium WebDriver python client可以访问Selenium WebDriver和Selenium standalone server,开发人员:David        Burns,        Adam Goucher, Maik Röder,Jason        Huggins, Luke        Semerau, Miki Tebeka和Eric Allenin。支持python版本2.6, 2.7, 3.2和3.3。

安装:

1 pip install U selenium

  • 文档
    • API文档
    • 官方文档
    • Selenium Wiki

需要选择一个合适IDE,要求如下:

  • 代码完成和智能提示的图形化代码编辑器
  • 函数和类的代码浏览器
  • 语法高亮
  • 项目管理
  • 代码模板
  • 单元测试和调试
  • 源代码控制支持

推荐:WingIDE,PyCharm,PyDev Eclipse plugin,PyScripter。相关下载地址如下:

  • WingIDE
  • pycharm
  • Eclipse
  • PyDev安装教程
  • PyDev官网
  • PyScripter

实例1:在网站python自动化测试上面寻找webdriver相关的页面,并输出相关的网址:

注意:本实例因为http://automationtesting.vipsinaapp.com及http://automationtesting.sinaapp.com已经因为新浪收费原因关闭匿名用户查询,已经不能执行。

12345678910111213141516171819202122232425262728293031323334 #!/usr/bin/env python# encoding: utf-8import time from selenium import webdriver # create a new Firefox sessiondriver = webdriver.Firefox()driver.implicitly_wait(30)driver.maximize_window() # navigate to the application home pagedriver.get(\”http://automationtesting.sinaapp.com/\”) # get the search textboxsearch_field = driver.find_element_by_name(\”q\”)search_field.clear() # enter search keyword and submitsearch_field.send_keys(\”webdriver\”)search_field.submit() time.sleep(6)products = driver.find_elements_by_xpath(\”//a[@class=\’searchable\’]\”)# get the number of anchor elements foundprint \”Found \” + str(len(products)) + \” pages:\” # iterate through each anchor element and# print the text that is name of the productfor product in products:    print product.get_attribute(\’href\’) # close the browser windowdriver.quit()

selenium.webdriver实现了浏览器驱动类,涉及 Firefox, Chrome, Internet Explorer,        Safari等浏览器及用于测试远程机器的类RemoteWebDriver。

driver.implicitly_wait(30)表示最多等待页面打开的时间为30秒。

执行结果:

123 Found 2 pages:http://automationtesting.sinaapp.com/blog/python_selenium1http://automationtesting.sinaapp.com/blog/appium

实例2打开网址,搜索产品,并列出产品名。实例的网站为:magentocommerce,代码下载地址:learnsewithpython。

注意:上面演示的网址可能需要翻墙

123456789101112131415161718