51Testing软件测试论坛
标题: Springboot集成selenide 自动化测试 [打印本页]
作者: 太鼓达人 时间: 2019-3-20 15:33
标题: 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类
[attach]123085[/attach]
三、测试类编写
- 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 配置到如下路径 这个路径也是默认路径
[attach]123086[/attach]
作者: Miss_love 时间: 2020-12-30 18:02
支持分享
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) |
Powered by Discuz! X3.2 |