diff --git a/.gitignore b/.gitignore index 0e6f9483e24527880fa13e3866795df95eef25c3..fdd78d10211a2869339d21ac0028dc11abf3021b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ hs_err_pid* */target/* */allure-report/* /target/* +*.versionsBackup diff --git a/automation-agent/README.md b/automation-agent/README.md index a589ef734dd7d67a379f6d8b43165b6f92adac49..77c5d699f6befc200ac85584d5a07c937d9c7214 100644 --- a/automation-agent/README.md +++ b/automation-agent/README.md @@ -1,33 +1,33 @@ -### 计算耗时代理类 +# automation-agent +`automation-agent` 功能:计算方法耗时,仅对`cn/testnewbie/`包下,且标注了@TimeCost的类和方法生效,所以请忽略 + +仅开发testnewbie时使用,请忽略 + +仅开发testnewbie时使用,请忽略 + +仅开发testnewbie时使用,请忽略 + +### 介绍 https://www.cnblogs.com/yihuihui/p/12509416.html - Java Agent(java 探针)虽说在 jdk1.5 之后就有了,但是对于绝大多数的业务开发 javaer 来说,这个东西还是比较神奇和陌生的; - - 我们需要统计方法耗时,所以想到的就是在方法的执行前,记录一个时间,执行完之后统计一下时间差。 直接修改字节码有点麻烦,因此我们借助神器javaassist来修改字节码。实现自定义的ClassFileTransformer。 -### 打包 -~~~ -mvn assembly:assembly -~~~ - ### 使用 - jvm 参数形式:调用 premain 方法 - -其中 jvm 方式,也就是说要使用这个 agent 的目标应用,在启动的时候, -需要指定 jvm 参数 -javaagent:xxx.jar,当我们提供的 agent 属于基础必备服务时,可以用这种方式 +jvm 参数形式: +调用 premain 方法 +要使用这个 agent 的目标应用,在启动的时候,需要指定 jvm 参数 -javaagent:xxx.jar +例如,在idea运行配置中,增加 如下参数 ~~~ --javaagent:G:/repository/com/testnewbie/automation-agent/1.0.0/automation-agent-1.0.0.jar --javaagent:G:/repository/com/testnewbie/automation-agent/1.0.0/automation-agent-1.0.0-jar-with-dependencies.jar --javaagent:D:/dev/Java/repository/com/testnewbie/automation-agent/1.0.0/automation-agent-1.0.0-jar-with-dependencies.jar - --javaagent:"${settings.localRepository}/com/testnewbie/automation-agent/1.0.0/automation-agent-1.0.0.jar +-javaagent:G:/repository/cn/testnewbie/automation/automation-agent/1.3.1/automation-agent-1.3.1-jar-with-dependencies.jar +-javaagent:D:/dev/Java/repository/cn/testnewbie/automation/automation-agent/1.3.1/automation-agent-1.3.1-jar-with-dependencies.jar +~~~ -~~~ diff --git a/automation-agent/pom.xml b/automation-agent/pom.xml index 725428c686994fdc0feebc7b8fde43f3e403ec0f..3501a9cb96b65260722481f965dba3c88fd3de34 100644 --- a/automation-agent/pom.xml +++ b/automation-agent/pom.xml @@ -5,19 +5,19 @@ cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT 4.0.0 automation-agent - 1.3.1 + 1.3.2-SNAPSHOT jar cn.testnewbie.automation automation-core - 1.3.1 + 1.3.2-SNAPSHOT org.javassist diff --git a/automation-agent/src/main/java/cn/testnewbie/agent/SimpleAgent.java b/automation-agent/src/main/java/cn/testnewbie/agent/SimpleAgent.java index 4f2ae065b1b1aba118c2061481804560262a10e1..4350ed52d656b87521e223b1086f419ee4f5f88e 100644 --- a/automation-agent/src/main/java/cn/testnewbie/agent/SimpleAgent.java +++ b/automation-agent/src/main/java/cn/testnewbie/agent/SimpleAgent.java @@ -3,7 +3,6 @@ package cn.testnewbie.agent; import java.lang.instrument.Instrumentation; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Date; /** * https://www.cnblogs.com/yihuihui/p/12509416.html @@ -16,8 +15,8 @@ public class SimpleAgent { * jvm 参数形式启动,运行此方法 * manifest需要配置属性Premain-Class * - * @param agentArgs - * @param inst + * @param agentArgs agentArgs + * @param inst inst */ public static void premain(String agentArgs, Instrumentation inst) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); @@ -31,8 +30,8 @@ public class SimpleAgent { * 动态 attach 方式启动,运行此方法 * manifest需要配置属性Agent-Class * - * @param agentArgs - * @param inst + * @param agentArgs agentArgs + * @param inst inst */ public static void agentmain(String agentArgs, Instrumentation inst) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); diff --git a/automation-core/README.md b/automation-core/README.md new file mode 100644 index 0000000000000000000000000000000000000000..7eed3d7b16cbb7af30056734283b03dd98962dfd --- /dev/null +++ b/automation-core/README.md @@ -0,0 +1,44 @@ +# automation-core + +`automation-core` 功能:核心包,会被其他组件依赖,一般不需要单独导入 + +# 介绍 + +## 1、annotation + +- `@CsvBeanSource` 提供将map格式的`CsvSource`,案例:example包下的`com.testexample.interfacetest`的`LoginTestUseCsvBeanSource.java` +- `@CsvBeanArgument` 配合`@CsvBeanSource`,将map转为bean,案例同上 + +## 2、cache + +##### 2.1 HttpCacheManage + +http接口测试过程中的缓存管理,将登陆信息,以map方式保存,执行case前,将map注入测试实例的 + +`public HashMap headerMap = new HashMap<>();` + +属性中,其中登录方法和登录信息的处理,需要用户继承,并在子类提供。 + +子类实现:example包下的`com.testexample.annotation`目录下的`LoginWith.java`、`LoginWithExtension.java` + +案例:example包下的com.testexample.interfacetest目录下的 +`LoginWithOnClassTest.java` +`LoginWithOnMethodTest.java` +`LoginWithSimpleTest.java` + +##### 2.2 IDataBaseStep + +数据库操作,包括执行脚本、校验数据库写库等 + +案例:example包下的`com.testexample.dbtest`目录下的`DataBaseStepTest.java` + + +## 3、util 工具类 + +##### 3.1 AssertUtil + +json字符串断言时使用 + +案例:example包下的com.testexample.interfacetest目录下的 +`LoginWithOnClassTest.java` +`LoginWithOnMethodTest.java` diff --git a/automation-core/pom.xml b/automation-core/pom.xml index e13a5879c5240a05d2dad61397eb78ddce3382f1..a2fc12d5ee8a48618b33233fe0f450abece0752d 100644 --- a/automation-core/pom.xml +++ b/automation-core/pom.xml @@ -5,12 +5,12 @@ cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT 4.0.0 automation-core - 1.3.1 + 1.3.2-SNAPSHOT jar diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/DataBaseStep.java b/automation-core/src/main/java/cn/testnewbie/automation/core/DataBaseStep.java deleted file mode 100644 index ec2ee9688b91835903dc8f117096fbbf48c995ee..0000000000000000000000000000000000000000 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/DataBaseStep.java +++ /dev/null @@ -1,114 +0,0 @@ -package cn.testnewbie.automation.core; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.log.Log; -import cn.hutool.log.LogFactory; -import cn.testnewbie.automation.core.db.SqlFileTools; -import io.qameta.allure.Step; -import org.apiguardian.api.API; - -import java.io.File; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.apiguardian.api.API.Status.EXPERIMENTAL; -import static org.junit.jupiter.api.Assertions.fail; - -/** - * @author zhanglx - */ -@API(status = EXPERIMENTAL, since = "1.0") -public class DataBaseStep { - private static final Log log = LogFactory.get(); - - /** - * 执行测试类目录下的跟测试类同名的sql文件 - */ - @Step("运行sql文件") - public void execSqlFile() { - String clazzName = this.getClass().getSimpleName(); - File f = new File(this.getClass().getResource("").getPath()); - - List sqlList = null; - try { - sqlList = SqlFileTools.loadSql(f.toPath() + File.separator + clazzName + ".sql"); - for (String sql : sqlList) { -// execSql(sql); - } - log.debug("====================execSqlFile End...===================="); - } catch (Exception e) { - fail("执行测试类目录下的跟测试类同名的sql文件:执行失败!"); - } - } - - /** - * 执行一个普通sql - * - * @param sql sql语句 - */ - @Step("执行sql:'{sql}' ") - public void execSql(String sql) { - if (StrUtil.isEmpty(sql)) { - log.error("请传入一个sql语句"); - fail("请传入一个sql语句"); - } - String upperCaseSql = sql.toUpperCase(); - upperCaseSql = upperCaseSql.replaceAll("\t", " "); - - if (upperCaseSql.indexOf(";") > -1) { - log.error("只能执行单个sql语句,且语句末尾不能带“;”"); - return; - } else if (upperCaseSql.indexOf("DELETE ") > -1) { - if (upperCaseSql.indexOf("WHERE ") == -1) { - log.error("delete语句必须包含where条件,防止误删,全表清空的情况"); - return; - } - } else if (upperCaseSql.indexOf("UPDATE ") > -1) { - if (upperCaseSql.indexOf("WHERE ") == -1) { - log.error("UPDATE语句必须包含where条件,防止误更新,全表更新的情况"); - return; - } - } -// execute(sql); - } - - /** - * 检查数据库 - * - * @param sql 查询sql - * @param checkData 查询结果集合 - */ - @Step("检查数据库:'{sql}' '{checkData}'") - public void checkDataBase(String sql, List checkData) { - if (StrUtil.isEmpty(sql)) { - log.error("请传入一个select语句"); - fail("请传入一个select语句"); - } - String upperCaseSql = sql.toUpperCase(); - upperCaseSql = upperCaseSql.replaceAll("\t", " "); - - if (upperCaseSql.indexOf(";") > -1) { - log.error("只能执行单个sql语句,且语句末尾不能带“;”"); - fail("只能执行单个sql语句,且语句末尾不能带“;”"); - } else if (upperCaseSql.indexOf("DELETE ") > -1) { - log.error("不能传入DELETE语句"); - fail("不能传入DELETE语句"); - } else if (upperCaseSql.indexOf("UPDATE ") > -1) { - log.error("不能传入UPDATE语句"); - fail("不能传入UPDATE语句"); - } else if (upperCaseSql.indexOf("SELECT ") == -1) { - log.error("请传入一个select语句"); - fail("请传入一个select语句"); - } - - for (Map map : checkData) { - Set keys = map.keySet(); - for (String key : keys) { - System.out.println(key + "=" + map.get(key)); - // todo - } - } - } - -} diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/cache/HttpCacheManage.java b/automation-core/src/main/java/cn/testnewbie/automation/core/cache/HttpCacheManage.java index 37514a8b2a8a392ea203208988ba182e51f0e694..55bbf062f7ce60ae8ff853af8564cdf8293f3c12 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/cache/HttpCacheManage.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/cache/HttpCacheManage.java @@ -165,7 +165,8 @@ public abstract class HttpCacheManage implements ICacheMan * 对于 HttpStep 来说,信息头就是一个map * * @param extensionContext the current extension context; - * @param annotation 登录信息 + * @param annotation 登录注解 + * @param authInfoMap 登录信息 * @throws NoSuchFieldException "测试类"或者"测试类的父类",没有"public HashMap<String, String> headerMap = new HashMap<>();" * @throws IllegalAccessException 上面的headerMap,没有以public修饰 */ diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/common/TNConstants.java b/automation-core/src/main/java/cn/testnewbie/automation/core/common/TNConstants.java index cca4be87840178697e85f4c459bd7dee78af0e8c..13cdcc33b93a13420e3ed367a01ef99d7b3eec8e 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/common/TNConstants.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/common/TNConstants.java @@ -14,6 +14,7 @@ public class TNConstants { public static final String DOT = "."; public static final String PERCENT = "%"; public static final String COMMA = ","; + public static final String SEMICOLON = ";"; /*** 数据库常量 ***/ public static final String NAME = "name"; @@ -25,6 +26,12 @@ public class TNConstants { public static final String TIME_FORMAT_PATTERN = "HH:mm:ss.SSS"; /*** http ***/ - public static final String APPLICATION_JSON = "application/json"; + public static final String APPLICATION_JSON = "application/json"; + + /*** Sql element ***/ + public static final String DELETE_KEYWORD = "DELETE "; + public static final String WHERE_KEYWORD = "WHERE "; + public static final String UPDATE_KEYWORD = "UPDATE "; + public static final String SELECT_KEYWORD = "SELECT "; } diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/db/DataBase.java b/automation-core/src/main/java/cn/testnewbie/automation/core/db/DataBase.java index 5a590e9e07fed38eb5dfe2d5be0d3c3a7364e477..cd9551f9f4a696875846f0faf4f7fce599b5d49f 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/db/DataBase.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/db/DataBase.java @@ -1,12 +1,20 @@ package cn.testnewbie.automation.core.db; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; +import cn.testnewbie.automation.core.common.TNConstants; import cn.testnewbie.automation.core.config.PropertyMgr; +import io.qameta.allure.Step; import org.apache.commons.dbcp2.BasicDataSourceFactory; import org.apiguardian.api.API; +import org.json.JSONException; +import org.junit.jupiter.api.Assertions; +import org.skyscreamer.jsonassert.JSONAssert; import javax.sql.DataSource; +import java.io.File; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,6 +22,7 @@ import java.sql.Statement; import java.util.List; import static org.apiguardian.api.API.Status.MAINTAINED; +import static org.junit.jupiter.api.Assertions.fail; /** * @author zhanglx @@ -58,7 +67,6 @@ public class DataBase { return conn; } - public List executeQuery(String sql) throws SQLException { if (conn == null) { conn = getConnection(); @@ -90,4 +98,128 @@ public class DataBase { } return list; } + + private boolean executeSql(String sql) throws SQLException { + if (conn == null) { + conn = getConnection(); + } + Statement stmt = null; + boolean result = false; + List list = null; + try { + stmt = conn.createStatement(); + result = stmt.execute(sql); + } catch (SQLException e) { + log.error(e); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + } catch (Exception e) { + log.error(e); + } + } + return result; + } + + /** + * 执行测试类目录下的跟测试类同名的sql文件 + */ + @Step("运行sql文件") + public void execSqlFile() { + String clazzName = this.getClass().getSimpleName(); + File f = new File(this.getClass().getResource("").getPath()); + + List sqlList; + try { + sqlList = SqlFileTools.loadSql(f.toPath() + File.separator + clazzName + ".sql"); + for (String sql : sqlList) { + execSql(sql); + } + log.debug("====================execSqlFile End...===================="); + } catch (Exception e) { + fail("执行测试类目录下的跟测试类同名的sql文件:执行失败!"); + } + } + + /** + * 执行一个普通sql + * + * @param sql sql语句 + * @return 如果有结果集,则为真 + * @throws SQLException sql异常 + */ + @Step("执行sql:'{sql}' ") + public boolean execSql(String sql) throws SQLException { + if (StrUtil.isEmpty(sql)) { + log.error("请传入一个sql语句"); + fail("请传入一个sql语句"); + } + String upperCaseSql = sql.toUpperCase(); + upperCaseSql = upperCaseSql.replaceAll("\t", " "); + + if (upperCaseSql.contains(";")) { + Assertions.fail("只能执行单个sql语句,且语句末尾不能带“;”"); + } else if (upperCaseSql.contains(TNConstants.DELETE_KEYWORD)) { + if (!upperCaseSql.contains(TNConstants.WHERE_KEYWORD)) { + Assertions.fail("delete语句必须包含where条件,防止误删,全表清空的情况"); + } + } else if (upperCaseSql.contains(TNConstants.UPDATE_KEYWORD)) { + if (!upperCaseSql.contains(TNConstants.WHERE_KEYWORD)) { + Assertions.fail("UPDATE语句必须包含where条件,防止误更新,全表更新的情况"); + } + } + return executeSql(sql); + } + + /** + * 检查数据库,默认非严格校验 + * 如有疑问,可以访问http://jsonassert.skyscreamer.org/cookbook.html + * + * @param sql 查询sql + * @param expectedJsonArray 期望值,JsonArray字符串格式 + * @throws SQLException sql执行异常 + * @throws JSONException json格式不对 + */ + @Step("检查数据库:'{sql}' '{checkData}'") + public void checkDataBase(String sql, String expectedJsonArray) throws SQLException, JSONException { + checkDataBase(sql, expectedJsonArray, false); + } + + /** + * 检查数据库 + * + * @param sql 查询sql + * @param expectedJsonArray 期望值,JsonArray字符串格式 + * @param strict 是否严格相等,如有疑问,可以访问http://jsonassert.skyscreamer.org/cookbook.html + * @throws SQLException sql执行异常 + * @throws JSONException json格式不对 + */ + @Step("检查数据库:'{sql}' '{checkData}'") + public void checkDataBase(String sql, String expectedJsonArray, boolean strict) throws SQLException, JSONException { + if (StrUtil.isEmpty(sql)) { + log.error("请传入一个select语句"); + fail("请传入一个select语句"); + } + String upperCaseSql = sql.toUpperCase(); + upperCaseSql = upperCaseSql.replaceAll("\t", " "); + + if (upperCaseSql.contains(TNConstants.SEMICOLON)) { + Assertions.fail("只能执行单个sql语句,且语句末尾不能带“;”"); + } else if (upperCaseSql.contains(TNConstants.DELETE_KEYWORD)) { + Assertions.fail("不能传入DELETE语句"); + } else if (upperCaseSql.contains(TNConstants.UPDATE_KEYWORD)) { + Assertions.fail("不能传入UPDATE语句"); + } else if (!upperCaseSql.contains(TNConstants.SELECT_KEYWORD)) { + Assertions.fail("请传入一个select语句"); + } + + List list = executeQuery(sql); + String actual = JSONUtil.toJsonStr(list); + log.debug("checkDataBase,期望:" + expectedJsonArray); + log.debug("checkDataBase,实际:" + actual); + JSONAssert.assertEquals(expectedJsonArray, actual, strict); + } + } diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/db/IDataBase.java b/automation-core/src/main/java/cn/testnewbie/automation/core/db/IDataBaseStep.java similarity index 87% rename from automation-core/src/main/java/cn/testnewbie/automation/core/db/IDataBase.java rename to automation-core/src/main/java/cn/testnewbie/automation/core/db/IDataBaseStep.java index e4fc4229becf094d0247288b4e3c51a44613363d..83a9261486005d888c6e7c4b748c7f16794f8350 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/db/IDataBase.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/db/IDataBaseStep.java @@ -8,6 +8,6 @@ import static org.apiguardian.api.API.Status.MAINTAINED; * @author zhanglx */ @API(status = MAINTAINED, since = "1.0") -public interface IDataBase { +public interface IDataBaseStep { DataBase db = new DataBase(); } diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/db/ResultSetUtil.java b/automation-core/src/main/java/cn/testnewbie/automation/core/db/ResultSetUtil.java index 7761ee9ec8cbe22e58e6cc2c0ee0acdfad526bc9..31013dccfc4baec335c54d3f5ab0aff3fae55ec0 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/db/ResultSetUtil.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/db/ResultSetUtil.java @@ -23,7 +23,7 @@ public class ResultSetUtil { /** * 通用取结果方案,返回list * - * @param rs + * @param rs 结果集 * @return 数据行list * @throws SQLException sql异常 */ @@ -44,7 +44,7 @@ public class ResultSetUtil { /** * 通用取结果方案,返回JSONArray * - * @param rs + * @param rs 结果集 * @return 返回JSONArray * @throws SQLException sql异常 */ diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/db/SqlFileTools.java b/automation-core/src/main/java/cn/testnewbie/automation/core/db/SqlFileTools.java index a221e00e59e3eefa8ecae63aafa7b62273aab2d0..6588c82d3177e6f0b1a41f2d66773b2c1eb8a33d 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/db/SqlFileTools.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/db/SqlFileTools.java @@ -27,7 +27,7 @@ public class SqlFileTools { /** * 加载解析sql 读取方式字符流 行读取 * - * @param file + * @param file sql脚本 * @return sql文件 * @throws Exception 异常 */ diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/AssertUtil.java b/automation-core/src/main/java/cn/testnewbie/automation/core/util/AssertUtil.java similarity index 91% rename from automation-core/src/main/java/cn/testnewbie/automation/core/AssertUtil.java rename to automation-core/src/main/java/cn/testnewbie/automation/core/util/AssertUtil.java index f8fb8ac9fd769e9f2e05d9f070a0539952c9d4ec..ce790920f94558b3d5e84ca372c2ad37595f8f3c 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/AssertUtil.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/util/AssertUtil.java @@ -1,4 +1,4 @@ -package cn.testnewbie.automation.core; +package cn.testnewbie.automation.core.util; import cn.hutool.json.JSON; import cn.hutool.json.JSONNull; @@ -24,8 +24,6 @@ import static org.apiguardian.api.API.Status.MAINTAINED; public class AssertUtil extends Assertions { private static final Log log = LogFactory.get(); - public static org.assertj.db.api.Assertions db; - /** * 使用JSONPath检查返回值 * @@ -49,6 +47,8 @@ public class AssertUtil extends Assertions { public static void assertByJSONPath(String jsonPath, Object expected, JSON json) { Object object = JSONUtil.getByPath(json, jsonPath); String message; + + // 找不到元素 if (object == null) { message = "JSONPath = " + jsonPath + ",期望值 = " + expected + @@ -60,8 +60,10 @@ public class AssertUtil extends Assertions { ",期望值 = " + expected + ",实际值 = " + object; + // 找到元素,但是元素内容是null if (object instanceof JSONNull) { - assertTrue(object.equals(expected)); + boolean jsonNullEquals = object.equals(expected); + assertTrue(jsonNullEquals); } else { Supplier failMessage = () -> { Allure.attachment(message, json.toStringPretty()); diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/ExcelUtil.java b/automation-core/src/main/java/cn/testnewbie/automation/core/util/ExcelUtil.java similarity index 39% rename from automation-core/src/main/java/cn/testnewbie/automation/core/ExcelUtil.java rename to automation-core/src/main/java/cn/testnewbie/automation/core/util/ExcelUtil.java index 1752a9a08f807a3a080f2b48069aad61568f32cf..533f7acb4a611ffe2c4e1253c6a1ba7d7c805c60 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/ExcelUtil.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/util/ExcelUtil.java @@ -1,4 +1,4 @@ -package cn.testnewbie.automation.core; +package cn.testnewbie.automation.core.util; public class ExcelUtil { diff --git a/automation-core/src/main/java/cn/testnewbie/automation/core/util/InputStreamToBytes.java b/automation-core/src/main/java/cn/testnewbie/automation/core/util/InputStreamToBytes.java index 30a9327e79fca6d40adf7559dd0f429a2d28fe93..d3878efcb02c0d376f35f047357c056fa36c6a7e 100644 --- a/automation-core/src/main/java/cn/testnewbie/automation/core/util/InputStreamToBytes.java +++ b/automation-core/src/main/java/cn/testnewbie/automation/core/util/InputStreamToBytes.java @@ -2,7 +2,6 @@ package cn.testnewbie.automation.core.util; import org.apiguardian.api.API; -import java.awt.*; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -23,7 +22,7 @@ public class InputStreamToBytes { /** * 将输入流转成bytes,方便allure添加到报告里面,如图片 * - * @param inputStream + * @param inputStream 输入流 * @return 字节数组 * @throws IOException IO异常 */ @@ -44,7 +43,8 @@ public class InputStreamToBytes { /** * 将输入流转成特定字符类型的字符串,再转成bytes,方便allure添加到报告里面,如中文文本 * - * @param inputStream + * @param inputStream 输入流 + * @param charset 字符集 * @return 字节数组 * @throws IOException IO异常 */ @@ -66,7 +66,7 @@ public class InputStreamToBytes { * 截图,并返回bytes * * @return 字节数组 - * @throws Exception IO异常、AWT异常 + * @throws Exception IO异常、AWT异常 */ public static byte[] screenshot() throws Exception { GuiCamera cam1 = new GuiCamera(null, "target/screenShot"); diff --git a/automation-core/start.bat b/automation-core/start.bat deleted file mode 100644 index a32a77f35c21aed8f02a8712b5166de1ac8b7b8d..0000000000000000000000000000000000000000 --- a/automation-core/start.bat +++ /dev/null @@ -1,39 +0,0 @@ -@rem 执行测试(需要安装maven命令) -call mvn clean test - -echo. -echo ------------------------------------------------------------------------ -echo errorlevel = %errorlevel% -echo ------------------------------------------------------------------------ -echo. - -set "results=.\target\allure-results\" -if not exist "%results%" ( - goto fail -) else ( - goto succeed -) - -:succeed -@rem 显示趋势图 -xcopy .\allure-report\history .\target\allure-results\history /e /Y /I - -@rem 显示环境 -xcopy .\src\test\resources\allure\environment.properties .\target\allure-results\ /e /Y /I - -@rem 分类 -xcopy .\src\test\resources\allure\categories.json .\target\allure-results\ /e /Y /I - -echo. -echo generate allure-report -echo ------------------------------------------------------------------------ -echo. - -@rem 生成报告(需要安装allure命令) -call allure generate target/allure-results/ -o allure-report --clean -goto end - -:fail -echo maven error - -:end diff --git a/automation-dingding/README.md b/automation-dingding/README.md index f8161cbdc63fa7b300e65b91e670712daed2a459..34103c3794382a418ffee854b2bda49d45ddb6b4 100644 --- a/automation-dingding/README.md +++ b/automation-dingding/README.md @@ -1,6 +1,15 @@ # automation-dingding `automation-dingding` 功能:用例执行完成,存在失败的case,发送钉钉通知(理论上Junit5的脚本都支持) +```sh + + + cn.testnewbie.automation + automation-dingding + 1.3.1 + +``` + ## 使用方法 1. 在项目 src/test/resources 下面新增配置文件“testnewbie.properties”,如果已经有了,可以在文件后面追加 @@ -17,6 +26,48 @@ secret= #通过手机号码指定“被@人列表” mobiles=153XXXXXXXX,153XXXXXXXX ``` -3. 执行测试,查看控制台信息,如果没有报错,配置正确,应该能正常收到钉钉通知 + +3. pom文件的maven-surefire-plugin下,增加配置项 +```sh + + + true + + +``` + +以下是完整的配置(可以注释掉自己不要的) +```sh + + maven-surefire-plugin + 2.22.2 + + false + + -Dfile.encoding=UTF-8 + -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" + + + ${project.build.directory}/allure-results + + + true + true + + SAME_THREAD + dynamic + + + + + org.aspectj + aspectjweaver + ${aspectj.version} + + + +``` + +4. 执行测试,查看控制台信息,如果没有报错,配置正确,应该能正常收到钉钉通知 有任何问题,可以在项目页面提issues,地址:https://gitee.com/testnewbie-projects/testnewbie-automation/issues 或者邮件联系 zlx.pvp@163.com diff --git a/automation-dingding/pom.xml b/automation-dingding/pom.xml index 9c66c095c2a9ad220ccd1e5ca94b79f73eef7383..e59ecc62b4385bb2f04be457789c507800cbf9aa 100644 --- a/automation-dingding/pom.xml +++ b/automation-dingding/pom.xml @@ -5,12 +5,12 @@ cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT 4.0.0 automation-dingding - 1.3.1 + 1.3.2-SNAPSHOT jar @@ -22,7 +22,7 @@ cn.testnewbie.automation automation-core - 1.3.1 + 1.3.2-SNAPSHOT org.junit.platform diff --git a/automation-email/README.md b/automation-email/README.md index 1fb58febc4b82443d0b3713fe55e0aae21e8dc3b..6bf531ae139706092f136b8e40276e78d70bffa0 100644 --- a/automation-email/README.md +++ b/automation-email/README.md @@ -1,6 +1,14 @@ # automation-email `automation-email` 功能:用例执行完成,存在失败的case,自动发送邮件(理论上Junit5的脚本都支持) +```sh + + + cn.testnewbie.automation + automation-email + 1.3.1 + +``` ## 使用方法 1. 在项目 src/test/resources 下面新增配置文件“testnewbie.properties”,如果已经有了,可以在文件后面追加 @@ -27,6 +35,48 @@ subject=自动化测试报告 #接收人,用英文,号分隔 mailTo=xxxxxxx@xxxx.com ``` -3. 执行测试,查看控制台信息,如果没有报错,配置正确,应该能正常收到邮件 + +3. pom文件的maven-surefire-plugin下,增加配置项 +```sh + + + true + + +``` + +以下是完整的配置(可以注释掉自己不要的) +```sh + + maven-surefire-plugin + 2.22.2 + + false + + -Dfile.encoding=UTF-8 + -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" + + + ${project.build.directory}/allure-results + + + true + true + + SAME_THREAD + dynamic + + + + + org.aspectj + aspectjweaver + ${aspectj.version} + + + +``` + +4. 执行测试,查看控制台信息,如果没有报错,配置正确,应该能正常收到邮件 有任何问题,可以在项目页面提issues,地址:https://gitee.com/testnewbie-projects/testnewbie-automation/issues 或者邮件联系 zlx.pvp@163.com diff --git a/automation-email/pom.xml b/automation-email/pom.xml index e97956fa4301154e7bb0ef70631a6b92b5cfe7ac..5c6c01625a50c2c78d3f500f2b408b8e50597131 100644 --- a/automation-email/pom.xml +++ b/automation-email/pom.xml @@ -7,11 +7,11 @@ cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT automation-email - 1.3.1 + 1.3.2-SNAPSHOT jar @@ -23,7 +23,7 @@ cn.testnewbie.automation automation-core - 1.3.1 + 1.3.2-SNAPSHOT org.junit.platform diff --git a/automation-email/src/main/java/cn/testnewbie/automation/mail/MailSummaryGeneratingListener.java b/automation-email/src/main/java/cn/testnewbie/automation/mail/MailSummaryGeneratingListener.java index 068ff20056c244790584c5642331c14ad8534b01..54a6207c3910f5d75c725253508bcd6a810cf0f8 100644 --- a/automation-email/src/main/java/cn/testnewbie/automation/mail/MailSummaryGeneratingListener.java +++ b/automation-email/src/main/java/cn/testnewbie/automation/mail/MailSummaryGeneratingListener.java @@ -93,7 +93,7 @@ public class MailSummaryGeneratingListener implements TestExecutionListener { case SUCCESSFUL: { if (testIdentifier.isContainer()) { this.summary.containersSucceeded.incrementAndGet(); - log.debug("Container SUCCESSFUL : " + testIdentifier.toString()); +// log.debug("Container SUCCESSFUL : " + testIdentifier.toString()); } if (testIdentifier.isTest()) { this.summary.testsSucceeded.incrementAndGet(); diff --git a/automation-email/src/main/java/cn/testnewbie/automation/mail/MailTestExecutionSummary.java b/automation-email/src/main/java/cn/testnewbie/automation/mail/MailTestExecutionSummary.java index a573dbfeadfdc8bdc5b4cee3d8acbd7f0eb00003..ce6e485417423a3395e99c54f92f717cb6cb7d7b 100644 --- a/automation-email/src/main/java/cn/testnewbie/automation/mail/MailTestExecutionSummary.java +++ b/automation-email/src/main/java/cn/testnewbie/automation/mail/MailTestExecutionSummary.java @@ -279,45 +279,41 @@ public class MailTestExecutionSummary implements TestExecutionSummary { } public String getSource(TestIdentifier testIdentifier) { - AtomicReference sourceString = new AtomicReference(); + AtomicReference sourceString = new AtomicReference<>(); testIdentifier.getSource().ifPresent(source -> sourceString.set(format("%s%s
", Constant.DOUBLE_TAB, source))); return sourceString.toString(); } public String getCaseInfo(TestIdentifier testIdentifier) { - AtomicReference sourceString = new AtomicReference(); + String sourceString = ""; if (testIdentifier.getSource().isPresent()) { TestSource testSource = testIdentifier.getSource().get(); if (testSource instanceof MethodSource) { MethodSource source = (MethodSource) testSource; - sourceString.set(format("%s.%s
", + sourceString = format("%s.%s
", source.getClassName(), - source.getMethodName() - )); + source.getMethodName()); } else if (testSource instanceof ClassSource) { ClassSource source = (ClassSource) testSource; - sourceString.set(format("%s.%s
", - source.getClassName(), - "*" - )); + sourceString = format("%s.%s
", + source.getClassName(), "*" + ); } else if (testSource instanceof PackageSource) { PackageSource source = (PackageSource) testSource; - sourceString.set(format("%s.%s
", + sourceString = format("%s.%s
", source.getPackageName(), - "*" - )); + "*"); } else if (testSource instanceof CompositeTestSource) { CompositeTestSource source = (CompositeTestSource) testSource; - sourceString.set(format("%s.%s
", + sourceString = format("%s.%s
", source.getSources().toString(), - "*" - )); + "*"); } else { log.error(testSource.toString()); } } - return sourceString.toString(); + return sourceString; } public void printStackTrace(PrintWriter writer, Throwable throwable, int max) { @@ -340,7 +336,6 @@ public class MailTestExecutionSummary implements TestExecutionSummary { public String getStackTrace(StackTraceElement[] parentTrace, Throwable throwable, String caption, String indentation, Set seenThrowables, int max) { StringBuilder stringBuilder = new StringBuilder(); - String temp = ""; if (seenThrowables.contains(throwable)) { stringBuilder.append(format("%s%s[%s%s]
", indentation, TAB, CIRCULAR, throwable)); diff --git a/automation-interface/pom.xml b/automation-interface/pom.xml index b2a7f92924b4156fd2888b98fcb0ba2649940607..77ccbf526a47526e4b866ad1c69f8bb40526ca11 100644 --- a/automation-interface/pom.xml +++ b/automation-interface/pom.xml @@ -7,11 +7,11 @@ cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT automation-interface - 1.3.1 + 1.3.2-SNAPSHOT UTF-8 @@ -23,7 +23,7 @@ cn.testnewbie.automation automation-core - 1.3.1 + 1.3.2-SNAPSHOT org.junit.jupiter diff --git a/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/DBExtension.java b/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/DBExtension.java index 12ec14d170aca5d9bdcca665a631434484ea04b7..8387836c933d2ef580a61ff81d3dbe2bb41d88f5 100644 --- a/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/DBExtension.java +++ b/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/DBExtension.java @@ -12,6 +12,7 @@ import static org.apiguardian.api.API.Status.EXPERIMENTAL; * @author zhanglx */ @API(status = EXPERIMENTAL, since = "1.0") +@Deprecated public class DBExtension implements BeforeAllCallback, AfterAllCallback, @@ -37,9 +38,9 @@ public class DBExtension implements * TestInstancePostProcessor定义了用于发布流程测试实例的"Extensions"的API。 * 常见的用例包括将依赖注入到测试实例中,在测试实例上调用自定义的初始化方法等等。 * 对于具体的例子,请参考["MockitoExtension"]和["SpringExtension"]的源代码。 - * @param testInstance - * @param context - * @throws Exception + * @param testInstance 测试实例 + * @param context 上下文 + * @throws Exception 异常 */ @Override public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception { diff --git a/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/Junit5Extension.java b/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/Junit5Extension.java index b9d216720c4793c7c53f89a95739e7c24d37a84a..c1105bf958a1146877254d2cfbee9c865a593f29 100644 --- a/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/Junit5Extension.java +++ b/automation-interface/src/main/java/cn/testnewbie/automation/interfacetest/junit5/Junit5Extension.java @@ -9,6 +9,7 @@ import java.util.Optional; import static org.apiguardian.api.API.Status.EXPERIMENTAL; @API(status = EXPERIMENTAL, since = "1.0") +@Deprecated public class Junit5Extension implements BeforeAllCallback, AfterAllCallback, diff --git a/automation-ui/README.md b/automation-ui/README.md new file mode 100644 index 0000000000000000000000000000000000000000..342ed3d9bd8e8fdbed5a8ee9351c2ab60fd01453 --- /dev/null +++ b/automation-ui/README.md @@ -0,0 +1,7 @@ +# automation-ui +`automation-ui` 对sikulixapi:2.0.4进行封装 + +## 介绍 + +还在开发中~ + diff --git a/automation-ui/pom.xml b/automation-ui/pom.xml index 65d69500a5db7f6904db281cd61cadad83b7e353..656955910a91d72841369b7fa8b7728e12c181f2 100644 --- a/automation-ui/pom.xml +++ b/automation-ui/pom.xml @@ -7,17 +7,17 @@ cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT automation-ui - 1.0.2-SNAPSHOT + 1.3.2-SNAPSHOT cn.testnewbie.automation automation-core - 1.3.1 + 1.3.2-SNAPSHOT org.junit.jupiter diff --git a/automation-ui/src/main/java/cn/testnewbie/automation/ui/SikuliXExecutor.java b/automation-ui/src/main/java/cn/testnewbie/automation/ui/SikuliXExecutor.java index 7f89fa6bc3074b4d020ff3a92010b7abb78ed2e9..41d9998967b54eed1ba6af2b26383e032ae8a2fb 100644 --- a/automation-ui/src/main/java/cn/testnewbie/automation/ui/SikuliXExecutor.java +++ b/automation-ui/src/main/java/cn/testnewbie/automation/ui/SikuliXExecutor.java @@ -4,10 +4,12 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; import cn.testnewbie.automation.ui.util.SikulixScreenShot; +import org.junit.jupiter.api.Assertions; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.sikuli.basics.Debug; +import org.sikuli.basics.Settings; import org.sikuli.script.Button; import org.sikuli.script.*; @@ -122,6 +124,7 @@ public class SikuliXExecutor { * @param imgName 图片名称 * @param imgSimilar 图片相似度。默认0.85,用默认值传null。 * @param waitSecond 等待秒数。 + * @return boolean 是否存在 */ public static boolean exist(String imgName, float imgSimilar, int waitSecond) { // 查找图片是否存在 @@ -135,6 +138,60 @@ public class SikuliXExecutor { } } + + /** + * 断言是否出现图片 + * + * @param imgName 图片名称 + * @param imgSimilar 图片相似度。默认0.85,用默认值传null。 + * @param waitSecond 等待秒数。 + */ + public static void AssertExist(String imgName, float imgSimilar, int waitSecond) { + Assertions.assertTrue(exist(imgName, imgSimilar, waitSecond), "图片不存在:" + imgName); + } + + + /** + * 断言图片是否消失 + * + * @param imgName 图片名称 + * @param imgSimilar 图片相似度。默认0.85,用默认值传null。 + * @param waitSecond 等待图片消失超时的秒数,建议大于3 + */ + public static void waitImgDisappear(String imgName, float imgSimilar, int waitSecond) { +// int second = 0; +// do { +// try { +// TimeUnit.MICROSECONDS.sleep(900); +// second++; +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// if (second >= waitSecond) { +// Assertions.fail("等待图片消失超时..."); +// } +// } while (SikuliXExecutor.exist("正在请求数据.png", 0.85f, 1)); + + Region region; + Settings.WaitAfterHighlight = 0.5; + try { + for (int i = 0; i < waitSecond; i++) { + region = findImgOnTheScreen(imgName, imgSimilar, 0, 0, false, 1); + if (region != null) { + // 1为高亮的时长,单位秒 + region.highlight(0.4); + log.info("highlight image name : {}", imgName); + } else { + imgNotFind(imgName, true); + return; + } + } + Assertions.fail("等待图片消失超时..."); + } catch (FindFailed findFailed) { + findFailed.printStackTrace(); + } + } + /** * 调用sikulix原生方法查找 */ @@ -337,6 +394,8 @@ public class SikuliXExecutor { /** * 清除输入框中已输入的value值,并输入新数据。 + * + * @param newValue 替换为提供的值 */ public static void replaceInputValue(String newValue) { deleteInputedValue(); diff --git a/automation-ui/src/main/java/cn/testnewbie/automation/ui/UIBase.java b/automation-ui/src/main/java/cn/testnewbie/automation/ui/UIBase.java index 6151f503c1c4af70f86951bbcbd9917ecabe036c..27697713cb26f4f0479d37d989511886189bda1d 100644 --- a/automation-ui/src/main/java/cn/testnewbie/automation/ui/UIBase.java +++ b/automation-ui/src/main/java/cn/testnewbie/automation/ui/UIBase.java @@ -6,6 +6,8 @@ import io.qameta.allure.Step; import org.openqa.selenium.WebDriver; import org.sikuli.script.ImagePath; +import java.util.concurrent.TimeUnit; + /** * UI自动化基类 @@ -27,6 +29,11 @@ public class UIBase { */ @Step public void quit() { + try { + TimeUnit.SECONDS.sleep(2); + } catch (InterruptedException e) { + e.printStackTrace(); + } log.info("用例执行结束,关闭浏览器"); driver.quit();// 关闭浏览器 } diff --git a/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/ScreenCaptureVideo.java b/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/ScreenCaptureVideo.java index 91e2d50efaedc414539b2578878b3c39ba76adbc..7b6f661a18c4007a2e6e71c5a24ef7b3dfeb710b 100644 --- a/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/ScreenCaptureVideo.java +++ b/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/ScreenCaptureVideo.java @@ -10,13 +10,14 @@ import java.io.IOException; * * @author zlx */ +@Deprecated public class ScreenCaptureVideo { private static String cmd = null; private static Process proc = null; /** * @param path =D:\\xxxx\\yyyy.flv - * @throws InterruptedException + * @throws InterruptedException 中断 */ public static void start(String path) throws InterruptedException { if (path.isEmpty() || path == null) { diff --git a/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/VideoRecorder.java b/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/VideoRecorder.java index 84163acba6310c6c17562e38d8d31b179a94b64e..d3518058e5b9b0b6706087e19967bca1370539c8 100644 --- a/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/VideoRecorder.java +++ b/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/VideoRecorder.java @@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit; /** * https://blog.csdn.net/ccystewart/article/details/105286289 */ +@Deprecated public class VideoRecorder { /** private static final Log logger = LogFactory.get(); diff --git a/example-ui/pom.xml b/example-ui/pom.xml index f077df708931e918f02a54135475ba4c12fad551..27170b344806dd1d12bd862e181ff13a45ae92dd 100644 --- a/example-ui/pom.xml +++ b/example-ui/pom.xml @@ -14,6 +14,7 @@ ${maven.compiler.source} 1.9.1 2.13.8 + 1.7.30 @@ -21,7 +22,7 @@ cn.testnewbie.automation automation-ui - 1.0.2-SNAPSHOT + 1.3.2-SNAPSHOT
@@ -54,6 +55,29 @@ aspectjweaver ${aspectj.version}
+ + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.slf4j + jul-to-slf4j + ${slf4j.version} + + + org.slf4j + log4j-over-slf4j + ${slf4j.version} + +
diff --git a/example-ui/src/test/java/cn/testnewbie/automation/ui/demo/SikuliXDemoTest.java b/example-ui/src/test/java/cn/testnewbie/automation/ui/demo/SikuliXDemoTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2a84661fb13d8591eb48e153532889ab897083a7 --- /dev/null +++ b/example-ui/src/test/java/cn/testnewbie/automation/ui/demo/SikuliXDemoTest.java @@ -0,0 +1,93 @@ +package cn.testnewbie.automation.ui.demo; + +import cn.hutool.log.Log; +import cn.hutool.log.LogFactory; +import cn.testnewbie.automation.core.annotation.TimeCost; +import cn.testnewbie.automation.ui.SikuliXExecutor; +import cn.testnewbie.automation.ui.UIBase; +import cn.testnewbie.automation.ui.util.SeleniumScreenShot; +import cn.testnewbie.automation.ui.util.SikulixScreenShot; +import io.qameta.allure.Step; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.chrome.ChromeDriver; +import org.sikuli.script.ImagePath; + +@TimeCost +public class SikuliXDemoTest extends UIBase { + private static final Log log = LogFactory.get(); + + static { + log.warn("本测试类 LoginTestUseCsvBeanSource ,需要开启`project-demo`服务才能正常执行通过..."); + log.warn("本case在window下编写,其他系统可能跑不通"); + log.warn("win10下,如果屏幕分辨率放大过,可能跑不通"); + log.warn("首次运行sikulix编写的脚本会失败,再次运行即可"); + } + + @Test + public void test() throws Exception { + testStart(); + testWithSikuliX(); + quit(); + } + + @Step("准备工作") + public void testStart() throws InterruptedException { + log.info("用户的当前工作目录:" + System.getProperty("user.dir")); + SikulixScreenShot.defaultDir = System.getProperty("user.dir"); + System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); + ImagePath.add("src/test/resources/img/SikuliXDemo/"); + + // webDriver = new FirefoxDriver(); + driver = new ChromeDriver(); + Thread.sleep(1000); + driver.manage().window().maximize(); + + // 隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉WebDriver查询Dom一定时间 + // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + // Cookie cookie = new Cookie("key", "value"); + // driver.manage().addCookie(cookie); + } + + @Step + public void testWithSikuliX() { + try { + log.info("开始执行脚本"); + // 浏览器输入地址 + driver.get("http://testnewbie-projects.gitee.io/testnewbieui/#/manualTest/main"); +// SikuliXExecutor.waitImgDisappear("加号.png", 0.85f, 7); + + SikuliXExecutor.clickImg("加号"); + SikuliXExecutor.clickImg("地址栏.png"); + SikuliXExecutor.inputValue("http://localhost:9999/api/login"); + SikuliXExecutor.clickImg("运行.png"); + SikuliXExecutor.AssertExist("参数错误.png", 0.85f, 1); + + SikuliXExecutor.clickImg("右侧的格式化.png", 0.85f, -23, 21, false, 2); + SikuliXExecutor.AssertExist("参数错误-格式化后.png", 0.85f, 1); + + SikuliXExecutor.clickImg("切换请求.png", 0.85f, 0, 0, false, 2); + SikuliXExecutor.clickImg("请求列表.png", 0.85f, 0, -10, false, 2); + + SikuliXExecutor.doubleClickImg("请求body框.png", 0.85f, 0, 0, false, 2); + SikuliXExecutor.inputValue("{\"account\":\"apitest\",\"customerNo\":\"0001\",\"password\":\"ba85be716df69c74e8daad0398b5aa85\"}"); + SikuliXExecutor.clickImg("格式化.png"); + SikuliXExecutor.clickImg("运行.png"); + + SikuliXExecutor.waitImgDisappear("正在请求数据.png", 0.85f, 7); + + SikuliXExecutor.AssertExist("状态200.png", 0.85f, 1); + SikuliXExecutor.clickImg("未保存.png"); + SikuliXExecutor.AssertExist("已保存.png", 0.85f, 1); + + } catch (Exception e) { + // 截图保留现场 + SeleniumScreenShot.screenShot(driver, "d:\\screenshot\\"); + log.error("error", e); + Assertions.fail("用例失败", e); + } finally { + quit(); + } + } + +} diff --git a/example-ui/src/test/java/cn/testnewbie/automation/ui/ocr/OcrTest.java b/example-ui/src/test/java/cn/testnewbie/automation/ui/ocr/OcrTest.java deleted file mode 100644 index 1ed0d20fe1e24dab5f51d718c51b029c303e5ee1..0000000000000000000000000000000000000000 --- a/example-ui/src/test/java/cn/testnewbie/automation/ui/ocr/OcrTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.testnewbie.automation.ui.ocr; - -import cn.testnewbie.automation.ui.SikuliXExecutor; -import cn.testnewbie.automation.ui.UIBase; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.sikuli.script.FindFailed; -import org.sikuli.script.OCR; - -/** - * java.lang.Error: Invalid memory access - *

- * Error opening data file C:\Users\Administrator\AppData\Roaming\Sikulix\SikulixTesseract\tessdata/chi_sim.traineddata - * Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. - * Failed loading language 'chi_sim' - * Tesseract couldn't load any languages! - */ -@Disabled -public class OcrTest extends UIBase { - - @Test - void ocr() throws FindFailed { -// Settings.OcrDataPath = System.getProperty("user.dir") + "\\src\\test\\resources\\"; - OCR.globalOptions().language("chi_sim"); - - SikuliXExecutor.screen.waitText("帮助", 2).click(); - - SikuliXExecutor.screen.waitText("Help", 2).click(); - SikuliXExecutor.screen.waitText("Window", 2).click(); - } -} diff --git a/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu/BaiDuTest.java b/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu/BaiDuTest.java index 9fe354eb3a9bbecf642ac96c5ec159f6d6897f9a..010c69cf7393338f5e1860ab962c12ce9d2f14f2 100644 --- a/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu/BaiDuTest.java +++ b/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu/BaiDuTest.java @@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author zhanglixing */ @Disabled +@Deprecated public class BaiDuTest extends UIBase { private static final Log log = LogFactory.get(); @@ -37,19 +38,10 @@ public class BaiDuTest extends UIBase { try { System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); - // WebDriver webDriver = new InternetExplorerDriver(); - // WebDriver webDriver = new FirefoxDriver(); - // WebDriver webDriver = new ChromeDriver(); driver = new ChromeDriver(); Thread.sleep(1000); driver.manage().window().maximize(); - // 隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉WebDriver查询Dom一定时间 - // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); - // Cookie cookie = new Cookie("key", "value"); - // driver.manage().addCookie(cookie); - // driver.save_screenshot("C:\error.jpg") - // 浏览器输入地址 driver.get("https://www.baidu.com/"); diff --git a/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu2/BaiDuTest2.java b/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu2/BaiDuTest2.java index dadfbbae7eb3d50d88f359c563ce8a7b3508b3c4..86727641645a49c5fc9b05acb1501d4bdf7e35d2 100644 --- a/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu2/BaiDuTest2.java +++ b/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu2/BaiDuTest2.java @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author zhanglixing */ @Disabled +@Deprecated public class BaiDuTest2 extends UIBase { private static final Log log = LogFactory.get(); @@ -114,7 +115,7 @@ public class BaiDuTest2 extends UIBase { Settings.setShowActions(true); try { - driver.get("http://49.4.49.173/#/login");// 浏览器输入地址 + driver.get("http://127.0.0.1/#/login");// 浏览器输入地址 //登录方式1 SikuliXExecutor.clickImg("登录页面.png", 0.65f, 0, 0, false, 10); diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\210\207\346\215\242\350\257\267\346\261\202.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\210\207\346\215\242\350\257\267\346\261\202.png" new file mode 100644 index 0000000000000000000000000000000000000000..076d6383aa6ca5dedf59618aca5810054d698377 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\210\207\346\215\242\350\257\267\346\261\202.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\212\240\345\217\267.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\212\240\345\217\267.png" new file mode 100644 index 0000000000000000000000000000000000000000..19a25f9a7cd6aeac0e025e6ba0bc52fbecc0be14 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\212\240\345\217\267.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257-\346\240\274\345\274\217\345\214\226\345\220\216.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257-\346\240\274\345\274\217\345\214\226\345\220\216.png" new file mode 100644 index 0000000000000000000000000000000000000000..ca4d776edaee579d583dab450d44bcbf37dbb03c Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257-\346\240\274\345\274\217\345\214\226\345\220\216.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257.png" new file mode 100644 index 0000000000000000000000000000000000000000..75121f174fa22254a8e088724878d171a2abdb77 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\217\263\344\276\247\347\232\204\346\240\274\345\274\217\345\214\226.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\217\263\344\276\247\347\232\204\346\240\274\345\274\217\345\214\226.png" new file mode 100644 index 0000000000000000000000000000000000000000..516a8b415cb78ddf0c26c1cb2cee8d73465aa6f2 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\217\263\344\276\247\347\232\204\346\240\274\345\274\217\345\214\226.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\234\260\345\235\200\346\240\217.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\234\260\345\235\200\346\240\217.png" new file mode 100644 index 0000000000000000000000000000000000000000..eac7a309c26515c0c6ccdb729f855cdae47e43bb Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\234\260\345\235\200\346\240\217.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\345\267\262\344\277\235\345\255\230.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\345\267\262\344\277\235\345\255\230.png" new file mode 100644 index 0000000000000000000000000000000000000000..afb8b41e13b99481ed244340bb486ff2c73b0313 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\345\267\262\344\277\235\345\255\230.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\346\234\252\344\277\235\345\255\230.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\346\234\252\344\277\235\345\255\230.png" new file mode 100644 index 0000000000000000000000000000000000000000..daa53c3be69f31b72f4d65b92028edd8544cea11 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\346\234\252\344\277\235\345\255\230.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\346\240\274\345\274\217\345\214\226.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\346\240\274\345\274\217\345\214\226.png" new file mode 100644 index 0000000000000000000000000000000000000000..7f037be9f20610eec2b988ed425c65928dd9b045 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\346\240\274\345\274\217\345\214\226.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\346\255\243\345\234\250\350\257\267\346\261\202\346\225\260\346\215\256.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\346\255\243\345\234\250\350\257\267\346\261\202\346\225\260\346\215\256.png" new file mode 100644 index 0000000000000000000000000000000000000000..930d75e161ce1ade54a188342905abe2566b75b8 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\346\255\243\345\234\250\350\257\267\346\261\202\346\225\260\346\215\256.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\347\212\266\346\200\201200.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\347\212\266\346\200\201200.png" new file mode 100644 index 0000000000000000000000000000000000000000..84db28aec22cd11564e6519b59447cc7712e2cfa Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\347\212\266\346\200\201200.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202body\346\241\206.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202body\346\241\206.png" new file mode 100644 index 0000000000000000000000000000000000000000..55249f5c27feacb4961b0902bf21321e1950b14c Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202body\346\241\206.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202\345\210\227\350\241\250.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202\345\210\227\350\241\250.png" new file mode 100644 index 0000000000000000000000000000000000000000..8d9677421b553c9fcca0af3b231fff1a038d3c72 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202\345\210\227\350\241\250.png" differ diff --git "a/example-ui/src/test/resources/img/SikuliXDemo/\350\277\220\350\241\214.png" "b/example-ui/src/test/resources/img/SikuliXDemo/\350\277\220\350\241\214.png" new file mode 100644 index 0000000000000000000000000000000000000000..2ee440087e36992bbc7b086b095ee55f110b8766 Binary files /dev/null and "b/example-ui/src/test/resources/img/SikuliXDemo/\350\277\220\350\241\214.png" differ diff --git a/example-ui/src/test/resources/logback.xml b/example-ui/src/test/resources/logback.xml new file mode 100644 index 0000000000000000000000000000000000000000..e95af2137f4b5bfd86fe82f81dad9210d1a9a8fa --- /dev/null +++ b/example-ui/src/test/resources/logback.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + + ${FILE_PATH}/log/test-newbie.log + + ${FILE_LOG_PATTERN} + + + ${FILE_PATH}/log/test-newbie-%d{yyyy-MM-dd}.%i.log + 30 + + 16MB + + + + + + + + + ${FILE_PATH}/log/test-newbie.error.log + + + ERROR + ACCEPT + DENY + + + + ${FILE_PATH}/log/test-newbie-error-%d{yyyy-MM-dd}.%i.log + + 30 + + 16MB + + + + ${FILE_LOG_PATTERN} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example-ui/src/test/resources/tessdata/chi_sim.traineddata b/example-ui/src/test/resources/tessdata/chi_sim.traineddata deleted file mode 100644 index 0f3378ec47f55b1aa8506611a278f0a7f6627a92..0000000000000000000000000000000000000000 --- a/example-ui/src/test/resources/tessdata/chi_sim.traineddata +++ /dev/null @@ -1,1435 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - tessdata/chi_sim.traineddata at master · tesseract-ocr/tessdata - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- Skip to content - - - - - - - - - -
- -
- - - - - -
- - - -
- - - - - - - - - -
-
-
- - - - - - - - - - - - - - - -
- -
- -
-

- - - / - - tessdata - - -

- - -
- -
    - -
  • - -
    - - - - - - - - Watch - - - - - -
    -
    -

    Notifications

    - -
    - -
    -
    - - - - - - - - -
    - -
    -
    -
    - - -
    -
    - -
    - -
  • - -
  • -
    -
    - - -
    -
    - - -
    - -
  • - -
  • -
    -
    - -
  • -
- -
- - -
- - -
-
- - - - - -
- - - - Permalink - - - -
- -
-
- - - master - - - -
-
-
- Switch branches/tags - -
- - - -
- -
- -
- - -
- -
- - - - - - - - - - - -
- - -
-
-
-
- -
- -
- - - - Go to file - - -
- - -
- -
- - - -
- -
-
- - @stweil - - -
- - Latest commit - 3737fed - May 10, 2018 - - - - - - History - - -
-
-
Signed-off-by: Stefan Weil <sw@weilnetz.de>
- -
- -
-
- - - 2 - - contributors - - -
- -

- Users who have contributed to this file -

-
- - - - - - - - -
-
- - - @theraysmith - - @stweil - - - -
-
- - - - - - -
- -
-
- - 42.3 MB -
- -
- -
- Download -
- -
- - - - -
- -
-
-
- - - -
-
- View raw -

(Sorry about that, but we can’t show files that are this big right now.)

-
-
- -
- - - -
- - -
- - -
-
- - -
- - - -
-
- -
-
- -
- - - - - - - - - - - - - - - - - - diff --git a/example/pom.xml b/example/pom.xml index f62141a3c2e5401bcbab10b2be796f3773b24e38..e7270472c6707429995def56af74e169a8713dea 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -23,17 +23,17 @@ cn.testnewbie.automation automation-interface - 1.3.1 + 1.3.2-SNAPSHOT cn.testnewbie.automation automation-email - 1.3.1 + 1.3.2-SNAPSHOT cn.testnewbie.automation automation-dingding - 1.3.1 + 1.3.2-SNAPSHOT mysql diff --git a/example/src/test/java/com/testexample/otherdemo/core/AssertJ.java b/example/src/test/java/com/testexample/dbtest/AssertJTest.java similarity index 61% rename from example/src/test/java/com/testexample/otherdemo/core/AssertJ.java rename to example/src/test/java/com/testexample/dbtest/AssertJTest.java index 63a5f0abd78376aa26eb43b7cadb79b63e0b3d84..488211a35bc3b1951bfe961aa3057f0922143326 100644 --- a/example/src/test/java/com/testexample/otherdemo/core/AssertJ.java +++ b/example/src/test/java/com/testexample/dbtest/AssertJTest.java @@ -1,10 +1,10 @@ -package com.testexample.otherdemo.core; +package com.testexample.dbtest; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; import cn.testnewbie.automation.core.common.TNConstants; import cn.testnewbie.automation.core.config.PropertyMgr; -import cn.testnewbie.automation.core.db.IDataBase; +import cn.testnewbie.automation.core.db.IDataBaseStep; import cn.testnewbie.automation.core.util.StopWatchUtil; import com.mysql.cj.jdbc.MysqlDataSource; import org.assertj.db.type.Request; @@ -16,9 +16,9 @@ import static org.assertj.db.api.Assertions.assertThat; @Disabled -public class AssertJ implements IDataBase { +public class AssertJTest implements IDataBaseStep { private static final Log log = LogFactory.get(); - StopWatchUtil stopWatchUtil = new StopWatchUtil("DataBaseTest"); + StopWatchUtil stopWatchUtil = new StopWatchUtil("AssertJTest"); @Test void assert_j() { @@ -26,15 +26,16 @@ public class AssertJ implements IDataBase { String username = PropertyMgr.getString(TNConstants.USERNAME); String password = PropertyMgr.getString(TNConstants.PASSWORD); Source source = new Source(url, username, password); - Request request = new Request(source, "SELECT name,method,url FROM au_step_http"); + Request request = new Request(source, "SELECT * FROM staff"); assertThat(request) - .column("method") - .hasValues("POST", "GET"); + .column("first_name") + .hasValues("Mike", "Jon"); + request = new Request(source, "SELECT first_name,last_name,address_id,email FROM staff"); assertThat(request) - .row().hasValues("www.baidu.com", "POST", "http://127.0.0.1:8090/demo/addDemo") - .row().hasValues("/demo/?id=15", "GET", "http://127.0.0.1:8090/demo/queryDemo"); + .row().hasValues("Mike", "Hillyer", 3, "Mike.Hillyer@sakilastaff.com") + .row().hasValues("Jon", "Stephens", 4, "Jon.Stephens@sakilastaff.com"); } @@ -43,23 +44,24 @@ public class AssertJ implements IDataBase { void assert_j2() { Request request = new Request(db.getDataSource(), - "SELECT name,method,url FROM au_step_http where id = ? ", + "SELECT first_name,last_name,address_id,email FROM staff where active = ?", new Object[]{"1"}); stopWatchUtil.goOn("assertThat1"); assertThat(request) - .column("method") - .hasValues("POST"); + .column("first_name") + .hasValues("Mike", "Jon"); // ------------------------------------------------ stopWatchUtil.goOn("assertThat2"); assertThat(request) - .row().hasValues("www.baidu.com", "POST", "http://127.0.0.1:8090/demo/addDemo"); + .row().hasValues("Mike", "Hillyer", 3, "Mike.Hillyer@sakilastaff.com"); + // ------------------------------------------------ stopWatchUtil.goOn("new Request 2 "); // ------------ - request = new Request(db.getDataSource(), "SELECT name,status,description FROM au_step_jdbc"); + request = new Request(db.getDataSource(), "SELECT first_name,last_name,address_id,email FROM staff where active = 1"); assertThat(request) - .column("description") - .hasValues("描述"); + .column("email") + .hasValues("Mike.Hillyer@sakilastaff.com", "Jon.Stephens@sakilastaff.com"); stopWatchUtil.stop(); // ------------ } @@ -80,17 +82,17 @@ public class AssertJ implements IDataBase { stopWatchUtil.goOn("new Request"); Request request = new Request(source2, - "SELECT name,method,url FROM au_step_http where id = ? ", - new Object[]{"1"}); + "SELECT first_name,last_name,address_id,email FROM staff where active = ?", + new Object[]{1}); stopWatchUtil.goOn("assertThat1"); // ------------ assertThat(request) - .column("method") - .hasValues("POST"); + .column("first_name") + .hasValues("Mike", "Jon"); stopWatchUtil.goOn("assertThat2"); // ------------ assertThat(request) - .row().hasValues("www.baidu.com", "POST", "http://127.0.0.1:8090/demo/addDemo"); + .row().hasValues("Mike", "Hillyer", 3, "Mike.Hillyer@sakilastaff.com"); stopWatchUtil.stop(); // ------------ } } diff --git a/example/src/test/java/com/testexample/dbtest/DataBaseStepTest.java b/example/src/test/java/com/testexample/dbtest/DataBaseStepTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1cac88af00668f1688cf62671bde6e9a807b2907 --- /dev/null +++ b/example/src/test/java/com/testexample/dbtest/DataBaseStepTest.java @@ -0,0 +1,54 @@ +package com.testexample.dbtest; + +import cn.hutool.json.JSONUtil; +import cn.hutool.log.Log; +import cn.hutool.log.LogFactory; +import cn.testnewbie.automation.core.db.IDataBaseStep; +import org.json.JSONException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; +import org.skyscreamer.jsonassert.JSONAssert; + +import java.sql.SQLException; +import java.util.List; + + +@Disabled +public class DataBaseStepTest implements IDataBaseStep { + private static final Log log = LogFactory.get(); + + @Test + void executeQuery() throws SQLException, JSONException { + String expected = "[{\"first_name\":\"Mike\",\"last_name\":\"Hillyer\",\"address_id\":3,\"email\":\"Mike.Hillyer@sakilastaff.com\"}," + + "{\"first_name\":\"Jon\",\"last_name\":\"Stephens\",\"address_id\":4,\"email\":\"Jon.Stephens@sakilastaff.com\"}]"; + + List list = db.executeQuery("SELECT first_name,last_name,address_id,email FROM staff"); + log.info(list.toString()); + String actual = JSONUtil.toJsonStr(list); + log.info(actual); + JSONAssert.assertEquals(expected, actual, false); + } + + @Test + void execSql1() throws SQLException { + boolean b = db.execSql("SELECT first_name,last_name,address_id,email FROM staff"); + log.info("execSql, result : " + b); + } + + @Test + void execSql2() throws SQLException, JSONException { + Assertions.assertThrows(AssertionFailedError.class, () -> db.execSql("update staff set username= 'Mike' ")); + Assertions.assertThrows(AssertionFailedError.class, () -> db.execSql("update staff set username= 'Mike' ; ")); + Assertions.assertThrows(AssertionFailedError.class, () -> db.execSql("update staff set username= 'Mike' where staff_id = 1 ; ")); + Assertions.assertFalse(db.execSql("update staff set username= 'Mike1' where staff_id = 1 ")); + Assertions.assertFalse(db.execSql("update staff set username= 'Mike' where staff_id = 1 ")); + db.checkDataBase("SELECT username FROM staff where staff_id = 1","[{\"username\":\"Mike\"}]"); + } + + + @Test + void execSql3() throws Exception { + } +} diff --git a/example/src/test/java/com/testexample/interfacetest/LoginTest.java b/example/src/test/java/com/testexample/interfacetest/LoginTest.java index 67275d8a93f4c82d3ec93f47e47cdb5074b19b42..b9f74e4f0b1aecf736cfceee48c1f9e87e6a6a79 100644 --- a/example/src/test/java/com/testexample/interfacetest/LoginTest.java +++ b/example/src/test/java/com/testexample/interfacetest/LoginTest.java @@ -14,7 +14,7 @@ import org.opentest4j.AssertionFailedError; import java.util.HashMap; -import static cn.testnewbie.automation.core.AssertUtil.assertByJSONPath; +import static cn.testnewbie.automation.core.util.AssertUtil.assertByJSONPath; import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; @Disabled diff --git a/example/src/test/java/com/testexample/interfacetest/LoginTestUseCsvBeanSource.java b/example/src/test/java/com/testexample/interfacetest/LoginTestUseCsvBeanSource.java index 5ecf00299ff2cbef29d0974b833f888277d56b6c..c552d2d3b7f808a7ec5ef1d413bdac10daa86596 100644 --- a/example/src/test/java/com/testexample/interfacetest/LoginTestUseCsvBeanSource.java +++ b/example/src/test/java/com/testexample/interfacetest/LoginTestUseCsvBeanSource.java @@ -8,7 +8,6 @@ import cn.testnewbie.automation.core.annotation.CsvBeanSource; import com.testexample.bean.LoginBean; import com.testexample.util.Md5Util; import io.qameta.allure.Step; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.params.ParameterizedTest; diff --git a/example/src/test/java/com/testexample/interfacetest/LoginWithOnClassTest.java b/example/src/test/java/com/testexample/interfacetest/LoginWithOnClassTest.java index a9575781f8d816f57ac63a8812d632ce157e7f09..cf4c4f26863debb45c45236cf984197311daa12a 100644 --- a/example/src/test/java/com/testexample/interfacetest/LoginWithOnClassTest.java +++ b/example/src/test/java/com/testexample/interfacetest/LoginWithOnClassTest.java @@ -2,7 +2,7 @@ package com.testexample.interfacetest; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; -import cn.testnewbie.automation.core.AssertUtil; +import cn.testnewbie.automation.core.util.AssertUtil; import cn.testnewbie.automation.interfacetest.step.HttpStep; import com.testexample.annotation.LoginWith; import com.testexample.common.Constants; diff --git a/example/src/test/java/com/testexample/interfacetest/LoginWithOnMethodTest.java b/example/src/test/java/com/testexample/interfacetest/LoginWithOnMethodTest.java index 53b22d3b7af896ecc86be6f7c0fa234f6c27b85a..8b6c02784b2bb87dcb98c990d9ef021ac4900ffa 100644 --- a/example/src/test/java/com/testexample/interfacetest/LoginWithOnMethodTest.java +++ b/example/src/test/java/com/testexample/interfacetest/LoginWithOnMethodTest.java @@ -2,7 +2,7 @@ package com.testexample.interfacetest; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; -import cn.testnewbie.automation.core.AssertUtil; +import cn.testnewbie.automation.core.util.AssertUtil; import cn.testnewbie.automation.interfacetest.step.HttpStep; import com.testexample.annotation.LoginWith; import com.testexample.common.Constants; diff --git a/example/src/test/java/com/testexample/otherdemo/core/DataBaseTest.java b/example/src/test/java/com/testexample/otherdemo/core/DataBaseTest.java deleted file mode 100644 index bd14e13b6ba13eacd0e790c0bb883ed9438d36d2..0000000000000000000000000000000000000000 --- a/example/src/test/java/com/testexample/otherdemo/core/DataBaseTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.testexample.otherdemo.core; - -import cn.hutool.json.JSONUtil; -import cn.hutool.log.Log; -import cn.hutool.log.LogFactory; -import cn.testnewbie.automation.core.db.IDataBase; -import cn.testnewbie.automation.core.util.StopWatchUtil; -import org.json.JSONException; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.skyscreamer.jsonassert.JSONAssert; - -import java.sql.SQLException; -import java.util.List; - - -@Disabled -public class DataBaseTest implements IDataBase { - private static final Log log = LogFactory.get(); - StopWatchUtil stopWatchUtil = new StopWatchUtil("DataBaseTest"); - - @Test - void executeQuery() throws SQLException, JSONException { -// db.getConnection(); - List list = db.executeQuery("SELECT name,method,url FROM au_step_http"); - log.info(list.toString()); - - String expected = "[{\"name\":\"/demo/?id=15\", \"method\":\"GET\", \"url\":\"http://127.0.0.1:8090/demo/queryDemo\"},{\"name\":\"www.baidu.com\", \"method\":\"POST\", \"url\":\"http://127.0.0.1:8090/demo/addDemo\"}]"; - String actual = JSONUtil.toJsonStr(list); - log.info(actual); - JSONAssert.assertEquals(expected, actual, false); - } - -} diff --git a/example/src/test/java/com/testexample/otherdemo/junit5demo/RegisterExtensionTest.java b/example/src/test/java/com/testexample/otherdemo/junit5demo/RegisterExtensionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3126e387e55e0ba08d63b9294f9f8fef28a16cd2 --- /dev/null +++ b/example/src/test/java/com/testexample/otherdemo/junit5demo/RegisterExtensionTest.java @@ -0,0 +1,42 @@ +package com.testexample.otherdemo.junit5demo; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; + +/** + * When an extension is registered declaratively via @ExtendWith, it can typically only be configured via annotations. + * In contrast, when an extension is registered via @RegisterExtension, it can be configured programmatically + * for example, in order to pass arguments to the extension’s constructor, a static factory method, or a builder API. + * + * https://zhuanlan.zhihu.com/p/262504347 + */ +public class RegisterExtensionTest { + + static class ExceptionHandler implements TestExecutionExceptionHandler { + private String message; + + ExceptionHandler(String message) { + this.message = message; + } + + @Override + public void handleTestExecutionException( + ExtensionContext context, Throwable throwable) throws Throwable { + throw new RuntimeException(String.format( + "Display name: [%s], reason: [%s], raw message: [%s]", + context.getDisplayName(), this.message, throwable.getMessage())); + } + } + + @RegisterExtension + static ExceptionHandler exceptionHandler = new ExceptionHandler("异常被捕获了"); + + @Test + void test() { + throw new RuntimeException("测试出错啦!"); + } + + +} diff --git a/example/src/test/java/com/testexample/otherdemo/util/AssertUtilTest.java b/example/src/test/java/com/testexample/otherdemo/util/AssertUtilTest.java index fad580e1486e515c33a3a6712154f75f406c761f..69bd4b5d99a4ac6b01cc843c06d65bad41ec6015 100644 --- a/example/src/test/java/com/testexample/otherdemo/util/AssertUtilTest.java +++ b/example/src/test/java/com/testexample/otherdemo/util/AssertUtilTest.java @@ -2,14 +2,14 @@ package com.testexample.otherdemo.util; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; -import cn.testnewbie.automation.core.AssertUtil; +import cn.testnewbie.automation.core.util.AssertUtil; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.HashMap; -import static cn.testnewbie.automation.core.AssertUtil.assertByJSONPath; +import static cn.testnewbie.automation.core.util.AssertUtil.assertByJSONPath; @DisplayName("AssertUtil工具类测试") public class AssertUtilTest { diff --git a/example/src/test/resources/testnewbie.properties b/example/src/test/resources/testnewbie.properties index 3598f3ac4d3ae417adf3dce28da07bd57d695d88..6c625d406a7fe9143a109510d6f6f1c7ca53007a 100644 --- a/example/src/test/resources/testnewbie.properties +++ b/example/src/test/resources/testnewbie.properties @@ -1,4 +1,3 @@ -logging.config = classpath:logback-spring.xml ### ------------------- 数据库配置 ------------------- #连接基本属性 diff --git a/pom.xml b/pom.xml index e0b892702ceaf59516b79cc00a44fab5c9ed0e08..a67a983ee50056559410b67bec5cc298e3595be9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 cn.testnewbie.automation automation-parent - 1.3.1 + 1.3.2-SNAPSHOT pom testnewbie parent pom testnewbie-automation parent pom