Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
auto-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
auto-test
Commits
9071c9ff
提交
9071c9ff
authored
3月 27, 2020
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成遍历测试执行类与方法
上级
ddfa4f29
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
56 行删除
+28
-56
SeleniumExecutor.java
...java/com/zjty/autotest/service/impl/SeleniumExecutor.java
+28
-56
没有找到文件。
src/main/java/com/zjty/autotest/service/impl/SeleniumExecutor.java
浏览文件 @
9071c9ff
...
@@ -7,7 +7,6 @@ import com.google.common.collect.Sets;
...
@@ -7,7 +7,6 @@ import com.google.common.collect.Sets;
import
com.zjty.autotest.pojo.report.ElementDetail
;
import
com.zjty.autotest.pojo.report.ElementDetail
;
import
com.zjty.autotest.pojo.report.Measure
;
import
com.zjty.autotest.pojo.report.Measure
;
import
com.zjty.autotest.pojo.report.Report
;
import
com.zjty.autotest.pojo.report.Report
;
import
com.zjty.autotest.pojo.test.ElementMapping
;
import
com.zjty.autotest.pojo.test.Input
;
import
com.zjty.autotest.pojo.test.Input
;
import
com.zjty.autotest.pojo.test.Project
;
import
com.zjty.autotest.pojo.test.Project
;
import
com.zjty.autotest.util.FileUtil
;
import
com.zjty.autotest.util.FileUtil
;
...
@@ -25,7 +24,6 @@ import org.springframework.stereotype.Service;
...
@@ -25,7 +24,6 @@ import org.springframework.stereotype.Service;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Predicate
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -63,8 +61,6 @@ public class SeleniumExecutor {
...
@@ -63,8 +61,6 @@ public class SeleniumExecutor {
private
Queue
<
String
>
urlQueue
=
Queues
.
newLinkedBlockingDeque
();
private
Queue
<
String
>
urlQueue
=
Queues
.
newLinkedBlockingDeque
();
private
List
<
ElementMapping
>
elementMappings
=
Lists
.
newArrayList
();
/**
/**
* 当前进行的窗口页
* 当前进行的窗口页
*/
*/
...
@@ -82,7 +78,6 @@ public class SeleniumExecutor {
...
@@ -82,7 +78,6 @@ public class SeleniumExecutor {
public
Report
execute
(
Project
project
)
{
public
Report
execute
(
Project
project
)
{
driver
=
WebDriverUtil
.
getWebDriver
(
project
.
getBrowser
());
driver
=
WebDriverUtil
.
getWebDriver
(
project
.
getBrowser
());
driver
.
manage
().
timeouts
().
pageLoadTimeout
(
2L
,
TimeUnit
.
SECONDS
);
inputs
=
project
.
getInputs
();
inputs
=
project
.
getInputs
();
List
<
Measure
>
measures
=
Lists
.
newArrayList
();
List
<
Measure
>
measures
=
Lists
.
newArrayList
();
String
os
=
""
;
String
os
=
""
;
...
@@ -127,7 +122,6 @@ public class SeleniumExecutor {
...
@@ -127,7 +122,6 @@ public class SeleniumExecutor {
//获取当前网页的所有元素并放入元素队列
//获取当前网页的所有元素并放入元素队列
Map
<
Attributes
,
WebElement
>
elements
=
getAllElements
(
driver
);
Map
<
Attributes
,
WebElement
>
elements
=
getAllElements
(
driver
);
log
.
info
(
"获取完毕...共{}个元素..."
,
elements
.
size
());
log
.
info
(
"获取完毕...共{}个元素..."
,
elements
.
size
());
elements
.
forEach
((
attributes
,
element
)
->
System
.
out
.
println
(
attributes
));
//元素序号重置
//元素序号重置
currentHistoryAttributes
.
clear
();
currentHistoryAttributes
.
clear
();
//开始遍历操作元素队列中的元素 返回各个元素测试信息
//开始遍历操作元素队列中的元素 返回各个元素测试信息
...
@@ -147,6 +141,10 @@ public class SeleniumExecutor {
...
@@ -147,6 +141,10 @@ public class SeleniumExecutor {
elementDetails
.
forEach
(
elementDetail
->
messages
.
add
(
elementDetail
.
getMessage
()));
elementDetails
.
forEach
(
elementDetail
->
messages
.
add
(
elementDetail
.
getMessage
()));
StringBuilder
message
=
new
StringBuilder
();
StringBuilder
message
=
new
StringBuilder
();
messages
.
forEach
(
message:
:
append
);
messages
.
forEach
(
message:
:
append
);
for
(
String
msg
:
messages
)
{
message
.
append
(
msg
);
message
.
append
(
';'
);
}
log
.
info
(
"遍历完毕..."
);
log
.
info
(
"遍历完毕..."
);
measure
=
new
Measure
(
measure
=
new
Measure
(
currentUrl
,
currentUrl
,
...
@@ -187,52 +185,26 @@ public class SeleniumExecutor {
...
@@ -187,52 +185,26 @@ public class SeleniumExecutor {
Map
<
Attributes
,
WebElement
>
reload
=
reload
();
Map
<
Attributes
,
WebElement
>
reload
=
reload
();
traversal
(
reload
,
elementDetails
);
traversal
(
reload
,
elementDetails
);
}
}
// if (sourceChanged) {
// Map<Attributes, WebElement> reload = reload();
// traversal(reload, elementDetails);
// }
elementDetails
.
add
(
elementDetail
);
elementDetails
.
add
(
elementDetail
);
}
}
}
}
// while (elementIndex < this.elements.size()) {
// WebElement element = this.elements.get(elementIndex);
// ElementDetail elementDetail = actClick(element,);
// elementIndex++;
// boolean urlChanged = checkURl();
// boolean sourceChanged = checkSource();
// if (urlChanged) {
// boolean newPage = !historyUrls.contains(driver.getCurrentUrl())
// && !Sets.newHashSet(urlQueue).contains(driver.getCurrentUrl())
// && sourceChanged;
// if (newPage) {
// log.info("检测到新url:{} 加入队列 ", driver.getCurrentUrl());
// urlQueue.add(driver.getCurrentUrl());
// urlQueue = queueDuplicateRemoval(urlQueue);
// }
// reload();
// }
// if (sourceChanged) {
// reload();
// }
// elementDetails.add(elementDetail);
// }
}
}
private
ElementDetail
actInput
(
Attributes
attributes
,
WebElement
element
)
{
private
ElementDetail
actInput
(
Attributes
attributes
,
WebElement
element
)
{
String
type
=
element
.
getTagName
(
);
String
type
=
String
.
format
(
"<%s>%s"
,
element
.
getTagName
(),
element
.
getText
()
);
String
message
=
null
;
String
message
=
""
;
Long
responseT
I
me
=
-
1L
;
Long
responseT
i
me
=
-
1L
;
boolean
success
=
false
;
boolean
success
=
false
;
try
{
try
{
if
(
isEnabled
(
element
))
{
if
(
isEnabled
(
element
))
{
log
.
info
(
"Input元素 -----
- text:[{}] ----- tag:[{}] ---- attrs:[{}]"
,
element
.
getText
(),
element
.
getTagName
(),
attributes
);
log
.
info
(
"Input元素 -----
tag:[{}] ------ text:[{}] ---- attrs:[{}]"
,
element
.
getTagName
(),
element
.
getText
(),
attributes
);
long
startTime
=
System
.
currentTimeMillis
();
long
startTime
=
System
.
currentTimeMillis
();
if
(!
inputs
.
isEmpty
())
{
if
(!
inputs
.
isEmpty
())
{
Input
input
=
inputs
.
remove
(
0
);
Input
input
=
inputs
.
remove
(
0
);
element
.
sendKeys
(
input
.
getValue
());
element
.
sendKeys
(
input
.
getValue
());
}
}
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
Long
responseTime
=
endTime
-
startTime
;
responseTime
=
endTime
-
startTime
;
success
=
true
;
success
=
true
;
Alert
alert
=
ExpectedConditions
.
alertIsPresent
().
apply
(
driver
);
Alert
alert
=
ExpectedConditions
.
alertIsPresent
().
apply
(
driver
);
if
(
nonNull
(
alert
))
{
if
(
nonNull
(
alert
))
{
...
@@ -242,11 +214,15 @@ public class SeleniumExecutor {
...
@@ -242,11 +214,15 @@ public class SeleniumExecutor {
}
}
}
}
}
catch
(
ElementNotInteractableException
e
)
{
}
catch
(
ElementNotInteractableException
e
)
{
message
=
"异常的布局;"
;
message
=
"异常的布局"
;
success
=
false
;
log
.
error
(
"error:存在可操作范围之外的元素"
);
}
catch
(
TimeoutException
e
)
{
message
=
"页面超时"
;
success
=
false
;
success
=
false
;
log
.
error
(
"error:存在可操作范围之外的元素"
);
log
.
error
(
"error:存在可操作范围之外的元素"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
message
=
"
预料之外的异常:"
+
e
.
getMessage
()
+
";
"
;
message
=
"
出现预料之外的异常
"
;
success
=
false
;
success
=
false
;
log
.
error
(
"error:"
+
e
);
log
.
error
(
"error:"
+
e
);
}
}
...
@@ -254,20 +230,20 @@ public class SeleniumExecutor {
...
@@ -254,20 +230,20 @@ public class SeleniumExecutor {
currentHistoryAttributes
.
add
(
attributes
);
currentHistoryAttributes
.
add
(
attributes
);
return
new
ElementDetail
(
return
new
ElementDetail
(
type
,
type
,
responseT
I
me
.
intValue
(),
responseT
i
me
.
intValue
(),
success
,
success
,
message
message
);
);
}
}
private
ElementDetail
actClick
(
Attributes
attributes
,
WebElement
element
)
{
private
ElementDetail
actClick
(
Attributes
attributes
,
WebElement
element
)
{
String
type
=
element
.
getTagName
(
);
String
type
=
String
.
format
(
"<%s>%s"
,
element
.
getTagName
(),
element
.
getText
()
);
String
message
=
null
;
String
message
=
""
;
Long
responseTIme
=
0L
;
Long
responseTIme
=
0L
;
boolean
success
=
false
;
boolean
success
=
false
;
try
{
try
{
if
(
isEnabled
(
element
))
{
if
(
isEnabled
(
element
))
{
log
.
info
(
"
Click 元素 ------ text:[{}] ----- tag:[{}] ---- attrs:[{}]"
,
element
.
getText
(),
element
.
getTagName
(),
attributes
);
log
.
info
(
"
Input元素 ----- tag:[{}] ------ text:[{}] ---- attrs:[{}]"
,
element
.
getTagName
(),
element
.
getText
(),
attributes
);
element
.
click
();
element
.
click
();
sleep
();
sleep
();
success
=
true
;
success
=
true
;
...
@@ -279,11 +255,15 @@ public class SeleniumExecutor {
...
@@ -279,11 +255,15 @@ public class SeleniumExecutor {
}
}
}
}
}
catch
(
ElementNotInteractableException
e
)
{
}
catch
(
ElementNotInteractableException
e
)
{
message
=
"异常的布局;"
;
message
=
"异常的布局"
;
success
=
false
;
log
.
error
(
"error:存在可操作范围之外的元素"
);
}
catch
(
TimeoutException
e
)
{
message
=
"页面超时"
;
success
=
false
;
success
=
false
;
log
.
error
(
"error:存在可操作范围之外的元素"
);
log
.
error
(
"error:存在可操作范围之外的元素"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
message
=
"
预料之外的异常:"
+
e
.
getMessage
()
+
";
"
;
message
=
"
出现预料之外的异常
"
;
success
=
false
;
success
=
false
;
log
.
error
(
"error:"
+
e
);
log
.
error
(
"error:"
+
e
);
}
}
...
@@ -344,14 +324,13 @@ public class SeleniumExecutor {
...
@@ -344,14 +324,13 @@ public class SeleniumExecutor {
@SuppressWarnings
(
"unused"
)
@SuppressWarnings
(
"unused"
)
private
void
sleep
()
{
private
void
sleep
()
{
try
{
try
{
Sleeper
.
SYSTEM_SLEEPER
.
sleep
(
Duration
.
ofSeconds
(
2L
));
Sleeper
.
SYSTEM_SLEEPER
.
sleep
(
Duration
.
ofSeconds
(
waitTime
));
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
private
Map
<
Attributes
,
WebElement
>
getAllElements
(
WebDriver
driver
)
{
private
Map
<
Attributes
,
WebElement
>
getAllElements
(
WebDriver
driver
)
{
elementMappings
.
clear
();
List
<
WebElement
>
webElements
=
Lists
.
newArrayList
();
List
<
WebElement
>
webElements
=
Lists
.
newArrayList
();
driver
.
findElements
(
By
.
xpath
(
"*"
))
driver
.
findElements
(
By
.
xpath
(
"*"
))
.
forEach
(
element
->
getSubElements
(
element
,
webElements
));
.
forEach
(
element
->
getSubElements
(
element
,
webElements
));
...
@@ -390,7 +369,7 @@ public class SeleniumExecutor {
...
@@ -390,7 +369,7 @@ public class SeleniumExecutor {
private
Boolean
isClickAble
(
WebElement
element
)
{
private
Boolean
isClickAble
(
WebElement
element
)
{
try
{
try
{
return
nonNull
(
ExpectedConditions
.
elementToBeClickable
(
element
).
apply
(
driver
));
return
nonNull
(
ExpectedConditions
.
elementToBeClickable
(
element
).
apply
(
driver
));
}
catch
(
Exception
e
){
}
catch
(
Exception
e
)
{
return
false
;
return
false
;
}
}
}
}
...
@@ -398,7 +377,7 @@ public class SeleniumExecutor {
...
@@ -398,7 +377,7 @@ public class SeleniumExecutor {
private
Boolean
isEnabled
(
WebElement
element
)
{
private
Boolean
isEnabled
(
WebElement
element
)
{
try
{
try
{
return
nonNull
(
ExpectedConditions
.
elementToBeClickable
(
element
).
apply
(
driver
));
return
nonNull
(
ExpectedConditions
.
elementToBeClickable
(
element
).
apply
(
driver
));
}
catch
(
Exception
e
){
}
catch
(
Exception
e
)
{
return
false
;
return
false
;
}
}
}
}
...
@@ -452,11 +431,4 @@ public class SeleniumExecutor {
...
@@ -452,11 +431,4 @@ public class SeleniumExecutor {
return
result
;
return
result
;
}
}
private
void
removeHistoryElements
()
{
elementMappings
.
forEach
((
elementMapping
)
->
{
if
(
historyAttributes
.
contains
(
elementMapping
.
getAttributes
()))
{
elementMappings
.
remove
(
elementMapping
);
}
});
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论