Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
auto-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
auto-test
Commits
0d1a333e
提交
0d1a333e
authored
3月 24, 2020
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成遍历测试执行类与方法
上级
a2093f05
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
34 行增加
和
13 行删除
+34
-13
ResourceController.java
...java/com/zjty/autotest/controller/ResourceController.java
+1
-1
SeleniumExecutor.java
...java/com/zjty/autotest/service/impl/SeleniumExecutor.java
+33
-11
AutotestApplicationTests.java
...test/java/com/zjty/autotest/AutotestApplicationTests.java
+0
-1
没有找到文件。
src/main/java/com/zjty/autotest/controller/ResourceController.java
浏览文件 @
0d1a333e
...
...
@@ -17,7 +17,7 @@ public class ResourceController {
return
"index.html"
;
}
@RequestMapping
(
"/
pic
/{name}"
)
@RequestMapping
(
"/
screenshot
/{name}"
)
public
String
picture
(
@PathVariable
String
name
){
return
name
+
".png"
;
}
...
...
src/main/java/com/zjty/autotest/service/impl/SeleniumExecutor.java
浏览文件 @
0d1a333e
...
...
@@ -16,6 +16,7 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Predicate
;
import
static
com
.
zjty
.
autotest
.
common
.
action
.
LabelType
.*;
...
...
@@ -58,6 +59,7 @@ public class SeleniumExecutor {
public
Report
execute
(
Project
project
)
{
driver
=
WebDriverUtil
.
getWebDriver
(
project
.
getBrowser
());
driver
.
manage
().
timeouts
().
implicitlyWait
(
10L
,
TimeUnit
.
SECONDS
);
inputs
=
project
.
getInputs
();
List
<
Measure
>
measures
=
Lists
.
newArrayList
();
String
os
=
""
;
...
...
@@ -108,8 +110,9 @@ public class SeleniumExecutor {
//如果出错 则提供截图
String
screenshot
=
""
;
if
(!
success
)
{
screenShot
(
currentUrl
);
screenshot
=
"http://localhost:13500/screenshots/"
+
currentUrl
;
String
screenshotName
=
alterUrlName
(
currentUrl
);
screenshot
(
screenshotName
);
screenshot
=
String
.
format
(
"http://localhost:13500/screenshots/%s"
,
screenshotName
);
}
log
.
info
(
"遍历完毕..."
);
measure
=
new
Measure
(
...
...
@@ -124,15 +127,12 @@ public class SeleniumExecutor {
}
private
String
traversal
()
{
String
message
=
null
;
String
Builder
message
=
new
StringBuilder
()
;
while
(
elementIndex
<
elements
.
size
())
{
WebElement
element
=
elements
.
get
(
elementIndex
);
message
=
act
(
element
);
if
(
nonNull
(
message
))
{
break
;
}
message
.
append
(
act
(
element
));
}
return
message
;
return
message
.
toString
()
;
}
private
String
act
(
WebElement
element
)
{
...
...
@@ -162,15 +162,21 @@ public class SeleniumExecutor {
}
catch
(
ElementNotInteractableException
e
)
{
message
=
"异常的布局;"
;
log
.
error
(
"error:在可操作范围之外的元素"
);
}
catch
(
TimeoutException
e
)
{
message
=
"第"
+
(
elementIndex
+
1
)
+
"个元素操作超时;"
;
log
.
error
(
"error:操作超时"
);
}
catch
(
Exception
e
)
{
message
=
"预料之外的异常:"
+
e
.
getMessage
()
+
";"
;
log
.
error
(
"error:"
+
e
.
getMessage
()
);
log
.
error
(
"error:"
+
e
);
}
return
message
;
}
private
Boolean
checkPage
()
{
boolean
pageChange
=
!
Objects
.
equals
(
currentUrl
,
driver
.
getCurrentUrl
());
boolean
pageChange
=
!
Objects
.
equals
(
getMainUrl
(
currentUrl
),
getMainUrl
(
driver
.
getCurrentUrl
())
);
if
(
pageChange
)
{
boolean
newPage
=
!
historyUrls
.
contains
(
driver
.
getCurrentUrl
());
if
(
newPage
)
{
...
...
@@ -183,6 +189,10 @@ public class SeleniumExecutor {
}
}
private
String
getMainUrl
(
String
url
)
{
return
url
.
substring
(
0
,
url
.
indexOf
(
url
));
}
private
void
inputValue
(
WebElement
element
,
List
<
Input
>
inputs
)
{
Predicate
<
Input
>
inputMatch
=
input
->
Objects
.
equals
(
element
.
getAttribute
(
input
.
getAttrName
()),
input
.
getAttrValue
());
Optional
<
Input
>
inputOptional
=
inputs
.
stream
().
filter
(
inputMatch
).
findAny
();
...
...
@@ -251,7 +261,19 @@ public class SeleniumExecutor {
}
private
void
screenShot
(
String
name
)
{
private
String
alterUrlName
(
String
fileName
)
{
// /\?*:"<>|
return
fileName
.
replace
(
"/"
,
""
)
.
replace
(
"\\"
,
""
)
.
replace
(
"?"
,
""
)
.
replace
(
"*"
,
""
)
.
replace
(
":"
,
""
)
.
replace
(
"<"
,
""
)
.
replace
(
">"
,
""
)
.
replace
(
"|"
,
""
);
}
private
void
screenshot
(
String
name
)
{
byte
[]
bytes
=
((
TakesScreenshot
)
driver
).
getScreenshotAs
(
OutputType
.
BYTES
);
FileUtil
.
output
(
bytes
,
FileUtil
.
WORK_PATH
+
"screenshots\\"
+
name
+
".png"
);
}
...
...
src/test/java/com/zjty/autotest/AutotestApplicationTests.java
浏览文件 @
0d1a333e
...
...
@@ -40,7 +40,6 @@ class AutotestApplicationTests {
caps
.
setCapability
(
CapabilityType
.
LOGGING_PREFS
,
logPrefs
);
WebDriver
driver
=
new
ChromeDriver
();
String
url
=
"file:///C:/MyProjects/auto-test/wps/index.html"
;
long
startTime
=
System
.
currentTimeMillis
();
driver
.
get
(
url
);
Project
project
=
new
Project
(
null
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论