本文将为您提供关于加载firefox后,SeleniumFireFoxDriver配置文件是否更改?的详细介绍,我们还将为您解释firefoxprofile配置的相关知识,同时,我们还将为您提供关于F
本文将为您提供关于加载firefox后,Selenium FireFoxDriver配置文件是否更改?的详细介绍,我们还将为您解释firefox profile配置的相关知识,同时,我们还将为您提供关于Firefox + Selenium WebDriver并自动下载csv文件、Firefox配置文件中的selenium禁用插件、javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?、org.openqa.selenium.firefox.FirefoxBinary的实例源码的实用信息。
本文目录一览:- 加载firefox后,Selenium FireFoxDriver配置文件是否更改?(firefox profile配置)
- Firefox + Selenium WebDriver并自动下载csv文件
- Firefox配置文件中的selenium禁用插件
- javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?
- org.openqa.selenium.firefox.FirefoxBinary的实例源码
加载firefox后,Selenium FireFoxDriver配置文件是否更改?(firefox profile配置)
ProfilesIni profile = new ProfilesIni();FirefoxProfile ffprofile = profile.getProfile("default");//using firefox default profileffprofile.setPreference("permissions.default.image", 2); // this make ff to block web page imagesWebDriver ff = new FirefoxDriver(ffprofile); // executing firefox with specified profile ff.navigate().to("www.google.com"); // loading web page//codes for changing image blocking ???????????
加载某些网页后如何更改图像遮挡?
答案1
小编典典可以通过开发工具栏CLI在运行中修改首选项,但与加载图像相比,它可能会带来更高的开销。这是Python示例:
from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChains, Keysff = webdriver.Firefox()ff.get(''http//<URL>'')ac = ActionChains(ff)# SHIFT+F2 opens dev toolbarac.key_down(Keys.SHIFT).send_keys(Keys.F2).key_up(Keys.SHIFT).perform()# command to disable imagesac.send_keys(''pref set permissions.default.image 2'').perform()ac.send_keys(Keys.ENTER).perform()# command to disable flashac.send_keys(''pref set plugin.state.flash 0'').perform()ac.send_keys(Keys.ENTER).perform()# disable dev toolbarac.key_down(Keys.SHIFT).send_keys(Keys.F2).key_up(Keys.SHIFT).perform()ac.key_down(Keys.SHIFT).send_keys(Keys.F2).key_up(Keys.SHIFT).perform()# reload the page to confirm there are no images or flashff.refresh()
Firefox + Selenium WebDriver并自动下载csv文件
如何解决Firefox + Selenium WebDriver并自动下载csv文件?
有时内容类型与您期望的不一样使用 Firefox插件(或类似工具)查找文件的真实内容类型并在代码中使用它
顺便说一句,对我来说,内容类型是
fp.set_preference("browser.helperApps.neverAsk.openFile", "application/octet-stream");
fp.set_preference("browser.helperApps.neverAsk.savetodisk", "application/octet-stream");
解决方法
我对Selenium WebDriver和Firefox有问题。我想在对话框窗口中下载没有确认的csv文件,并且我有如下代码:
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.dir",download_dir)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")
但似乎不起作用。我尝试了与 browser.helperApps.neverAsk.saveToDisk的* 许多组合 *
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/csv,text/plan,text/comma-separated-values")
要么
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/csv")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/plain")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/comma-separated-values")
但没有任何区别,Firefox也不会自动下载。我该如何解决?
Firefox配置文件中的selenium禁用插件
有人可以告诉我如何使用Java为我的客户firefox配置文件禁用插件吗?我发现有几个网站显示要添加加载项,但是关于禁用插件一无所获。
我的Firefox配置文件:
FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setAcceptUntrustedCertificates(true); firefoxProfile.setAssumeUntrustedCertificateIssuer(false); firefoxProfile.setPreference("browser.download.folderList",2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false); firefoxProfile.setPreference("browser.download.dir",reportFolder); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf,application/csv,application/vnd.ms-excel"); firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false); firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false); firefoxProfile.setPreference("browser.download.manager.showWhenStartinge",false); firefoxProfile.setPreference("browser.download.panel.shown",false); firefoxProfile.setPreference("browser.download.useToolkitUI",true); firefoxProfile.setPreference("pdfjs.disabled", true); firefoxProfile.setPreference("pdfjs.firstRun", false);driver = new FirefoxDriver(firefoxProfile);
问题是默认情况下启用了某些插件。Adobe Acrobat,Google Update,Java,Microsoft
Office,Flash,Director和Silverlight的Shockwave。
我需要禁用其中一些,因为它们弄乱了我的测试。
答案1
小编典典除非您创建明确安装了firefox扩展/插件的配置文件,否则Selenium Webdriver将创建一个空白配置文件并使用该配置文件。
您能告诉我们您使用什么代码来调用FF驱动程序吗?
javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?
我将Selenium的Firefox符号暴露在ClearScript JavaScript环境中.在以下JavaScript代码中,从C#公开/导出的符号以CS为前缀.
// Preamble_Launchbrowser.js driverService = CSFirefoxDriverService.CreateDefaultService(); driverService.FirefoxBinaryPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"; driverService.HideCommandPromptwindow = true; driverService.SuppressInitialDiagnosticinformation = true; var options = new CSFirefoxOptions(); driver = new CSFirefoxDriver(driverService,options,CSTimeSpan.FromSeconds(10)); driver.Url = "http://www.google.com.au/";
目前我不支持配置文件,但想以某种方式添加它们.如何在FirefoxDriverService的上下文中指定配置文件?
解决方法
At present I have no support for profiles,but would like to add them somehow. How would I specify a profile in the context of a FirefoxDriverService?
如果我错过了这一点,请原谅我.
只需使用此命令行firefox.exe -p启动FireFox即可创建新的配置文件.
然后,当您运行javascript时,在新创建的配置文件下的FireFox中运行它.
org.openqa.selenium.firefox.FirefoxBinary的实例源码
@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,desiredCapabilities); } catch (WebDriverException ex) { LOG.warn(ex.getMessage()); awakenAllDrivers(); return openFirefoxDriver(desiredCapabilities,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,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,Capabilities capabilities) { super(new org.openqa.selenium.firefox.FirefoxDriver(binary,capabilities)); }
public FirefoxDriver(FirefoxBinary binary,Capabilities desiredCapabilities,Capabilities requiredCapabilities) { super(new org.openqa.selenium.firefox.FirefoxDriver(binary,desiredCapabilities,requiredCapabilities)); }
public AetFirefoxDriver(FirefoxBinary binary,FirefoxProfile profile) { super(binary,DesiredCapabilities.firefox()); }
public AetFirefoxDriver(FirefoxBinary binary,Capabilities capabilities) { super(binary,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()); }
我们今天的关于加载firefox后,Selenium FireFoxDriver配置文件是否更改?和firefox profile配置的分享已经告一段落,感谢您的关注,如果您想了解更多关于Firefox + Selenium WebDriver并自动下载csv文件、Firefox配置文件中的selenium禁用插件、javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?、org.openqa.selenium.firefox.FirefoxBinary的实例源码的相关信息,请在本站查询。
本文标签: