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
b4ddcda5
Commit
b4ddcda5
authored
Nov 22, 2018
by
马博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8fb108e1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
31 deletions
+54
-31
test.java
src/test/java/ui/cases/test.java
+30
-25
WebDriverFactory.java
src/test/java/ui/common/WebDriverFactory.java
+23
-5
WebDriverType.java
src/test/java/ui/common/WebDriverType.java
+1
-1
No files found.
src/test/java/ui/cases/test.java
View file @
b4ddcda5
package
ui
.
cases
;
import
base.DuibaBaseUi
;
import
base.DuibaLog
;
import
com.codeborne.selenide.WebDriverRunner
;
import
com.codeborne.selenide.testng.ScreenShooter
;
...
...
@@ -32,9 +33,9 @@ import static com.codeborne.selenide.Selenide.open;
* Created by mabo on 2018/10/18
*/
//@Listeners({ ScreenShooter.class})
public
class
test
{
public
class
test
extends
DuibaBaseUi
{
// StatusCheckor checkor=new StatusCheckor();
WebDriver
driver
=
WebDriverFactory
.
createWebDriver
(
WebDriverType
.
CHRMOE
,
ProxyFactory
.
createProxy
());
//
WebDriver driver= WebDriverFactory.createWebDriver(WebDriverType.CHRMOE, ProxyFactory.createProxy());
@Test
...
...
@@ -42,10 +43,14 @@ public class test {
ScreenShooter
.
captureSuccessfulTests
=
true
;
//StatusCheckor checkor=new StatusCheckor();
// ProxyFactory.addCheckor(checkor);
WebDriverRunner
.
setWebDriver
(
driver
);
//
WebDriverRunner.setWebDriver(driver);
open
(
"https://www.baidu.com"
);
Reporter
.
log
(
"----------------------"
);
screenshot
();
Reporter
.
log
(
"----------------------"
);
$
(
By
.
id
(
"kw"
)).
setValue
(
"selenium"
);
Assert
.
assertEquals
(
1
,
2
);
...
...
@@ -58,7 +63,7 @@ public class test {
}
@Test
public
void
test1
(){
Reporter
.
log
(
"rererfddfdfdfdfdfdf
"
);
open
(
"https://www.biying.com
"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
Reporter
.
log
(
"rererfddfdfdfdfdfdf"
);
...
...
@@ -79,25 +84,25 @@ public class test {
}
@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
());
}
//
@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/WebDriverFactory.java
View file @
b4ddcda5
...
...
@@ -3,14 +3,18 @@ package ui.common;
import
org.openqa.selenium.Proxy
;
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.logging.LogType
;
import
org.openqa.selenium.logging.LoggingPreferences
;
import
org.openqa.selenium.remote.CapabilityType
;
import
org.openqa.selenium.remote.DesiredCapabilities
;
import
org.openqa.selenium.remote.RemoteWebDriver
;
import
org.openqa.selenium.safari.SafariDriver
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.logging.Level
;
...
...
@@ -49,23 +53,25 @@ public class WebDriverFactory {
}
return
browser
;
}
public
static
WebDriver
createWebDriver
(
WebDriverType
driverType
,
Proxy
proxy
){
// configure it as a desired capability
public
static
RemoteWebDriver
createWebDriver
(
WebDriverType
driverType
,
Proxy
proxy
){
DesiredCapabilities
capabilities
=
new
DesiredCapabilities
();
//capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
capabilities
.
setCapability
(
CapabilityType
.
PROXY
,
proxy
);
// 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
);
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
;
Remote
WebDriver
browser
=
null
;
String
driverPath
=
null
;
switch
(
driverType
){
case
CHRMOE:
...
...
@@ -81,6 +87,18 @@ public class WebDriverFactory {
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
;
...
...
src/test/java/ui/common/WebDriverType.java
View file @
b4ddcda5
...
...
@@ -4,5 +4,5 @@ package ui.common;
* Created by mabo on 2018/11/13
*/
public
enum
WebDriverType
{
CHRMOE
,
FIREFOX
,
SAFARI
;
CHRMOE
,
FIREFOX
,
SAFARI
,
MOBLIE
;
}
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