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
7aaccd29
Commit
7aaccd29
authored
Apr 25, 2019
by
马博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
f2b9790a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
289 additions
and
5 deletions
+289
-5
DuibaBaseUi.java
src/test/java/base/DuibaBaseUi.java
+225
-4
插件场景测试_pluginTest.java
...java/http/cases/PluginActivityTest/插件场景测试_pluginTest.java
+0
-1
WebDriverFactory.java
src/test/java/ui/common/WebDriverFactory.java
+64
-0
No files found.
src/test/java/base/DuibaBaseUi.java
View file @
7aaccd29
...
@@ -2,10 +2,7 @@ package base;
...
@@ -2,10 +2,7 @@ package base;
import
com.codeborne.selenide.WebDriverRunner
;
import
com.codeborne.selenide.WebDriverRunner
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.*
;
import
org.openqa.selenium.OutputType
;
import
org.openqa.selenium.TakesScreenshot
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.remote.RemoteWebDriver
;
import
org.openqa.selenium.remote.RemoteWebDriver
;
import
org.testng.ITestResult
;
import
org.testng.ITestResult
;
import
org.testng.Reporter
;
import
org.testng.Reporter
;
...
@@ -28,6 +25,9 @@ public class DuibaBaseUi extends DuibaBase{
...
@@ -28,6 +25,9 @@ public class DuibaBaseUi extends DuibaBase{
public
ITestResult
result
;
public
ITestResult
result
;
public
void
open
(
String
url
){
driver
.
get
(
url
);
}
public
void
switchChrome
(){
public
void
switchChrome
(){
WebDriverRunner
.
closeWebDriver
();
WebDriverRunner
.
closeWebDriver
();
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
CHRMOE
,
ProxyFactory
.
createProxy
());
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
CHRMOE
,
ProxyFactory
.
createProxy
());
...
@@ -132,6 +132,72 @@ public class DuibaBaseUi extends DuibaBase{
...
@@ -132,6 +132,72 @@ public class DuibaBaseUi extends DuibaBase{
}
}
}
/**
* 点击通过text(),包含
* @param name
* @throws Exception
*/
public
final
void
clickByTextContains
(
String
name
)
throws
Exception
{
String
xpath
=
"//*[contains(text(),'"
+
name
+
"')]"
;
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementByXPath
(
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
clickByTextContains
(
String
name
,
int
index
)
throws
Exception
{
String
xpath
=
"//*[contains(text(),'"
+
name
+
"')]"
;
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementsByXPath
(
xpath
).
get
(
index
).
click
();
logger
.
info
(
"ByXpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
public
final
void
clickByTextEqual
(
String
name
,
int
index
)
throws
Exception
{
String
xpath
=
"//*[text()='"
+
name
+
"']"
;
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementsByXPath
(
xpath
).
get
(
index
).
click
();
logger
.
info
(
"ByXpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
}
/**
/**
...
@@ -158,6 +224,73 @@ public class DuibaBaseUi extends DuibaBase{
...
@@ -158,6 +224,73 @@ public class DuibaBaseUi extends DuibaBase{
}
}
public
final
void
clickByXpath
(
String
xpath
)
throws
Exception
{
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
){
logger
.
info
(
"xpath:"
+
xpath
+
" click失败"
);
throw
e
;
}
}
}
}
public
final
void
clickByXpath
(
String
xpath
,
int
index
)
throws
Exception
{
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementsByXPath
(
xpath
).
get
(
index
).
click
();
logger
.
info
(
"xpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
){
logger
.
info
(
"xpath:"
+
xpath
+
" click失败"
);
throw
e
;
}
}
}
}
/**
* 点击通过text(),等于
* @param name
* @throws Exception
*/
public
final
void
clickByClass
(
String
name
,
int
index
)
throws
Exception
{
String
xpath
=
"//*[@class='"
+
name
+
"']"
;
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementsByXPath
(
xpath
).
get
(
index
).
click
();
logger
.
info
(
"xpath:"
+
xpath
+
" click"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
public
final
void
clickByClassNoWait
(
String
name
)
throws
Exception
{
public
final
void
clickByClassNoWait
(
String
name
)
throws
Exception
{
String
xpath
=
"//*[@class='"
+
name
+
"']"
;
String
xpath
=
"//*[@class='"
+
name
+
"']"
;
...
@@ -245,6 +378,17 @@ public class DuibaBaseUi extends DuibaBase{
...
@@ -245,6 +378,17 @@ public class DuibaBaseUi extends DuibaBase{
}
}
/**
* 校验元素,通过text
* @param text
* @return
*/
public
boolean
isExistContainsText
(
String
text
){
String
xpath
=
"//*[contains(text(),'"
+
text
+
"')]"
;
return
ElementExist
(
xpath
);
}
/**
/**
* 校验元素,通过class
* 校验元素,通过class
* @param byclass
* @param byclass
...
@@ -264,4 +408,81 @@ public class DuibaBaseUi extends DuibaBase{
...
@@ -264,4 +408,81 @@ public class DuibaBaseUi extends DuibaBase{
}
}
public
void
inputByContainsAttribut
(
String
atttibut
,
String
name
,
String
tag
,
String
input
)
throws
Exception
{
String
xpath
=
"//"
+
tag
+
"[contains(@"
+
atttibut
+
",'"
+
name
+
"')]"
;
int
i
=
3
;
while
(
i
>
0
){
try
{
System
.
out
.
println
(
i
);
driver
.
findElementByXPath
(
xpath
).
sendKeys
(
input
);
logger
.
info
(
"ByXpath:"
+
xpath
+
" input"
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
)
throw
e
;
}
}
}
public
final
void
inputByXpath
(
String
xpath
,
String
text
)
throws
Exception
{
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementByXPath
(
xpath
).
clear
();
driver
.
findElementByXPath
(
xpath
).
sendKeys
(
text
);
logger
.
info
(
"xpath:"
+
xpath
+
" send"
+
text
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
){
logger
.
info
(
"xpath:"
+
xpath
+
" send失败"
);
throw
e
;
}
}
}
}
public
final
void
inputByXpath
(
String
xpath
,
String
text
,
int
index
)
throws
Exception
{
int
i
=
5
;
while
(
i
>
0
){
try
{
driver
.
findElementsByXPath
(
xpath
).
get
(
index
).
clear
();
driver
.
findElementsByXPath
(
xpath
).
get
(
index
).
sendKeys
(
text
);
logger
.
info
(
"xpath:"
+
xpath
+
" send:"
+
text
);
return
;
}
catch
(
Exception
e
)
{
// TODO: handle exception
sleep
(
1
);
i
--;
if
(
i
==
0
){
logger
.
info
(
"xpath:"
+
xpath
+
" send失败"
);
throw
e
;
}
}
}
}
public
void
scrollToTop
(){
((
JavascriptExecutor
)
driver
).
executeScript
(
"window.scrollTo(document.body.scrollHeight,0)"
);
}
public
void
scrollToDown
(){
((
JavascriptExecutor
)
driver
).
executeScript
(
"window.scrollTo(0,document.body.scrollHeight)"
);
}
}
}
src/test/java/http/cases/PluginActivityTest/插件场景测试_pluginTest.java
View file @
7aaccd29
...
@@ -3,7 +3,6 @@ package http.cases.PluginActivityTest;
...
@@ -3,7 +3,6 @@ package http.cases.PluginActivityTest;
import
base.DuibaLog
;
import
base.DuibaLog
;
import
base.DuibaTestBase
;
import
base.DuibaTestBase
;
import
com.sun.javafx.scene.control.skin.TableColumnHeader
;
import
http.service.Activity.ActivityPlugin
;
import
http.service.Activity.ActivityPlugin
;
import
http.service.Authorization
;
import
http.service.Authorization
;
import
http.service.Manager.PluginService
;
import
http.service.Manager.PluginService
;
...
...
src/test/java/ui/common/WebDriverFactory.java
View file @
7aaccd29
...
@@ -69,6 +69,70 @@ public class WebDriverFactory {
...
@@ -69,6 +69,70 @@ public class WebDriverFactory {
chromeOptions
.
addArguments
(
"--args --disable-web-security --user-data-dir"
);
chromeOptions
.
addArguments
(
"--args --disable-web-security --user-data-dir"
);
Properties
prop
=
System
.
getProperties
();
String
OS
=
prop
.
getProperty
(
"os.name"
);
boolean
bl
=
OS
.
startsWith
(
"Mac"
);
String
basePath
=
WebDriverType
.
class
.
getClassLoader
().
getResource
(
""
).
getPath
();
basePath
=
basePath
.
replaceAll
(
"%20"
,
" "
);
//repaceAll("%20",'');
File
directory
=
new
File
(
""
);
System
.
out
.
println
(
"-----路径:"
+
directory
.
getAbsolutePath
());
RemoteWebDriver
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
MOBLIE:
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
(
chromeOptions
);
break
;
case
FIREFOX:
browser
=
new
FirefoxDriver
(
capabilities
);
break
;
case
SAFARI:
browser
=
new
SafariDriver
(
capabilities
);
break
;
default
:
browser
=
new
ChromeDriver
(
capabilities
);
}
return
browser
;
}
public
static
RemoteWebDriver
createRemoteWebDriver
(
WebDriverType
driverType
){
DesiredCapabilities
capabilities
=
new
DesiredCapabilities
();
// 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
);
final
ChromeOptions
chromeOptions
=
new
ChromeOptions
();
Map
<
String
,
String
>
mobileEmulation
=
new
HashMap
<
String
,
String
>();
mobileEmulation
.
put
(
"deviceName"
,
"Nexus 5"
);
chromeOptions
.
setExperimentalOption
(
"mobileEmulation"
,
mobileEmulation
);
chromeOptions
.
addArguments
(
"--args --disable-web-security --user-data-dir"
);
Properties
prop
=
System
.
getProperties
();
Properties
prop
=
System
.
getProperties
();
String
OS
=
prop
.
getProperty
(
"os.name"
);
String
OS
=
prop
.
getProperty
(
"os.name"
);
boolean
bl
=
OS
.
startsWith
(
"Mac"
);
boolean
bl
=
OS
.
startsWith
(
"Mac"
);
...
...
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