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
931c6f91
Commit
931c6f91
authored
Nov 22, 2018
by
马博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
b4ddcda5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
325 additions
and
0 deletions
+325
-0
DuibaBaseUi.java
src/test/java/base/DuibaBaseUi.java
+194
-0
优惠券_ExchangeTest_ui.java
src/test/java/ui/cases/Exchange/优惠券_ExchangeTest_ui.java
+33
-0
实物_ExchangeTest_ui.java
src/test/java/ui/cases/Exchange/实物_ExchangeTest_ui.java
+30
-0
支付宝_ExchangeTest_ui.java
src/test/java/ui/cases/Exchange/支付宝_ExchangeTest_ui.java
+30
-0
uitest.java
src/test/java/ui/cases/uitest.java
+38
-0
No files found.
src/test/java/base/DuibaBaseUi.java
0 → 100644
View file @
931c6f91
package
base
;
import
com.codeborne.selenide.WebDriverRunner
;
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.openqa.selenium.remote.RemoteWebDriver
;
import
org.testng.ITestResult
;
import
org.testng.Reporter
;
import
org.testng.annotations.*
;
import
ui.common.ProxyFactory
;
import
ui.common.WebDriverFactory
;
import
ui.common.WebDriverType
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Set
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
$
;
/**
* Created by mabo on 2018/11/20
*/
public
class
DuibaBaseUi
extends
DuibaBase
{
RemoteWebDriver
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
MOBLIE
,
ProxyFactory
.
createProxy
());
public
ITestResult
result
;
public
void
switchChrome
(){
WebDriverRunner
.
closeWebDriver
();
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
CHRMOE
,
ProxyFactory
.
createProxy
());
WebDriverRunner
.
setWebDriver
(
driver
);
}
public
void
switchMobile
(){
WebDriverRunner
.
closeWebDriver
();
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
MOBLIE
,
ProxyFactory
.
createProxy
());
WebDriverRunner
.
setWebDriver
(
driver
);
}
@BeforeClass
public
final
void
init
(){
WebDriverRunner
.
setWebDriver
(
driver
);
}
@BeforeMethod
(
alwaysRun
=
true
)
public
final
void
beforeMethodInit
(
ITestResult
result
)
throws
Exception
{
Reporter
.
setCurrentTestResult
(
result
);
this
.
result
=
result
;
}
@AfterMethod
(
alwaysRun
=
true
)
public
final
void
afterMethodScreenshot
()
throws
Exception
{
if
(!
result
.
isSuccess
())
screenshot
();
}
public
final
void
screenshot
()
throws
IOException
{
boolean
ev
=
Boolean
.
parseBoolean
(
System
.
getProperty
(
"ServiceDoctor"
));
String
path
=
null
;
String
url
=
null
;
if
(
ev
){
File
file
=
new
File
(
"C:/image"
);
path
=
file
.
getAbsolutePath
();
url
=
"http://172.16.80.106/"
;
}
else
{
File
file
=
new
File
(
" "
);
path
=
file
.
getAbsolutePath
();
url
=
file
.
getAbsolutePath
();
}
Reporter
.
setCurrentTestResult
(
result
);
// Reporter.log(file.getAbsolutePath());
String
time
=
String
.
valueOf
(
System
.
currentTimeMillis
());
Reporter
.
log
(
"<img src='"
+
url
+
result
.
getName
()
+
"_"
+
time
+
".jpg' hight='800' width='600' onclick=\"window.open('"
+
url
+
result
.
getName
()
+
"_"
+
time
+
".jpg"
+
"')\" />"
);
//"http://172.16.80.106"
File
srcFile
=
((
TakesScreenshot
)
driver
).
getScreenshotAs
(
OutputType
.
FILE
);
//执行屏幕截取
FileUtils
.
copyFile
(
srcFile
,
new
File
(
path
+
result
.
getName
()
+
"_"
+
time
+
".jpg"
));
}
@AfterClass
public
final
void
close
(){
WebDriverRunner
.
closeWebDriver
();
}
/**
* 等待
* @param time 秒
*/
public
final
void
sleep
(
int
time
){
try
{
Thread
.
sleep
(
time
*
1000
);
logger
.
info
(
"sleep:"
+
time
);
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
/**
* 点击通过text(),等于
* @param name
* @throws Exception
*/
public
final
void
clickByTextEqual
(
String
name
)
throws
Exception
{
String
xpath
=
"//*[text()='"
+
name
+
"']"
;
int
i
=
5
;
while
(
i
>
0
){
try
{
$
(
By
.
xpath
(
xpath
)).
click
();
logger
.
info
(
"ByXpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
/**
* 点击通过text(),等于
* @param name
* @throws Exception
*/
public
final
void
clickByClass
(
String
name
)
throws
Exception
{
String
xpath
=
"//*[@class='"
+
name
+
"']"
;
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementByXPath
(
xpath
).
click
();
logger
.
info
(
"xpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
/**
* 点击,通过属性,包含
* @param atttibut
* @param name
* @param tag
* @throws Exception
*/
public
void
clickByContainsAttribut
(
String
atttibut
,
String
name
,
String
tag
)
throws
Exception
{
String
xpath
=
"//"
+
tag
+
"[contains(@"
+
atttibut
+
",'"
+
name
+
"')]"
;
int
i
=
3
;
while
(
i
>
0
){
try
{
System
.
out
.
println
(
i
);
driver
.
findElementByXPath
(
xpath
).
click
();
logger
.
info
(
"ByXpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
/**
* 切换窗口
*/
public
void
switchWindow
(){
String
handle
=
null
;
Set
<
String
>
handles
=
driver
.
getWindowHandles
();
for
(
String
hand:
handles
)
handle
=
hand
;
driver
.
switchTo
().
window
(
handle
);
}
}
src/test/java/ui/cases/Exchange/优惠券_ExchangeTest_ui.java
0 → 100644
View file @
931c6f91
package
ui
.
cases
.
Exchange
;
import
base.DuibaBaseUi
;
import
org.openqa.selenium.By
;
import
org.testng.annotations.Test
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
$
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
open
;
/**
* Created by mabo on 2018/11/21
*/
public
class
优惠券
_ExchangeTest_ui
extends
DuibaBaseUi
{
@Test
public
void
优惠券兑换
_
正常流程
()
throws
Exception
{
open
(
"http://47.97.214.108/user/index"
);
clickByTextEqual
(
"4762"
);
switchWindow
();
sleep
(
2
);
clickByClass
(
"btn-close"
);
screenshot
();
clickByTextEqual
(
"ui自动化-优惠券"
);
screenshot
();
clickByTextEqual
(
"马上兑换"
);
screenshot
();
clickByTextEqual
(
"确定"
);
screenshot
();
sleep
(
5
);
screenshot
();
}
}
src/test/java/ui/cases/Exchange/实物_ExchangeTest_ui.java
0 → 100644
View file @
931c6f91
package
ui
.
cases
.
Exchange
;
import
base.DuibaBaseUi
;
import
org.testng.annotations.Test
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
open
;
/**
* Created by mabo on 2018/11/22
*/
public
class
实物
_ExchangeTest_ui
extends
DuibaBaseUi
{
@Test
public
void
实物兑换
_
正常流程
()
throws
Exception
{
open
(
"http://47.97.214.108/user/index"
);
clickByTextEqual
(
"4762"
);
switchWindow
();
sleep
(
2
);
clickByClass
(
"btn-close"
);
screenshot
();
clickByTextEqual
(
"ui自动化-实物"
);
screenshot
();
clickByTextEqual
(
"马上兑换"
);
screenshot
();
clickByTextEqual
(
"确定"
);
screenshot
();
sleep
(
5
);
screenshot
();
}
}
src/test/java/ui/cases/Exchange/支付宝_ExchangeTest_ui.java
0 → 100644
View file @
931c6f91
package
ui
.
cases
.
Exchange
;
import
base.DuibaBaseUi
;
import
org.testng.annotations.Test
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
open
;
/**
* Created by mabo on 2018/11/22
*/
public
class
支付宝
_ExchangeTest_ui
extends
DuibaBaseUi
{
@Test
public
void
支付宝
_
正常流程
()
throws
Exception
{
open
(
"http://47.97.214.108/user/index"
);
clickByTextEqual
(
"4762"
);
switchWindow
();
sleep
(
2
);
clickByClass
(
"btn-close"
);
screenshot
();
clickByTextEqual
(
"支付宝充值"
);
screenshot
();
clickByTextEqual
(
"马上兑换"
);
screenshot
();
clickByTextEqual
(
"确定"
);
screenshot
();
sleep
(
5
);
screenshot
();
}
}
src/test/java/ui/cases/uitest.java
0 → 100644
View file @
931c6f91
package
ui
.
cases
;
import
base.DuibaBaseUi
;
import
com.codeborne.selenide.testng.ScreenShooter
;
import
org.openqa.selenium.By
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
import
java.io.IOException
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
$
;
import
static
com
.
codeborne
.
selenide
.
Selenide
.
open
;
/**
* Created by mabo on 2018/11/21
*/
public
class
uitest
extends
DuibaBaseUi
{
@Test
public
void
中文
1
()
throws
IOException
{
ScreenShooter
.
captureSuccessfulTests
=
true
;
//StatusCheckor checkor=new StatusCheckor();
// ProxyFactory.addCheckor(checkor);
// WebDriverRunner.setWebDriver(driver);
open
(
"https://www.biying.com"
);
$
(
By
.
id
(
"kw"
)).
setValue
(
"selenium"
);
Assert
.
assertEquals
(
1
,
2
);
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); //转换时间格式
// String time = dateFormat.format(Calendar.getInstance().getTime()); //获取当前时间
}
}
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