package com.testET.util;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.safari.SafariDriver;
import com.opera.core.systems.OperaDriver;
/**
* @author liuxin
*
* Selenium 工具类
* */
public class ETUtils {
/********/
private static ETUtils model = new ETUtils();
private static WebDriver webDriver;
private static Navigation navigation;
private ETUtils(){}
public static ETUtils getInstance(){
return model;
}
/**
* 浏览器设定
* 实例化Selenium2对象
*
* @param Int browserString
* 1,谷歌
* 2,火狐
* 3,IE
* 4,Opera
* 5,Safari
* */
public void setBrowser(int browserInt,String driverPath){
//"C:/Program Files/Chrome WebDriver/chromedriver.exe"
switch(browserInt){
case 1:
System.setProperty("webdriver.chrome.driver",driverPath);
webDriver = new ChromeDriver();
break;
case 2:
System.setProperty("webdriver.firefox.driver",driverPath);
webDriver = new FirefoxDriver();
break;
case 3:
System.setProperty("webdriver.internetExplorer.driver",driverPath);
webDriver = new InternetExplorerDriver();
break;
case 4:
System.setProperty("webdriver.opera.driver",driverPath);
webDriver = new OperaDriver();
break;
case 5:
//对Safari的支持由于技术限制在本版本中未包含
System.setProperty("webdriver.safari.driver",driverPath);
webDriver = new SafariDriver();
break;
}
}
/**
* 地址导航
*
* @param String url
* */
public void UrlNav(String url){
navigation = webDriver.navigate();
navigation.to(url);
}
/**
* 地址导航
*
* @param URL url
* */
public void UrlNav(URL url){
navigation = webDriver.navigate();
navigation.to(url);
}
/**
* 事件处理函数
*
* @param xpath String
* @param case事件 int
*
* 1,按钮事件
* 2,输入事件
*
* */
public void handleClickEvent(String xpath){
WebElement webEle = webDriver.findElement(By.xpath(xpath));
webEle.click();
}
public void handleInputEvent(String xpath , String inputString){
WebElement webEle = webDriver.findElement(By.xpath(xpath));
webEle.clear();
webEle.sendKeys(inputString);
}
}
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.safari.SafariDriver;
import com.opera.core.systems.OperaDriver;
/**
* @author liuxin
*
* Selenium 工具类
* */
public class ETUtils {
/********/
private static ETUtils model = new ETUtils();
private static WebDriver webDriver;
private static Navigation navigation;
private ETUtils(){}
public static ETUtils getInstance(){
return model;
}
/**
* 浏览器设定
* 实例化Selenium2对象
*
* @param Int browserString
* 1,谷歌
* 2,火狐
* 3,IE
* 4,Opera
* 5,Safari
* */
public void setBrowser(int browserInt,String driverPath){
//"C:/Program Files/Chrome WebDriver/chromedriver.exe"
switch(browserInt){
case 1:
System.setProperty("webdriver.chrome.driver",driverPath);
webDriver = new ChromeDriver();
break;
case 2:
System.setProperty("webdriver.firefox.driver",driverPath);
webDriver = new FirefoxDriver();
break;
case 3:
System.setProperty("webdriver.internetExplorer.driver",driverPath);
webDriver = new InternetExplorerDriver();
break;
case 4:
System.setProperty("webdriver.opera.driver",driverPath);
webDriver = new OperaDriver();
break;
case 5:
//对Safari的支持由于技术限制在本版本中未包含
System.setProperty("webdriver.safari.driver",driverPath);
webDriver = new SafariDriver();
break;
}
}
/**
* 地址导航
*
* @param String url
* */
public void UrlNav(String url){
navigation = webDriver.navigate();
navigation.to(url);
}
/**
* 地址导航
*
* @param URL url
* */
public void UrlNav(URL url){
navigation = webDriver.navigate();
navigation.to(url);
}
/**
* 事件处理函数
*
* @param xpath String
* @param case事件 int
*
* 1,按钮事件
* 2,输入事件
*
* */
public void handleClickEvent(String xpath){
WebElement webEle = webDriver.findElement(By.xpath(xpath));
webEle.click();
}
public void handleInputEvent(String xpath , String inputString){
WebElement webEle = webDriver.findElement(By.xpath(xpath));
webEle.clear();
webEle.sendKeys(inputString);
}
}