From bfdcbc9264f079f086424848d09f094a9bb09235 Mon Sep 17 00:00:00 2001 From: zhanglx Date: Thu, 11 Mar 2021 22:12:44 +0800 Subject: [PATCH 1/6] =?UTF-8?q?md=E6=95=B4=E7=90=86=EF=BC=8C=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + automation-agent/README.md | 34 ++--- automation-agent/pom.xml | 6 +- .../java/cn/testnewbie/agent/SimpleAgent.java | 9 +- automation-core/README.md | 44 ++++++ automation-core/pom.xml | 4 +- .../automation/core/DataBaseStep.java | 114 --------------- .../core/cache/HttpCacheManage.java | 3 +- .../automation/core/common/TNConstants.java | 9 +- .../automation/core/db/DataBase.java | 134 +++++++++++++++++- .../db/{IDataBase.java => IDataBaseStep.java} | 2 +- .../automation/core/db/ResultSetUtil.java | 4 +- .../automation/core/db/SqlFileTools.java | 2 +- .../core/{ => util}/AssertUtil.java | 10 +- .../automation/core/{ => util}/ExcelUtil.java | 2 +- .../core/util/InputStreamToBytes.java | 8 +- automation-core/start.bat | 39 ----- automation-dingding/README.md | 53 ++++++- automation-dingding/pom.xml | 6 +- automation-email/README.md | 52 ++++++- automation-email/pom.xml | 6 +- .../mail/MailSummaryGeneratingListener.java | 2 +- .../mail/MailTestExecutionSummary.java | 29 ++-- automation-interface/pom.xml | 6 +- .../interfacetest/junit5/DBExtension.java | 7 +- .../interfacetest/junit5/Junit5Extension.java | 1 + automation-ui/README.md | 7 + automation-ui/pom.xml | 6 +- .../automation/ui/SikuliXExecutor.java | 3 + .../ui/util/ScreenCaptureVideo.java | 3 +- .../automation/ui/util/VideoRecorder.java | 1 + example-ui/pom.xml | 2 +- .../testnewbie/automation/ui/ocr/OcrTest.java | 31 ---- example/pom.xml | 6 +- .../AssertJ.java => dbtest/AssertJTest.java} | 44 +++--- .../testexample/dbtest/DataBaseStepTest.java | 54 +++++++ .../testexample/interfacetest/LoginTest.java | 2 +- .../LoginTestUseCsvBeanSource.java | 1 - .../interfacetest/LoginWithOnClassTest.java | 2 +- .../interfacetest/LoginWithOnMethodTest.java | 2 +- .../otherdemo/core/DataBaseTest.java | 34 ----- .../junit5demo/RegisterExtensionTest.java | 42 ++++++ .../otherdemo/util/AssertUtilTest.java | 4 +- pom.xml | 2 +- 44 files changed, 504 insertions(+), 329 deletions(-) create mode 100644 automation-core/README.md delete mode 100644 automation-core/src/main/java/cn/testnewbie/automation/core/DataBaseStep.java rename automation-core/src/main/java/cn/testnewbie/automation/core/db/{IDataBase.java => IDataBaseStep.java} (87%) rename automation-core/src/main/java/cn/testnewbie/automation/core/{ => util}/AssertUtil.java (91%) rename automation-core/src/main/java/cn/testnewbie/automation/core/{ => util}/ExcelUtil.java (39%) delete mode 100644 automation-core/start.bat create mode 100644 automation-ui/README.md delete mode 100644 example-ui/src/test/java/cn/testnewbie/automation/ui/ocr/OcrTest.java rename example/src/test/java/com/testexample/{otherdemo/core/AssertJ.java => dbtest/AssertJTest.java} (61%) create mode 100644 example/src/test/java/com/testexample/dbtest/DataBaseStepTest.java delete mode 100644 example/src/test/java/com/testexample/otherdemo/core/DataBaseTest.java create mode 100644 example/src/test/java/com/testexample/otherdemo/junit5demo/RegisterExtensionTest.java diff --git a/.gitignore b/.gitignore index 0e6f948..fdd78d1 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 a589ef7..77c5d69 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 725428c..3501a9c 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 4f2ae06..4350ed5 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 0000000..7eed3d7 --- /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 e13a587..a2fc12d 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 ec2ee96..0000000 --- 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 37514a8..55bbf06 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 cca4be8..13cdcc3 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 5a590e9..cd9551f 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 e4fc422..83a9261 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 7761ee9..31013dc 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 a221e00..6588c82 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 f8fb8ac..ce79092 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 1752a9a..533f7ac 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 30a9327..d3878ef 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 a32a77f..0000000 --- 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 f8161cb..34103c3 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 9c66c09..e59ecc6 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 1fb58fe..6bf531a 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 e97956f..5c6c016 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 068ff20..54a6207 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 a573dbf..ce6e485 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 b2a7f92..77ccbf5 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 12ec14d..8387836 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 b9d2167..c1105bf 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 0000000..342ed3d --- /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 65d6950..6569559 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 7f89fa6..503af40 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 @@ -122,6 +122,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) { // 查找图片是否存在 @@ -337,6 +338,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/util/ScreenCaptureVideo.java b/automation-ui/src/main/java/cn/testnewbie/automation/ui/util/ScreenCaptureVideo.java index 91e2d50..7b6f661 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 84163ac..d351805 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 f077df7..3bce425 100644 --- a/example-ui/pom.xml +++ b/example-ui/pom.xml @@ -21,7 +21,7 @@ cn.testnewbie.automation automation-ui - 1.0.2-SNAPSHOT + 1.3.2-SNAPSHOT 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 1ed0d20..0000000 --- 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/pom.xml b/example/pom.xml index f62141a..e727047 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 63a5f0a..488211a 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 0000000..1cac88a --- /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 67275d8..b9f74e4 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 5ecf002..c552d2d 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 a957578..cf4c4f2 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 53b22d3..8b6c027 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 bd14e13..0000000 --- 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 0000000..3126e38 --- /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 fad580e..69bd4b5 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/pom.xml b/pom.xml index e0b8927..a67a983 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 -- Gitee From f81513c1bca91d9a689fae8b41223391ea780a93 Mon Sep 17 00:00:00 2001 From: zhanglx Date: Thu, 11 Mar 2021 22:15:00 +0800 Subject: [PATCH 2/6] =?UTF-8?q?md=E6=95=B4=E7=90=86=EF=BC=8C=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/src/test/resources/testnewbie.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/example/src/test/resources/testnewbie.properties b/example/src/test/resources/testnewbie.properties index 3598f3a..6c625d4 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 ### ------------------- 数据库配置 ------------------- #连接基本属性 -- Gitee From 6869ed9f630a13031d1348705a459a1248f7792e Mon Sep 17 00:00:00 2001 From: zhanglx Date: Thu, 11 Mar 2021 23:31:45 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Eui=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/ui/SikuliXExecutor.java | 13 + .../cn/testnewbie/automation/ui/UIBase.java | 7 + .../automation/ui/demo/SikuliXDemoTest.java | 92 ++ .../automation/ui/testbaidu/BaiDuTest.java | 9 - ...7\346\215\242\350\257\267\346\261\202.png" | Bin 0 -> 683 bytes .../SikuliXDemo/\345\212\240\345\217\267.png" | Bin 0 -> 253 bytes ...4\345\274\217\345\214\226\345\220\216.png" | Bin 0 -> 1299 bytes ...2\346\225\260\351\224\231\350\257\257.png" | Bin 0 -> 966 bytes ...4\346\240\274\345\274\217\345\214\226.png" | Bin 0 -> 950 bytes .../\345\234\260\345\235\200\346\240\217.png" | Bin 0 -> 1220 bytes .../\345\267\262\344\277\235\345\255\230.png" | Bin 0 -> 467 bytes .../\346\234\252\344\277\235\345\255\230.png" | Bin 0 -> 468 bytes .../\346\240\274\345\274\217\345\214\226.png" | Bin 0 -> 420 bytes ...7\346\261\202\346\225\260\346\215\256.png" | Bin 0 -> 554 bytes .../\347\212\266\346\200\201200.png" | Bin 0 -> 376 bytes ...0\257\267\346\261\202body\346\241\206.png" | Bin 0 -> 2070 bytes ...7\346\261\202\345\210\227\350\241\250.png" | Bin 0 -> 657 bytes .../SikuliXDemo/\350\277\220\350\241\214.png" | Bin 0 -> 430 bytes example-ui/src/test/resources/logback.xml | 93 ++ .../resources/tessdata/chi_sim.traineddata | 1435 ----------------- 20 files changed, 205 insertions(+), 1444 deletions(-) create mode 100644 example-ui/src/test/java/cn/testnewbie/automation/ui/demo/SikuliXDemoTest.java create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\345\210\207\346\215\242\350\257\267\346\261\202.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\345\212\240\345\217\267.png" create mode 100644 "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" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\345\217\202\346\225\260\351\224\231\350\257\257.png" create mode 100644 "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" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\345\234\260\345\235\200\346\240\217.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\345\267\262\344\277\235\345\255\230.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\346\234\252\344\277\235\345\255\230.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\346\240\274\345\274\217\345\214\226.png" create mode 100644 "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" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\347\212\266\346\200\201200.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202body\346\241\206.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\350\257\267\346\261\202\345\210\227\350\241\250.png" create mode 100644 "example-ui/src/test/resources/img/SikuliXDemo/\350\277\220\350\241\214.png" create mode 100644 example-ui/src/test/resources/logback.xml delete mode 100644 example-ui/src/test/resources/tessdata/chi_sim.traineddata 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 503af40..4f8a589 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,6 +4,7 @@ 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; @@ -136,6 +137,18 @@ 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); + } + /** * 调用sikulix原生方法查找 */ 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 6151f50..2769771 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/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 0000000..c9601f8 --- /dev/null +++ b/example-ui/src/test/java/cn/testnewbie/automation/ui/demo/SikuliXDemoTest.java @@ -0,0 +1,92 @@ +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; + +import java.util.concurrent.TimeUnit; + +@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.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"); + + while (SikuliXExecutor.exist("正在请求数据.png", 0.85f, 1)) { + TimeUnit.SECONDS.sleep(1); + } + 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); + } + } + +} 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 9fe354e..7da79de 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 @@ -37,19 +37,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/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 GIT binary patch literal 683 zcmeAS@N?(olHy`uVBq!ia0vp^Agsf|1|+|+yw_r2U@G!-aSX|5d^`KT|K$LYz@j=3mY5*hy{G;kOkl%w=S@$9i1&=Xlw~Czbb( zaj}8gyLsCz{iJ7UZS{P#{gq(ad+`bL&pBP+DlPxvzt{fvi@&b!T`X_^v7k;&c71o) z>j>RV-}d(9B-E&O4!>|c6j#rva&Kb~I7|IhmMf$#rbz5W%NeY-yT*4NqLHrkb3u}h8IR|Q!{E(?r_ zJ2Gc?`}c2(yVBpW&|edB2L;q%V!))C@-IzN8u`cRSiXO7!dYH0QB3*2tGa``_~1%H;EULj9*6vr+3 zvndfdL@)v>plgX$rq)N%MT+)MP8zV4KJl6ulH*r;$;sqNyUpE;r6#lbqEtfP1aGvw z>gk;l*HSY<{FC!MHq{HVUz1Io;`jp>SJ}2KG7ef&V489@?Gel7R8zMj<}=)YiIBn5 L)z4*}Q$iB}os2U# literal 0 HcmV?d00001 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 GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0vp^=0L2%!3HFCXD%uRQb#;p977^n-(KI#b;v-X^ZBe06GBRx&+X@bIQdb8X5UmOar0Ox-`CT5b28_g=C_zy_PInil2!Kl=j~r5cYhUh z&3;;$|6xZ?KuL7>V#~0bH%@aZou0qrcK$^FX(!t5xxZBR(|uvl&wpxt$*u!A3FhZb t_&mFA6vSM(9#ptSIbCuly-H5>e_b(<#-@bg@>-MEjnLGcaXZ?PEF#3OTb>{4H`xhBy!QVn&Cry!C{q?i$Q}>eG zs_Xkp?O&)LSslIf|EIN2-Q~86=l{+Ay5zU{fj3j0t=qzreromG@UJWCU!ULhj@fSE zah0FRS$`ht)~ERdNf}=`74)xI8p>3H&;tQ7JkFyHauRgR^n6+9i+&A^R-^$FJeJ9iWWL_seN!j;& zJqJi?47yvb{U*nW&q3 z_PE@=PuhwKA6qg#`E1#)tyWSnY|Zct3itoCST*u(%4*h>rw`sMoT(Br{g$z}x#N54 zmCf3`)%&kRb1`Z2CUXc2O%a^%6X^OD>B$Tik=+iA+LqgEeBLY#|C{~$<2!5p^=kD| zx7V!ifB(7vmSI?Jop*+3(?&hHZ7nOGcV^zzt~{z~AFjLCsBlZ%*X`dH|KooC^t06# zzr&WNru9viJN(;v-M>FkJ08hRvAVcMAyU_2ZEMy{<*?b&+pL`~dG=ph8k!q8tMt7U;|0S=B$`(&Vc~%r|~XzR!7dQQdPTciL8#m&uv2*>^3^zn}bm{}VCA zS(~@~oBzj+L-&3Di`sVe_jc)f#S`o9+&Zi16@UHTv}@m&@~_^rHMjg>nA)>7`wCv# z*Pi}1?Qg{KTGiE|9`fGN?LpI5rSeREAOH8B?)p`4@6BrA@BGRV(d_Ggf6ukQ5`T|O z_lwg0@G?1U=cRvZ^`gD^Uiy?C|1~P~#e^ri4!NT7xz%sogqHq|zMWk)heP-A<~@B| z8!O*V)$;dVbj<4Z?7R18XSPZontF_D>G99GFVk1AN%txGmM{7-|5fSh2{tPy7lg%z z%v~eAt8_#BuX~%e$MR<6hMn&2{3&A`{I*H2@QYLT1# z#5=TlI*>I}>-}D4uhXR+e+*ymm^XWu>~EdB3td*O-Rd5b=)~kAx@$M93yO0g**u2p zYmmN0j_Evo8W%#b)otOe7krh~~ta*6gonHHsviuiKw-@eag%&k2`yTPV>3h1n m!J(WRRP>;wNl=+o&oDFAa6`bvRV={5j=|H_&t;ucLK6TU*IvZ{ literal 0 HcmV?d00001 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 GIT binary patch literal 966 zcmV;%13CPOP) zS#I1g3_zPA2TfX_JySl4o+Tgs?3vO|0Rw`-Rid}*J-~=fYebq_Xios1^@uSxey2d02YTp006K!1Ofnn#UT&?04xrH003Zd z2m}BCi(>|Y*RS9I9lfmmdsXgYr^Z?Kl{P8wa@g0dc((Axi)Vk9s9pF&sg)% zls`WVUcP)2uY38`7_qZ08~NOxKG?(0nP(dHTPxd+J>-@4Ux}>!TKU#*+F{kFT}$;_ z`bKqB`N7jO%Mtx8>PJuRkqQJOWa~I<5Z}elQT7@L-oUmds}VWm@cd>?;+o9U<4wqs zfKg30s9c4k0>Sh6TH>B)OJ=Z<{3b2?VIQLXHnUgIrf0S??X`5?m$mi=+WXt*R~dVE zn`hKOkQv}o4zQK?oxzhy9Zl*~nqCVlZyL2z!?Gt+PgF;wes41_YR}P~x_`D&{azoj z+PweFNc(zqRr}wXytgqV*|^=?&b6|=+_S44x7M7pSO3cN|EhUFDi`So6?25vZZ0Fs zl1w=(2Poaol;1mtK4WLJo(vH`%$(2KWL=M@fU4}1^ksdLZQmpOAF;>ssdR4nOuM#H zKAEvn$%y~6^S~MQjL1DoQbXBjR+UnyilUMFXYHv@p;WFcuF4V1Ywg* zR}G#_vH^~VKmY)+IQ;if0D#3I5C8xy4uJpwU~vcp004_aAOHYZ90CCVz~T@H000(; oKmY)+I0OO!fW;vY001n`A0Ndi{rOMIN&o-=07*qoM6N<$f-jTX6951J literal 0 HcmV?d00001 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 GIT binary patch literal 950 zcmeAS@N?(olHy`uVBq!ia0vp^g+T1h!3HGV=VwSWFfiA8x;TbZ%y~PhynY?r6-kUe){{6iBKJ(#wXU@ITc|W;4O)qkj;PFDExqgeA4;PmFzIHZauBF8v z>Dc{cOJ5$>IFmL>? z3I_uU^Fmf9|GjhEk!fFk-K`X4nXcjbgX8BHi!;Vod!-73@3!w%?-!fj>^(*4NZ^#x zGdiXZDs%U3sj^bd%eiVg;fzCVSIpJC*Xg_0oxQOv;O4sY=c~T4PClt3*?;_G|NQ-v z1Mbude=83C^Q(A{&$&kmsXvND-W2D~^msGFC?sY6>u1Y@g|7AnPG5F0bcUIw(}J9M z)naF#<%Kft$JNsv<07wIH@j~dXsds&b%MmJsjjuTo3CCq+k5v~yg*FS)fOR*7q6<9 z&znZqJmAe8u|y^Q+8rUtjG_{r|V9pWkVL&z}L4d*~h+4S-~wdbMmyiCf)azzrFwNT)%kJD}}EaOHvlBo{+|JE9Hd4?Io{f z{JNcT6R1{W^HBi@Ls_ZjtWyS_^EzyP&c9rIU-$aecAhm-3Bj=ox(Z&tH_GcY4dh)H zb9mFXyQ{95eywBcnml`64N%RJNUN8jd}EVwyEt7+He-}5JK(#@Z{#WTqG zo=36dign?sPp8OUHx~ZNGjX?9-%^3==Wytj8Ss+`)oG2{NeO`CJgD{rP)P2bL~TcjU-pFt>hw#44NlTzvve;v!* q`|?ixd4!y*Eqi(0REeOUfk?nYXpx8lj7f9#*DR<3jhD z*_#0X_F<0)p9H{QUEjN#80o9jo{0otPcb$)FgmMRH64-W5VD`Qmf~#8CRV?wlo=7q z;ns{G*El=^#*kk>qDG}RX1PJ|mW?NL<-snImiGp+(?jhQU3W^Pj>T?5LUPYH+q}A+ z-1O#v5!JD=d@kxCFR(;ZnIiH-wy}JoD3PJyK zme(?>DMrDQYbSf(skS{K77dwM@v9~V;OCifE&tT5zA188XZxXNLwl>38|%1eV!Qce-u+@I6g&!U4(#n#l(L7-!xS6Pif=7mgwDx|3OSJVTh$Ezolp@selN2!1~&cn^DKOdFS_Q_>|LQDDC%#@0046A z)AGpc5C96km{7x?r0bThl#ya4ppTEIv} zJfax+L!AN1e2Tzj_WQYuD!Q19I|Cl8#sF_X`9w)~X~ENlybR3zV(% zgA++GKV`(iO!8sPW=+f$Q-3;S-wNTJQbylOV!f9_Ue|*ZUq`TB{$mI2JUxoWaWug zv#O`z^^846#^}S=60$|6)3&3-Ls^P@Ss4Jxiw|;M$8ehH84@@HL*yG9)`8d$~FauHKke) z$6LkhKQtUHZIymZe_aOE?Ymc$>?(}U#m5MmlANyoo|xWB?#`4fsk!M9QYTPWb09w2 zy_L(#io;^8pY;8uqJL8m^JL)g{%B~1%1|HSxX}Qz_?-`i$=gmS; z0jV`_U2Q+ijr2S&Fa$0KNo79EDB|`R-$iI-6={^-NR8a6d%GlQ$p0u?GD`dlo=pIG zciVG`MUoZE!4>uVR(Qhs7mPb`xL5|)Y%Mh-mrm9(5ZmMgqZK_fjl56IPV c|3XAFjw$q(U8@sc*8d8C4Z#Js1f9G7H`|O)KL7v# literal 0 HcmV?d00001 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 GIT binary patch literal 467 zcmeAS@N?(olHy`uVBq!ia0vp^fk14`!3HGXZ+?=_z`!`m)5S5QV$R!JfnJ9l1de^Y zdx1IQcCpCbMuoTo><5LpYG1Ird|>N(e&Lp|i#2~^>d7UG|K7M+w*UWRA?}msZyveU zYyX?cdeyn#Eaw!Jn3R+hK*WNZR}Q}YuD54zeardvxi5b2yJETXT4`*A-m{0lvP7Rv z7hiVW<*mOAV@+LUE}Oo;!TY>?p9!yurg7$o229EpXZF@wr1S9FW~mh&y8aI*Ty5}A zcW_~GaX}%TwEg%|5dXwfb=Dt|A#WA}jB7*K)d*As{_vBc4 r+WNa+xq9F_Gmf=yUMsP<>W#P$=Z4fTTRD}1k;UNY>gTe~DWM4fs|?d! literal 0 HcmV?d00001 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 GIT binary patch literal 468 zcmeAS@N?(olHy`uVBq!ia0vp^-au^1!3HEb)5M|~7#L@Jx;TbpG`_uU=*Mg*(E8Bu zmb5}4i`1_#Ut*fX&N)ZvIr`6^*QTsc$jp+`HTBrJzRl}zY*gOAUrEK|b^pgS(P>}G zeQvB;7bSl{)m29!iBXWdBf=s0XYcv^iGLlRJobL_eEU(wqvo>i&)&H`$y6_@e!E}q zrZ;*@jR!VedgSj~)HvHGY^~77 z<(=FIot7Q7vv>ZwDcAh?Eb(0N9KmZkyQXK}mRTJWVW}$jC}{2W)E}0w?@XC8c?X;M zsxixD;GAL8NbT=t;k6R)3ilLfeloNZxe}7+VaUu6{1-oD!M$zvVIk)a#6TkBr zrWH^tu~aiA(0`@IQ%&Sy5I+>NvVeOD_nFbAQoy+V=efP_;|Vmt4h}O0R|VPI!t>L( zxjzXCFyyi^G9MZYU+_qeb`*a1@fbnAF{W|W>Kcx~v@`Kreh4+d6sGsAdRB4mV{^VY zFb9vs)qr~@)HXmtdC?Rz6tAE8>Vhl4wjS7fUc(za61W2F%;@Tk=s$qHY!MYu+qZ1m zIYnY@aSbETfWjlZw1NzsPi>o>E8AJ~-nS(f=)g(v;5k3IR!r;x?3FLh0UBKksC~;v z-4KMq09V1Y+l~SjWP)8}`5>MHevb~+09ld&(gLJO21pB#CK(_tK$;snA)XkPe1q2j O0000U>Qz zQ^$|bujTIcX1KgK8>VR*0Eou;{qwtAU!5Nv2LRQK^E@xez#uZ?^3Tyh0MNq8(E$L^ z3PcRT0}+GpK*S(Chl=>&>80v?$xiC4+0k>JzTj9+TOC*?^!@F%%J*uw`cL25xRx<; zf4Lv+xP)~5wbu;%G>e!{mL>vj!b>8c-`W_~%$?g)KQ-dx{sv$_y6+QPGnqHzB^wUS zkN2iZ{qtF z!o9JRYT^8xBt)8-^XzL8Jr_&q#`C_g!42SN*GycC_PCcG@e)*=xv;stXitqSjn|_c z$TW$#RNLlQUQS4Y^zQSP&T|XDbS#OS+Hi|PYh0i&_@{Ufo^UlW02GKAga;x9;em)j scpzdB9*7u(2OEalY(fD@yUfx3n0&cuX z!fGcBd>kelX+|nc(Oj6wRMyD4sr#Tud(*~)CoP{i|B7=y_mTgT^|`df_YzD;i{9xw z+*>H(pusBO#n=+WfW(Y^I%CPY*VA|8-rjDO`M&?-HGd#Y%UJ1s`;)uRL~onrnzz3$+?oHU;*GWK&C}CUR?pwMQ0HBG zmDm3%rOw6wrL#1H+}d)Q;&&~JFwgyW=*_8fCH>WjtL}z>Xt5A`x8=IehnG=ORwshj@7UOUTmJjX y|K%_LZ4DFf{2bGHHOQmxN533~$B_KElW}Gn+bReD%UQq>W$<+Mb6Mw<&;$V252T*} literal 0 HcmV?d00001 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 GIT binary patch literal 2070 zcmeHI`%{w#7X6|OFAWGNAaT$jR+dGOMnOfPLa1S2gBH6A7{G!&0^#BCCSL-zN-RPk zJWUE(6(~gm6iJp>NQ;?J9>K?^UkN4wV%dgBB7_h~2w8S#cV=g6Xa9ly<<6ZsbLZZ< z=iGB|pU0kqTRK?+000lcpg#cs7;P&bF*n_cKg=Xa0l-Wgf7U5!v4h}AHt4zlBem?eO z_pJz1FKgsRVY}*a9wF;G5*2)RH!CIv*1Y%KIY;nanVs(Yz27gzTbaQ__S{&GFX%5v z-C4ek^FP_nXdpf$JpZs#>=8f>n@tWUz+{x|zKcDKH5Xynqk=v>w9M4>IkR1b)r0<_ zZAKr-m7jV@(!$Ue$KU0EUj20{k)Tp`DN>Y`CMYZ=b_9_&?@yMGV?lc))8*@nOoau}^2YRe0zYnihBevsmX7oc2J5<>8ItbW+tGC6*HXHxn6EwvazJIHycbm3#3-LXX9T2a(%z-y-radgqS4Z)GPIcAj+aqF2 z-@TDL@ECcjFpgMPT?iEzSS9z@qw}Ge+>sL1IO}&k|b8*U!e5#^3J`-=Bg->m3eM-05QyD}+ z#8HC3NRY!$y24=d^YGjMP3-$wk9;N-_5DF=5Tw?VYin{VCbIX1@@HzyLna28QFQ*vSmfsNJsj zqcT0|^)}zsX>h)BOCAJ;(jm0F%eKs&ACF_`sGAGIKQ}MziJo|Mp;>X1IH;7hPfGVL z^}tRz9SmIl<}g4-bUF47DqdY3QqjTPm$cf(g>7;6=T-%)Ln{NuN2#W$)$&Rp?CJw; z)x~d959yiuHHN|+@ECoDl=pQ?HU?yY>-QUudChM>+ByTe0-4zm2Dt3>-b?*0AtS#I zZR&+OGEZG*+-(GxKJA)HYk7Sbuur&%8KsTJrDTP2gnx1|Lb);o%h zsQQOg-oJqTtlmk8ejO~1@YXdh-p(WIWMd_4-DPNF;7V&Kh#)9F9qUu>PrbJbyPgB9 zcrk_V5j}d+p~!{5?#Gst z3+;ViuyjUbM^(+On1k{t^1WBlL2!6@^e)C2fEB;>GCr~XK@&XWi)BOZHk#o+DHqV{TgK-qi!=*n{ zzrN6hvV)~pKeYIQaran)T`# zTjnoZK2hg>cchxeX(2W4hD{D&x@8jske;T~+_ZeTvi0z7=`eu(x^fnZIk^M*iM*efOhx4?Rn*WJ5C~U$v-APMAGw%@>hbTAXXr z&rW_m`%ZP3&!=S*SyWm@=gz6Ln7s8w@3HI4PG2*3oSOJTL`(bbOGq&LW51p@Pul`B>>z)+(CX!(as{?joYFzz;YF=;V$!H2vPhQUM z-;{In-l{+`Ca9+@stlLtJYPF0=D+2#Cu>$Nu`Rvxt;Xh=x75ycSLN7GcDcTkmOkP8 z*}Y8t`M#$qoARyX7oS%>KJ%D}|GAT1U7LIx#4P?uzBg67otl~6^U;;j*8BbnzX_i6 zrtMa;UfXqNSNw@X7S%Iz?IzCIHtn_kf7#Ps=Dz}k{qxS}y-0kxgXc1@ZEV+OFB6-h zX`-hus;1p;pSC>T_3n3ncKyvWPx&uD{^ie9Ipfz=_Ivh}x#j=cIq~cMj?|B@`4Dk} v%9^J7Yrj`m)>YB_uQ}#T|Cq1F{XqNEalY(fIb(e(%E$630G1 z&+(m|AiA}qi(^-cSh;I}_`!ug^sO}S#w_96)m`iuT^Jw`l4G*6HEZve(v$piZhe1n z?|hZ>y_%D$RaejJbNCeSCv-i!`#1PmV|1B7X?3z(ddZZakJe|;h6NON_I% z_07{Q_GKt0?9ys$k>I*L-6C_#h4hNDi4SM)+_N=T=G~gb2R`IDJ6X)Qf5SPqxG|UM zpFk_upTEpGYj>?l-q8M`y#Imphvkpt8|#~9C?k!ZpWcmwLY1_IJk4Q1#cX(>6WJ`jgI3u_StGcHNduz<6NrboFyt I=akR{08jqDB>(^b literal 0 HcmV?d00001 diff --git a/example-ui/src/test/resources/logback.xml b/example-ui/src/test/resources/logback.xml new file mode 100644 index 0000000..e95af21 --- /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 0f3378e..0000000 --- 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.)

-
-
- -
- - - -
- - -
- - -
-
- - -
- - - -
-
- -
-
- -
- - - - - - - - - - - - - - - - - - -- Gitee From c0b603ef4d56f6271bb776e95129d0c6e300d00e Mon Sep 17 00:00:00 2001 From: zhanglx Date: Thu, 11 Mar 2021 23:34:24 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=97=A5=E5=BF=97=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example-ui/pom.xml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/example-ui/pom.xml b/example-ui/pom.xml index 3bce425..27170b3 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
@@ -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} + +
-- Gitee From d159dc6e92b210654dbc25fc656df9e705dd6884 Mon Sep 17 00:00:00 2001 From: zhanglx Date: Fri, 12 Mar 2021 00:40:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/ui/SikuliXExecutor.java | 47 ++++++++++++++++++- .../automation/ui/demo/SikuliXDemoTest.java | 11 +++-- .../automation/ui/testbaidu/BaiDuTest.java | 1 + .../automation/ui/testbaidu2/BaiDuTest2.java | 1 + 4 files changed, 53 insertions(+), 7 deletions(-) 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 4f8a589..41d9998 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 @@ -9,6 +9,7 @@ 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.*; @@ -139,14 +140,56 @@ 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); + 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(); + } } /** 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 index c9601f8..2a84661 100644 --- 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 @@ -13,8 +13,6 @@ import org.junit.jupiter.api.Test; import org.openqa.selenium.chrome.ChromeDriver; import org.sikuli.script.ImagePath; -import java.util.concurrent.TimeUnit; - @TimeCost public class SikuliXDemoTest extends UIBase { private static final Log log = LogFactory.get(); @@ -57,6 +55,8 @@ public class SikuliXDemoTest extends UIBase { 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"); @@ -74,9 +74,8 @@ public class SikuliXDemoTest extends UIBase { SikuliXExecutor.clickImg("格式化.png"); SikuliXExecutor.clickImg("运行.png"); - while (SikuliXExecutor.exist("正在请求数据.png", 0.85f, 1)) { - TimeUnit.SECONDS.sleep(1); - } + SikuliXExecutor.waitImgDisappear("正在请求数据.png", 0.85f, 7); + SikuliXExecutor.AssertExist("状态200.png", 0.85f, 1); SikuliXExecutor.clickImg("未保存.png"); SikuliXExecutor.AssertExist("已保存.png", 0.85f, 1); @@ -86,6 +85,8 @@ public class SikuliXDemoTest extends UIBase { 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/testbaidu/BaiDuTest.java b/example-ui/src/test/java/cn/testnewbie/automation/ui/testbaidu/BaiDuTest.java index 7da79de..010c69c 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(); 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 dadfbba..f2b476e 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(); -- Gitee From 81bbd4bbdb008f9f5375e0ac628fc0744b73d4b0 Mon Sep 17 00:00:00 2001 From: zhanglx Date: Fri, 12 Mar 2021 00:41:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/testnewbie/automation/ui/testbaidu2/BaiDuTest2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f2b476e..8672764 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 @@ -115,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); -- Gitee