Selenium 名字的来源

在这里,我还想说一下关于 Selenium 名字的来源,很有意思的 : > : Selenium 的中文名为 “ 硒 ” ,是一种化学元素的名字,它 对 汞 ( Mercury )有天然的解毒作用,实验表明汞暴露水平越高,硒对汞毒性的拮抗作用越明显,所以说硒是汞的克星。大家应该知道 Mercury 测试工具系 列吧( QTP , QC , LR , WR... ),他们功能强大,但却价格不菲,大家对此又爱又恨!故 thoughtworks 特意把他们的 Web 开源测试工具命 名为 Selenium ,以此帮助大家脱离汞毒。

产品类别

Selenium IDE

一个用于构造测试脚本的原型工具。它是一个Firefox插件,并且提供了一个易于使用的开发自动化测试的接口。Selenium IDE有一个录制功能,可以记录用户执行的动作,然后可以导出它们作可重用的脚本

Remote Control

Selenium RC是最重要的Seleniumx项目,在WebDriver/Selenium合并产生Selenium 2

WebDriver

Selenium 2是该项目的未来方向,和对Selenium工具包的最新的增加物。

Grid

如果你必须运行你的测试集在多个环境,你可以有不同的远程机器的支持和运行你的测试在同一时间在不同的远程机器上。在任何一种情形下,Selenium都将充分利用并行处理,极大地改善运行你的测试所花费的时间。

浏览器支持

官方文档 http://docs.seleniumhq.org/docs/01_introducing_selenium.jsp#supported-browsers-and-platforms

实战操作

准备

IE Chrome的Driver安装和准备

https://code.google.com/p/selenium/wiki/ChromeDriver

https://code.google.com/p/selenium/wiki/InternetExplorerDriver

RemoteControl的不同浏览器Java代码

package base;

import org.openqa.selenium.*;

import org.openqa.selenium.ie.*;

import org.openqa.selenium.remote.*;

import static org.testng.Assert.*;

import org.testng.annotations.*;

import com.thoughtworks.selenium.Selenium;

import java.io.*;

import java.net.*;

public class BaseRC {

protected Selenium selenium;

private WebDriver driver = null;

private StringBuffer verificationErrors = new StringBuffer();

@Parameters({ "platform", "browser", "version", "url" })

@BeforeTest(alwaysRun = true)

public void setup(String platform, String browser, String version,

String url) throws MalformedURLException, IOException {

DesiredCapabilities caps = null;

// Browsers

if (browser.equalsIgnoreCase("Internet Explorer")) {

System.setProperty("webdriver.ie.driver",

"c:\\test\\IEDriverServer.exe");

caps = DesiredCapabilities.internetExplorer();

// IE安全设置

caps.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,

true);

// browser zoom level must be set to 100%

} else if (browser.equalsIgnoreCase("Firefox")) {

System.setProperty("webdriver.firefox.bin",

"C:\\test\\Firefox4\\firefox.exe");

caps = DesiredCapabilities.firefox();

} else if (browser.equalsIgnoreCase("chrome")) {

System.setProperty("webdriver.chrome.driver",

"c:\\test\\chromedriver.exe");

caps = DesiredCapabilities.chrome();

caps.setCapability(

"chrome.binary",

"C:\\test\\Chrome31\\chrome.exe");

} else if (browser.equalsIgnoreCase("iPad"))

caps = DesiredCapabilities.ipad();

else if (browser.equalsIgnoreCase("Android"))

caps = DesiredCapabilities.android();

// Platforms

if (platform.equalsIgnoreCase("Windows"))

caps.setPlatform(org.openqa.selenium.Platform.WINDOWS);

else if (platform.equalsIgnoreCase("MAC"))

caps.setPlatform(org.openqa.selenium.Platform.MAC);

else if (platform.equalsIgnoreCase("Andorid"))

caps.setPlatform(org.openqa.selenium.Platform.ANDROID);

// Version

caps.setVersion(version);

driver = new RemoteWebDriver(new URL(

"http://localhost:4444/wd/hub"), caps);

selenium = new WebDriverBackedSelenium(driver, url);

}

@AfterTest

public void afterTest() {

// Close the browser

driver.quit();

selenium.stop();

String verificationErrorString = verificationErrors.toString();

if (!"".equals(verificationErrorString)) {

fail(verificationErrorString);

}

}

}

WebDriver的不同浏览器Java代码

package base;

import org.openqa.selenium.*;

import org.openqa.selenium.firefox.*;

import org.openqa.selenium.ie.*;

import org.openqa.selenium.chrome.*;

import org.openqa.selenium.remote.*;

import org.openqa.selenium.support.ui.ExpectedCondition;

import org.openqa.selenium.support.ui.WebDriverWait;

import static org.testng.Assert.*;

import org.testng.annotations.*;

import java.io.*;

import java.net.*;

public class BaseWebDriver {

protected WebDriver driver = null;

private StringBuffer verificationErrors = new StringBuffer();

@Parameters({ "platform", "browser", "version", "url" })

@BeforeTest(alwaysRun = true)

public void setup(String platform, String browser, String version,

String url) throws MalformedURLException, IOException {

DesiredCapabilities caps = null;

// Browsers

if (browser.equalsIgnoreCase("Internet Explorer")) {

System.setProperty("webdriver.ie.driver",

"c:\\test\\IEDriverServer.exe");

caps = DesiredCapabilities.internetExplorer();

// IE安全设置

caps.setCapability(

InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,

true);

// browser zoom level must be set to 100%

} else if (browser.equalsIgnoreCase("Firefox")) {

System.setProperty("webdriver.firefox.bin",

"C:\\test\\Firefox4\\firefox.exe");

caps = DesiredCapabilities.firefox();

} else if (browser.equalsIgnoreCase("chrome")) {

System.setProperty("webdriver.chrome.driver",

"c:\\test\\chromedriver.exe");

caps = DesiredCapabilities.chrome();

caps.setCapability(

"chrome.binary",

"C:\\test\\Chrome31\\chrome.exe");

} else if (browser.equalsIgnoreCase("iPad"))

caps = DesiredCapabilities.ipad();

else if (browser.equalsIgnoreCase("Android"))

caps = DesiredCapabilities.android();

// Platforms

if (platform.equalsIgnoreCase("Windows"))

caps.setPlatform(org.openqa.selenium.Platform.WINDOWS);

else if (platform.equalsIgnoreCase("MAC"))

caps.setPlatform(org.openqa.selenium.Platform.MAC);

else if (platform.equalsIgnoreCase("Andorid"))

caps.setPlatform(org.openqa.selenium.Platform.ANDROID);

// Version

caps.setVersion(version);

driver = new RemoteWebDriver(new URL(

"http://localhost:4444/wd/hub"), caps);

driver.get(url);

//

WebDriverWait wait = new WebDriverWait(driver, 10);

wait.until(new ExpectedCondition<WebElement>() {

@Override

public WebElement apply(WebDriver d) {

return d.findElement(By.id("login"));

}

});

}

/* @Test(description = "TestDemo")

public void testDemo() throws InterruptedException {

// Sleep until the div we want is visible or 5 seconds is over

long end = System.currentTimeMillis() + 5000;

while (System.currentTimeMillis() < end) {

WebElement resultsDiv = driver.findElement(By.id("container"));

// If results have been returned, the results are displayed in a

// drop down.

if (resultsDiv.isDisplayed()) {

break;

}

}

}*/

@AfterTest

public void afterTest() {

// Close the browser

driver.quit();

//driver.close();

String verificationErrorString = verificationErrors.toString();

if (!"".equals(verificationErrorString)) {

fail(verificationErrorString);

}

}

}

Grid下的不同浏览器运行脚本

总控运行

rem  http://localhost:4444/grid/console 可以查看hub总控的信息

java -jar selenium-server-standalone-2.35.0.jar -role hub -port 4444 -nodeTimeout 600

各种浏览器运行的脚本

参数设置相同的部分[IP RC/WD运行模式]

@echo off

set a=0

for %%a in (%*) do set /a a+=1

echo "%a% argc"

Rem 可变的设置

set PORT=8902

if %a%==1 (

if "%1%"=="" (

set IP="localhost"

) else (

set IP=%1%

)

set MODE="webdriver"

) else (

if "%1%"=="" (

set IP="localhost"

) else (

set IP=%1%

)

if "%2%"=="rc" (

set MODE="node"

set PORT=9902

) else (

set MODE="webdriver"

)

)

echo %IP% %MODE%

不同浏览器的运行参数

java -Dwebdriver.chrome.driver="c:\test\chromedriver.exe" -jar selenium-server-standalone-2.35.0.jar -role %MODE% -hubHost %IP% -port %PORT% -timeout 20000 -browser "browserName=chrome,version=31,maxInstances=2,platform=WINDOWS,chrome.binary=C:\test\Chrome31\chrome.exe"

rem java -jar selenium-server-standalone-2.35.0.jar -h 可以查看帮助参数

rem !!! -browser参数中,逗号之间不要有空格

java -jar selenium-server-standalone-2.35.0.jar -role %MODE% -hubHost %IP% -port %PORT% -timeout 20000 -browser "browserName=firefox,version=4,maxInstances=1,platform=WINDOWS,firefox_binary=C:\test\Firefox4\firefox.exe"

java -Dwebdriver.ie.driver="c:\test\IEDriverServer.exe" -jar selenium-server-standalone-2.35.0.jar -role %MODE% -hubHost %IP% -port %PORT% -timeout 20000 -browser "browserName=internet explorer,version=8,maxInstances=1,platform=WINDOWS"

参考

v 零成本实现Web自动化测试-基于Selenium和Bromine 4407693.2230619944

v Selenium测试实践-基于电子商务平台 关春银等

v Selenium Testing Tools Cookbook

Over 90 recipes to build, maintain, and improve test automation with Selenium WebDriver Unmesh Gundecha

v webdriver文档

v Selenium私房菜(新手入门教程)

http://seleniumhq.org/

http://www.compendiumdev.co.uk/selenium

http://tech.it168.com/a2013/0906/1530/000001530755_all.shtml

https://code.google.com/p/selenium/downloads/list

v Selenium IDE + YSlow +Showslow 实现页面性能评估自动化,如果需要评估页面的性能,http://www.webpagetest.org/ 参考这个webpagetest工具更完善,可以本地安装,开源软件

Web自动化测试 Selenium 1/3的更多相关文章

  1. Web自动化测试Selenium 学习笔记(一)

    1.Web自动化测试简介自动化基础:自动化用例编写.Selenium优势及原理.自动化环境搭建Selenium基础:常见8大元素定位(表格).常见元素处理.下拉框元素处理.不同窗口切换.元素进阶.元素 ...

  2. web 自动化测试 selenium基础到应用(目录)

    第一章   自动化测试前提及整体介绍 1-1功能测试和自动化测试的区别 1-2自动化测试流程有哪些 1-3自动化测试用例和手工用例的区别 1-4 自动化测试用例编写 1-5 selenium的优势以及 ...

  3. web自动化测试—selenium操作游览器属性

    # coding=utf-8'''web游览器属性: 页面最大化 maximize_window() 获取当前页面地址 current_url 代码 page_source title title 后 ...

  4. web自动化测试-selenium多表单切换

    一.概述 1.在web应用中会经常遇到frame/iframe表单嵌套页面的应用 2.WebDriver只能在一个页面上对元素进行识别与定位 3.对于frame/iframe表单内嵌的页面上元素无法识 ...

  5. Web自动化测试—— Selenium+Python Windows环境搭建

    环境搭建前的准备: 1.到Python官网下载Python安装包:https://www.python.org/ 如果不能访问,可以试试下面的解决办法: a).安装VPN网络连接工具,推荐用Green ...

  6. Web自动化测试 Selenium 3/3 https的配置

    Https的信任问题处理 具体步骤如下(以demo为例) 1) ./ca.sh : 使用默认的服务器192.168.1.1的证书 ./ca.sh IP : 使用IP设置的证书 2) 以上运行后把 ge ...

  7. Web自动化测试 Selenium 2/3

    TesNG和Selenium集成使用 TestNG 是一个设计用来简化广泛的测试需求的测试框架,从单元测试(隔 离测试一个类)到集成测试(测试由有多个类多个包甚至多个外部框架组成的整 个系统,例如运用 ...

  8. web自动化测试---selenium分布式测试

    使用selenium框架还可以进行分布式测试,操作如下: 准备俩台PC:A和B,ip分别为IP_A和IP_B 下载最新的selenium-standalone的jar包,可以到下面地址下载各版本的包: ...

  9. web自动化测试—selenium游览器多窗口操作

    # coding=utf-8'''web游览器多窗口操作: 获取当前窗口句柄 current_window_handle 获取所有窗口句柄 window_handles 切换窗口 switch_to_ ...

随机推荐

  1. tiltShift.js - CSS3 滤镜实现移轴镜头效果

    tiltShift.js 是一款很棒的 jQuery 插件,使用 CSS3 图片滤镜来实现照片的移轴镜头效果.使用非常简单,使用 data 属性配置参数.温馨提示:为保证最佳的效果,请在 IE10+. ...

  2. Windows下elasticsearch插入数据报错!

    按照官方文档操作,但是windows下有些不同,它不认识单引号',因此如果这样操作,就会报错: C:\Users\neusoft>curl localhost:9200/b1/b2/1 -d { ...

  3. Lucene查询语法详解

    Lucene查询 Lucene查询语法以可读的方式书写,然后使用JavaCC进行词法转换,转换成机器可识别的查询. 下面着重介绍下Lucene支持的查询: Terms词语查询 词语搜索,支持 单词 和 ...

  4. 索引深入浅出(3/10):聚集索引的B树结构

    在SQL Server里,有2种表是以存储为基础的.有聚集索引的表叫聚集表,没有聚集索引的表叫堆表.在上一篇文章,我们讨论了堆表的特性和存储结构.在这篇文章里,我们来看下聚集表. 有聚集索引的表叫聚集 ...

  5. [Asp.net 5] Configuration-新一代的配置文件(ConfigurationSource的多种实现)

    关于配置文件的目录:[Asp.net 5] Configuration-新一代的配置文件 在前面我们介绍了,系统中用IConfigurationSource表示不同配置文件的来源,起到读取.设置.加载 ...

  6. ASP.NET Core 开发-缓存(Caching)

    ASP.NET Core 缓存Caching,.NET Core 中为我们提供了Caching 的组件. 目前Caching 组件提供了三种存储方式. Memory Redis SqlServer 学 ...

  7. C# ACCESS数据库操作类

    这个是针对ACCESS数据库操作的类,同样也是从SQLHELPER提取而来,分页程序的调用可以参考MSSQL那个类的调用,差不多的,只是提取所有记录的数量的时候有多一个参数,这个需要注意一下! usi ...

  8. Oracle 数据库 基础学习 (一) SQL基本知识

    Oracle 从零开始,不知所措.要掌握一种技能,最好的方式是先学会怎么使用它,然后再深入学习,先有样子,再有技术.   一,什么是数据库? 为什么需要数据库? 数据库实质上是一个信息的列表,或者是一 ...

  9. C# Winform反序列化复杂json字符串

    最近接的私单是一个CS项目,里面所有的操作都是通过调用API接口来进行的. 接口详细说明 协议:https  请求方式:post  https://xx.xxx.net/app/clients 提交j ...

  10. spring MVC @Resource不支持Lazy加载

    今天迁一系统时发现有个bean使用@Resource注入了另外一个bean,这个被注入的bean是将被deprecated的类,而且只有一两个功能使用到,为了先调整进行测试,增加了@Lazy注解,启动 ...