package br.com.pixeon.util;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Webdriver {
private static WebDriver driver;
/**
* Retorna o driver utilizado no teste.
* @return Driver
*/
public static WebDriver obterInstancia() {
if (driver == null) {
System.out.println("-->> Driver == null");
}
return driver;
}
/**
* Fecha o driver utilizado no teste.
*/
public static void fecharInstancia() {
if (driver != null) {
driver.quit();
driver = null;
}
}
/**
*
* @param version
* @throws MalformedURLException
*/
public static void criarInstancia(String version)
throws MalformedURLException {
System.out.println("-->> Entrou na criacao da instancia.");
DesiredCapabilities caps = null;
if (version.equalsIgnoreCase("local")) {
System.out.println("-->> Criando nova instância do driver como local.");
driver = new FirefoxDriver();
}
if (version.equalsIgnoreCase("XPGC35")) {
System.out.println("-->> Criando nova instância do driver como XPGC35.");
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "XP");
caps.setCapability("version", "35");
}
if (!version.equalsIgnoreCase("local")) {
// Grid Amazon-Pixeon
// driver = new RemoteWebDriver(new
// URL("http://10.8.0.6:4444/wd/hub"), caps);
// Grid Local-Pixeon
driver = new RemoteWebDriver(new URL(
"http://10.10.1.121:4444/wd/hub"), caps);
}
driver.get(Util.URL);
driver.manage().window().maximize();
}
/**
*Cria a instância do driver de acordo com o parâmetro passado.
* @param version Código utilizado para criação do driver.
* @throws MalformedURLException
*/
public static void criarNovaInstancia(String version) throws MalformedURLException {
DesiredCapabilities caps = null;
switch (version) {
case "XPGC35":
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "XP");
caps.setCapability("version", "35");
break;
case "XPGC34":
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "XP");
caps.setCapability("version", "34");
break;
case "XPFF30":
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "XP");
caps.setCapability("version", "30");
break;
case "XPFF29":
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "XP");
caps.setCapability("version", "29");
break;
case "WIN7GC35":
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "VISTA");
caps.setCapability("version", "35");
break;
case "WIN7GC34":
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "VISTA");
caps.setCapability("version", "34");
break;
case "WIN7FF30":
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "VISTA");
caps.setCapability("version", "30");
break;
case "WIN7FF29":
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "VISTA");
caps.setCapability("version", "29");
break;
case "WIN7IE10":
caps = DesiredCapabilities.internetExplorer();
caps.setCapability("platform", "VISTA");
caps.setCapability("version", "10");
break;
case "WIN7IE11":
caps = DesiredCapabilities.internetExplorer();
caps.setCapability("platform", "VISTA");
caps.setCapability("version", "11");
break;
case "WIN8GC35":
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "WIN8");
caps.setCapability("version", "35");
break;
case "WIN8GC34":
caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "WIN8");
caps.setCapability("version", "34");
break;
case "WIN8FF30":
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "WIN8");
caps.setCapability("version", "30");
break;
case "WIN8FF29":
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "WIN8");
caps.setCapability("version", "29");
break;
case "WIN8IE11":
caps = DesiredCapabilities.internetExplorer();
caps.setCapability("platform", "WIN8");
caps.setCapability("version", "11");
break;
case "MACSF6":
caps = DesiredCapabilities.safari();
caps.setCapability("platform", "MAC");
caps.setCapability("version", "6");
break;
case "local":
driver = new FirefoxDriver();
break;
}
if(!version.equalsIgnoreCase("local")){
System.out.println("-->>> IP Selenium Server: " + Util.IP_SELENIUM_SERVER);
driver = new RemoteWebDriver(new URL("http://"+Util.IP_SELENIUM_SERVER+ ":4444/wd/hub"), caps);
}
driver.get(Util.URL);
driver.manage().window().maximize();
}
}