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

Web 自动化测试的更多相关文章

  1. web自动化测试中绕开验证码登陆的方式

    web自动化测试中登陆需验证码是很大的一个困扰.现推荐一种简单的避开验证码登陆的方式,先代码进入登录页,人工输入验证码登录后浏览器自动保存cookie,再在新的标签中登录. 具体代码如下: publi ...

  2. Web自动化测试工具调研

    背景 Web自动化测试越来越被重视, 因为现在Web已经是工程化的状态. 如何通过工具测试, 保证Web开发的质量,提升开发效率,是Web工具的诞生的来由. Web测试分为以下几个方面: 1. 界面测 ...

  3. Web自动化测试学习方向(Selenium)

    目前越来越多的人想学自动化测试,认为自动化测试好牛逼.经常在测试交流群里看见有HR发招聘广告说:招初级(功能测试),招中级(性能测试),招高级(自动化测试)...... 我不去讨论他们这个初中高级的说 ...

  4. Web自动化测试 Selenium 1/3

    Selenium 名字的来源 在这里,我还想说一下关于 Selenium 名字的来源,很有意思的 : > : Selenium 的中文名为 “ 硒 ” ,是一种化学元素的名字,它 对 汞 ( M ...

  5. TestNG测试框架在基于Selenium进行的web自动化测试中的应用

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ TestNG+Selenium+Ant TestNG这个测试框架可以很好的和基于Selenium的 ...

  6. 使用 Sahi 实现 Web 自动化测试

    Sahi 是 Tyto Software 旗下的一个基于业务的开源 Web 应用自动化测试工具.Sahi 运行为一个代理服务器,并通过注入 JavaScript 来访问 Web 页面中的元素.Sahi ...

  7. 从手工测试转型web自动化测试继而转型成专门做自动化测试的学习路线。

    在开始之前先自学两个工具商业web自动化测试工具请自学QTP:QTP的学习可以跳过,我是跳过了的.开源web自动化测试工具请自学Selenium:我当年是先学watir(耗时1周),再学seleniu ...

  8. Windows环境搭建Web自动化测试框架Watir

    Windows环境搭建Web自动化测试框架Watir 一.前言     Web自动化测试一直是一个比较迫切的问题,对于现在web开发的敏捷开发,却没有相对应的敏捷测试,故开此主题,一边研究,一边将We ...

  9. Web自动化测试学习点总结

    "大不可量,深不可测"这是出自<韩非子·主道>的一段话.关于自动化测试也是如此,web系统开发完成,测试人员对页面进行测试,寻找bug.这个过程,需要摸索着前进. 什么 ...

  10. 自动化测试(—)Web自动化测试理解

          最近几天,由于工作需要接触Web自动化测试,所以我从网上找的资料,学习了解,然后自己总结汇总的随笔,如文章中有不足的地方,请大家多多指教:或者文章内容与他人相似,望见谅. 手工测试跟自动化 ...

随机推荐

  1. MAC 开启与关闭SIP

    1. 查看SIP状态 在终端中输入csrutil status,就可以看到是enabled还是disabled. 2. 关闭SIP S1  重启MAC,按住cmd+R直到屏幕上出现苹果的标志和进度条, ...

  2. nginx防止DDOS攻击配置

    转自:http://www.escorm.com/archives/452 防御DDOS是一个系统工程,攻击花样多,防御的成本高瓶颈多,防御起来即被动又无奈.DDOS的特点是分布式,针对带宽和服务攻击 ...

  3. Cocos Creator学习笔记

    1.动态加载图片 cc.Class({ extends: cc.Component, properties: { label: { default: null, type: cc.Label }, l ...

  4. [Python设计模式] 第17章 程序中的翻译官——适配器模式

    github地址:https://github.com/cheesezh/python_design_patterns 适配器模式 适配器模式,将一个类的接口转换成客户希望的另外一个接口.Adapte ...

  5. 几种序列化协议(protobuf,xstream,jackjson,jdk,hessian)相关数据对比

    测试结果 序列化数据对比 bytes字节数对比 具体的数字:   protobuf jackson xstream Serializable hessian2 hessian2压缩 hessian1 ...

  6. Python之多线程和多进程

    一.多线程 1.顺序执行单个线程,注意要顺序执行的话,需要用join. #coding=utf-8 from threading import Thread import time def my_co ...

  7. Git把Tag推送到远程仓库

    # 创建附注标签 $ git tag -a v0.1.2 -m “0.1.2版本” 列出标签 $ git tag # 在控制台打印出当前仓库的所有标签 $ git tag -l ‘v0.1.*’ # ...

  8. easyui中combobox 取值

    <input id="cmbstrTrainType" class="easyui-combobox" name="cmbstrTrainTyp ...

  9. 【iCore1S 双核心板_ARM】例程十七:FSMC实验——读写FPGA

    实验现象: 先烧写FPGA程序,再烧写ARM程序,ARM程序烧写完毕后即开始读写RAM测试,测试成功,绿色ARM·LED亮,测试失败,红色ARM·LED闪烁. 核心代码: int main(void) ...

  10. go get fatal: could not read Username for 'https://code.xxx.org': terminal prompts disabled

    用go get下载私有代码库的时候,莫名其妙产生了以下错误,公有代码库没有影响. chenchideMacBook-Pro:~ chenchi$ go get code.xxx.org/adarch/ ...