Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
auto-test-case
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
auto-test-case
Commits
89b48347
提交
89b48347
authored
1月 11, 2021
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[feature]
增加按键操作 简化异常信息
上级
59ac5428
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
13 行删除
+31
-13
CommandType.java
...ain/java/com/zjty/autotest/common/action/CommandType.java
+2
-0
SeleniumExecutor.java
...main/java/com/zjty/autotest/service/SeleniumExecutor.java
+25
-13
SeleniumHelper.java
...java/com/zjty/autotest/service/helper/SeleniumHelper.java
+4
-0
没有找到文件。
src/main/java/com/zjty/autotest/common/action/CommandType.java
浏览文件 @
89b48347
...
...
@@ -12,6 +12,8 @@ public interface CommandType {
String
TYPE
=
"type"
;
String
SEND_KEYS
=
"sendKeys"
;
String
MOUSE_OVER
=
"mouseOver"
;
String
SET_WINDOW_SIZE
=
"setWindowSize"
;
...
...
src/main/java/com/zjty/autotest/service/SeleniumExecutor.java
浏览文件 @
89b48347
...
...
@@ -34,7 +34,7 @@ import static java.util.Objects.nonNull;
/**
* @author C
*/
@SuppressWarnings
({
"SpringAutowiredFieldsWarningInspection"
,
"Duplicates"
,
"SpringJavaAutowiredFieldsWarningInspection"
,
"DuplicateExpressions"
})
@SuppressWarnings
({
"SpringAutowiredFieldsWarningInspection"
,
"Duplicates"
,
"SpringJavaAutowiredFieldsWarningInspection"
})
@Slf4j
@Service
public
class
SeleniumExecutor
{
...
...
@@ -239,7 +239,7 @@ public class SeleniumExecutor {
break
;
case
CLICK:
content
=
format
(
"单击:[%s]"
,
target
);
waitForELement
(
target
,
targets
);
waitForELement
(
target
,
targets
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
...
...
@@ -263,7 +263,7 @@ public class SeleniumExecutor {
break
;
case
DOUBLE_CLICK:
content
=
format
(
"双击:[%s]"
,
target
);
waitForELement
(
target
,
targets
);
waitForELement
(
target
,
targets
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
...
...
@@ -285,7 +285,7 @@ public class SeleniumExecutor {
break
;
case
MOUSE_DOWN:
content
=
format
(
"长单击:[%s]"
,
target
);
waitForELement
(
target
,
targets
);
waitForELement
(
target
,
targets
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
...
...
@@ -307,7 +307,7 @@ public class SeleniumExecutor {
break
;
case
MOUSE_MOVE:
content
=
format
(
"鼠标移动至:[%s]"
,
target
);
waitForELement
(
target
,
targets
);
waitForELement
(
target
,
targets
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
...
...
@@ -328,7 +328,7 @@ public class SeleniumExecutor {
break
;
case
MOUSE_UP:
content
=
format
(
"停止长按:[%s]"
,
target
);
waitForELement
(
target
,
targets
);
waitForELement
(
target
,
targets
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
...
...
@@ -350,7 +350,7 @@ public class SeleniumExecutor {
case
SELECT:
String
label
=
seleniumHelper
.
getValue
(
value
);
content
=
format
(
"下拉框选择:[%s]"
,
label
);
waitForELement
(
target
,
targets
);
waitForELement
(
target
,
targets
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
...
...
@@ -396,6 +396,19 @@ public class SeleniumExecutor {
success
=
false
;
}
break
;
case
SEND_KEYS:
content
=
format
(
"输入按键:[%s]"
,
value
);
element
=
getElement
(
target
,
targets
);
costTime
=
System
.
currentTimeMillis
()
-
stepStartTime
;
if
(
nonNull
(
element
))
{
String
key
=
seleniumHelper
.
getKeyForSend
(
value
);
element
.
sendKeys
(
Keys
.
valueOf
(
key
));
success
=
true
;
}
else
{
message
=
"无法定位该元素"
;
success
=
false
;
}
break
;
case
CLOSE:
content
=
"关闭窗口"
;
try
{
...
...
@@ -413,7 +426,7 @@ public class SeleniumExecutor {
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getLocalizedMessage
());
Arrays
.
stream
(
e
.
getStackTrace
()).
forEach
(
System
.
out
::
println
);
message
=
e
.
getLocalizedMessage
(
);
message
=
format
(
"出现异常:%s"
,
e
.
getClass
().
getSimpleName
()
);
success
=
false
;
}
stepStartTime
=
System
.
currentTimeMillis
();
...
...
@@ -440,16 +453,15 @@ public class SeleniumExecutor {
}
private
void
movetoElementView
(
WebElement
element
)
{
JavascriptExecutor
jse
=
(
JavascriptExecutor
)
driver
;
jse
.
executeScript
(
"arguments[0].scrollIntoView(true);"
,
element
);
}
private
void
waitForELement
(
String
target
,
List
<
List
<
String
>>
targets
){
private
void
waitForELement
(
String
target
,
List
<
List
<
String
>>
targets
)
{
try
{
new
WebDriverWait
(
driver
,
3
).
until
(
webDriver
->
nonNull
(
getElement
(
target
,
targets
)));
}
catch
(
Exception
ignored
){
new
WebDriverWait
(
driver
,
3
).
until
(
webDriver
->
nonNull
(
getElement
(
target
,
targets
)));
}
catch
(
Exception
ignored
)
{
}
}
...
...
@@ -468,7 +480,7 @@ public class SeleniumExecutor {
}
}
return
null
;
}
else
{
}
else
{
return
element
;
}
}
...
...
src/main/java/com/zjty/autotest/service/helper/SeleniumHelper.java
浏览文件 @
89b48347
...
...
@@ -46,6 +46,10 @@ public class SeleniumHelper {
return
name_value
[
1
];
}
public
String
getKeyForSend
(
String
value
)
{
return
value
.
replace
(
"${KEY_"
,
""
).
replace
(
"}"
,
""
);
}
private
Map
<
String
,
String
>
handleMap
=
new
HashMap
<>();
private
Set
<
String
>
historyHandles
=
new
HashSet
<>();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论