当前位置:网站首页>【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();
}
边栏推荐
- VMD combined with ISSA to optimize LSSVM power prediction
- 缓动动画,有关窗口的一些常见操作,BOM操作
- Interpretation of EfficientNet: Composite scaling method of neural network (based on tf-Kersa reproduction code)
- MySQL(4)
- 用手机也能轻松玩转MATLAB编程
- 关于我写的循环遍历
- 对象的扩展补充
- 叔本华的《人生的智慧》感悟
- NelSon:一款新的适配matlab编程语法的编程工具
- [漏洞问题] log4j漏洞 关于2.17.0升级到2.18.0 方案
猜你喜欢

什么是多态。

curl (7) Failed connect to localhost8080; Connection refused

Detailed ResNet: What problem is ResNet solving?

ubuntu18.04安装redis教程

HbuilderX 启动微信小程序 无法打开项目

Computer knowledge: desktop computers should choose the brand and assembly, worthy of collection

MySQL大总结

Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案

MATLAB版量化交易技术分析工具TA-Lib【不付费也可获取,不要被付费吓跑】

如何用matlab做高精度计算?【第三辑】(完)
随机推荐
Triton部署mmdeploy导出的TensorRT模型失败篇
窥探晶体世界的奥秘 —— 230种空间群晶体结构模型全在这里
HbuilderX 启动微信小程序 无法打开项目
Time Series Forecasting Based on Reptile Search RSA Optimized LSTM
力扣每日一题-第47天-15. 三数之和
从零开始单相在线式不间断电源(UPS)(硬件)
JVM调优实践
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
MySQL重置root密码
系统流量预估、架构设计方案
Gramm Angle field GAF time-series data into the image and applied to the fault diagnosis
IoU, GIoU, DIoU and CIoU in target detection
更改mysql数据库默认的字符集(mysql 存储 emoji表情)
C语言实现-华为太空人手表
adb无法桥接夜神模拟器
MySQL大总结
异步编程之promise,任务队列,事件循环
Promise.all 使用方法
MySQL外键(详解)
Unable to preventDefault inside passive event listener due to target being treated as passive. See