Commit b4ddcda5 authored by 马博's avatar 马博

update

parent 8fb108e1
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());
// }
}
......@@ -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;
RemoteWebDriver 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;
......
......@@ -4,5 +4,5 @@ package ui.common;
* Created by mabo on 2018/11/13
*/
public enum WebDriverType {
CHRMOE,FIREFOX,SAFARI;
CHRMOE,FIREFOX,SAFARI,MOBLIE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment