Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
auto-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
auto-test
Commits
f4a8b261
提交
f4a8b261
authored
3月 27, 2020
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成遍历测试执行类与方法
上级
7e444a56
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
193 行增加
和
29 行删除
+193
-29
ElementMapping.java
...main/java/com/zjty/autotest/pojo/test/ElementMapping.java
+0
-25
JavaScriptError.java
...ain/java/com/zjty/autotest/pojo/test/JavaScriptError.java
+159
-0
AutotestApplicationTests.java
...test/java/com/zjty/autotest/AutotestApplicationTests.java
+34
-4
没有找到文件。
src/main/java/com/zjty/autotest/pojo/test/ElementMapping.java
deleted
100644 → 0
浏览文件 @
7e444a56
package
com
.
zjty
.
autotest
.
pojo
.
test
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.jsoup.nodes.Attributes
;
import
org.openqa.selenium.WebElement
;
/**
* <p>Description : autotest
* <p>Date : 2020/3/26 16:25
* <p>@author : C
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
ElementMapping
{
Integer
order
;
WebElement
webElement
;
Attributes
attributes
;
}
src/main/java/com/zjty/autotest/pojo/test/JavaScriptError.java
0 → 100644
浏览文件 @
f4a8b261
package
com
.
zjty
.
autotest
.
pojo
.
test
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.openqa.selenium.JavascriptExecutor
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.firefox.FirefoxProfile
;
/**
* Holds information about a JavaScript error that has occurred in the browser.
* This can be currently only used with the {@link FirefoxDriver} (see {@link #addExtension(FirefoxProfile)}.
* @author Marc Guillemot
* @version $Revision: $
*/
public
class
JavaScriptError
{
private
final
String
errorMessage
;
private
final
String
sourceName
;
private
final
int
lineNumber
;
private
final
String
console
;
JavaScriptError
(
final
Map
<
String
,
?
extends
Object
>
map
)
{
errorMessage
=
(
String
)
map
.
get
(
"errorMessage"
);
sourceName
=
(
String
)
map
.
get
(
"sourceName"
);
lineNumber
=
((
Number
)
map
.
get
(
"lineNumber"
)).
intValue
();
console
=
(
String
)
map
.
get
(
"console"
);
}
JavaScriptError
(
final
String
errorMessage
,
final
String
sourceName
,
final
int
lineNumber
,
String
console
)
{
this
.
errorMessage
=
errorMessage
;
this
.
sourceName
=
sourceName
;
this
.
lineNumber
=
lineNumber
;
this
.
console
=
console
;
}
public
String
getErrorMessage
()
{
return
errorMessage
;
}
public
int
getLineNumber
()
{
return
lineNumber
;
}
public
String
getSourceName
()
{
return
sourceName
;
}
/**
* If Firebug is installed and active, this will contain the content of the Firebug Console since
* the previous JavaScript error.
* @return
*/
public
String
getConsole
()
{
return
console
;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
console
==
null
)
?
0
:
console
.
hashCode
());
result
=
prime
*
result
+
((
errorMessage
==
null
)
?
0
:
errorMessage
.
hashCode
());
result
=
prime
*
result
+
lineNumber
;
result
=
prime
*
result
+
((
sourceName
==
null
)
?
0
:
sourceName
.
hashCode
());
return
result
;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
)
{
return
false
;
}
if
(
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
JavaScriptError
other
=
(
JavaScriptError
)
obj
;
if
(
console
==
null
)
{
if
(
other
.
console
!=
null
)
{
return
false
;
}
}
else
if
(!
console
.
equals
(
other
.
console
))
{
return
false
;
}
if
(
errorMessage
==
null
)
{
if
(
other
.
errorMessage
!=
null
)
{
return
false
;
}
}
else
if
(!
errorMessage
.
equals
(
other
.
errorMessage
))
{
return
false
;
}
if
(
lineNumber
!=
other
.
lineNumber
)
{
return
false
;
}
if
(
sourceName
==
null
)
{
if
(
other
.
sourceName
!=
null
)
{
return
false
;
}
}
else
if
(!
sourceName
.
equals
(
other
.
sourceName
))
{
return
false
;
}
return
true
;
}
@Override
public
String
toString
()
{
String
s
=
errorMessage
+
" ["
+
sourceName
+
":"
+
lineNumber
+
"]"
;
if
(
console
!=
null
)
{
s
+=
"\nConsole: "
+
console
;
}
return
s
;
}
/**
* Gets the collected JavaScript errors that have occurred since last call to this method.
* @param driver the driver providing the possibility to retrieved JavaScript errors (see {@link #addExtension(FirefoxProfile)}.
* @return the errors or an empty list if the driver doesn't provide access to the JavaScript errors
*/
@SuppressWarnings
(
"unchecked"
)
public
static
List
<
JavaScriptError
>
readErrors
(
final
WebDriver
driver
)
{
final
String
script
=
"return window.JSErrorCollector_errors ? window.JSErrorCollector_errors.pump() : []"
;
final
List
<
Object
>
errors
=
(
List
<
Object
>)
((
JavascriptExecutor
)
driver
).
executeScript
(
script
);
final
List
<
JavaScriptError
>
response
=
new
ArrayList
<
JavaScriptError
>();
for
(
final
Object
rawError
:
errors
)
{
response
.
add
(
new
JavaScriptError
((
Map
<
String
,
?
extends
Object
>)
rawError
));
}
return
response
;
}
/**
* Adds the Firefox extension collecting JS errors to the profile what allows later use of {@link #readErrors(WebDriver)}.
* <p>
* Example:<br>
* <code><pre>
* final FirefoxProfile profile = new FirefoxProfile();
* JavaScriptError.addExtension(profile);
* final WebDriver driver = new FirefoxDriver(profile);
* </pre></code>
* @param ffProfile the Firefox profile to which the extension should be added.
* @throws IOException in case of problem
*/
public
static
void
addExtension
(
final
FirefoxProfile
ffProfile
)
throws
IOException
{
ffProfile
.
addExtension
(
JavaScriptError
.
class
,
"JSErrorCollector.xpi"
);
}
}
src/test/java/com/zjty/autotest/AutotestApplicationTests.java
浏览文件 @
f4a8b261
...
@@ -4,18 +4,36 @@ import com.google.common.collect.Lists;
...
@@ -4,18 +4,36 @@ import com.google.common.collect.Lists;
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.Input
;
import
com.zjty.autotest.pojo.test.Input
;
import
com.zjty.autotest.pojo.test.JavaScriptError
;
import
com.zjty.autotest.pojo.test.Project
;
import
com.zjty.autotest.pojo.test.Project
;
import
com.zjty.autotest.service.impl.SeleniumExecutor
;
import
com.zjty.autotest.service.impl.SeleniumExecutor
;
import
com.zjty.autotest.util.WebDriverUtil
;
import
com.zjty.autotest.util.WebDriverUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.checkerframework.checker.units.qual.C
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.JavascriptExecutor
;
import
org.openqa.selenium.PageLoadStrategy
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.chrome.ChromeOptions
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.firefox.FirefoxOptions
;
import
org.openqa.selenium.firefox.FirefoxProfile
;
import
org.openqa.selenium.logging.LogEntry
;
import
org.openqa.selenium.logging.LogEntry
;
import
org.openqa.selenium.logging.LogType
;
import
org.openqa.selenium.logging.LogType
;
import
org.openqa.selenium.logging.LoggingPreferences
;
import
org.openqa.selenium.logging.Logs
;
import
org.openqa.selenium.remote.CapabilityType
;
import
org.openqa.selenium.support.ui.Sleeper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
java.io.IOException
;
import
java.time.Duration
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.logging.Level
;
@Slf4j
@Slf4j
@SpringBootTest
@SpringBootTest
...
@@ -27,7 +45,7 @@ class AutotestApplicationTests {
...
@@ -27,7 +45,7 @@ class AutotestApplicationTests {
@Test
@Test
public
void
execute
()
throws
InterruptedException
{
public
void
execute
()
throws
InterruptedException
{
String
url
=
"file:///C:/code/errorTest.html"
;
String
url
=
"file:///C:/code/errorTest.html"
;
// String url = "https://
bbs.colg.cn/forum-171-1.html
";
// String url = "https://
workbook.zjtys.com.cn/#/login
";
test1
(
url
);
test1
(
url
);
...
@@ -35,10 +53,22 @@ class AutotestApplicationTests {
...
@@ -35,10 +53,22 @@ class AutotestApplicationTests {
}
}
private
void
test1
(
String
url
){
private
void
test1
(
String
url
){
WebDriver
driver
=
WebDriverUtil
.
getWebDriver
(
"firefox"
);
// GeckoDriver v0.26.0
FirefoxOptions
options
=
new
FirefoxOptions
();
LoggingPreferences
logPrefs
=
new
LoggingPreferences
();
logPrefs
.
enable
(
LogType
.
BROWSER
,
Level
.
ALL
);
// options.setPageLoadStrategy(PageLoadStrategy.EAGER);
options
.
setCapability
(
CapabilityType
.
LOGGING_PREFS
,
logPrefs
);
WebDriver
driver
=
new
FirefoxDriver
(
options
);
driver
.
get
(
url
);
driver
.
get
(
url
);
for
(
String
s
:
driver
.
manage
().
logs
().
getAvailableLogTypes
())
{
driver
.
findElement
(
By
.
xpath
(
"/html/body/button[1]"
)).
click
();
System
.
out
.
println
(
s
);
driver
.
findElement
(
By
.
xpath
(
"/html/body/button[2]"
)).
click
();
driver
.
findElement
(
By
.
xpath
(
"/html/body/button[3]"
)).
click
();
driver
.
findElement
(
By
.
xpath
(
"/html/body/button[4]"
)).
click
();
driver
.
findElement
(
By
.
xpath
(
"/html/body/button[5]"
)).
click
();
for
(
LogEntry
logEntry
:
driver
.
manage
().
logs
().
get
(
LogType
.
BROWSER
))
{
System
.
out
.
println
(
String
.
format
(
"[%s] [%s]"
,
logEntry
.
getLevel
(),
logEntry
.
getMessage
()));
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论