Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
automated-testing
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
automated-testing
Commits
3468b668
提交
3468b668
authored
2月 14, 2020
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
测试用例增加标题字段。测试步骤的操作类型增加switch(切换至指定的元素)和home(回到起始页面),由2种增加至4种。
上级
fe91e65f
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
86 行增加
和
74 行删除
+86
-74
Action.java
.../java/com/zjty/automatedtesting/common/action/Action.java
+2
-5
Assertion.java
...va/com/zjty/automatedtesting/common/action/Assertion.java
+1
-1
TestCaseController.java
.../zjty/automatedtesting/controller/TestCaseController.java
+1
-1
Measure.java
...n/java/com/zjty/automatedtesting/pojo/report/Measure.java
+8
-13
Report.java
...in/java/com/zjty/automatedtesting/pojo/report/Report.java
+12
-7
Step.java
src/main/java/com/zjty/automatedtesting/pojo/test/Step.java
+8
-18
TestCase.java
...in/java/com/zjty/automatedtesting/pojo/test/TestCase.java
+2
-0
TestCaseVo.java
.../java/com/zjty/automatedtesting/pojo/test/TestCaseVo.java
+14
-4
SeleniumServiceImpl.java
...om/zjty/automatedtesting/service/SeleniumServiceImpl.java
+35
-24
TransHelper.java
...n/java/com/zjty/automatedtesting/service/TransHelper.java
+2
-0
application.properties
src/main/resources/application.properties
+1
-1
没有找到文件。
src/main/java/com/zjty/automatedtesting/common/action/Action.java
浏览文件 @
3468b668
...
...
@@ -12,10 +12,7 @@ public interface Action {
String
CLICK
=
"click"
;
String
GET_TEXT
=
"gettext"
;
String
READ_ONLY
=
"readonly"
;
String
REGISTER
=
"register"
;
String
SWITCH
=
"switch"
;
String
HOME
=
"home"
;
}
src/main/java/com/zjty/automatedtesting/common/action/Assertion.java
浏览文件 @
3468b668
...
...
@@ -4,6 +4,6 @@ public interface Assertion {
String
VALUE
=
"value"
;
String
TITLE
=
"ti
e
le"
;
String
TITLE
=
"ti
t
le"
;
}
src/main/java/com/zjty/automatedtesting/controller/TestCaseController.java
浏览文件 @
3468b668
...
...
@@ -20,7 +20,7 @@ import java.util.Map;
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@RequestMapping
(
"/testcase"
)
@RestController
@Api
(
value
=
"自动化测试管理接口
"
)
@Api
(
tags
=
"测试用例
"
)
public
class
TestCaseController
{
@Autowired
...
...
src/main/java/com/zjty/automatedtesting/pojo/report/Measure.java
浏览文件 @
3468b668
...
...
@@ -24,49 +24,44 @@ public class Measure {
/**
* 步骤序号
*/
@ApiModelProperty
(
value
=
"步骤序号"
,
example
=
"1"
)
@JSONField
(
ordinal
=
1
)
@ApiModelProperty
(
value
=
"步骤序号"
,
example
=
"1"
,
position
=
1
)
private
Integer
order
;
/**
* 步骤名
*/
@ApiModelProperty
(
value
=
"步骤名"
,
example
=
"输入关键字"
)
@JSONField
(
ordinal
=
2
)
@ApiModelProperty
(
value
=
"步骤名"
,
example
=
"输入关键字"
,
position
=
2
)
private
String
title
;
/**
* 是否成功
*/
@ApiModelProperty
(
value
=
"是否成功"
,
example
=
"true"
)
@JSONField
(
ordinal
=
3
)
@ApiModelProperty
(
value
=
"是否成功"
,
example
=
"true"
,
position
=
3
)
private
Boolean
success
;
/**
* 判断类型
*/
@ApiModelProperty
(
value
=
"判断类型"
,
example
=
"value"
,
notes
=
"目前有2种:value-当前元素的值 title-页面标题"
)
@JSONField
(
ordinal
=
4
)
@ApiModelProperty
(
value
=
"判断类型"
,
example
=
"value"
,
notes
=
"目前有2种:value-当前元素的值 title-页面标题"
,
position
=
4
)
private
String
assertion
;
/**
* 期望结果
*/
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
)
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
,
position
=
5
)
@JSONField
(
ordinal
=
5
)
private
String
expected
;
/**
* 实际结果
*/
@ApiModelProperty
(
value
=
"实际结果"
,
example
=
"ty"
)
@JSONField
(
ordinal
=
6
)
@ApiModelProperty
(
value
=
"实际结果"
,
example
=
"ty"
,
position
=
6
)
private
String
practice
;
/**
* 信息
*/
@ApiModelProperty
(
value
=
"相关信息"
,
example
=
"成功."
)
@JSONField
(
ordinal
=
7
)
@ApiModelProperty
(
value
=
"相关信息"
,
example
=
"成功."
,
position
=
7
)
private
String
message
;
}
src/main/java/com/zjty/automatedtesting/pojo/report/Report.java
浏览文件 @
3468b668
...
...
@@ -22,22 +22,27 @@ import java.util.List;
public
class
Report
{
/**
*
url
*
测试用例标题
*/
@ApiModelProperty
(
value
=
"网站地址"
,
example
=
"http://www.baidu.com"
)
private
String
url
;
@ApiModelProperty
(
value
=
"测试用例标题"
,
example
=
"百度一下"
,
position
=
1
)
private
String
title
;
/**
* 浏览器
*/
@ApiModelProperty
(
value
=
"浏览器"
,
example
=
"firefox"
)
private
String
explorer
;
@ApiModelProperty
(
value
=
"浏览器"
,
example
=
"firefox"
,
position
=
2
)
private
String
browser
;
/**
* 网站地址
*/
@ApiModelProperty
(
value
=
"网站地址"
,
example
=
"http://www.baidu.com"
,
position
=
3
)
private
String
url
;
/**
* 每个步骤结果详情
*/
@ApiModelProperty
(
value
=
"每个步骤结果详情"
)
@ApiModelProperty
(
value
=
"每个步骤结果详情"
,
position
=
4
)
private
List
<
Measure
>
measures
;
}
src/main/java/com/zjty/automatedtesting/pojo/test/Step.java
浏览文件 @
3468b668
...
...
@@ -22,62 +22,52 @@ import lombok.NoArgsConstructor;
@ApiModel
(
value
=
"测试用例步骤"
)
public
class
Step
{
/**
* 步骤序号
*/
@ApiModelProperty
(
value
=
"序号"
,
example
=
"1"
)
@JSONField
(
ordinal
=
1
)
@ApiModelProperty
(
value
=
"序号"
,
example
=
"1"
,
position
=
1
)
private
Integer
order
;
/**
* 标题
*/
@ApiModelProperty
(
value
=
"步骤的标题"
,
example
=
"输入关键字"
)
@JSONField
(
ordinal
=
2
)
@ApiModelProperty
(
value
=
"步骤的标题"
,
example
=
"输入关键字"
,
position
=
2
)
private
String
title
;
/**
* 元素的定位类型
*/
@ApiModelProperty
(
value
=
"元素的定位类型"
,
example
=
"id"
)
@JSONField
(
ordinal
=
3
)
@ApiModelProperty
(
value
=
"元素的定位类型"
,
example
=
"id"
,
position
=
3
)
private
String
type
;
/**
* 元素的定位关键值
*/
@ApiModelProperty
(
value
=
"元素的定位关键值"
,
example
=
"kw"
)
@JSONField
(
ordinal
=
4
)
@ApiModelProperty
(
value
=
"元素的定位关键值"
,
example
=
"kw"
,
position
=
4
)
private
String
key
;
/**
* 元素的操作方式
*/
@ApiModelProperty
(
value
=
"元素的操作方式"
,
example
=
"input"
,
notes
=
"目前有2种:input-输入 click-点击"
)
@JSONField
(
ordinal
=
5
)
@ApiModelProperty
(
value
=
"元素的操作方式"
,
example
=
"input"
,
notes
=
"目前有2种:input-输入 click-点击"
,
position
=
5
)
private
String
action
;
/**
* 输入值 操作为input时需要
*/
@ApiModelProperty
(
value
=
"输入值 操作为input时需要"
,
example
=
"ty"
)
@JSONField
(
ordinal
=
6
)
@ApiModelProperty
(
value
=
"输入值 操作为input时需要"
,
example
=
"ty"
,
position
=
6
)
private
String
value
;
/**
* 判断类型
*/
@ApiModelProperty
(
value
=
"判断类型"
,
example
=
"value"
,
notes
=
"目前有2种:value-当前元素的值 title-页面标题"
)
@JSONField
(
ordinal
=
7
)
@ApiModelProperty
(
value
=
"判断类型"
,
example
=
"value"
,
notes
=
"目前有2种:value-当前元素的值 title-页面标题"
,
position
=
7
)
private
String
assertion
;
/**
* 期望结果
*/
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
)
@JSONField
(
ordinal
=
8
)
@ApiModelProperty
(
value
=
"期望结果"
,
example
=
"ty"
,
position
=
8
)
private
String
expected
;
}
src/main/java/com/zjty/automatedtesting/pojo/test/TestCase.java
浏览文件 @
3468b668
...
...
@@ -29,6 +29,8 @@ public class TestCase {
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
Integer
id
;
String
title
;
/**
* 浏览器
*/
...
...
src/main/java/com/zjty/automatedtesting/pojo/test/TestCaseVo.java
浏览文件 @
3468b668
...
...
@@ -19,24 +19,34 @@ import java.util.List;
@ApiModel
(
value
=
"测试用例"
)
public
class
TestCaseVo
{
@ApiModelProperty
(
value
=
"主键"
,
example
=
"1"
)
/**
* 主键
*/
@ApiModelProperty
(
value
=
"主键"
,
example
=
"1"
,
position
=
0
)
Integer
id
;
/**
* 测试用例标题
*/
@ApiModelProperty
(
value
=
"测试用例标题"
,
example
=
"百度一下"
,
position
=
1
)
String
title
;
/**
* 浏览器
*/
@ApiModelProperty
(
value
=
"浏览器"
,
example
=
"firefox"
)
@ApiModelProperty
(
value
=
"浏览器"
,
example
=
"firefox"
,
position
=
2
)
String
browser
;
/**
* 起始网站
*/
@ApiModelProperty
(
value
=
"网站地址"
,
example
=
"http://www.baidu.com"
)
@ApiModelProperty
(
value
=
"网站地址"
,
example
=
"http://www.baidu.com"
,
position
=
3
)
String
url
;
/**
* 步骤详情
*/
@ApiModelProperty
(
value
=
"步骤详情"
)
@ApiModelProperty
(
value
=
"步骤详情"
,
position
=
4
)
List
<
Step
>
steps
;
}
src/main/java/com/zjty/automatedtesting/service/SeleniumServiceImpl.java
浏览文件 @
3468b668
...
...
@@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import
static
com
.
zjty
.
automatedtesting
.
common
.
action
.
Action
.*;
import
static
com
.
zjty
.
automatedtesting
.
common
.
action
.
ByType
.*;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
/**
* @author C
...
...
@@ -36,7 +37,7 @@ public class SeleniumServiceImpl implements SeleniumService {
public
Report
execute
(
TestCaseVo
testCase
)
{
WebDriver
driver
=
initDriver
(
testCase
.
getBrowser
());
driver
.
get
(
testCase
.
getUrl
());
return
executeSteps
(
driver
,
testCase
);
return
executeSteps
(
testCase
.
getUrl
(),
driver
,
testCase
);
}
/**
...
...
@@ -54,54 +55,57 @@ public class SeleniumServiceImpl implements SeleniumService {
}
else
if
(
Objects
.
equals
(
browser
,
Browser
.
IE
))
{
System
.
setProperty
(
"webdriver.ie.driver"
,
CommonUtils
.
IE_EXE
);
return
new
ChromeDriver
();
}
else
{
}
else
{
throw
new
RuntimeException
(
"该浏览器不存在:"
+
browser
);
}
}
private
Report
executeSteps
(
WebDriver
driver
,
TestCaseVo
testCase
)
{
private
Report
executeSteps
(
String
url
,
WebDriver
driver
,
TestCaseVo
testCase
)
{
List
<
Measure
>
measures
=
Lists
.
newArrayList
();
List
<
Step
>
steps
=
testCase
.
getSteps
().
stream
().
sorted
(
Comparator
.
comparingInt
(
Step:
:
getOrder
)).
collect
(
Collectors
.
toList
());
for
(
Step
step
:
steps
)
{
boolean
success
=
false
;
String
practice
=
""
;
String
practice
=
null
;
String
message
;
log
.
info
(
"Executing Step:{}"
,
step
.
getTitle
());
WebElement
webElement
=
null
;
log
.
info
(
"执行步骤:{}"
,
step
.
getTitle
());
try
{
if
(
Objects
.
equals
(
step
.
getAction
(),
HOME
)){
driver
.
get
(
url
);
}
else
{
webElement
=
getWebElement
(
step
.
getType
(),
step
.
getKey
(),
driver
);
if
(
Objects
.
equals
(
step
.
getAction
(),
INPUT
))
{
String
value
=
isNull
(
step
.
getValue
())
?
""
:
step
.
getValue
();
WebElement
webElement
=
getWebElement
(
step
.
getType
(),
step
.
getKey
(),
driver
);
webElement
.
sendKeys
(
value
);
}
else
if
(
Objects
.
equals
(
step
.
getAction
(),
CLICK
))
{
WebElement
webElement
=
getWebElement
(
step
.
getType
(),
step
.
getKey
(),
driver
);
webElement
.
click
();
}
else
if
(
Objects
.
equals
(
step
.
getAction
(),
SWITCH
))
{
driver
.
switchTo
().
frame
(
webElement
);
}
else
{
throw
new
RuntimeException
(
"不匹配的操作类型:"
+
step
.
getAction
());
}
}
if
(
Objects
.
equals
(
step
.
getAssertion
(),
Assertion
.
VALUE
))
{
WebElement
webElement
=
getWebElement
(
step
.
getType
(),
step
.
getKey
(),
driver
);
if
(
nonNull
(
webElement
)){
practice
=
webElement
.
getAttribute
(
"value"
);
if
(
Objects
.
equals
(
practice
,
step
.
getExpected
()))
{
success
=
true
;
message
=
String
.
format
(
"[%s] success."
,
step
.
getTitle
());
}
else
{
message
=
String
.
format
(
"[%s] failed.the value is incorrect. expected:%s practice:[%s] "
,
step
.
getTitle
(),
step
.
getExpected
(),
practice
);
}
}
else
if
(
Objects
.
equals
(
step
.
getAssertion
(),
Assertion
.
TITLE
))
{
}
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
=
String
.
format
(
"[%s] success."
,
step
.
getTitle
())
;
message
=
"成功"
;
}
else
{
message
=
String
.
format
(
"[%s] failed.the page is incorrect. expected:[%s] practice:[%s] "
,
step
.
getTitle
(),
step
.
getExpected
(),
practice
);
}
}
else
{
throw
new
RuntimeException
(
"不匹配的判断类型:"
+
step
.
getAssertion
());
message
=
String
.
format
(
"失败 实际与预期不符 预期:[%s] 实际:[%s] "
,
step
.
getExpected
(),
practice
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
success
=
false
;
message
=
String
.
format
(
"error detected:[%s]"
,
e
.
getMessage
());
message
=
String
.
format
(
"出现错误:[%s]"
,
e
.
getMessage
());
log
.
error
(
"出现错误:"
,
e
);
}
measures
.
add
(
new
Measure
(
step
.
getOrder
(),
...
...
@@ -114,15 +118,17 @@ public class SeleniumServiceImpl implements SeleniumService {
));
}
return
new
Report
(
testCase
.
getTitle
(),
testCase
.
getUrl
(),
testCase
.
getBrowser
(),
measures
);
}
@SuppressWarnings
(
"DuplicatedCode"
)
private
WebElement
getWebElement
(
String
getMethod
,
String
key
,
WebDriver
driver
)
{
WebElement
webElement
;
WebElement
webElement
=
null
;
if
(
Objects
.
equals
(
getMethod
,
XPATH
))
{
webElement
=
driver
.
findElement
(
By
.
xpath
(
key
));
}
else
if
(
Objects
.
equals
(
getMethod
,
CSS
))
{
...
...
@@ -131,9 +137,14 @@ public class SeleniumServiceImpl implements SeleniumService {
webElement
=
driver
.
findElement
(
By
.
id
(
key
));
}
else
if
(
Objects
.
equals
(
getMethod
,
NAME
))
{
webElement
=
driver
.
findElement
(
By
.
name
(
key
));
}
else
{
throw
new
RuntimeException
(
"未找到元素 type:"
+
getMethod
+
" key: "
+
key
);
}
if
(
Objects
.
nonNull
(
webElement
))
{
return
webElement
;
}
else
{
throw
new
RuntimeException
(
"未找到元素 定位方式:"
+
getMethod
+
" 关键值: "
+
key
);
}
}
}
src/main/java/com/zjty/automatedtesting/service/TransHelper.java
浏览文件 @
3468b668
...
...
@@ -15,6 +15,7 @@ public class TransHelper {
String
steps
=
JsonUtil
.
toJSon
(
testCaseVo
.
getSteps
());
return
new
TestCase
(
testCaseVo
.
getId
(),
testCaseVo
.
getTitle
(),
testCaseVo
.
getBrowser
(),
testCaseVo
.
getUrl
(),
steps
...
...
@@ -25,6 +26,7 @@ public class TransHelper {
List
<
Step
>
steps
=
JsonUtil
.
readValueToList
(
testCase
.
getSteps
(),
Step
.
class
);
return
new
TestCaseVo
(
testCase
.
getId
(),
testCase
.
getTitle
(),
testCase
.
getBrowser
(),
testCase
.
getUrl
(),
steps
...
...
src/main/resources/application.properties
浏览文件 @
3468b668
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.url
=
jdbc:mysql://localhost:3306/automated_testing?useSSL=false&serverTimezone=UTC
spring.datasource.url
=
jdbc:mysql://localhost:3306/automated_testing?useSSL=false&serverTimezone=UTC
&allowPublicKeyRetrieval=true
spring.datasource.username
=
root
spring.datasource.password
=
root
spring.jpa.hibernate.ddl-auto
=
update
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论