Selenium搭配TestNG
用Maven来构建TestNG依赖:

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; public class TestNG {
private WebDriver driver; @BeforeMethod
//测试之前的准备工作
public void beforeMethod(){
System.setProperty("webdriver.firefox.marionette", "src/main/resourcec/geckodriver.exe");
String baiduHomePage;
baiduHomePage = "https://www.baidu.com/"; driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(baiduHomePage);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
} Assert.assertEquals(driver.getTitle(), "百度一下,你就知道");
} @Test
//测试用例
public void testNG(){
driver.findElement(By.xpath(".//*[@id='kw']")).sendKeys("Selenium");
driver.findElement(By.xpath(".//*[@id='su']")).click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
} Reporter.log("搜索Selenium的测试用例");
Assert.assertEquals(driver.getTitle(), "Selenium_百度搜索");
} @AfterMethod
//测试之后的清理工作
public void afterMethod(){
driver.close();
driver.quit();
}
}
Selenium搭配TestNG的更多相关文章
- 自动化测试框架selenium+java+TestNG——配置篇
最近来总结下自动化测试 selenium的一些常用框架测试搭配,由简入繁,最简单的就是selenium+java+TestNG了,因为我用的是java,就只是总结下java了. TestNG在线安装: ...
- IDEA+Java:Selenium+Maven+TestNG基本WebUI自动化测试环境搭建
IDEA+java:Selenium+Maven+TestNG 本文介绍的测试环境,应该是最基本的测试环境了,也是很多文章都有写,这里做一个完整的图文配置整理,方便阅读理解! 使用maven的好处,由 ...
- selenium webdriver testng自动化测试数据驱动
selenium webdriver testng自动化测试数据驱动 selenium webdriver testng自动化测试数据驱动 一.数据驱动测试概念 数据驱动测试是相同的测试脚本使用不同的 ...
- maven+selenium+java+testng+jenkins自动化测试
最近在公司搭建了一套基于maven+selenium+java+testng+jenkins的自动化测试框架,免得以后重写记录下 工程目录 pom.xml <project xmlns=&quo ...
- selenium第一课(selenium+java+testNG+maven)
selenium介绍和环境搭建 一.简单介绍 1.selenium:Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包 ...
- Selenium+Java+TestNG环境配置
1. JDK 2.eclipse+TestNG >TestNG安装. Name:testng Location:http://beust.com/eclipse.如图: 3.seleniu ...
- Selenium WebDriver TestNg Maven Eclipse java 简单实例
环境准备 前提条件Eclipse 已经安装过 TestNg ,Maven 插件 新建一个普通的java项目 点击右键 configure->convert to Maven Project 之后 ...
- selenium 利用testNG对异常进行自动截图
哈哈哈,很久没写博客了,懒了. 因为一些原因最近需要把监听事件重新整理一下,开始没细想,直接copy网上的,其实结果发现报错很多,或者是达不到效果,然后把之前的代码翻出来,仔细看了一下.下面给一些需要 ...
- jenkins、ant、selenium、testng搭建自动化测试框架
如果在你的理解中自动化测试就是在eclipse里面讲webdriver的包引入,然后写一些测试脚本,这就是你所说的自动化测试,其实这个还不能算是真正的自动化测试,你见过每次需要运行的时候还需要打开ec ...
随机推荐
- table自适应
当table大于屏幕时,table可以左右滑动 //给table的父元素设置样式 .edit_table{ width:100%; overflow: auto; }
- Consider defining a bean of type 'package' in your configuration [Spring-Boot]
https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-config ...
- mysql时间日期函数
now(), current_timestamp(); -- 当前日期时间 current_date(); -- 当前日期 current_time(); -- 当前时间 date('yyyy-mm- ...
- vim 操作手册
三种模式 编辑模式(i当前位置插入光标:a后一位置插入光标).控制模式(esc).可视模式(v). 编辑模式时可以正常输入. 控制模式是vim的核心,通过按键可以快速实现操作. 可视模式是进行选块操作 ...
- python—递归函数
递归函数 定义:即在函数定义中自己调用自己 递归就是在过程或函数中自我调用 递归必须有递归出口,即递归结束条件 举个栗子-阶乘: def fact(n): if n == 1: return 1 re ...
- pdf.js 在线阅读PDF
在网上找了一下如何在线显示pdf文件.个人还是觉得这个是比较不错的,这里做一个记录. gitHub:https://github.com/mozilla/pdf.js 这是一个开源 ...
- 菜鸟笔记 -- Chapter 6.3 对象
6.3 对象 Java是一门面向对象的程序设计语言,对象是由类抽象出来的,所有的问题都是通过对象来处理的,对象可以操作类的属性和方法解决相应的问题,所以了解对象的产生.操作和生存周期对学习Java语言 ...
- cornerstone提交报错"but is missing"以及xocde提示"missing from working copy"
问题描述 xocde提示"missing from working copy" 虽然这种警告不会影响程序到运行,但是数量很多,而且在svn提交的时候回出现这种问题 使用的svn工具 ...
- Redis工具之Jedis
//jedis的连接池 public void test1(){ //创建连接池配置对象 JedisPoolConfig poolConfig = new JedisPoolConfig(); poo ...
- JetBrains 授权服务器(License Server):
JetBrains 授权服务器(License Server): https://www.imsxm.com/jetbrains-license-server.html