引自:http://blog.sina.com.cn/s/blog_44e5fca90100hsud.html
1. testNG并发执行测试用例的方法
在配置testNG的test.xml中,通过suit标签的属性可以指定并发执行,例如:
<suite name="My suite" parallel="methods" thread-count="5">
指定每一个测试方法使用单独的线程,总线程数为5
parallel可以为:
methods : 每个method使用一个线程
tests :每个<test>标签中的所有方法使用一个线程
classes : 每个class使用一个线程
2 使用selenium grid
grid的机制是,启动一个hub,然后启动多个remote control,启动remote control时告知hub的位置,这样这些rc就可以注册到hub上,测试程序与hub通讯,当测试被并发地发给hub时,hub会自动将这些测试命令分发给已经注册的rc,rc接到命令后执行测试。
到这里D:\opensource\selenium\selenium-grid-1.0.4\doc\website\download.html下个最新版的selenium grid,里面的文档有详细的使用方法,现在简诉如下:
selenium grid要求安装jdk和ant,其目录下有一build.xml文件,其中定义的主要target如下:
检查配置:ant sanity-check
启动hub:ant launch-hub
其中hub的配置是在grid_configuration.yml文件里,该文件要在classpath的根里
启动后在http://host:port/console可以看到hub当前的状态
启动rc(按默认配置):ant run-demo-in-sequence
启动rc(指定参数):ant -Dport=5555 -Dhost=192.168.1.16 -DhubURL=http://192.168.1.1:4444 launch-remote-control
其中host和port是rc的地址,hubURL是hub的地址
正常启动后,可以在http://host:port/console看到hub中当前注册的rc
Grid 只是提供运行脚本的环境,无法决定脚本以什么样的形式去跑(并行的方式,或者多环境的方式)。脚本以什么样的形式跑,由脚本本身和脚本的runner (一般用junit或者TestNG)的配置所决定.
并行和多环境的是怎么实现的。
第 一,并行。并行很简单。。脚本就是普通的脚本。然后如果你的runner支持并行运行的话。你就配置成并行。那运行起来就是并行的。。目前junit本身 不支持并行,一般都是用TestNG. 只要让TestNG 并行的运行测试,无论你的测试环境是由一个grid拖几个rc组成,还是 单一一个rc组成。。实际上 运行起来 测试就是并行的,唯一的区别是。如果用了grid的话,grid会把并发数量平均分配到不同的rc上去,然后每个rc会启动一个浏览器运行测试。而没有用 grid情况就是同一个rc直接跑多个,就是一个rc直接打开多个浏览器窗口运行多个测试。
第 二,多环境。 说多环境,这里也要澄清一下。 不是说给一个普通的测试脚本,丢给grid就可以自动实现多环境同时测试了。那是完全错误的。。这里需要几点。1. 一个普通脚本能测试一个某一种环境。所以如果你要测试多个环境就需要多个脚本。而这些脚本的区别仅在于setup的时候定义 DefaultSelenium("localhost",4444,"*firefox",Url); 这里。 因此两个测试方法也可以到同一个文件里面。写两个不同的方法,不同的定义DefaultSelenium部分,但调用同样的测试步骤。(就是 selenium.open...开始到selenium.stop...). 这样一个文件下就算包含测试两个不同环境的测试方法了。
2. 让这两个测试方法,并行运行。。那又是testng的事情了。配置testng的suite。不细说。可以查看testng的文档。
3. grid配置的测试的rc环境,里面需要有刚才两个测试方法所需要的环境。
import static com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage.closeSeleniumSession;
import static com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage.session;
import static com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage.startSeleniumSession;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.Selenium;
public class Sample {
private Selenium selenium;
@BeforeMethod
@Parameters({"seleniumHost", "seleniumPort", "browser", "webSite"})
protected void startSession(String seleniumHost, int seleniumPort, String browser, String webSite) throws Exception {
startSeleniumSession(seleniumHost, seleniumPort, browser, webSite);
selenium = session();
selenium.setTimeout("120000");
}
@AfterMethod
protected void closeSession() throws Exception {
closeSeleniumSession();
}
@Test
public void test1() {
selenium.open("/");
selenium.type("q", "test1");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
}
【略】
}
分享到:
相关推荐
Selenium测试吸引人示例项目使用: Selenium WebDriver TestNg 魅力2 Maven执行命令要运行测试并生成魅力报告: mvn clean site -P [singleThreaded,nogrid,grid,parallelSuite]singleThreaded-按顺序执行测试,省略...
selenium grid + TestNG 入门demo selenium grid + TestNG 入门demo
设计模式:具有可加载组件(POC)和AAA的页面对象模型在此框架中使用了以下工具: Java,Selenium,TestNG,Cucumber,确保REST,Gradle,Travis CI,魅力报告,Slack API,SeleniumGrid,WebDriverManager,Faker...
Explore the Selenium grid architecture and build your own grid for browser and mobile devices Use ExtentReports for processing results and SauceLabs for cloud-based test services Unlock the full ...
Users will learn how to design and build a Selenium Grid from scratch to allow the framework to scale and support different browsers, mobile devices, versions, and platforms, and how they can leverage...
Perform cross browser and distributed testing with Selenium Grid Use Actions API for performing various keyboard and mouse actions Who this book is for Selenium WebDriver 3 Practical Guide is for ...
平行Selenium网如何使用Selenium网格对TestNG进行WebDriver并行测试的超简单示例。 根据说明使用TestNG并行运行WebDriver测试将以下内容下载到C:\ Selenium 在网格中心和所有网格节点上 到将运行测试的所有网格节点...
高清扫描版,包含完整书签目录 第1章 初始selenium 第2章 牛刀小试只selenium ide 第3章 selenium玩转页面元素 第4章 初始selenium webdriver 第5章 玩转selenium ...第9章 selenium grid 第10章 selenium的兄弟姐妹
Moving on, the book shows you how to utilize the Advanced User Interactions API, how you can run any JavaScript you need through Selenium, and how to quickly spin up a Selenium Grid using Docker ...
在多个浏览器运行的情况下使用 Selenium Grid 使所有这些工作正常进行。 指示 运行包含的 .bat 脚本以使其运行或使用 Maven 任务“clean test”。 配置和设置 蚀 要使其在常规 Eclipse Kepler 或更高版本上运行,请...
使用Selenium 3.x + Testng + Jenkins + Maven 使用页面对象模型 使用log4j 如何使用: 安装maven配置环境变量 git clone mvn test也可以直接使用jenkins,触发mvn test 使用接口处理不同版本的页面,使用java...
赛琳在Java中启用测试自动化SeLion建立在TestNG和Selenium的基础上,提供了一组功能,可让您在短时间内使用WebDriver并开始运行。 它可以用于测试Web和移动应用程序。 您可以添加为Maven依赖项的客户端模块。 基于...
是Selenium Grid扩展,可使用docker容器动态扩展本地网格。 魅力报告整合 是一种灵活的轻量级多语言测试报告工具,它以简洁的Web报告格式非常简洁地显示了已测试的内容 并行化 该框架可以并行运行多个测试。 进行...
Java +Selenium+ Testng + Maven + PO +多线程+ slf4j + log4j +截图+ rangereports + redis +多浏览器+ h5 +优先级设置+ jenkins + grid平台 框架功能 PO思想模式 多线程 slf4j + log4j日志 错误截图 ranger
现在,您可以使用此存储库将在 Selenium Automation Grid平台上运行的Selenium测试的测试执行结果发送到Calliope分析。 在此存储库中,我们使用TestNG框架运行Selenium测试,该测试在上执行,执行后的测试结果将被推...
基于开源技术Selenium WebDriver、TestNG、Java、Apache POI的简单web测试框架 该框架旨在帮助您快速开始 Web 测试、根据需要进行扩展并避免常见的陷阱。 它只允许您操作浏览器。 主要特点: 使用 Selenium ...
TestNG和Maven的使用也使该项目非常适合CI / CD,可与Jenkins等工具一起使用 该项目使用网站进行编码。 除了自动化项目之外,此存储库还包含一个测试用例表,其中包含“创建新帐户”用例的测试用例。 该文件位于/ ...
这是Web自动化框架,使用Java,Selenium / Webdriver,TestNG和Maven实现。 页面对象模型(POM)用于使代码更具可读性,可维护性和可重用性。 先决条件: Java Maven Selenium / WebDriver TestNg 浏览器(Fire...
这是一个Java Selenium框架,它使用testng,maven,extent report,selenium,java等来完成不同的任务。 项目特色 -支持并行测试。 -可以设置多个浏览器。 -每次运行后为所有测试用例生成屏幕快照的报告。 -为失败的...
'diwng.xml' 和 diw-grid.xml' 是 TestNG 相关文件,通过使用 diwng.xml 可以进行线性模式的测试,需要使用 diw-grid.xml 进行并行模式的测试。 如何运行: 要运行该项目,请安装 。 使用以下 maven 命令线性运行...