Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
test-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马博
test-platform
Commits
8b84cb59
Commit
8b84cb59
authored
Nov 20, 2018
by
钱雯君
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into qwj_181029
parents
81b2cc79
f0f0f15b
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
657 additions
and
12 deletions
+657
-12
reportng-1.1.6.jar
lib/reportng-1.1.6.jar
+0
-0
pom.xml
pom.xml
+57
-9
MysqlConnPool.java
src/test/java/base/MysqlConnPool.java
+1
-0
TestListener.java
src/test/java/base/TestListener.java
+23
-2
Authorization.java
src/test/java/http/service/Authorization.java
+1
-1
mytest.java
src/test/java/ui/cases/mytest.java
+77
-0
test.java
src/test/java/ui/cases/test.java
+96
-0
Checkor.java
src/test/java/ui/common/Checkor.java
+40
-0
LimitQueue.java
src/test/java/ui/common/LimitQueue.java
+138
-0
ProxyFactory.java
src/test/java/ui/common/ProxyFactory.java
+67
-0
RequestCheckor.java
src/test/java/ui/common/RequestCheckor.java
+28
-0
StatusCheckor.java
src/test/java/ui/common/StatusCheckor.java
+26
-0
WebDriverFactory.java
src/test/java/ui/common/WebDriverFactory.java
+95
-0
WebDriverType.java
src/test/java/ui/common/WebDriverType.java
+8
-0
chromedriver
src/test/resources/chromedriver
+0
-0
chromedriver.exe
src/test/resources/chromedriver.exe
+0
-0
No files found.
lib/reportng-1.1.6.jar
0 → 100644
View file @
8b84cb59
File added
pom.xml
View file @
8b84cb59
...
...
@@ -70,18 +70,42 @@
</dependency>
<!-- 依赖reportNg-->
<!--<dependency>-->
<!--<groupId>org.uncommons</groupId>-->
<!--<artifactId>reportng</artifactId>-->
<!--<version>1.1.4</version>-->
<!--<scope>test</scope>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.testng</groupId>-->
<!--<artifactId>testng</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<dependency>
<groupId>
org.uncommons
</groupId>
<artifactId>
reportng
</artifactId>
<version>
1.1.4
</version>
<scope>
test
</scope>
<exclusions>
<exclusion>
<groupId>
org.testng
</groupId>
<artifactId>
testng
</artifactId>
</exclusion>
</exclusions>
<version>
1.1.6
</version>
<scope>
system
</scope>
<systemPath>
${project.basedir}/lib/reportng-1.1.6.jar
</systemPath>
</dependency>
<dependency>
<groupId>
velocity
</groupId>
<artifactId>
velocity
</artifactId>
<version>
1.4
</version>
</dependency>
<dependency>
<groupId>
com.google.inject
</groupId>
<artifactId>
guice
</artifactId>
<version>
4.0
</version>
</dependency>
<!-- 依赖Guice -->
<dependency>
<groupId>
com.google.inject
</groupId>
...
...
@@ -211,7 +235,31 @@
<dependency>
<groupId>
com.codeborne
</groupId>
<artifactId>
selenide
</artifactId>
<version>
5.0.0
</version>
<version>
4.4.3
</version>
<exclusions>
<exclusion>
<groupId>
org.seleniumhq.selenium
</groupId>
<artifactId>
selenium-java
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.seleniumhq.selenium
</groupId>
<artifactId>
selenium-java
</artifactId>
<version>
3.4.0
</version>
<exclusions>
<exclusion>
<groupId>
commons-logging
</groupId>
<artifactId>
commons-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V-->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
21.0
</version>
</dependency>
</dependencies>
...
...
src/test/java/base/MysqlConnPool.java
View file @
8b84cb59
...
...
@@ -35,6 +35,7 @@ public class MysqlConnPool {
@Value
(
"${db.maxtotal}"
)
int
maxtotal
;
public
static
BasicDataSource
bds
;
public
DuibaLog
log
=
DuibaLog
.
getLogger
();
...
...
src/test/java/base/TestListener.java
View file @
8b84cb59
package
base
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Iterator
;
import
org.testng.*
;
...
...
@@ -8,7 +10,7 @@ import org.testng.*;
* Created by mabo on 2018/9/29
*/
public
class
TestListener
implements
ITestListener
{
p
rivate
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
p
ublic
DuibaLog
logger
=
DuibaLog
.
getLogger
();
public
void
onFinish
(
ITestContext
context
)
{
Iterator
<
ITestResult
>
listOfFailedTests
=
context
.
getFailedTests
().
getAllResults
().
iterator
();
...
...
@@ -33,15 +35,22 @@ public class TestListener implements ITestListener {
// TODO Auto-generated method stub
logger
.
info
(
"on "
+
Thread
.
currentThread
().
getId
());
Reporter
.
setCurrentTestResult
(
result
);
logger
.
info
(
"----------------------------"
+
result
.
getName
()+
"----------------------------"
);
logger
.
info
(
"start time:"
+
stampToDate
(
String
.
valueOf
(
result
.
getStartMillis
())));
logger
.
info
(
"current Thread:"
+
Thread
.
currentThread
().
getId
());
}
public
void
onTestSuccess
(
ITestResult
result
)
{
// TODO Auto-generated method stub
logger
.
info
(
"end time:"
+
stampToDate
(
String
.
valueOf
(
result
.
getEndMillis
())));
}
public
void
onTestFailure
(
ITestResult
result
)
{
// TODO Auto-generated method stub
logger
.
info
(
"end time:"
+
stampToDate
(
String
.
valueOf
(
result
.
getEndMillis
())));
}
public
void
onTestSkipped
(
ITestResult
result
)
{
...
...
@@ -86,4 +95,16 @@ public class TestListener implements ITestListener {
}
}
/*
* 将时间戳转换为时间
*/
public
static
String
stampToDate
(
String
s
){
String
res
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
long
lt
=
new
Long
(
s
);
Date
date
=
new
Date
(
lt
);
res
=
simpleDateFormat
.
format
(
date
);
return
res
;
}
}
\ No newline at end of file
src/test/java/http/service/Authorization.java
View file @
8b84cb59
...
...
@@ -91,7 +91,7 @@ public class Authorization {
dafuwengCookiesMap
.
put
(
uid
,
dafuwengCookies
);
i
--;
}
if
(
dafuwengCookies
==
null
||
i
==
0
){
if
(
(
dafuwengCookiesMap
.
get
(
uid
)==
null
||
dafuwengCookiesMap
.
get
(
uid
).
size
()==
0
)
){
logger
.
info
(
"dafuweng登陆app失败,cookies为null"
);
}
return
dafuwengCookiesMap
.
get
(
uid
);
...
...
src/test/java/ui/cases/mytest.java
0 → 100644
View file @
8b84cb59
package
ui
.
cases
;
/**
* Created by mabo on 2018/11/15
*/
import
org.testng.Assert
;
import
org.testng.ITestResult
;
import
org.testng.Reporter
;
import
org.testng.annotations.AfterMethod
;
import
org.testng.annotations.Test
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.font.FontRenderContext
;
import
java.awt.geom.Rectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.IOException
;
/**
* Created by mabo on 2018/11/15
*/
public
class
mytest
{
@Test
public
void
careInterfaceSmoke
(){
Assert
.
assertEquals
(
1
,
2
);
}
@AfterMethod
(
alwaysRun
=
true
)
public
void
afterMethod
(
ITestResult
result
)
throws
Exception
{
if
(!
result
.
isSuccess
())
catchExceptions
(
result
);
}
public
void
catchExceptions
(
ITestResult
result
)
{
System
.
out
.
println
(
"result"
+
result
);
String
methodName
=
result
.
getName
();
System
.
out
.
println
(
methodName
);
if
(!
result
.
isSuccess
())
{
File
file
=
new
File
(
""
);
Reporter
.
setCurrentTestResult
(
result
);
System
.
out
.
println
(
file
.
getAbsolutePath
());
Reporter
.
log
(
file
.
getAbsolutePath
());
String
filePath
=
file
.
getAbsolutePath
();
filePath
=
filePath
.
replace
(
"/opt/apache-tomcat-7.0.64/webapps"
,
"http://172.18.44.114:8080"
);
Reporter
.
log
(
"<img src='"
+
filePath
+
"/"
+
result
.
getName
()
+
".jpg' hight='100' width='100'/>"
);
int
width
=
100
;
int
height
=
100
;
String
s
=
"这是一张测试图片"
;
File
screenShotFile
=
new
File
(
file
.
getAbsolutePath
()
+
"/"
+
result
.
getName
()
+
".jpg"
);
Font
font
=
new
Font
(
"Serif"
,
Font
.
BOLD
,
10
);
BufferedImage
bi
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics2D
g2
=
(
Graphics2D
)
bi
.
getGraphics
();
g2
.
setBackground
(
Color
.
BLACK
);
g2
.
clearRect
(
0
,
0
,
width
,
height
);
g2
.
setPaint
(
Color
.
RED
);
FontRenderContext
context
=
g2
.
getFontRenderContext
();
Rectangle2D
bounds
=
font
.
getStringBounds
(
s
,
context
);
double
x
=
(
width
-
bounds
.
getWidth
())
/
2
;
double
y
=
(
height
-
bounds
.
getHeight
())
/
2
;
double
ascent
=
-
bounds
.
getY
();
double
baseY
=
y
+
ascent
;
g2
.
drawString
(
s
,
(
int
)
x
,
(
int
)
baseY
);
try
{
ImageIO
.
write
(
bi
,
"jpg"
,
screenShotFile
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/test/java/ui/cases/test.java
View file @
8b84cb59
package
ui
.
cases
;
import
base.DuibaLog
;
import
com.codeborne.selenide.WebDriverRunner
;
import
com.codeborne.selenide.testng.ScreenShooter
;
import
org.apache.commons.io.FileUtils
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.OutputType
;
import
org.openqa.selenium.TakesScreenshot
;
import
org.openqa.selenium.WebDriver
;
import
org.testng.Assert
;
import
org.testng.ITestResult
;
import
org.testng.Reporter
;
import
org.testng.annotations.AfterMethod
;
import
org.testng.annotations.Listeners
;
import
org.testng.annotations.Test
;
import
ui.common.ProxyFactory
;
import
ui.common.StatusCheckor
;
import
ui.common.WebDriverFactory
;
import
ui.common.WebDriverType
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Calendar
;
import
java.util.Date
;
import
static
com
.
codeborne
.
selenide
.
Condition
.
text
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
$
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
open
;
/**
* Created by mabo on 2018/10/18
*/
//@Listeners({ ScreenShooter.class})
public
class
test
{
// StatusCheckor checkor=new StatusCheckor();
WebDriver
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
CHRMOE
,
ProxyFactory
.
createProxy
());
@Test
public
void
中文
()
throws
IOException
{
ScreenShooter
.
captureSuccessfulTests
=
true
;
//StatusCheckor checkor=new StatusCheckor();
// ProxyFactory.addCheckor(checkor);
WebDriverRunner
.
setWebDriver
(
driver
);
open
(
"https://www.baidu.com"
);
$
(
By
.
id
(
"kw"
)).
setValue
(
"selenium"
);
Assert
.
assertEquals
(
1
,
2
);
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); //转换时间格式
// String time = dateFormat.format(Calendar.getInstance().getTime()); //获取当前时间
}
@Test
public
void
test1
(){
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
}
@Test
public
void
test2
(){
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Assert
.
assertEquals
(
1
,
2
);
}
@AfterMethod
(
alwaysRun
=
true
)
public
void
afterMethod
(
ITestResult
result
)
throws
Exception
{
if
(!
result
.
isSuccess
())
catchExceptions
(
result
);
}
public
void
catchExceptions
(
ITestResult
result
)
throws
IOException
{
File
file
=
new
File
(
"C:/image"
);
Reporter
.
setCurrentTestResult
(
result
);
Reporter
.
log
(
file
.
getAbsolutePath
());
String
time
=
String
.
valueOf
(
System
.
currentTimeMillis
());
Reporter
.
log
(
"<img src='"
+
"http://172.16.80.106"
+
"/"
+
result
.
getName
()
+
"_"
+
time
+
".jpg' hight='600' width='600'/>"
);
File
srcFile
=
((
TakesScreenshot
)
driver
).
getScreenshotAs
(
OutputType
.
FILE
);
//执行屏幕截取
FileUtils
.
copyFile
(
srcFile
,
new
File
(
file
.
getAbsolutePath
()
+
"/"
+
result
.
getName
()
+
"_"
+
time
+
".jpg"
));
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
System
.
currentTimeMillis
());
System
.
out
.
println
(
Calendar
.
getInstance
().
getTimeInMillis
());
System
.
out
.
println
(
new
Date
().
getTime
());
}
}
src/test/java/ui/common/Checkor.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
import
base.DuibaLog
;
import
net.lightbody.bmp.util.HttpMessageContents
;
import
net.lightbody.bmp.util.HttpMessageInfo
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by mabo on 2018/11/13
*/
public
abstract
class
Checkor
{
DuibaLog
logger
=
DuibaLog
.
getLogger
();
String
name
;
List
<
String
>
failList
=
new
ArrayList
<>();
public
List
<
String
>
getFailList
(){
List
<
String
>
result
;
result
=
new
ArrayList
<>(
this
.
failList
);
this
.
failList
.
clear
();
// logger.info(failList.toString());
return
result
;
}
public
abstract
void
check
(
io
.
netty
.
handler
.
codec
.
http
.
HttpResponse
httpResponse
,
HttpMessageContents
httpMessageContents
,
HttpMessageInfo
httpMessageInfo
);
@Override
public
int
hashCode
(){
System
.
out
.
println
(
this
.
getClass
().
getName
());
System
.
out
.
println
(
this
.
getClass
().
getName
().
hashCode
());
return
this
.
getClass
().
getName
().
hashCode
();
}
public
boolean
equals
(
Object
object
){
return
this
.
hashCode
()==
object
.
hashCode
();
}
}
src/test/java/ui/common/LimitQueue.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.Queue
;
/**
* Created by mabo on 2018/11/13
*/
public
class
LimitQueue
<
E
>
implements
Queue
<
E
>
{
/**
* 队列长度,实例化类的时候指定
*/
private
int
limit
;
Queue
<
E
>
queue
=
new
LinkedList
<
E
>();
public
LimitQueue
(
int
limit
){
this
.
limit
=
limit
;
}
/**
* 入队
*/
@Override
public
boolean
offer
(
E
e
){
if
(
queue
.
size
()
>=
limit
){
//如果超出长度,入队时,先出队
queue
.
poll
();
}
return
queue
.
offer
(
e
);
}
/**
* 出队
*/
@Override
public
E
poll
()
{
return
queue
.
poll
();
}
/**
* 获取队列
*
* @return
*/
public
Queue
<
E
>
getQueue
(){
return
queue
;
}
/**
* 获取限制大小
*/
public
int
getLimit
(){
return
limit
;
}
@Override
public
boolean
add
(
E
e
)
{
return
queue
.
add
(
e
);
}
@Override
public
E
element
()
{
return
queue
.
element
();
}
@Override
public
E
peek
()
{
return
queue
.
peek
();
}
@Override
public
boolean
isEmpty
()
{
return
queue
.
size
()
==
0
?
true
:
false
;
}
@Override
public
int
size
()
{
return
queue
.
size
();
}
@Override
public
E
remove
()
{
return
queue
.
remove
();
}
@Override
public
boolean
addAll
(
Collection
<?
extends
E
>
c
)
{
return
queue
.
addAll
(
c
);
}
@Override
public
void
clear
()
{
queue
.
clear
();
}
@Override
public
boolean
contains
(
Object
o
)
{
return
queue
.
contains
(
o
);
}
@Override
public
boolean
containsAll
(
Collection
<?>
c
)
{
return
queue
.
containsAll
(
c
);
}
@Override
public
Iterator
<
E
>
iterator
()
{
return
queue
.
iterator
();
}
@Override
public
boolean
remove
(
Object
o
)
{
return
queue
.
remove
(
o
);
}
@Override
public
boolean
removeAll
(
Collection
<?>
c
)
{
return
queue
.
removeAll
(
c
);
}
@Override
public
boolean
retainAll
(
Collection
<?>
c
)
{
return
queue
.
retainAll
(
c
);
}
@Override
public
Object
[]
toArray
()
{
return
queue
.
toArray
();
}
@Override
public
<
T
>
T
[]
toArray
(
T
[]
a
)
{
return
queue
.
toArray
(
a
);
}
}
src/test/java/ui/common/ProxyFactory.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
import
io.netty.handler.codec.http.HttpRequest
;
import
net.lightbody.bmp.BrowserMobProxy
;
import
net.lightbody.bmp.BrowserMobProxyServer
;
import
net.lightbody.bmp.client.ClientUtil
;
import
net.lightbody.bmp.filters.RequestFilter
;
import
net.lightbody.bmp.filters.ResponseFilter
;
import
net.lightbody.bmp.util.HttpMessageContents
;
import
net.lightbody.bmp.util.HttpMessageInfo
;
import
org.openqa.selenium.Proxy
;
import
java.util.HashSet
;
import
java.util.Set
;
/**
* Created by mabo on 2018/11/13
*/
public
class
ProxyFactory
{
static
Proxy
seleniumProxy
;
static
Set
<
Checkor
>
checkorList
=
new
HashSet
<>();
public
static
void
addCheckor
(
Checkor
checkor
){
checkorList
.
add
(
checkor
);
}
public
static
Proxy
createProxy
(){
if
(
seleniumProxy
!=
null
)
return
seleniumProxy
;
BrowserMobProxy
proxy
=
new
BrowserMobProxyServer
();
RequestCheckor
requestCheckor
=
new
RequestCheckor
();
proxy
.
addRequestFilter
(
new
RequestFilter
()
{
@Override
public
io
.
netty
.
handler
.
codec
.
http
.
HttpResponse
filterRequest
(
HttpRequest
httpRequest
,
HttpMessageContents
httpMessageContents
,
HttpMessageInfo
httpMessageInfo
)
{
//System.out.println("请求:"+httpMessageInfo.getOriginalUrl());
requestCheckor
.
check
(
httpRequest
,
httpMessageContents
,
httpMessageInfo
);
//System.out.println("是否冗余:"+requestCheckor.isRedundant);
if
(
requestCheckor
.
isRedundant
){
System
.
out
.
println
(
requestCheckor
.
urlQueue
.
toArray
());
}
return
null
;
}
});
proxy
.
addResponseFilter
(
new
ResponseFilter
()
{
@Override
public
void
filterResponse
(
io
.
netty
.
handler
.
codec
.
http
.
HttpResponse
httpResponse
,
HttpMessageContents
httpMessageContents
,
HttpMessageInfo
httpMessageInfo
)
{
for
(
Checkor
checkor:
checkorList
){
checkor
.
check
(
httpResponse
,
httpMessageContents
,
httpMessageInfo
);
}
//System.out.println(i++);
}
});
proxy
.
start
();
// get the Selenium proxy object
seleniumProxy
=
ClientUtil
.
createSeleniumProxy
(
proxy
);
return
seleniumProxy
;
}
public
static
void
main
(
String
[]
args
){
addCheckor
(
new
StatusCheckor
());
addCheckor
(
new
StatusCheckor
());
System
.
out
.
println
(
checkorList
.
size
());
}
}
src/test/java/ui/common/RequestCheckor.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
import
io.netty.handler.codec.http.HttpRequest
;
import
net.lightbody.bmp.util.HttpMessageContents
;
import
net.lightbody.bmp.util.HttpMessageInfo
;
/**
* Created by mabo on 2018/11/13
*/
public
class
RequestCheckor
{
public
LimitQueue
<
String
>
urlQueue
=
new
LimitQueue
<>(
5
);
boolean
isRedundant
=
false
;
public
void
check
(
HttpRequest
httpRequest
,
HttpMessageContents
httpMessageContents
,
HttpMessageInfo
httpMessageInfo
){
String
url
=
httpMessageInfo
.
getOriginalUrl
();
if
(
urlQueue
.
contains
(
url
)){
System
.
out
.
println
(
"冗余:"
+
url
);
isRedundant
=
true
;
}
urlQueue
.
offer
(
url
);
}
public
boolean
isRedundant
(){
boolean
result
=
this
.
isRedundant
;
this
.
isRedundant
=
false
;
this
.
urlQueue
.
clear
();
return
result
;
}
}
src/test/java/ui/common/StatusCheckor.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
import
io.netty.handler.codec.http.HttpResponse
;
import
io.netty.handler.codec.http.HttpResponseStatus
;
import
net.lightbody.bmp.util.HttpMessageContents
;
import
net.lightbody.bmp.util.HttpMessageInfo
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
/**
* Created by mabo on 2018/11/13
*/
public
class
StatusCheckor
extends
Checkor
{
Logger
logger
=
LogManager
.
getLogger
(
StatusCheckor
.
class
);
@Override
public
void
check
(
HttpResponse
httpResponse
,
HttpMessageContents
httpMessageContents
,
HttpMessageInfo
httpMessageInfo
)
{
// logger.info(httpResponse.getStatus()+":"+httpMessageInfo.getOriginalUrl()+" - "+httpMessageContents.getContentType());
if
(!(
httpResponse
.
getStatus
().
equals
(
HttpResponseStatus
.
OK
))){
logger
.
info
(
httpMessageInfo
.
getOriginalUrl
()+
":"
+
httpResponse
.
getStatus
());
this
.
failList
.
add
(
httpMessageInfo
.
getOriginalUrl
());
}
}
}
src/test/java/ui/common/WebDriverFactory.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
import
org.openqa.selenium.Proxy
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.logging.LogType
;
import
org.openqa.selenium.logging.LoggingPreferences
;
import
org.openqa.selenium.remote.CapabilityType
;
import
org.openqa.selenium.remote.DesiredCapabilities
;
import
org.openqa.selenium.safari.SafariDriver
;
import
java.io.File
;
import
java.util.Properties
;
import
java.util.logging.Level
;
/**
* Created by mabo on 2018/11/13
*/
public
class
WebDriverFactory
{
public
static
WebDriver
createWebDriver
(
WebDriverType
driverType
){
Properties
prop
=
System
.
getProperties
();
String
OS
=
prop
.
getProperty
(
"os.name"
);
boolean
bl
=
OS
.
startsWith
(
"Mac"
);
String
basePath
=
WebDriverType
.
class
.
getClassLoader
().
getResource
(
""
).
getPath
();
WebDriver
browser
=
null
;
String
driverPath
=
null
;
switch
(
driverType
){
case
CHRMOE:
if
(
bl
){
driverPath
=
basePath
+
"chromedriver"
;
}
else
{
driverPath
=
basePath
+
"chromedriver.exe"
;
}
System
.
setProperty
(
"webdriver.chrome.driver"
,
driverPath
);
//add x
new
File
(
driverPath
).
setExecutable
(
true
);
browser
=
new
ChromeDriver
();
break
;
case
FIREFOX:
browser
=
new
FirefoxDriver
();
break
;
case
SAFARI:
browser
=
new
SafariDriver
();
break
;
default
:
browser
=
new
ChromeDriver
();
}
return
browser
;
}
public
static
WebDriver
createWebDriver
(
WebDriverType
driverType
,
Proxy
proxy
){
// configure it as a desired capability
DesiredCapabilities
capabilities
=
new
DesiredCapabilities
();
//capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
capabilities
.
setCapability
(
CapabilityType
.
PROXY
,
proxy
);
LoggingPreferences
logPrefs
=
new
LoggingPreferences
();
logPrefs
.
enable
(
LogType
.
BROWSER
,
Level
.
ALL
);
capabilities
.
setCapability
(
CapabilityType
.
LOGGING_PREFS
,
logPrefs
);
capabilities
.
setCapability
(
CapabilityType
.
SUPPORTS_APPLICATION_CACHE
,
false
);
capabilities
.
setCapability
(
CapabilityType
.
SUPPORTS_LOCATION_CONTEXT
,
false
);
capabilities
.
setCapability
(
CapabilityType
.
SUPPORTS_WEB_STORAGE
,
false
);
Properties
prop
=
System
.
getProperties
();
String
OS
=
prop
.
getProperty
(
"os.name"
);
boolean
bl
=
OS
.
startsWith
(
"Mac"
);
String
basePath
=
WebDriverType
.
class
.
getClassLoader
().
getResource
(
""
).
getPath
();
WebDriver
browser
=
null
;
String
driverPath
=
null
;
switch
(
driverType
){
case
CHRMOE:
if
(
bl
){
driverPath
=
basePath
+
"chromedriver"
;
}
else
{
driverPath
=
basePath
+
"chromedriver.exe"
;
}
System
.
setProperty
(
"webdriver.chrome.driver"
,
driverPath
);
//add x
new
File
(
driverPath
).
setExecutable
(
true
);
browser
=
new
ChromeDriver
(
capabilities
);
break
;
case
FIREFOX:
browser
=
new
FirefoxDriver
(
capabilities
);
break
;
case
SAFARI:
browser
=
new
SafariDriver
(
capabilities
);
break
;
default
:
browser
=
new
ChromeDriver
(
capabilities
);
}
return
browser
;
}
}
src/test/java/ui/common/WebDriverType.java
0 → 100644
View file @
8b84cb59
package
ui
.
common
;
/**
* Created by mabo on 2018/11/13
*/
public
enum
WebDriverType
{
CHRMOE
,
FIREFOX
,
SAFARI
;
}
src/test/resources/chromedriver
0 → 100755
View file @
8b84cb59
File added
src/test/resources/chromedriver.exe
0 → 100755
View file @
8b84cb59
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment