当前位置:网站首页>【selenium自动化】第四篇,结合testNg
【selenium自动化】第四篇,结合testNg
2022-08-04 06:04:00 【linrui7】
一、添加testNg pom依赖
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
二、使用 入参形式
@BeforeTest
public static void init() {
System.out.println("-----初始化webdriver.chrome.driver-----");
System.setProperty("webdriver.chrome.driver", "chromedriver");
}
@Test(description = "",dataProvider = "uid")
public static void test06(int id,int vlue) throws InterruptedException {
WebDriver webDriver = new ChromeDriver();
webDriver.get("https://mail.qq.com/");
webDriver.switchTo().frame("login_frame");
webDriver.findElement(By.id("u")).sendKeys(vlue + "");
webDriver.switchTo().defaultContent();
webDriver.findElement(By.linkText("基本版")).click();
Thread.sleep(5000);
webDriver.quit();
}
@DataProvider
public Object[][] uid(){
Object[][] objects=new Object[][]{
{
1,88888},
{
2,99999},
{
3,12345}
};
return objects;
}
三、使用群组,只执行部分
<suite name="suite" verbose="1" >
<test name = "test" >
<groups>
<run>
<include name = "group1" />
</run>
</groups>
<packages>
<package name = "com.linrui.Day03" />
</packages>
<classes>
<class name="com.linrui.Day03" />
</classes>
</test>
</suite>
@Test(description = "",dataProvider = "uid",groups = "group1")
public static void test07(int id,int vlue) throws InterruptedException {
WebDriver webDriver = new ChromeDriver();
webDriver.get("https://mail.qq.com/");
webDriver.switchTo().frame("login_frame");
webDriver.findElement(By.id("u")).sendKeys(vlue + "");
webDriver.switchTo().defaultContent();
webDriver.findElement(By.linkText("基本版")).click();
Thread.sleep(5000);
webDriver.quit();
}
四、多窗口切换
@Test(description = "")
public static void test08() throws InterruptedException {
WebDriver webDriver = new ChromeDriver();
webDriver.get("https://baidu.com/");
String windowHandle1 = webDriver.getWindowHandle();
webDriver.findElement(By.xpath("//*[@id=\"s-hotsearch-wrapper\"]/div/a[1]/div")).click();
webDriver.getWindowHandles().forEach(value -> {
System.out.println(windowHandle1 + "\r\n" + value);
webDriver.switchTo().window(value);
if (!value.equals(windowHandle1)) {
System.out.println("URL:" + webDriver.getCurrentUrl());
}
});
Thread.sleep(5000);
webDriver.quit();
}
边栏推荐
- 简析强制缓存和协商缓存
- SQL如何从字符串截取指定字符(LEFT、MID、RIGHT三大函数)
- Interpretation of EfficientNet: Composite scaling method of neural network (based on tf-Kersa reproduction code)
- Gramm Angle field GAF time-series data into the image and applied to the fault diagnosis
- 网页中常用的两种绘图技术,用canvas绘图,绘制出一个三角形,矩形,柱状图,扇形图
- What is the connection between GRNN, RBF, PNN, KELM?
- matlab让我的旧手机起死回生
- MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
- entity、domain、vo、pojo的区别与联系
- [漏洞问题] log4j漏洞 关于2.17.0升级到2.18.0 方案
猜你喜欢
Verilog“七宗罪”
用手机也能轻松玩转MATLAB编程
在线问题反馈模块实战(十八):实现excel台账文件记录批量导入功能
Base64编码原理
误差指标分析计算之matlab实现【开源1.0.0版】
Hardware Knowledge: Introduction to RTMP and RTSP Traditional Streaming Protocols
Centos通过Docker搭建MySQL的PXC集群
NelSon:一款新的适配matlab编程语法的编程工具
Computer knowledge: desktop computers should choose the brand and assembly, worthy of collection
Computer software: recommend a disk space analysis tool - WizTree
随机推荐
微信小程序实现活动倒计时
IDEA中创建编写JSP
软件稳定性思考
对产品设计,架构设计的一点思考
Centos通过Docker搭建MySQL的PXC集群
53个全球免费学术资源数据库整理,查资料写论文必备【开学必备】
LeetCode(剑指 Offer)- 18. 删除链表的节点
打破千篇一律,DIY属于自己独一无二的商城
TypeScript基本类型、类、封装、继承、泛型、接口、命名空间
科研绘图图表类型种类繁多,本文告诉你如何选择!
likeshop外卖点餐系统【100%开源无加密】
2DCNN, 1DCNN, BP, SVM fault diagnosis and result visualization of matlab
IDEA 控制台 中文乱码问题(如果网上教程都无法解决你的问题的话)
SystemVerilog-条件(三元)运算符
对象的扩展补充
指定区域内随机填充圆之matlab实现
Interpretation of EfficientNet: Composite scaling method of neural network (based on tf-Kersa reproduction code)
Computer software: recommend a disk space analysis tool - WizTree
七夕专属程序员的浪漫
matlab封闭曲线拟合 (针对一些列离散点)