@Override public WebDriver createDriver() throws Exception { final FirefoxBinary binary = new FirefoxBinary(); if (headless) { binary.addCommandLineOptions("-headless"); } final Map<String, String> environmentVariables = new HashMap<>(); if (!headless && xvfbPort != null) { environmentVariables.put("DISPLAY", ":" + String.valueOf(xvfbPort)); } final WebDriver driver = new FirefoxDriver( new GeckoDriverService.Builder() .usingFirefoxBinary(binary) .withEnvironment(environmentVariables) .build() ); manage(driver); return driver; }
/** * @author andre.tschirch * * Example test method for using specific Firefox version e.g. v17. * * Test method for running a successful login and the right presentation of * the activity state of the admin navigation link, which must be active, * for browser Firefox. */ // @Test public void navAdminFirefox17() { ProfilesIni profile = new ProfilesIni(); FirefoxProfile firefoxProfile = profile.getProfile("firefox17"); WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("D:/schatzsuche/firefox17/firefox.exe")), firefoxProfile); TestBrowser browser = Helpers.testBrowser(driver, 3333); TestServer server = Helpers.testServer(3333, Helpers.fakeApplication()); TestServer startedServer = null; try { server.start(); startedServer = server; new NavAdminCallbackComposite().invoke(browser); } catch(Throwable t) { throw new RuntimeException(t); } finally { if(browser != null) { browser.quit(); } if(startedServer != null) { startedServer.stop(); } } }
public static void assumeHavingFirefoxConfigured() { try { new FirefoxBinary(); } catch ( WebDriverException e ) { if ( e.getMessage().contains("Cannot find firefox binary in PATH") ) { assumeThat( "Please define the path to your firefox executable using " + DefaultFirefoxBinaryProvider.FIREFOX_BINARY_LOCATION_SYSTEM_PROPERTY_KEY + " system property, or add your firefox executable to the PATH variable! " + "This is just an assumption to keep our build green.", System.getProperty(DefaultFirefoxBinaryProvider.FIREFOX_BINARY_LOCATION_SYSTEM_PROPERTY_KEY), is(notNullValue())); } else { throw e; } } }
/** * 本地初始化Firefox浏览器driver */ public Firefox() { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("acceptSslCerts", false); FirefoxBrowserProfile firefoxProfile = new FirefoxBrowserProfile(); String sProfile = firefoxProfile.getDefaultProfile(); if (sProfile.equals("")) { this.driver = new FirefoxDriver(); } else { try { FirefoxProfile profile = new FirefoxProfile(new File(sProfile)); FirefoxBinary firefoxBinary = new FirefoxBinary(new File(firefoxProfile.getFirefoxBinInstallPath())); profile.setAcceptUntrustedCertificates(false); this.driver = new FirefoxDriver(firefoxBinary, profile); } catch (Exception e) { throw new RuntimeException("Failed to start firefox browser,please check!", e); } } }
@BeforeClass public static void buildDriver() { // System.setProperty("webdriver.chrome.driver", // "/home/csokol/programas/chromedriver/chromedriver"); // driver = new ChromeDriver(); String localTest = System.getenv("LOCAL_TEST"); if ("remote".equals(localTest)) { driver = ghostDriver(); } else { FirefoxBinary firefox = new FirefoxBinary(); String display = System.getProperty("DISPLAY", ":0"); firefox.setEnvironmentProperty("DISPLAY", display); driver = new FirefoxDriver(); } driver.manage().window().setSize(new Dimension(1280, 800)); waitForFirstBodyPresence(); }
/** * {@inheritDoc} */ @Override public WebDriver getWebDriverInstance() { WebDriver retVal = super.getWebDriver(); if (null == retVal) { FirefoxFeatureProfile bPro = getBrowserProfile(); if (null == bPro) { retVal = new FirefoxDriver(); } else { FirefoxBinary binary = new FirefoxBinary(); binary.addCommandLineOptions("-no-remote"); retVal = new FirefoxDriver(binary, bPro.getProfile()); } setWebDriver(retVal); } return retVal; }
@Override public void start() throws CandybeanException { String profileName = candybean.config.getValue("browser.firefox.profile", "default"); File ffBinaryPath = new File(candybean.config.getPathValue("browser.firefox.binary")); if(!ffBinaryPath.exists()){ String error = "Unable to find firefox browser driver from the specified location in the configuration file! \n" + "Please add a configuration to the candybean config file for key \"browser.firefox.binary\" that" + "indicates the location of the binary."; logger.severe(error); throw new CandybeanException(error); } else { FirefoxProfile ffProfile = (new ProfilesIni()).getProfile(profileName); FirefoxBinary ffBinary = new FirefoxBinary(ffBinaryPath); logger.info("Instantiating Firefox with profile name: " + profileName + " and binary path: " + ffBinaryPath); super.wd = new FirefoxDriver(ffBinary, ffProfile); super.start(); // requires wd to be instantiated first } }
@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; }
/** * * @param config * @return A FirefoxDriver. */ @Override public RemoteWebDriver make(HashMap<String, String> config) { FirefoxBinary ffBinary = new FirefoxBinary(); if (System.getProperty(DISPLAY_PROPERTY) != null) { ffBinary.setEnvironmentProperty( DISPLAY_PROPERTY.toUpperCase(), System.getProperty(DISPLAY_PROPERTY)); } else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) { ffBinary.setEnvironmentProperty( DISPLAY_PROPERTY.toUpperCase(), System.getenv(DISPLAY_PROPERTY.toUpperCase())); } RemoteWebDriver remoteWebDriver = new FirefoxDriver(ffBinary, firefoxProfile); if (screenHeight != -1 && screenWidth!= -1) { remoteWebDriver.manage().window().setSize(new Dimension(screenWidth, screenHeight)); } return remoteWebDriver; }
/** * * @param filePath * the binary path location of the firefox app (where it's * installed) * @return */ private static FirefoxBinary getFFBinary(String filePath) { File[] possibleLocations = { new File(filePath != null ? filePath : ""), new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe"), new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"), }; File ffbinary = null; for (File curr : possibleLocations) { if (curr.exists()) { ffbinary = curr; break; } } if (ffbinary == null) { throw new RuntimeException( "Unable to find firefox binary, please ensure that firefox is installed " + "on your system. If it is then please determine the path to your firefox.exe and set it as " + "binaryPath=<FIREFOX PATH HERE>"); } else { return new FirefoxBinary(ffbinary); } }
/** * 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)); } logger.info("Generating Firefox driver ({}) ...", pathWebdriver); System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver); final FirefoxOptions firefoxOptions = new FirefoxOptions(); final FirefoxBinary firefoxBinary = new FirefoxBinary(); final DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); setLoggingLevel(capabilities); // Proxy configuration if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { capabilities.setCapability(CapabilityType.PROXY, Context.getProxy()); } if (Context.isHeadless()) { firefoxBinary.addCommandLineOptions("--headless"); firefoxOptions.setBinary(firefoxBinary); } firefoxOptions.setLogLevel(Level.OFF); capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, firefoxOptions); return new FirefoxDriver(capabilities); }
@Override protected FirefoxDriver constructWebDriver(DesiredCapabilities desiredCapabilities) { FirefoxBinary firefoxBinary = getFirefoxConfiguration().getFirefoxBinary(); FirefoxProfile profile = getFirefoxConfiguration().getFirefoxProfile(); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setBinary(firefoxBinary); firefoxOptions.setProfile(profile); return new FirefoxDriver(firefoxOptions); }
@BeforeClass public static void setUp() throws IOException { String travisCiFlag = System.getenv().get("TRAVIS"); FirefoxBinary firefoxBinary = "true".equals(travisCiFlag) ? getFirefoxBinaryForTravisCi() : new FirefoxBinary(); driver = new FirefoxDriver(firefoxBinary, new FirefoxProfile()); }
private static FirefoxBinary getFirefoxBinaryForTravisCi() throws IOException { String firefoxPath = getFirefoxPath(); Logger staticLog = LoggerFactory.getLogger(UseNewFirefoxOnTravisTest.class); staticLog.info("Firefox path: " + firefoxPath); return new FirefoxBinary(new File(firefoxPath)); }
private AetFirefoxDriver getFirefoxDriver(FirefoxProfile fp, DesiredCapabilities capabilities) throws IOException { AetFirefoxDriver driver; if (StringUtils.isBlank(path)) { driver = new AetFirefoxDriver(capabilities); } else { FirefoxBinary binary = new FirefoxBinary(new File(path)); driver = new AetFirefoxDriver(binary, fp, capabilities); } driver.manage().timeouts().pageLoadTimeout(5L, TimeUnit.MINUTES); return driver; }
private FirefoxDriver createFirefoxDriver(String display, String binaryPath, DesiredCapabilities desiredCapabilities) { FirefoxProfile profile = createDefaultFirefoxProfile(); FirefoxBinary binary = !StringUtils.isBlank(binaryPath) ? new FirefoxBinary(new File(binaryPath)) : new FirefoxBinary(); LOG.info("Binding to {} display", display); availableDisplays.compute(display, (d, value) -> value == null ? 1 : value + 1); binary.setEnvironmentProperty(DISPLAY, display); LOG.info("Firefox path is: {}", binaryPath); return openFirefoxDriver(desiredCapabilities, profile, binary); }
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); } }
/** * @param config Key/value pairs treated as required capabilities, with the exception of: * <ul> * <li>binary: path to Firefox binary to use</li> * <li>profile: path to Firefox profile to use</li> * </ul> * @return A FirefoxDriver. */ @Override public RemoteWebDriver make(HashMap<String, String> config) { FirefoxBinary fb = config.containsKey("binary") ? new FirefoxBinary(new File(config.get("binary"))) : new FirefoxBinary(); FirefoxProfile fp = config.containsKey("profile") ? new FirefoxProfile(new File(config.get("profile"))) : new FirefoxProfile(); HashMap<String, String> caps = new HashMap<String, String>(config); caps.remove("binary"); caps.remove("profile"); return new FirefoxDriver(fb, fp, new DesiredCapabilities(caps)); }
private WebDriver getFirefoxDriver(String displayPort) { FirefoxDriver driver = null; if(displayPort != null){ FirefoxBinary binary = new FirefoxBinary(); binary.setEnvironmentProperty("DISPLAY", displayPort); driver = new FirefoxDriver(binary,null); }else{ driver = new FirefoxDriver(); } driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICITLY_WAIT_SECS, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(DEFAULT_PAGE_LOAD_TIMEOUT_SECS, TimeUnit.SECONDS); return driver; }
@Override public WebDriver getDriver() { log.info(String.format("Firefox Profile: %s", firefoxProfile)); System.setProperty("webdriver.firefox.marionette",binaryPath); if (StringUtils.isNotBlank(binaryPath)) { File file = new File(binaryPath); Preconditions.checkArgument(file.exists()); log.info("Using the following FireFox executable: " + file); FirefoxBinary firefoxBinary = new FirefoxBinary((file)); return new FirefoxDriver(firefoxBinary, firefoxProfile); } return new FirefoxDriver(firefoxProfile); }
public WebDriver build() { if (profile==null) { profile = createFirefoxProfile(locales); } if (binary == null) { return path == null ? new FirefoxDriver(profile) : new FirefoxDriver(new FirefoxBinary(path), profile); } else { return new FirefoxDriver(binary, profile); } }
@Test public void autoCompeleteUsingSelenium() throws InterruptedException { FirefoxBinary binary = new FirefoxBinary(new File("src/main/resources/Firefox/Contents/MacOS/firefox-bin")); FirefoxProfile profile = new FirefoxProfile(new File("src/main/resources/Firefox/Profiles/default")); WebDriver driver = new FirefoxDriver(binary, profile); driver.get("http://www.w3schools.com/html/html5_draganddrop.asp"); WebElement source = driver.findElement(id("drag1")); System.out.println(source.getAttribute("src")); WebElement target = driver.findElement(id("div2")); System.out.println(target.getTagName() + "=" + target.toString()); Actions actions = new Actions(driver); actions.dragAndDrop(source, target); actions.perform(); }
@Override public FirefoxDriver get() { String binaryDir = "src/main/resources/Firefox/Contents/MacOS/firefox-bin"; File firefoxBinary = new File(binaryDir); FirefoxBinary binary = new FirefoxBinary(firefoxBinary); String dirName = "src/main/resources/Firefox/Profiles/default"; File profileDir = new File(dirName); FirefoxProfile profile = new FirefoxProfile(profileDir); return new FirefoxDriver(binary, profile); }
/** * This methods creates a firefoxDriver instance and set a DISPLAY * environment variable * @param display * @return an instance of firefoxDriver */ public FirefoxDriver getFirefoxDriver(String display) { if (webDriver == null) { FirefoxBinary ffBinary = new FirefoxBinary(); if (StringUtils.isNotBlank(display)) { Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + display); ffBinary.setEnvironmentProperty("DISPLAY", display); } ProfileFactory pf = ProfileFactory.getInstance(); webDriver = new FirefoxDriver(ffBinary, pf.getOnlineProfile()); webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); webDriver.manage().timeouts().pageLoadTimeout(310, TimeUnit.SECONDS); } return webDriver; }
@Override public void adjustFirefoxBinary(FirefoxBinary firefoxBinary) { setDisplay(firefoxBinary); }
private void setDisplay(FirefoxBinary result) { String display = System.getProperty(DISPLAY_SYSTEM_PROPERTY_KEY); if (display != null) { result.setEnvironmentProperty("DISPLAY", display); } }
/** * @return fully configured firefox binary */ public FirefoxBinary getFirefoxBinary() { FirefoxBinary firefoxBinary = firefoxBinaryProvider.getFirefoxBinary(); firefoxConfigurationParticipantList.forEach(participant -> participant.adjustFirefoxBinary(firefoxBinary)); return firefoxBinary; }
public FirefoxDriver(FirefoxBinary binary) { super(new org.openqa.selenium.firefox.FirefoxDriver(binary)); }
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) { super(new org.openqa.selenium.firefox.FirefoxDriver(binary, profile)); }
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) { super(new org.openqa.selenium.firefox.FirefoxDriver(binary, profile, capabilities)); }
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities desiredCapabilities, Capabilities requiredCapabilities) { super(new org.openqa.selenium.firefox.FirefoxDriver(binary, profile, desiredCapabilities, requiredCapabilities)); }
public AetFirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) { super(binary, profile, DesiredCapabilities.firefox()); }
public AetFirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) { super(binary, profile, capabilities, null); }
/** * * @return the webdriver * @throws IOException if there is a problem loading the * properties file */ private WebDriver createWebDriver() throws IOException { Resource propertiesFile = new ClassPathResource( "META-INF/spring/application.properties"); Properties properties = new Properties(); properties.load(propertiesFile.getInputStream()); String webdriverMode = properties.getProperty("selenium.webdriver.mode", "local"); String driverName = properties.getProperty("selenium.webdriver.impl", "org.openqa.selenium.firefox.FirefoxDriver"); WebDriverBrowserType browser = WebDriverBrowserType.fromString(driverName); String display = properties.getProperty("selenium.display.port", ":0"); if (webdriverMode.equals("local")) { switch (browser) { case CHROME: String chromeLocation = properties .getProperty("selenium.webdriver.chromedriver.location"); Map<String,String> environment = new HashMap<String,String>(); environment.put("DISPLAY", display); ChromeDriverService chromeService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(chromeLocation)) .usingAnyFreePort().withEnvironment(environment).build(); chromeService.start(); return new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome()); case SAFARI: return new SafariDriver(); case INTERNET_EXPLORER: String internetExplorerLocation = properties .getProperty("selenium.webdriver.ie.location"); InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService(); ieService.start(); return new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer()); case FIREFOX: default: FirefoxBinary firefoxBinary = new FirefoxBinary(); firefoxBinary.setEnvironmentProperty("DISPLAY", display); ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); return new FirefoxDriver(firefoxBinary, profile); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (browser) { case CHROME: capabilities = DesiredCapabilities.chrome(); break; case INTERNET_EXPLORER: capabilities = DesiredCapabilities.internetExplorer(); break; case SAFARI: capabilities = DesiredCapabilities.safari(); break; case FIREFOX: default: capabilities = DesiredCapabilities.firefox(); } String platformName = properties.getProperty("selenium.webdriver.platformName", "LINUX"); WebDriverPlatformType platform = WebDriverPlatformType.valueOf(platformName); switch (platform) { case MAC: capabilities.setPlatform(Platform.MAC); break; case WINDOWS: capabilities.setPlatform(Platform.WINDOWS); break; case LINUX: default: capabilities.setPlatform(Platform.LINUX); } return new RemoteWebDriver(new URL("http://build.e-monocot.org:4444/wd/hub"), capabilities); } }
public RemoteWebDriver build() { FirefoxProfile firefoxProfile = new FirefoxProfile(); configureFirefoxMaxScriptRunTime(firefoxProfile); configureFirefoxToSaveFilesToDiskWithoutAsking(firefoxProfile); /* add Firefox extensions if needed */ if (TestPropertiesHelper.addFireFoxExtentions()) { addFirefoxExtensions(firefoxProfile); } final FirefoxBinary firefoxBinary = TestPropertiesHelper.useExecutableDriverPath()? new FirefoxBinary(FileUtils.getFile(TestPropertiesHelper.specificExecutablePath())): new FirefoxBinary(); firefoxBinary.setTimeout(FIREFOX_STARTUP_TIMEOUT); return new FirefoxDriver(firefoxBinary, firefoxProfile); }
public FirefoxBuildr setFirefoxBinary(FirefoxBinary binary) { this.binary = binary; return this; }
private static WebDriver getFirefoxDriver(String language) { DesiredCapabilities firefoxCapabilities = getFirefoxCapabilities(language); return ScriptMethods.environment("webdriver.firefox.binary") == null ? new FirefoxDriver(firefoxCapabilities) : new FirefoxDriver(new FirefoxBinary(new File(ScriptMethods.environment("webdriver.firefox.binary"))), (FirefoxProfile) firefoxCapabilities.getCapability(FirefoxDriver.PROFILE), firefoxCapabilities); }
public FirefoxBrowserFactory usingBinary(FirefoxBinary fb) { binary = fb; return this; }
@Override public FirefoxDriver init() { FirefoxBinary binary = new FirefoxBinary(new File("/opt/local/lib/firefox-x11/firefox-bin")); binary.setEnvironmentProperty("DISPLAY", ":88"); return new FirefoxDriver(binary, new FirefoxProfile()); }