use of org.openqa.selenium.firefox.FirefoxProfile in project selenium-tests by Wikia.
the class FirefoxBrowser method setOptions.
@Override
public void setOptions() {
// to path where executive file of FF is placed
if ("WINDOWS 8".equalsIgnoreCase(System.getProperty("os.name"))) {
System.setProperty("webdriver.firefox.bin", "c:" + File.separator + "Program Files (x86)" + File.separator + "Mozilla Firefox" + File.separator + "Firefox.exe");
}
// Check if user who is running tests have write access in ~/.mozilla dir and home dir
if ("LINUX".equalsIgnoreCase(System.getProperty("os.name"))) {
File homePath = new File(System.getenv("HOME") + File.separator);
File mozillaPath = new File(homePath + File.separator + ".mozilla");
File tmpFile;
if (mozillaPath.exists()) {
try {
tmpFile = File.createTempFile("webdriver", null, mozillaPath);
} catch (IOException ex) {
PageObjectLogging.log("Can't create file", ex, false);
throw new WebDriverException("Can't create file in path: %s".replace("%s", mozillaPath.getAbsolutePath()));
}
} else {
try {
tmpFile = File.createTempFile("webdriver", null, homePath);
} catch (IOException ex) {
PageObjectLogging.log("Can't create file", ex, false);
throw new WebDriverException("Can't create file in path: %s".replace("%s", homePath.getAbsolutePath()));
}
}
tmpFile.delete();
}
firefoxProfile = new FirefoxProfile(new File(ClassLoader.getSystemResource("FirefoxProfiles/Default").getPath()));
if ("true".equals(Configuration.getPageLoadStrategy())) {
firefoxProfile.setPreference("webdriver.load.strategy", "unstable");
}
if ("true".equals(Configuration.getDisableFlash())) {
firefoxProfile.setPreference("plugin.state.flash", 0);
}
}
use of org.openqa.selenium.firefox.FirefoxProfile in project simba-os by cegeka.
the class Browser method open.
public static void open() {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.no_proxies_on", "localhost");
profile.setPreference("intl.accept_languages", "en");
browser = new FirefoxDriver(profile);
browser.manage().timeouts().implicitlyWait(TIME_OUT_IN_SECONDS, TimeUnit.SECONDS);
}
use of org.openqa.selenium.firefox.FirefoxProfile in project iTest by e-government-ua.
the class SetupAndTeardown method SetUp.
@BeforeMethod(alwaysRun = true)
public void SetUp() throws IOException {
// driver = new FirefoxDriver(profileFF);
if (null == driver) {
/**
* ******* Для локального тестирования установить switch ("chrome")
* для jenkins switch ("firefox") **********
*/
switch("firefox") {
case "firefox":
/**
* ******* Закоментить для для запуска на своем профиле и
* откоментить для запуска на дефолтном **********
*/
//Save the path of the XPI files as per your saved location
String cryptopluginPath = "src/test/resources/files/cryptoplugin_ext_id@privatbank.ua.xpi";
File cryptoplugin = new File(cryptopluginPath);
FirefoxProfile profile = new FirefoxProfile();
// profile.addExtension(cryptoplugin);
profile.setEnableNativeEvents(true);
profile.setAcceptUntrustedCertificates(true);
// profile.addExtension(cryptoplugin);
/**
* ******* Раскомментить для запуска на своем профиле и
* закоментить для дефолтного **********
*/
// ProfilesIni allProfiles = new ProfilesIni();
// FirefoxProfile profile = allProfiles.getProfile("default");
profile.setPreference("extensions.cryptoplugin_ext_id@privatbank.currentVersion", "9.9.9");
profile.setEnableNativeEvents(true);
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
profile.setPreference("javascript.enabled", true);
profile.setPreference("geo.enabled", false);
profile.setPreference("extensions.cryptoplugin_ext_id@privatbank.ua.currentVersion", "999.999.999");
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("unexpectedAlertBehaviour", "ignore");
System.out.println("Tests will be run (or rerun) in Firefox with custom profile...");
driver = WebDriverFactory.getDriver(capabilities);
/**
* ******* Для локального тестирования **********
*/
// case "chrome":
// System.setProperty("webdriver.chrome.driver", "src\\test\\resources\\files\\chromedriver.exe");
// capabilities = DesiredCapabilities.chrome();
// options = new ChromeOptions();
// System.out.println("Tests will be run (or rerun) in Chrome with custom profile...");
// break;
// default:
this.driver = new FirefoxDriver();
System.out.println("Tests will be run (or rerun) in Firefox...");
break;
}
driver = WebDriverFactory.getDriver(capabilities);
this.driver.manage().timeouts().implicitlyWait(CV.implicitTimeWait, TimeUnit.SECONDS);
this.driver.manage().window().maximize();
this.driver.manage().deleteAllCookies();
}
}
use of org.openqa.selenium.firefox.FirefoxProfile in project nutch by apache.
the class HttpWebClient method getDriverForPage.
public static WebDriver getDriverForPage(String url, Configuration conf) {
WebDriver driver = null;
DesiredCapabilities capabilities = null;
long pageLoadWait = conf.getLong("page.load.delay", 3);
try {
String driverType = conf.get("selenium.driver", "firefox");
switch(driverType) {
case "firefox":
String allowedHost = conf.get("selenium.firefox.allowed.hosts", "localhost");
long firefoxBinaryTimeout = conf.getLong("selenium.firefox.binary.timeout", 45);
boolean enableFlashPlayer = conf.getBoolean("selenium.firefox.enable.flash", false);
int loadImage = conf.getInt("selenium.firefox.load.image", 1);
int loadStylesheet = conf.getInt("selenium.firefox.load.stylesheet", 1);
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary();
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost);
profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer);
profile.setPreference("permissions.default.stylesheet", loadStylesheet);
profile.setPreference("permissions.default.image", loadImage);
binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout));
driver = new FirefoxDriver(binary, profile);
break;
case "chrome":
driver = new ChromeDriver();
break;
case "safari":
driver = new SafariDriver();
break;
case "opera":
driver = new OperaDriver();
break;
case "phantomjs":
driver = new PhantomJSDriver();
break;
case "remote":
String seleniumHubHost = conf.get("selenium.hub.host", "localhost");
int seleniumHubPort = Integer.parseInt(conf.get("selenium.hub.port", "4444"));
String seleniumHubPath = conf.get("selenium.hub.path", "/wd/hub");
String seleniumHubProtocol = conf.get("selenium.hub.protocol", "http");
String seleniumGridDriver = conf.get("selenium.grid.driver", "firefox");
String seleniumGridBinary = conf.get("selenium.grid.binary");
switch(seleniumGridDriver) {
case "firefox":
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("firefox_binary", seleniumGridBinary);
System.setProperty("webdriver.reap_profile", "false");
driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities);
break;
case "phantomjs":
capabilities = DesiredCapabilities.phantomjs();
capabilities.setBrowserName("phantomjs");
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, seleniumGridBinary);
driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities);
break;
default:
LOG.error("The Selenium Grid WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), DesiredCapabilities.firefox());
break;
}
break;
default:
LOG.error("The Selenium WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
driver = new FirefoxDriver();
break;
}
LOG.debug("Selenium {} WebDriver selected.", driverType);
driver.manage().timeouts().pageLoadTimeout(pageLoadWait, TimeUnit.SECONDS);
driver.get(url);
} catch (Exception e) {
if (e instanceof TimeoutException) {
LOG.debug("Selenium WebDriver: Timeout Exception: Capturing whatever loaded so far...");
return driver;
}
cleanUpDriver(driver);
throw new RuntimeException(e);
}
return driver;
}
use of org.openqa.selenium.firefox.FirefoxProfile in project SneakerBot by Penor.
the class Adidas method splash.
@SuppressWarnings("deprecation")
public void splash() {
try {
WebDriverWait wait = new WebDriverWait(driver, 60L);
print("Loading webpage: " + url);
driver.get(url);
wait.until(new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver d) {
// + String.valueOf(((JavascriptExecutor) d).executeScript("return document.readyState")));
return String.valueOf(((JavascriptExecutor) d).executeScript("return document.readyState")).equals("complete");
}
});
// TODO: Get to splash page.
boolean displayed = wait.until(x -> x.findElement(By.className("sk-fading-circle"))).isDisplayed();
if (displayed) {
print(proxy != null ? ("[" + proxy.getPassword() + ":" + proxy.getPort() + "] -> ") : "" + "waiting at splash page!");
while (driver.findElements(By.className("g-recaptcha")).size() == 0) Thread.sleep(5000L);
print(proxy != null ? ("[" + proxy.getPassword() + ":" + proxy.getPort() + "] -> ") : "" + "passed splash page!");
driver.manage().getCookies().stream().forEach(c -> {
if (c.getValue().contains("hmac")) {
hmac = c.getValue();
hmacExpiration = c.getExpiry();
}
});
if (driver.findElements(By.className("g-recaptcha")).size() > 0)
siteKey = driver.findElement(By.className("g-recaptcha")).getAttribute("data-sitekey");
if (driver.findElements(By.id("flashproductform")).size() > 0)
clientId = driver.findElement(By.id("flashproductform")).getAttribute("action").split("clientId=")[1];
Date timeLeft = new Date(hmacExpiration.getTime() - System.currentTimeMillis());
print("[Success] -> SiteKey: " + siteKey + " Client ID: " + clientId + " HMAC: " + hmac + " Time Left: " + timeLeft.getMinutes() + "m" + timeLeft.getSeconds() + "s");
} else
print("Error, Element displayed: " + displayed);
if (manual) {
FirefoxProfile profile = new FirefoxProfile();
if (proxy != null) {
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", proxy.getAddress());
profile.setPreference("network.proxy.http_port", proxy.getPort());
profile.setPreference("network.proxy.ssl", proxy.getAddress());
profile.setPreference("network.proxy.ssl_port", proxy.getPort());
}
// profile.setPreference("general.useragent.override", driver.set);
WebDriver checkout = new FirefoxDriver(profile);
for (Cookie cookie : driver.manage().getCookies()) checkout.manage().addCookie(cookie);
checkout.get(driver.getCurrentUrl());
} else
while (!carted && hmacExpiration.getTime() > System.currentTimeMillis()) atc();
} catch (Exception e) {
String name = e.getClass().getName();
print("[Exception] -> " + name);
carted = true;
if (name.equals("org.openqa.selenium.TimeoutException"))
carted = false;
} finally {
print(carted ? "Closing driver, and ending" : "Failed, Retrying...");
if (carted) {
driver.quit();
Thread.currentThread().interrupt();
}
}
}
Aggregations