提交 9df8ed0e authored 作者: 黄承天's avatar 黄承天

修复Chrome驱动无法运行的问题。判断预期结果前和每个步骤执行后会等待2秒以保证结果更精准。

上级 807f10f3
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</parent> </parent>
<groupId>com.zjty</groupId> <groupId>com.zjty</groupId>
<artifactId>automated-testing</artifactId> <artifactId>automated-testing</artifactId>
<version>0.0.4-SNAPSHOT</version> <version>0.0.5-SNAPSHOT</version>
<name>automated-testing</name> <name>automated-testing</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
...@@ -44,12 +44,7 @@ ...@@ -44,12 +44,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>21.0</version> <version>28.2-jre</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency> </dependency>
<!--fastJson--> <!--fastJson-->
<dependency> <dependency>
......
...@@ -42,6 +42,7 @@ public class Report { ...@@ -42,6 +42,7 @@ public class Report {
/** /**
* 网站地址 * 网站地址
*/ */
@Column(columnDefinition = "text")
private String url; private String url;
/** /**
......
...@@ -22,26 +22,27 @@ public class Case { ...@@ -22,26 +22,27 @@ public class Case {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id; private Integer id;
/** /**
* 标题 * 标题
*/ */
String title; private String title;
/** /**
* 浏览器 * 浏览器
*/ */
String browser; private String browser;
/** /**
* 起始网站 * 起始网站
*/ */
String url; @Column(columnDefinition = "text")
private String url;
/** /**
* 步骤详情 * 步骤详情
*/ */
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
String steps; private String steps;
} }
...@@ -16,12 +16,14 @@ import org.openqa.selenium.WebDriver; ...@@ -16,12 +16,14 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.zjty.automatedtesting.common.action.Action.*; import static com.zjty.automatedtesting.common.action.Action.*;
...@@ -64,7 +66,7 @@ public class SeleniumServiceImpl implements SeleniumService { ...@@ -64,7 +66,7 @@ public class SeleniumServiceImpl implements SeleniumService {
return new ChromeDriver(); return new ChromeDriver();
} else if (Objects.equals(browser, Browser.IE)) { } else if (Objects.equals(browser, Browser.IE)) {
System.setProperty("webdriver.ie.driver", CommonUtils.IE_EXE); System.setProperty("webdriver.ie.driver", CommonUtils.IE_EXE);
return new ChromeDriver(); return new InternetExplorerDriver();
} else { } else {
throw new RuntimeException("该浏览器不存在:" + browser); throw new RuntimeException("该浏览器不存在:" + browser);
} }
...@@ -94,12 +96,12 @@ public class SeleniumServiceImpl implements SeleniumService { ...@@ -94,12 +96,12 @@ public class SeleniumServiceImpl implements SeleniumService {
} else { } else {
throw new RuntimeException("不匹配的操作类型:" + step.getAction()); throw new RuntimeException("不匹配的操作类型:" + step.getAction());
} }
} }
if (isNull(step.getAssertion())){ if (isNull(step.getAssertion()) || Objects.equals(step.getAssertion(), "")) {
success = true; success = true;
message = "成功"; message = "成功";
}else { } else {
waitTime(2000L);
if (Objects.equals(step.getAssertion(), Assertion.VALUE)) { if (Objects.equals(step.getAssertion(), Assertion.VALUE)) {
if (nonNull(webElement)) { if (nonNull(webElement)) {
practice = webElement.getAttribute("value"); practice = webElement.getAttribute("value");
...@@ -109,16 +111,17 @@ public class SeleniumServiceImpl implements SeleniumService { ...@@ -109,16 +111,17 @@ public class SeleniumServiceImpl implements SeleniumService {
} else { } else {
throw new RuntimeException("不匹配的判断类型:" + step.getAssertion()); throw new RuntimeException("不匹配的判断类型:" + step.getAssertion());
} }
if (Objects.equals(practice, step.getExpected())) { if (Objects.equals(practice, step.getExpected())) {
success = true; success = true;
message = "成功"; message = "成功";
}else { } else {
success = false; success = false;
message = String.format("失败 实际与预期不符 预期:[%s] 实际:[%s] ", step.getExpected(), practice); message = String.format("失败 实际与预期不符 预期:[%s] 实际:[%s] ", step.getExpected(), practice);
} }
} }
waitTime(2000L);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
success = false; success = false;
message = String.format("出现错误:[%s]", e.getMessage()); message = String.format("出现错误:[%s]", e.getMessage());
log.error("出现错误:", e); log.error("出现错误:", e);
...@@ -176,4 +179,12 @@ public class SeleniumServiceImpl implements SeleniumService { ...@@ -176,4 +179,12 @@ public class SeleniumServiceImpl implements SeleniumService {
} }
private void waitTime(Long time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
log.error("暂停等待时出现异常:" + e);
}
}
} }
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>adapter</title><link href=static/css/serviceConfig.008ef5a3.css rel=prefetch><link href=static/js/serviceConfig.15284ede.js rel=prefetch><link href=static/css/app.f596fcc9.css rel=preload as=style><link href=static/css/chunk-vendors.717c90ab.css rel=preload as=style><link href=static/js/app.b64cb21f.js rel=preload as=script><link href=static/js/chunk-vendors.5f648e7a.js rel=preload as=script><link href=static/css/chunk-vendors.717c90ab.css rel=stylesheet><link href=static/css/app.f596fcc9.css rel=stylesheet></head><body><noscript><strong>We're sorry but adapter doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=static/js/chunk-vendors.5f648e7a.js></script><script src=static/js/app.b64cb21f.js></script></body></html> <!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>adapter</title><link href=static/css/serviceConfig.f14ab9ce.css rel=prefetch><link href=static/js/serviceConfig.767d4038.js rel=prefetch><link href=static/css/app.f596fcc9.css rel=preload as=style><link href=static/css/chunk-vendors.717c90ab.css rel=preload as=style><link href=static/js/app.80934e38.js rel=preload as=script><link href=static/js/chunk-vendors.5f648e7a.js rel=preload as=script><link href=static/css/chunk-vendors.717c90ab.css rel=stylesheet><link href=static/css/app.f596fcc9.css rel=stylesheet></head><body><noscript><strong>We're sorry but adapter doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=static/js/chunk-vendors.5f648e7a.js></script><script src=static/js/app.80934e38.js></script></body></html>
\ No newline at end of file \ No newline at end of file
...@@ -8,4 +8,4 @@ spring.jpa.hibernate.ddl-auto=update ...@@ -8,4 +8,4 @@ spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=false spring.jpa.show-sql=false
spring.resources.static-locations=classpath:/adapter/ spring.resources.static-locations=classpath:/adapter/
\ No newline at end of file
## 自动测试-数据库设计
### 引言
本文档旨在描述自动测试系统中的数据库结构与设计。面向参与开发、测试、维护之人。
### 数据库
#### 概述
- 数据库选取MySQL。
- 数据库名:automated_testing
- 字符集:utf8
- 本数据库中的所有表均以“AUTO_TEST_”为前缀,如测试用例表名称为AUTO_TEST_CASE。
- 所有表以int自增类型为主键。
- 在表字段中集合形式的数据以json格式字符串存储。在调用时数据会在程序中进行转换后提供,或进行转换后保存。
#### 表结构设计
测试用例
表名:AUTO_TEST_CASE
| 字段名 | 类型 | 长度 | 是否可null | 备注 |
| ------- | ------- | ---- | ---------- | ------------------------------------------------------------ |
| id | int | | 否 | 主键 |
| title | varchar | 255 | 是 | 标题 |
| browser | varchar | 255 | 是 | 浏览器 Chrome、Firefox、IE |
| url | text | | 是 | 起始网站地址 |
| steps | text | | 是 | 各步骤详情,以json格式字符串形式存储。在程序中可以转换为集合类型。 |
测试报告
表名:AUTO_TEST_REPORT
| 字段名 | 类型 | 长度 | 是否可null | 备注 |
| -------- | ------- | ---- | ---------- | ------------------------------------------------------------ |
| id | int | | 否 | 主键 |
| case_id | int | | 是 | 所属测试用例的id |
| title | varchar | 255 | 是 | 标题 |
| browser | varchar | 255 | 是 | 浏览器 Chrome、Firefox、IE |
| url | text | | 是 | 起始网站地址 |
| measures | text | | 是 | 各步骤结果详情,以json格式字符串形式存储。在程序中可以转换为集合类型。 |
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论