Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
automated-testing
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
automated-testing
Commits
36e96fdd
提交
36e96fdd
authored
3月 02, 2020
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
数据结构改动
测试步骤的断言改为集合形式 并重新定义了断言的数据结构和判断机制
上级
c30917f8
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
236 行增加
和
92 行删除
+236
-92
Assertion.java
...va/com/zjty/automatedtesting/common/action/Assertion.java
+9
-2
SystemController.java
...om/zjty/automatedtesting/controller/SystemController.java
+8
-3
TestCaseController.java
.../zjty/automatedtesting/controller/TestCaseController.java
+11
-4
Measure.java
...n/java/com/zjty/automatedtesting/pojo/report/Measure.java
+2
-21
Assert.java
...main/java/com/zjty/automatedtesting/pojo/test/Assert.java
+46
-0
Step.java
src/main/java/com/zjty/automatedtesting/pojo/test/Step.java
+11
-9
System.java
...main/java/com/zjty/automatedtesting/pojo/test/System.java
+2
-0
SystemVo.java
...in/java/com/zjty/automatedtesting/pojo/test/SystemVo.java
+26
-0
CaseService.java
...n/java/com/zjty/automatedtesting/service/CaseService.java
+10
-3
SystemService.java
...java/com/zjty/automatedtesting/service/SystemService.java
+8
-1
CaseServiceImpl.java
...m/zjty/automatedtesting/service/impl/CaseServiceImpl.java
+23
-4
SeleniumServiceImpl.java
...ty/automatedtesting/service/impl/SeleniumServiceImpl.java
+52
-39
SystemServiceImpl.java
...zjty/automatedtesting/service/impl/SystemServiceImpl.java
+10
-0
TransHelper.java
...a/com/zjty/automatedtesting/service/impl/TransHelper.java
+18
-0
FileUtil.java
src/main/java/com/zjty/automatedtesting/util/FileUtil.java
+0
-6
没有找到文件。
src/main/java/com/zjty/automatedtesting/common/action/Assertion.java
浏览文件 @
36e96fdd
package
com
.
zjty
.
automatedtesting
.
common
.
action
;
package
com
.
zjty
.
automatedtesting
.
common
.
action
;
/**
* equals、not_equals、exist、not_exist
*/
public
interface
Assertion
{
public
interface
Assertion
{
String
VALUE
=
"value
"
;
String
EQUALS
=
"equals
"
;
String
TITLE
=
"title"
;
String
NOT_EQUALS
=
"not_equals"
;
String
EXIST
=
"exist"
;
String
NOT_EXIST
=
"not_exist"
;
}
}
src/main/java/com/zjty/automatedtesting/controller/SystemController.java
浏览文件 @
36e96fdd
...
@@ -2,7 +2,9 @@ package com.zjty.automatedtesting.controller;
...
@@ -2,7 +2,9 @@ package com.zjty.automatedtesting.controller;
import
com.zjty.automatedtesting.pojo.test.System
;
import
com.zjty.automatedtesting.pojo.test.System
;
import
com.zjty.automatedtesting.pojo.test.SystemVo
;
import
com.zjty.automatedtesting.service.SystemService
;
import
com.zjty.automatedtesting.service.SystemService
;
import
com.zjty.automatedtesting.service.impl.TransHelper
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -19,6 +21,9 @@ public class SystemController {
...
@@ -19,6 +21,9 @@ public class SystemController {
@Autowired
@Autowired
SystemService
systemService
;
SystemService
systemService
;
@Autowired
TransHelper
transHelper
;
@ApiOperation
(
value
=
"新增测试系统."
)
@ApiOperation
(
value
=
"新增测试系统."
)
@PostMapping
(
value
=
"/create"
)
@PostMapping
(
value
=
"/create"
)
public
ResponseEntity
<
System
>
create
(
@RequestBody
System
system
){
public
ResponseEntity
<
System
>
create
(
@RequestBody
System
system
){
...
@@ -28,10 +33,10 @@ public class SystemController {
...
@@ -28,10 +33,10 @@ public class SystemController {
@ApiOperation
(
value
=
"根据id获取测试系统."
)
@ApiOperation
(
value
=
"根据id获取测试系统."
)
@GetMapping
(
value
=
"/get/{id}"
)
@GetMapping
(
value
=
"/get/{id}"
)
public
ResponseEntity
<
System
>
findById
(
@PathVariable
String
id
){
public
ResponseEntity
<
System
Vo
>
findById
(
@PathVariable
String
id
){
System
system
=
systemService
.
findById
(
id
);
System
system
=
systemService
.
findById
(
id
);
return
ResponseEntity
.
ok
(
system
);
SystemVo
result
=
transHelper
.
toSystemVo
(
system
);
return
ResponseEntity
.
ok
(
result
);
}
}
}
}
src/main/java/com/zjty/automatedtesting/controller/TestCaseController.java
浏览文件 @
36e96fdd
...
@@ -47,10 +47,17 @@ public class TestCaseController {
...
@@ -47,10 +47,17 @@ public class TestCaseController {
.
collect
(
Collectors
.
toList
()));
.
collect
(
Collectors
.
toList
()));
}
}
@ApiOperation
(
value
=
"保存测试用例."
,
notes
=
"不附带id为新增 附带id为修改"
)
@ApiOperation
(
value
=
"新增测试用例."
,
notes
=
"不附带id"
)
@PostMapping
(
value
=
"/save"
)
@PostMapping
(
value
=
"/create"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
save
(
@RequestBody
CaseVo
caseVo
)
{
public
ResponseEntity
<
Map
<
String
,
String
>>
create
(
@RequestBody
CaseVo
caseVo
)
{
caseService
.
save
(
caseVo
);
caseService
.
create
(
caseVo
);
return
ResponseEntity
.
ok
(
ImmutableMap
.
of
(
"message"
,
"success"
));
}
@ApiOperation
(
value
=
"修改测试用例."
,
notes
=
"必须附带id"
)
@PostMapping
(
value
=
"/update"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
update
(
@RequestBody
CaseVo
caseVo
)
{
caseService
.
update
(
caseVo
);
return
ResponseEntity
.
ok
(
ImmutableMap
.
of
(
"message"
,
"success"
));
return
ResponseEntity
.
ok
(
ImmutableMap
.
of
(
"message"
,
"success"
));
}
}
...
...
src/main/java/com/zjty/automatedtesting/pojo/report/Measure.java
浏览文件 @
36e96fdd
...
@@ -34,32 +34,13 @@ public class Measure {
...
@@ -34,32 +34,13 @@ public class Measure {
/**
/**
* 是否成功
* 是否成功
*/
*/
@ApiModelProperty
(
value
=
"是否成功"
,
example
=
"true"
,
position
=
3
)
@ApiModelProperty
(
value
=
"是否成功
true/false
"
,
example
=
"true"
,
position
=
3
)
private
Boolean
success
;
private
Boolean
success
;
/**
* 判断类型
*/
@ApiModelProperty
(
value
=
"判断类型"
,
example
=
"value"
,
notes
=
"目前有2种:value-当前元素的值 title-页面标题"
,
position
=
4
)
private
String
assertion
;
/**
* 期望结果
*/
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
,
position
=
5
)
@JSONField
(
ordinal
=
5
)
private
String
expected
;
/**
* 实际结果
*/
@ApiModelProperty
(
value
=
"实际结果"
,
example
=
"ty"
,
position
=
6
)
private
String
practice
;
/**
/**
* 信息
* 信息
*/
*/
@ApiModelProperty
(
value
=
"相关信息"
,
example
=
"成功."
,
position
=
7
)
@ApiModelProperty
(
value
=
"相关信息"
,
example
=
"成功."
,
position
=
4
)
private
String
message
;
private
String
message
;
}
}
src/main/java/com/zjty/automatedtesting/pojo/test/Assert.java
0 → 100644
浏览文件 @
36e96fdd
package
com
.
zjty
.
automatedtesting
.
pojo
.
test
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"断言"
)
public
class
Assert
{
/**
* 元素的定位类型
*/
@ApiModelProperty
(
value
=
"元素的定位类型"
,
example
=
"id"
,
position
=
1
)
private
String
locateType
;
/**
* 元素的定位关键值
*/
@ApiModelProperty
(
value
=
"元素的定位关键值"
,
example
=
"kw"
,
position
=
2
)
private
String
locateKey
;
/**
* 断言类型
*/
@ApiModelProperty
(
value
=
"断言类型"
,
example
=
"equals"
,
position
=
3
)
private
String
assertType
;
/**
* 断言键
*/
@ApiModelProperty
(
value
=
"断言键"
,
example
=
"name"
,
position
=
4
)
private
String
assertKey
;
/**
* 断言值
*/
@ApiModelProperty
(
value
=
"断言值"
,
example
=
"wd"
,
position
=
5
)
private
String
assertValue
;
}
src/main/java/com/zjty/automatedtesting/pojo/test/Step.java
浏览文件 @
36e96fdd
...
@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
...
@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
/**
/**
* <p>Description : selenium-test
* <p>Description : selenium-test
...
@@ -21,49 +23,49 @@ public class Step {
...
@@ -21,49 +23,49 @@ public class Step {
/**
/**
* 步骤序号
* 步骤序号
*/
*/
@ApiModelProperty
(
value
=
"序号"
,
example
=
"1"
,
position
=
1
)
@ApiModelProperty
(
value
=
"序号"
,
example
=
"1"
,
position
=
1
)
private
Integer
order
;
private
Integer
order
;
/**
/**
* 标题
* 标题
*/
*/
@ApiModelProperty
(
value
=
"步骤的标题"
,
example
=
"输入关键字"
,
position
=
2
)
@ApiModelProperty
(
value
=
"步骤的标题"
,
example
=
"输入关键字"
,
position
=
2
)
private
String
title
;
private
String
title
;
/**
/**
* 元素的定位类型
* 元素的定位类型
*/
*/
@ApiModelProperty
(
value
=
"元素的定位类型"
,
example
=
"id"
,
position
=
3
)
@ApiModelProperty
(
value
=
"元素的定位类型"
,
example
=
"id"
,
position
=
3
)
private
String
type
;
private
String
type
;
/**
/**
* 元素的定位关键值
* 元素的定位关键值
*/
*/
@ApiModelProperty
(
value
=
"元素的定位关键值"
,
example
=
"kw"
,
position
=
4
)
@ApiModelProperty
(
value
=
"元素的定位关键值"
,
example
=
"kw"
,
position
=
4
)
private
String
key
;
private
String
key
;
/**
/**
* 元素的操作方式
* 元素的操作方式
*/
*/
@ApiModelProperty
(
value
=
"元素的操作方式"
,
example
=
"input"
,
notes
=
"目前有2种:input-输入 click-点击"
,
position
=
5
)
@ApiModelProperty
(
value
=
"元素的操作方式"
,
example
=
"input"
,
position
=
5
)
private
String
action
;
private
String
action
;
/**
/**
* 输入值 操作为input时需要
* 输入值 操作为input时需要
*/
*/
@ApiModelProperty
(
value
=
"输入值 操作为input时需要"
,
example
=
"ty"
,
position
=
6
)
@ApiModelProperty
(
value
=
"输入值 操作为input时需要"
,
example
=
"ty"
,
position
=
6
)
private
String
value
;
private
String
value
;
/**
/**
* 判断类型
* 判断类型
*/
*/
@ApiModelProperty
(
value
=
"判断类型"
,
example
=
"value"
,
notes
=
"目前有2种:value-当前元素的值 title-页面标题"
,
position
=
7
)
@ApiModelProperty
(
value
=
"判断类型"
,
position
=
7
)
private
String
assertion
;
private
List
<
Assert
>
asserts
;
/**
/**
* 期望结果
* 期望结果
*/
*/
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
,
position
=
8
)
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
,
position
=
8
)
private
String
expected
;
private
String
expected
;
}
}
src/main/java/com/zjty/automatedtesting/pojo/test/System.java
浏览文件 @
36e96fdd
package
com
.
zjty
.
automatedtesting
.
pojo
.
test
;
package
com
.
zjty
.
automatedtesting
.
pojo
.
test
;
import
io.swagger.annotations.ApiModel
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -15,6 +16,7 @@ import javax.persistence.*;
...
@@ -15,6 +16,7 @@ import javax.persistence.*;
@Entity
@Entity
@Table
(
name
=
"AUTO_TEST_SYSTEM"
)
@Table
(
name
=
"AUTO_TEST_SYSTEM"
)
@GenericGenerator
(
name
=
"jpa-uuid"
,
strategy
=
"uuid"
)
@GenericGenerator
(
name
=
"jpa-uuid"
,
strategy
=
"uuid"
)
public
class
System
{
public
class
System
{
@Id
@Id
...
...
src/main/java/com/zjty/automatedtesting/pojo/test/SystemVo.java
0 → 100644
浏览文件 @
36e96fdd
package
com
.
zjty
.
automatedtesting
.
pojo
.
test
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"测试系统"
)
public
class
SystemVo
{
@ApiModelProperty
(
value
=
"主键id 也是系统编码"
,
example
=
"40285a81"
)
private
String
id
;
@ApiModelProperty
(
value
=
"系统名"
,
example
=
"A系统"
)
private
String
name
;
@ApiModelProperty
(
value
=
"测试用例"
)
private
List
<
CaseVo
>
cases
;
}
src/main/java/com/zjty/automatedtesting/service/CaseService.java
浏览文件 @
36e96fdd
...
@@ -8,14 +8,21 @@ import java.util.List;
...
@@ -8,14 +8,21 @@ import java.util.List;
@Service
@Service
public
interface
CaseService
{
public
interface
CaseService
{
/**
* 新增测试用例
* 不可附带id
* @param caseVo testCaseVo
* @return 保存的id
*/
Integer
create
(
CaseVo
caseVo
);
/**
/**
* 保存测试用例
* 保存测试用例
* 不附带id为新增
* 必须附带id
* 附带id为修改
* @param caseVo testCaseVo
* @param caseVo testCaseVo
* @return 保存的id
* @return 保存的id
*/
*/
Integer
sav
e
(
CaseVo
caseVo
);
Integer
updat
e
(
CaseVo
caseVo
);
/**
/**
* 指定id删除测试用例
* 指定id删除测试用例
...
...
src/main/java/com/zjty/automatedtesting/service/SystemService.java
浏览文件 @
36e96fdd
...
@@ -12,7 +12,14 @@ public interface SystemService {
...
@@ -12,7 +12,14 @@ public interface SystemService {
* 不可附带id
* 不可附带id
* @return 保存后的测试系统对象
* @return 保存后的测试系统对象
*/
*/
System
create
(
System
systemVo
);
System
create
(
System
system
);
/**
* 更新测试系统
* 必须附带id
* @return 保存后的测试系统对象
*/
System
update
(
System
system
);
/**
/**
* 根据id查找测试系统
* 根据id查找测试系统
...
...
src/main/java/com/zjty/automatedtesting/service/impl/CaseServiceImpl.java
浏览文件 @
36e96fdd
...
@@ -12,6 +12,9 @@ import java.util.Objects;
...
@@ -12,6 +12,9 @@ import java.util.Objects;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@Service
@Service
public
class
CaseServiceImpl
implements
CaseService
{
public
class
CaseServiceImpl
implements
CaseService
{
...
@@ -23,13 +26,29 @@ public class CaseServiceImpl implements CaseService {
...
@@ -23,13 +26,29 @@ public class CaseServiceImpl implements CaseService {
TransHelper
transHelper
;
TransHelper
transHelper
;
@Override
@Override
public
Integer
save
(
CaseVo
caseVo
)
{
public
Integer
create
(
CaseVo
caseVo
)
{
Case
aCase
=
transHelper
.
toTestCase
(
caseVo
);
Integer
id
;
Integer
id
;
if
(
Objects
.
isNull
(
aCase
.
getId
())
||
repository
.
existsById
(
aCase
.
getId
()))
{
if
(
isNull
(
caseVo
.
getId
()))
{
Case
aCase
=
transHelper
.
toTestCase
(
caseVo
);
id
=
repository
.
save
(
aCase
).
getId
();
id
=
repository
.
save
(
aCase
).
getId
();
}
else
{
}
else
{
throw
new
RuntimeException
(
"指定的id不存在:"
+
aCase
.
getId
());
throw
new
RuntimeException
(
"新增不可附带id"
);
}
return
id
;
}
@Override
public
Integer
update
(
CaseVo
caseVo
)
{
Integer
id
;
if
(
nonNull
(
caseVo
.
getId
())){
if
(
repository
.
existsById
(
caseVo
.
getId
()))
{
Case
aCase
=
transHelper
.
toTestCase
(
caseVo
);
id
=
repository
.
save
(
aCase
).
getId
();
}
else
{
throw
new
RuntimeException
(
"指定的id不存在:"
+
caseVo
.
getId
());
}
}
else
{
throw
new
RuntimeException
(
"修改必须附带id"
);
}
}
return
id
;
return
id
;
}
}
...
...
src/main/java/com/zjty/automatedtesting/service/impl/SeleniumServiceImpl.java
浏览文件 @
36e96fdd
package
com
.
zjty
.
automatedtesting
.
service
.
impl
;
package
com
.
zjty
.
automatedtesting
.
service
.
impl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.
zjty.automatedtesting.common.action.Asser
tion
;
import
com.
mysql.cj.exceptions.AssertionFailedExcep
tion
;
import
com.zjty.automatedtesting.common.action.Browser
;
import
com.zjty.automatedtesting.common.action.Browser
;
import
com.zjty.automatedtesting.pojo.report.Measure
;
import
com.zjty.automatedtesting.pojo.report.Measure
;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.test.Assert
;
import
com.zjty.automatedtesting.pojo.test.Step
;
import
com.zjty.automatedtesting.pojo.test.Step
;
import
com.zjty.automatedtesting.pojo.test.CaseVo
;
import
com.zjty.automatedtesting.pojo.test.CaseVo
;
import
com.zjty.automatedtesting.service.ReportService
;
import
com.zjty.automatedtesting.service.ReportService
;
import
com.zjty.automatedtesting.service.SeleniumService
;
import
com.zjty.automatedtesting.service.SeleniumService
;
import
com.zjty.automatedtesting.util.CommonUtils
;
import
com.zjty.automatedtesting.util.CommonUtils
;
import
com.zjty.automatedtesting.util.JsonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.*
;
import
org.openqa.selenium.WebDriver
;
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.openqa.selenium.ie.InternetExplorerDriver
;
...
@@ -25,10 +23,10 @@ import org.springframework.stereotype.Service;
...
@@ -25,10 +23,10 @@ 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
.*;
import
static
com
.
zjty
.
automatedtesting
.
common
.
action
.
Assertion
.*;
import
static
com
.
zjty
.
automatedtesting
.
common
.
action
.
ByType
.*;
import
static
com
.
zjty
.
automatedtesting
.
common
.
action
.
ByType
.*;
import
static
com
.
zjty
.
automatedtesting
.
util
.
JsonUtil
.
toJSon
;
import
static
com
.
zjty
.
automatedtesting
.
util
.
JsonUtil
.
toJSon
;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
isNull
;
...
@@ -79,9 +77,8 @@ public class SeleniumServiceImpl implements SeleniumService {
...
@@ -79,9 +77,8 @@ public class SeleniumServiceImpl implements SeleniumService {
List
<
Step
>
steps
=
testCase
.
getSteps
().
stream
().
sorted
(
Comparator
.
comparingInt
(
Step:
:
getOrder
)).
collect
(
Collectors
.
toList
());
List
<
Step
>
steps
=
testCase
.
getSteps
().
stream
().
sorted
(
Comparator
.
comparingInt
(
Step:
:
getOrder
)).
collect
(
Collectors
.
toList
());
for
(
Step
step
:
steps
)
{
for
(
Step
step
:
steps
)
{
boolean
success
;
boolean
success
;
String
practice
=
null
;
String
message
=
"通过测试"
;
String
message
;
WebElement
webElement
;
WebElement
webElement
=
null
;
log
.
info
(
"执行步骤:{}"
,
step
.
getTitle
());
log
.
info
(
"执行步骤:{}"
,
step
.
getTitle
());
try
{
try
{
if
(
Objects
.
equals
(
step
.
getAction
(),
HOME
))
{
if
(
Objects
.
equals
(
step
.
getAction
(),
HOME
))
{
...
@@ -96,45 +93,20 @@ public class SeleniumServiceImpl implements SeleniumService {
...
@@ -96,45 +93,20 @@ public class SeleniumServiceImpl implements SeleniumService {
}
else
if
(
Objects
.
equals
(
step
.
getAction
(),
SWITCH
))
{
}
else
if
(
Objects
.
equals
(
step
.
getAction
(),
SWITCH
))
{
driver
.
switchTo
().
frame
(
webElement
);
driver
.
switchTo
().
frame
(
webElement
);
}
else
{
}
else
{
throw
new
RuntimeException
(
"不匹配的操作类型:"
+
step
.
getAction
());
throw
new
WebDriverException
(
"不匹配的操作类型:"
+
step
.
getAction
());
}
}
if
(
isNull
(
step
.
getAssertion
())
||
Objects
.
equals
(
step
.
getAssertion
(),
""
))
{
success
=
true
;
message
=
"成功"
;
}
else
{
waitTime
(
2000L
);
if
(
Objects
.
equals
(
step
.
getAssertion
(),
Assertion
.
VALUE
))
{
if
(
nonNull
(
webElement
))
{
practice
=
webElement
.
getAttribute
(
"value"
);
}
}
else
if
(
Objects
.
equals
(
step
.
getAssertion
(),
Assertion
.
TITLE
))
{
practice
=
driver
.
getTitle
();
}
else
{
throw
new
RuntimeException
(
"不匹配的判断类型:"
+
step
.
getAssertion
());
}
if
(
Objects
.
equals
(
practice
,
step
.
getExpected
()))
{
success
=
true
;
message
=
"成功"
;
}
else
{
success
=
false
;
message
=
String
.
format
(
"失败 实际与预期不符 预期:[%s] 实际:[%s] "
,
step
.
getExpected
(),
practice
);
}
}
}
}
success
=
assertions
(
step
.
getAsserts
(),
driver
);
waitTime
(
2000L
);
waitTime
(
2000L
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
success
=
false
;
success
=
false
;
message
=
String
.
format
(
"出现错误:[%s]"
,
e
.
getMessage
());
message
=
String
.
format
(
"出现错误:[%s]"
,
e
.
getMessage
());
log
.
error
(
"出现错误
:"
,
e
);
log
.
error
(
"出现错误
: "
+
e
.
getMessage
()
);
}
}
measures
.
add
(
new
Measure
(
measures
.
add
(
new
Measure
(
step
.
getOrder
(),
step
.
getOrder
(),
step
.
getTitle
(),
step
.
getTitle
(),
success
,
success
,
step
.
getAssertion
(),
step
.
getExpected
(),
practice
,
message
message
));
));
}
}
...
@@ -155,10 +127,51 @@ public class SeleniumServiceImpl implements SeleniumService {
...
@@ -155,10 +127,51 @@ public class SeleniumServiceImpl implements SeleniumService {
);
);
Integer
id
=
reportService
.
save
(
report
);
Integer
id
=
reportService
.
save
(
report
);
reportVo
.
setId
(
id
);
reportVo
.
setId
(
id
);
driver
.
close
();
waitTime
(
4000L
);
driver
.
quit
();
return
reportVo
;
return
reportVo
;
}
}
private
Boolean
assertions
(
List
<
Assert
>
asserts
,
WebDriver
driver
)
{
String
practice
=
""
;
for
(
Assert
assertion
:
asserts
)
{
WebElement
element
=
getWebElement
(
assertion
.
getLocateType
(),
assertion
.
getLocateKey
(),
driver
);
boolean
hasKey
=
nonNull
(
assertion
.
getAssertKey
())
&&
!
Objects
.
equals
(
assertion
.
getAssertKey
(),
""
);
if
(
Objects
.
equals
(
assertion
.
getAssertType
(),
EQUALS
))
{
if
(
hasKey
)
{
practice
=
element
.
getAttribute
(
assertion
.
getAssertKey
());
}
if
(
Objects
.
equals
(
assertion
.
getAssertValue
(),
practice
))
{
return
true
;
}
else
{
throw
new
AssertionFailedException
(
""
);
}
}
else
if
(
Objects
.
equals
(
assertion
.
getAssertType
(),
NOT_EQUALS
))
{
if
(
hasKey
)
{
practice
=
element
.
getAttribute
(
assertion
.
getAssertKey
());
}
if
(!
Objects
.
equals
(
assertion
.
getAssertValue
(),
practice
))
{
return
true
;
}
else
{
throw
new
AssertionFailedException
(
""
);
}
}
else
if
(
Objects
.
equals
(
assertion
.
getAssertType
(),
EXIST
))
{
if
(
nonNull
(
element
))
{
return
true
;
}
else
{
throw
new
AssertionFailedException
(
""
);
}
}
else
if
(
Objects
.
equals
(
assertion
.
getAssertType
(),
NOT_EXIST
))
{
if
(
isNull
(
element
))
{
return
true
;
}
else
{
throw
new
AssertionFailedException
(
""
);
}
}
}
return
true
;
}
@SuppressWarnings
(
"DuplicatedCode"
)
@SuppressWarnings
(
"DuplicatedCode"
)
private
WebElement
getWebElement
(
String
getMethod
,
String
key
,
WebDriver
driver
)
{
private
WebElement
getWebElement
(
String
getMethod
,
String
key
,
WebDriver
driver
)
{
WebElement
webElement
=
null
;
WebElement
webElement
=
null
;
...
@@ -176,7 +189,7 @@ public class SeleniumServiceImpl implements SeleniumService {
...
@@ -176,7 +189,7 @@ public class SeleniumServiceImpl implements SeleniumService {
if
(
Objects
.
nonNull
(
webElement
))
{
if
(
Objects
.
nonNull
(
webElement
))
{
return
webElement
;
return
webElement
;
}
else
{
}
else
{
throw
new
Runtim
eException
(
"未找到元素 定位方式:"
+
getMethod
+
" 关键值: "
+
key
);
throw
new
ElementNotVisibl
eException
(
"未找到元素 定位方式:"
+
getMethod
+
" 关键值: "
+
key
);
}
}
}
}
...
...
src/main/java/com/zjty/automatedtesting/service/impl/SystemServiceImpl.java
浏览文件 @
36e96fdd
...
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
...
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@Service
@Service
...
@@ -25,6 +26,15 @@ public class SystemServiceImpl implements SystemService {
...
@@ -25,6 +26,15 @@ public class SystemServiceImpl implements SystemService {
}
}
}
}
@Override
public
System
update
(
System
system
)
{
if
(
nonNull
(
system
.
getId
()))
{
return
repository
.
save
(
system
);
}
else
{
throw
new
RuntimeException
(
"新增数据必须附带id"
);
}
}
@Override
@Override
public
System
findById
(
String
id
)
{
public
System
findById
(
String
id
)
{
return
repository
.
findById
(
id
).
orElseThrow
(()
->
new
RuntimeException
(
"未找到该id的测试系统"
));
return
repository
.
findById
(
id
).
orElseThrow
(()
->
new
RuntimeException
(
"未找到该id的测试系统"
));
...
...
src/main/java/com/zjty/automatedtesting/service/impl/TransHelper.java
浏览文件 @
36e96fdd
...
@@ -5,13 +5,21 @@ import com.zjty.automatedtesting.pojo.report.Measure;
...
@@ -5,13 +5,21 @@ import com.zjty.automatedtesting.pojo.report.Measure;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.test.*
;
import
com.zjty.automatedtesting.pojo.test.*
;
import
com.zjty.automatedtesting.pojo.test.System
;
import
com.zjty.automatedtesting.service.CaseService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.List
;
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@Service
@Service
public
class
TransHelper
{
public
class
TransHelper
{
@Autowired
CaseService
caseService
;
public
Case
toTestCase
(
CaseVo
caseVo
)
{
public
Case
toTestCase
(
CaseVo
caseVo
)
{
String
steps
=
JSON
.
toJSONString
(
caseVo
.
getSteps
());
String
steps
=
JSON
.
toJSONString
(
caseVo
.
getSteps
());
return
new
Case
(
return
new
Case
(
...
@@ -19,6 +27,7 @@ public class TransHelper {
...
@@ -19,6 +27,7 @@ public class TransHelper {
caseVo
.
getSystemId
(),
caseVo
.
getSystemId
(),
caseVo
.
getTitle
(),
caseVo
.
getTitle
(),
caseVo
.
getBrowser
(),
caseVo
.
getBrowser
(),
caseVo
.
getEnvironment
(),
caseVo
.
getUrl
(),
caseVo
.
getUrl
(),
steps
steps
);
);
...
@@ -31,6 +40,7 @@ public class TransHelper {
...
@@ -31,6 +40,7 @@ public class TransHelper {
aCase
.
getSystemId
(),
aCase
.
getSystemId
(),
aCase
.
getTitle
(),
aCase
.
getTitle
(),
aCase
.
getBrowser
(),
aCase
.
getBrowser
(),
aCase
.
getEnvironment
(),
aCase
.
getUrl
(),
aCase
.
getUrl
(),
steps
steps
);
);
...
@@ -47,5 +57,13 @@ public class TransHelper {
...
@@ -47,5 +57,13 @@ public class TransHelper {
);
);
}
}
public
SystemVo
toSystemVo
(
System
system
){
List
<
CaseVo
>
cases
=
caseService
.
findBySystemId
(
system
.
getId
());
return
new
SystemVo
(
system
.
getId
(),
system
.
getName
(),
cases
);
}
}
}
src/main/java/com/zjty/automatedtesting/util/FileUtil.java
浏览文件 @
36e96fdd
...
@@ -2,7 +2,6 @@ package com.zjty.automatedtesting.util;
...
@@ -2,7 +2,6 @@ package com.zjty.automatedtesting.util;
import
com.zjty.automatedtesting.pojo.report.Measure
;
import
com.zjty.automatedtesting.pojo.report.Measure
;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.test.Case
;
import
com.zjty.automatedtesting.pojo.test.Case
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -12,7 +11,6 @@ import java.nio.charset.StandardCharsets;
...
@@ -12,7 +11,6 @@ import java.nio.charset.StandardCharsets;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
isNull
;
...
@@ -108,8 +106,6 @@ public class FileUtil {
...
@@ -108,8 +106,6 @@ public class FileUtil {
String
rowTemp
=
"<tr>\n"
+
String
rowTemp
=
"<tr>\n"
+
"\t<td>#{order}</td>\n"
+
"\t<td>#{order}</td>\n"
+
"\t<td>#{title}</td>\n"
+
"\t<td>#{title}</td>\n"
+
"\t<td>#{expected}</td>\n"
+
"\t<td>#{practice}</td>\n"
+
"\t<td>#{success}</td>\n"
+
"\t<td>#{success}</td>\n"
+
"\t<td>#{message}</td>\n"
+
"\t<td>#{message}</td>\n"
+
"</tr>\n"
;
"</tr>\n"
;
...
@@ -118,8 +114,6 @@ public class FileUtil {
...
@@ -118,8 +114,6 @@ public class FileUtil {
String
row
=
rowTemp
String
row
=
rowTemp
.
replace
(
"#{order}"
,
isNull
(
measure
.
getOrder
())
?
""
:
measure
.
getOrder
().
toString
())
.
replace
(
"#{order}"
,
isNull
(
measure
.
getOrder
())
?
""
:
measure
.
getOrder
().
toString
())
.
replace
(
"#{title}"
,
isNull
(
measure
.
getTitle
())
?
""
:
measure
.
getTitle
())
.
replace
(
"#{title}"
,
isNull
(
measure
.
getTitle
())
?
""
:
measure
.
getTitle
())
.
replace
(
"#{expected}"
,
isNull
(
measure
.
getExpected
())
?
""
:
measure
.
getExpected
())
.
replace
(
"#{practice}"
,
isNull
(
measure
.
getPractice
())
?
""
:
measure
.
getPractice
())
.
replace
(
"#{success}"
,
measure
.
getSuccess
()
?
"成功"
:
"失败"
)
.
replace
(
"#{success}"
,
measure
.
getSuccess
()
?
"成功"
:
"失败"
)
.
replace
(
"#{message}"
,
measure
.
getMessage
());
.
replace
(
"#{message}"
,
measure
.
getMessage
());
content
.
append
(
row
);
content
.
append
(
row
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论