org.openqa.selenium.firefox.FirefoxDriver Java Examples

The following examples show how to use org.openqa.selenium.firefox.FirefoxDriver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FirefoxCustomProfile.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 7 votes vote down vote up
public static void main(String... args) throws IOException {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.addExtension(
                new File("./src/test/resources/extensions/xpath_finder.xpi"));

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

        try {
            driver.get("http://www.google.com");
        } finally {
            driver.quit();
        }

    }
 
Example #2
Source File: SeleniumDriverHandler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static WebDriver getFirefoxDriver(){
    /*
        Need to have an updated Firefox, but also need
        to download and put the geckodriver in your own home dir.
        See:

        https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
        https://github.com/mozilla/geckodriver/releases

        However, drivers for FireFox have been often unstable.
        Therefore, I do recommend to use Chrome instead
     */

    setupDriverExecutable("geckodriver", "webdriver.gecko.driver");

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability("marionette", true);
    desiredCapabilities.setJavascriptEnabled(true);

    return  new FirefoxDriver(desiredCapabilities);
}
 
Example #3
Source File: FireFoxProxyViaProfile.java    From at.info-knowledge-base with MIT License 6 votes vote down vote up
@BeforeMethod
public void setUpProxy() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", proxyIp);
    profile.setPreference("network.proxy.http_port", port);

    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    //or
    //driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
 
Example #4
Source File: Shadow.java    From shadow-automation-selenium with Apache License 2.0 6 votes vote down vote up
public Shadow(WebDriver driver) {
	
	if (driver instanceof ChromeDriver) {
		sessionId  = ((ChromeDriver)driver).getSessionId();
		chromeDriver = (ChromeDriver)driver;
	} else if (driver instanceof FirefoxDriver) {
		sessionId  = ((FirefoxDriver)driver).getSessionId();
		firfoxDriver = (FirefoxDriver)driver;
	} else if (driver instanceof InternetExplorerDriver) {
		sessionId  = ((InternetExplorerDriver)driver).getSessionId();
		ieDriver = (InternetExplorerDriver)driver;
	} else if (driver instanceof RemoteWebDriver) {
		sessionId  = ((RemoteWebDriver)driver).getSessionId();
		remoteWebDriver = (RemoteWebDriver)driver;
	} 
	this.driver = driver;
}
 
Example #5
Source File: FirefoxFrozenPreferences.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
public static void main(String... args) {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.shell.checkDefaultBrowser", true);
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setAcceptUntrustedCertificates(false);

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("http://facebook.com");
    }
 
Example #6
Source File: ForcedAnnotationReaderTest.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
static Stream<Arguments> forcedTestProvider() {
    return Stream.of(
            Arguments.of(AppiumDriverHandler.class,
                    ForcedAppiumJupiterTest.class, AppiumDriver.class,
                    "appiumNoCapabilitiesTest"),
            Arguments.of(AppiumDriverHandler.class,
                    ForcedAppiumJupiterTest.class, AppiumDriver.class,
                    "appiumWithCapabilitiesTest"),
            Arguments.of(ChromeDriverHandler.class,
                    ForcedBadChromeJupiterTest.class, ChromeDriver.class,
                    "chromeTest"),
            Arguments.of(FirefoxDriverHandler.class,
                    ForcedBadFirefoxJupiterTest.class, FirefoxDriver.class,
                    "firefoxTest"),
            Arguments.of(EdgeDriverHandler.class,
                    ForcedEdgeJupiterTest.class, EdgeDriver.class,
                    "edgeTest"),
            Arguments.of(OperaDriverHandler.class,
                    ForcedOperaJupiterTest.class, OperaDriver.class,
                    "operaTest"),
            Arguments.of(SafariDriverHandler.class,
                    ForcedSafariJupiterTest.class, SafariDriver.class,
                    "safariTest"));
}
 
Example #7
Source File: TgTestRun.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Properly Returns the WebDriver Object to the pool when finished or
 * close and quit the driver if the object pool is not used
 */
private void properlyCloseWebDriver() {
    getLog().debug("Closing Firefox driver.");
    if (firefoxDriverObjectPool != null && 
            getDriver() instanceof FirefoxDriver) {
        //set the blank page before returning the webDriver instance
        getDriver().get("");
        try {
            firefoxDriverObjectPool.returnObject((FirefoxDriver)getDriver());
        } catch (Exception ex) {
            getLog().warn("Firefox driver cannot be returned due to  " + ex.getMessage());
        }
    } else {
        try {
            getDriver().close();
            getDriver().quit();
        } catch (Exception e) {
            getLog().warn("An error occured while closing driver."
                    + " A defunct firefox process may run on the system. "
                    + " Trying to kill before leaving");
            if (getDriver() instanceof FirefoxDriver) {
                ((FirefoxDriver)getDriver()).kill();
            }
        }
    }
}
 
Example #8
Source File: WebDriverCreator.java    From webtau with Apache License 2.0 6 votes vote down vote up
private static FirefoxDriver createFirefoxDriver() {
    FirefoxOptions options = new FirefoxOptions();

    if (BrowserConfig.getFirefoxBinPath() != null) {
        options.setBinary(BrowserConfig.getFirefoxBinPath());
    }

    if (BrowserConfig.getFirefoxDriverPath() != null) {
        System.setProperty(FIREFOX_DRIVER_PATH_KEY, BrowserConfig.getChromeDriverPath().toString());
    }

    if (BrowserConfig.isHeadless()) {
        options.setHeadless(true);
    }

    if (System.getProperty(FIREFOX_DRIVER_PATH_KEY) == null) {
        setupDriverManagerConfig();
        downloadDriverMessage("firefox");
        WebDriverManager.firefoxdriver().setup();
    }

    return new FirefoxDriver(options);
}
 
Example #9
Source File: SeleniumDriverHandler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static WebDriver getFirefoxDriver(){
    /*
        Need to have an updated Firefox, but also need
        to download and put the geckodriver in your own home dir.
        See:

        https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
        https://github.com/mozilla/geckodriver/releases

        However, drivers for FireFox have been often unstable.
        Therefore, I do recommend to use Chrome instead
     */

    setupDriverExecutable("geckodriver", "webdriver.gecko.driver");

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability("marionette", true);
    desiredCapabilities.setJavascriptEnabled(true);

    return  new FirefoxDriver(desiredCapabilities);
}
 
Example #10
Source File: RemoteDesiredCapabilitiesFactory.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
public static DesiredCapabilities build(RemoteCapability capability){
 DesiredCapabilities desiredCapabilities;
 if(RemoteCapability.CHROME.equals(capability)){
  ChromeOptions options = new ChromeOptions();
     desiredCapabilities = DesiredCapabilities.chrome();
     desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
  return desiredCapabilities;
 } else if (RemoteCapability.FIREFOX.equals(capability)){
  FirefoxProfile profile = new FirefoxProfile();
  desiredCapabilities = DesiredCapabilities.firefox();
  desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);
  return desiredCapabilities;
 } else if (RemoteCapability.INTERNET_EXPLORER.equals(capability)){
  desiredCapabilities = DesiredCapabilities.internetExplorer();
  return desiredCapabilities;
 } else if (RemoteCapability.PHANTOMJS.equals(capability)){
  desiredCapabilities = DesiredCapabilities.phantomjs();
  return desiredCapabilities;
 }
 throw new IllegalArgumentException("No such capability");
}
 
Example #11
Source File: FirefoxDriverPoolableObjectFactory.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public FirefoxDriver makeObject() throws Exception {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY_KEY) != null) {
        Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + System.getProperty(DISPLAY_PROPERTY_KEY));
        ffBinary.setEnvironmentProperty("DISPLAY", System.getProperty(DISPLAY_PROPERTY_KEY));
    }
    FirefoxDriver fd = new FirefoxDriver(ffBinary, ProfileFactory.getInstance().getScenarioProfile());
    if (this.implicitelyWaitDriverTimeout != null) {
        fd.manage().timeouts().implicitlyWait(this.implicitelyWaitDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    if (this.pageLoadDriverTimeout != null) {
        fd.manage().timeouts().pageLoadTimeout(this.pageLoadDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    return fd;
}
 
Example #12
Source File: FirefoxDriverHandler.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        FirefoxOptions firefoxOptions = (FirefoxOptions) getOptions(
                parameter, testInstance);
        if (capabilities.isPresent()) {
            firefoxOptions.merge(capabilities.get());
        }
        object = new FirefoxDriver(firefoxOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #13
Source File: WebDriverFactory.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static DesiredCapabilities getFFUAECaps(DesiredCapabilities caps, Emulator emulator) {
    FirefoxProfile profile = new FirefoxProfile();
    if (!emulator.getUserAgent().trim().isEmpty()) {
        profile.setPreference("general.useragent.override", emulator.getUserAgent());
    }
    caps.setCapability(FirefoxDriver.PROFILE, profile);
    return caps;
}
 
Example #14
Source File: BrowserService.java    From collect-earth with MIT License 5 votes vote down vote up
private void setGeckoDriverPath() {
	String geckoDriverPath = "";
	if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
		geckoDriverPath = "resources/geckodriver_mac";
	} else if (SystemUtils.IS_OS_UNIX) {
		if (System.getProperty("os.arch").contains("64")
				|| System.getProperty("sun.arch.data.model").equals("64")) {
			geckoDriverPath = "resources/geckodriver_64";
		} else {
			geckoDriverPath = "resources/geckodriver_32";
		}
	} else if (SystemUtils.IS_OS_WINDOWS) {
		try {
			if (System.getProperty("os.arch").contains("64")
					|| System.getProperty("sun.arch.data.model").equals("64"))
				geckoDriverPath = "resources/geckodriver_64.exe";
			else
				geckoDriverPath = "resources/geckodriver_32.exe";
		} catch (Exception e) {
			geckoDriverPath = "resources/geckodriver_64.exe";
		}
	} else {
		throw new IllegalArgumentException("Geckodriver is not supported in the current OS");
	}

	File geckoDriverFile = new File(geckoDriverPath);

	// if above property is not working or not opening the application in browser
	// then try below property
	System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, geckoDriverFile.getAbsolutePath());
	System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");

}
 
Example #15
Source File: FirefoxDriverResource.java    From adf-selenium with Apache License 2.0 5 votes vote down vote up
@Override
protected RemoteWebDriver createDriver(String language) {
    RemoteWebDriver driver = new FirefoxDriver(createProfile(language));
    if (!Long.valueOf(10).equals(driver.executeScript("return arguments[0]", 10))) {
        throw new WebDriverException("This browser version is not supported due to Selenium bug 8387. See https://code.google.com/p/selenium/issues/detail?id=8387");
    }
    return driver;
}
 
Example #16
Source File: FirefoxFactory.java    From webtester-core with Apache License 2.0 5 votes vote down vote up
public FirefoxFactory() {
    super(new Function<DesiredCapabilities, WebDriver>() {
        @Override
        public WebDriver apply(DesiredCapabilities capabilities) {
            capabilities.setCapability("marionette", false);
            return new FirefoxDriver(capabilities);
        }
    });
}
 
Example #17
Source File: CaptureVideo.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
public static void main(String[] argv) {
	// initialize web driver
	WebDriver driver = new FirefoxDriver();
	driver.get("http://automated-testing.info");

	// capture video
	initScreen();
	startVideoCapturing();
	stopVideoCapturing();

	// initialize web driver
	driver.quit();
}
 
Example #18
Source File: WebDriverTest.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Before
    public void setUp() throws Exception {
//        driver = new ChromeDriver();
        driver = new FirefoxDriver();
        baseUrl = "http://localhost:8080";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
 
Example #19
Source File: LocalWebDriverTest.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
@Test
public void testWithFirefoxAndOpera(FirefoxDriver firefox,
        OperaDriver opera) {
    firefox.get("http://www.seleniumhq.org/");
    opera.get("http://junit.org/junit5/");

    assertTrue(firefox.getTitle().startsWith("Selenium"));
    assertTrue(opera.getTitle().equals("JUnit 5"));
}
 
Example #20
Source File: TestBrowserFactory.java    From webtester-core with Apache License 2.0 5 votes vote down vote up
@Override
public Browser createBrowser() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAcceptUntrustedCertificates(true);
    profile.setEnableNativeEvents(false);
    return createBrowser(new FirefoxDriver(profile));
}
 
Example #21
Source File: TestBaseCase.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
/**
 * 用枚举类型列出浏览器列表,用于设置浏览器类型的函数参数
 * @author zheng
 *
 */
private WebDriver setDriver(String browsername)
{
	switch (browsername)
	{

		case "FirefoxDriver" :
			System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
			FirefoxProfile firefoxProfile=new FirefoxProfile();
			//设置默认下载路径
			firefoxProfile.setPreference("browser.download.folderList", 2);
			firefoxProfile.setPreference("browser.download.dir", "D:\\自动化测试下载文件");
			//加载firebug插件
			firefoxProfile.setPreference("extensions.firebug.currentVersion", "2.0.13");
			firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "none");
			//加载firepath插件
			firefoxProfile.setPreference("extensions.firepath.currentVersion", "0.9.7.1.1");
			firefoxProfile.setPreference("extensions.firepath.allPagesActivation", "on");
			this.driver=new FirefoxDriver(firefoxProfile);
			break;
		case "ChormeDriver":
			System.setProperty("webdriver.chrome.driver", "resource\\chromedriver.exe");
			this.driver=new ChromeDriver();
			break;
		case "InternetExplorerDriver":
			System.setProperty("webdriver.ie.driver", "resource\\IEDriverServer_Win32_2.48.0\\IEDriverServer.exe");
			DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
			dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
			dc.setCapability("ignoreProtectedModeSettings", true);
			this.driver=new InternetExplorerDriver(dc);
			break;
		case "HtmlUnitDriver":
			this.driver=new HtmlUnitDriver();
			break;
		default:
			this.driver=new FirefoxDriver();
			break;
	}
	return driver;
}
 
Example #22
Source File: TestCase.java    From simpleWebtest with Apache License 2.0 5 votes vote down vote up
/**
 * 如果当前进程没有绑定driver,创建一个然后绑定上,如果已经有了就直接返回
 * create a driver for this thread if not exist. or return it directly
 */
public static WebDriver getDriver(){
	WebDriver driver= DriverManager.ThreadDriver.get();
	if (driver==null){
		if (browserType.equals("firefox")){
			 driver = new EventFiringWebDriver(new FirefoxDriver()).register(new LogEventListener());
			 ThreadDriver.set(driver);
			//找东西前等三秒wait 3 second for every find by
		    DriverManager.getDriver().manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
		}
		//有需求的同学自己在这里添加IE等浏览器的支持
		//you can add ie/chrome or other driver here
		}
	return driver;
}
 
Example #23
Source File: WisdomFluentLeniumTest.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver getDefaultDriver() {
    String browser = System.getProperty("fluentlenium.browser");
    LOGGER.debug("Selecting Selenium Browser using " + browser);
    if (browser == null) {
        LOGGER.debug("Using default HTML Unit Driver");
        return new HtmlUnitDriver();
    }

    if ("chrome".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Chrome");
        return new ChromeDriver();
    }

    if ("firefox".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Firefox");
        return new FirefoxDriver();
    }

    if ("ie".equalsIgnoreCase(browser) || "internetexplorer".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Internet Explorer");
        return new InternetExplorerDriver();
    }

    if ("safari".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Safari");
        return new SafariDriver();
    }

    throw new IllegalArgumentException("Unknown browser : " + browser);
}
 
Example #24
Source File: SeleniumWrapper.java    From SeleniumBestPracticesBook with Apache License 2.0 5 votes vote down vote up
public SeleniumWrapper(String browser) {
  if (browser.equals("firefox")) {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", "127.0.0.1");
    profile.setPreference("network.proxy.http_port", 9999);
    profile
        .setPreference("network.proxy.no_proxies_on",
                       "localhost, 127.0.0.1, *awful-valentine.com");

    selenium = new FirefoxDriver(profile);
  }
}
 
Example #25
Source File: SeleniumDriver.java    From jsflight with Apache License 2.0 5 votes vote down vote up
private FirefoxDriver openFirefoxDriver(DesiredCapabilities desiredCapabilities, FirefoxProfile profile,
        FirefoxBinary binary)
{
    try
    {
        return new FirefoxDriver(binary, profile, desiredCapabilities);
    }
    catch (WebDriverException ex)
    {
        LOG.warn(ex.getMessage());
        awakenAllDrivers();
        return openFirefoxDriver(desiredCapabilities, profile, binary);
    }
}
 
Example #26
Source File: BrowserStatement.java    From neodymium-library with MIT License 5 votes vote down vote up
public BrowserStatement()
{
    // that is like a dirty hack to provide testing ability
    if (multibrowserConfiguration == null)
        multibrowserConfiguration = MultibrowserConfiguration.getInstance();

    final String ieDriverPath = Neodymium.configuration().getIeDriverPath();
    final String chromeDriverPath = Neodymium.configuration().getChromeDriverPath();
    final String geckoDriverPath = Neodymium.configuration().getFirefoxDriverPath();

    // shall we run old school firefox?
    final boolean firefoxLegacy = Neodymium.configuration().useFirefoxLegacy();
    System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, Boolean.toString(!firefoxLegacy));

    if (!StringUtils.isEmpty(ieDriverPath))
    {
        System.setProperty("webdriver.ie.driver", ieDriverPath);
    }
    if (!StringUtils.isEmpty(chromeDriverPath))
    {
        System.setProperty("webdriver.chrome.driver", chromeDriverPath);
    }
    if (!StringUtils.isEmpty(geckoDriverPath))
    {
        System.setProperty("webdriver.gecko.driver", geckoDriverPath);
    }

    // get test specific browser definitions (aka browser tag see browser.properties)
    // could be one value or comma separated list of values
    String browserDefinitionsProperty = System.getProperty(SYSTEM_PROPERTY_BROWSERDEFINITION, "");
    browserDefinitionsProperty = browserDefinitionsProperty.replaceAll("\\s", "");

    // parse test specific browser definitions
    if (!StringUtils.isEmpty(browserDefinitionsProperty))
    {
        browserDefinitions.addAll(Arrays.asList(browserDefinitionsProperty.split(",")));
    }
}
 
Example #27
Source File: TestWebdriverEnv.java    From simpleWebtest with Apache License 2.0 5 votes vote down vote up
@Test
public void checkEnv(){
	//首先打一个hello world来测试一你的IDE里testng的插件是否已经安装好
	//check if you success installed testng on your IDE
	System.out.println("Hello World, TestNG");
	
	//看看你电脑上能不能正确用firefox driver启动firefox
	//check if firefox driver runs successfully on your computer
	WebDriver driver=new FirefoxDriver();
	driver.get("https://github.com/zhangting85/simpleWebtest");
}
 
Example #28
Source File: GoogleTest.java    From adf-selenium with Apache License 2.0 5 votes vote down vote up
/**
 * Most basic Selenium example that searches for a term on google.
 * Does not close the browser on test completion to keep the test as simple as possible.
 */
@Test
public void simpleTest() {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://google.com/?hl=en");
    WebElement searchBox = driver.findElement(name("q"));
    searchBox.sendKeys("adf selenium");
    searchBox.submit();
}
 
Example #29
Source File: DriverFactory.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Generates a firefox webdriver.
 *
 * @return
 *         A firefox webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateFirefoxDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.FIREFOX);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    log.info("Generating Firefox driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver);

    final FirefoxOptions firefoxOptions = new FirefoxOptions();
    final FirefoxBinary firefoxBinary = new FirefoxBinary();

    firefoxOptions.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    firefoxOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

    setLoggingLevel(firefoxOptions);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        firefoxOptions.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    if (Context.isHeadless()) {
        firefoxBinary.addCommandLineOptions("--headless");
        firefoxOptions.setBinary(firefoxBinary);
    }
    firefoxOptions.setLogLevel(FirefoxDriverLogLevel.FATAL);

    return new FirefoxDriver(firefoxOptions);
}
 
Example #30
Source File: BotStyleTest.java    From adf-selenium with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    final FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    profile.setPreference("app.update.enabled", false);
    driver = new FirefoxDriver(profile);

    DialogManager.init(driver, TIMEOUT_MSECS);
    dialogManager = DialogManager.getInstance();
}