use of org.openqa.selenium.firefox.FirefoxOptions in project selenium_java by sergueik.
the class WebRtcFirefoxTest method setupTest.
@Before
public void setupTest() {
FirefoxOptions options = new FirefoxOptions();
// This flag avoids granting the access to the camera
options.addPreference("media.navigator.permission.disabled", true);
// This flag force to use fake user media (synthetic video of multiple
// color)
options.addPreference("media.navigator.streams.fake", true);
driver = new FirefoxDriver(options);
}
use of org.openqa.selenium.firefox.FirefoxOptions in project selenium_java by sergueik.
the class HeadlessFirefoxSeleniumExample method main.
public static void main(String[] args) {
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "/home/sergueik/Downloads/geckodriver");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
try {
driver.get("http://www.google.com");
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
WebElement queryBox = driver.findElement(By.name("q"));
queryBox.sendKeys("headless firefox");
WebElement searchBtn = driver.findElement(By.name("btnK"));
searchBtn.click();
WebElement iresDiv = driver.findElement(By.id("ires"));
iresDiv.findElements(By.tagName("a")).get(0).click();
System.out.println(driver.getPageSource());
} finally {
driver.quit();
}
}
use of org.openqa.selenium.firefox.FirefoxOptions in project sonar-scanner-jenkins by SonarSource.
the class JenkinsOrchestrator method start.
public void start() {
if (started.getAndSet(true)) {
throw new IllegalStateException("Jenkins is already started");
}
int port = config.getInt("jenkins.container.port", 0);
if (port <= 0) {
port = NetworkUtils.getNextAvailablePort(NetworkUtils.getLocalhost());
}
distribution.setPort(port);
FileSystem fileSystem = config.fileSystem();
ServerInstaller serverInstaller = new ServerInstaller(fileSystem);
server = serverInstaller.install(distribution);
server.setUrl(String.format("http://localhost:%d", port));
jenkinsWrapper = new JenkinsWrapper(server, config, fileSystem.javaHome(), port);
jenkinsWrapper.start();
FirefoxProfile profile = new FirefoxProfile();
// force language to be English
profile.setPreference("intl.accept_languages", "en");
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get(server.getUrl());
// Fix window size for having reproducible test behavior
driver.manage().window().setPosition(new Point(20, 20));
driver.manage().window().setSize(new Dimension(1024, 768));
try {
cli = new CLI(new URL(server.getUrl()));
} catch (Exception e) {
throw new RuntimeException(e);
}
// Force updatecenter initialization
driver.get(server.getUrl() + "/pluginManager");
findElement(By.linkText("Advanced")).click();
findElement(buttonByText("Check now")).click();
}
use of org.openqa.selenium.firefox.FirefoxOptions in project structr by structr.
the class SeleniumTest method startDriver.
@Before
public void startDriver() {
switch(activeBrowser) {
case FIREFOX:
System.setProperty("webdriver.gecko.driver", getBrowserDriverLocation(activeBrowser));
final FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(true);
driver = new FirefoxDriver(firefoxOptions);
break;
case CHROME:
System.setProperty("webdriver.chrome.driver", getBrowserDriverLocation(activeBrowser));
System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
driver = new ChromeDriver(chromeOptions);
break;
case NONE:
// Don't create a driver in main thread, useful for parallel testing
break;
}
}
use of org.openqa.selenium.firefox.FirefoxOptions in project zeppelin by apache.
the class WebDriverManager method getWebDriver.
public static WebDriver getWebDriver() {
WebDriver driver = null;
try {
int firefoxVersion = WebDriverManager.getFirefoxVersion();
LOG.info("Firefox version " + firefoxVersion + " detected");
downLoadsDir = FileUtils.getTempDirectory().toString();
String tempPath = downLoadsDir + "/firefox/";
downloadGeekoDriver(firefoxVersion, tempPath);
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", downLoadsDir);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("app.update.auto", false);
profile.setPreference("app.update.enabled", false);
profile.setPreference("dom.max_script_run_time", 0);
profile.setPreference("dom.max_chrome_script_run_time", 0);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
profile.setPreference("network.proxy.type", 0);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(profile);
ImmutableMap<String, String> displayImmutable = ImmutableMap.<String, String>builder().build();
if ("true".equals(System.getenv("TRAVIS"))) {
// Run with DISPLAY 99 for TRAVIS or other build machine
displayImmutable = ImmutableMap.of("DISPLAY", ":99");
}
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
driver = new FirefoxDriver(new GeckoDriverService.Builder().usingDriverExecutable(new File(tempPath + "geckodriver")).withEnvironment(displayImmutable).build(), firefoxOptions);
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
}
if (driver == null) {
try {
driver = new ChromeDriver();
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
}
}
if (driver == null) {
try {
driver = new SafariDriver();
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while SafariDriver ", e);
}
}
String url;
if (System.getenv("url") != null) {
url = System.getenv("url");
} else {
url = "http://localhost:8080";
}
long start = System.currentTimeMillis();
boolean loaded = false;
driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
driver.get(url);
while (System.currentTimeMillis() - start < 60 * 1000) {
// wait for page load
try {
(new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
}
});
loaded = true;
break;
} catch (TimeoutException e) {
LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
driver.navigate().to(url);
}
}
if (loaded == false) {
fail();
}
driver.manage().window().maximize();
return driver;
}
Aggregations