Commit 7aaccd29 authored by 马博's avatar 马博

test

parent f2b9790a
......@@ -2,10 +2,7 @@ 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.*;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.ITestResult;
import org.testng.Reporter;
......@@ -28,6 +25,9 @@ public class DuibaBaseUi extends DuibaBase{
public ITestResult result;
public void open(String url){
driver.get(url);
}
public void switchChrome(){
WebDriverRunner.closeWebDriver();
driver= WebDriverFactory.createWebDriver(WebDriverType.CHRMOE, ProxyFactory.createProxy());
......@@ -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{
}
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{
String xpath = "//*[@class='"+name+"']";
......@@ -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
* @param byclass
......@@ -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)");
}
}
......@@ -3,7 +3,6 @@ package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.sun.javafx.scene.control.skin.TableColumnHeader;
import http.service.Activity.ActivityPlugin;
import http.service.Authorization;
import http.service.Manager.PluginService;
......
......@@ -69,6 +69,70 @@ public class WebDriverFactory {
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();
String OS = prop.getProperty("os.name");
boolean bl=OS.startsWith("Mac");
......
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