Springboot集成selenide 自动化测试
一、导入相应依赖pom.xml如下因为selenide包含了selenium的api为了能自主配置selenium 所以selenide模块移除了selenium 然后自定义配置了selenium<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>4.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-edge-driver</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.53.1</version>
</dependency>
二、在指定位置生成测试类文件在springboot的测试目录下创建Test类
三、测试类编写import com.codeborne.selenide.Configuration;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.*;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) //name_ascending 是如果跑整个class 会根据方法名顺序跑
public class UserTest {
@BeforeClass
public static void setUp() {
Configuration.timeout = 6000;
Configuration.browser = "chrome"; //设置浏览器驱动,默认路径看下图 也可以不用默认路径
//Configuration.reportsFolder = "test-result/reports"; selenide失败回自动保存快照这是配置快照保存目录 默认也是这个
}
//自动化 访问百度
@Test
public void step00_test() {
open("https://www.baidu.com");
$("body").shouldHave(text("百度"));
sleep(5000);
}
@Test
public void step01_addUserSuccess() {
loginSuperForestry();
open("/admin");
$(".wrapper-content").shouldHave(text("添加账号"));
String user = "qq" + Double.valueOf(Math.random() * 1000000).intValue();
setUserMessage(user, "哈哈", 0);
$("#addUser").click();
$("#userTable").shouldHave(text(user));
}
四、配置浏览器驱动(pom.xml配置好后,如果仓库没有驱动,需要手动配置)
配置driver配置到如下路径这个路径也是默认路径
支持分享
页:
[1]