本文整理汇总了Java中org.openqa.selenium.firefox.FirefoxProfile.addExtension方法的典型用法代码示例。如果您正苦于以下问题:Java FirefoxProfile.addExtension方法的具体用法?Java FirefoxProfile.addExtension怎么用?Java FirefoxProfile.addExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.firefox.FirefoxProfile
的用法示例。
在下文中一共展示了FirefoxProfile.addExtension方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjustFirefoxProfile
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
@Override
public void adjustFirefoxProfile(FirefoxProfile firefoxProfile) {
try {
URL adBlockerXPIResourceURL = this.getClass().getResource(ADBLOCK_XPI_RESOURCE_PATH);
if (adBlockerXPIResourceURL != null && new File(adBlockerXPIResourceURL.toURI()).exists()) {
firefoxProfile.addExtension(new File(adBlockerXPIResourceURL.getFile()));
} else {
throw new IllegalStateException("Expected a file called '" + ADBLOCK_XPI_RESOURCE_PATH +
"' in classpath root! First try a 'mvn clean install' on your maven project. " +
"If it does not help, your maven module is not correctly configured. " +
"For configuration details please read the JavaDOC of " + this.getClass().getName() + "!");
}
} catch (URISyntaxException e) {
throw new RuntimeException("Cannot install adblocker extension!", e);
}
}
示例2: setDesiredCapabilities
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
public static void setDesiredCapabilities() {
logger.info("start init Firefox profile!");
String plugin = SeleniumUtil.class.getResource("/plugin/killspinners-1.2.1-fx.xpi").getPath();
try {
profile = new FirefoxProfile();
// profile = new ProfilesIni().getProfile("default");
profile.addExtension(new File(plugin));
// 鍘绘帀css
// profile.setPreference("permissions.default.stylesheet", 2);
// 鍘绘帀鍥剧墖
// profile.setPreference("permissions.default.image", 2);
// 鍘绘帀flash
profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
capability = DesiredCapabilities.firefox();
capability.setCapability("firefox_profile", profile);
} catch (Exception e) {
logger.error("init firefox plugin(killspinnners) is error! ", e);
}
logger.info("init Firefox profile is success!");
}
示例3: addFirefoxExtensions
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
/**
* Load extensions (currently FireBug and FireCookie) .
* <p>
* Original research: http://stackoverflow.com/questions/3421793/how-do-i-run-firebug-within-selenium-2
*/
private void addFirefoxExtensions(FirefoxProfile profile) {
try {
File extDir = new ClassPathResource("selenium/firefox/extensions").getFile();
// get all .xpi files from extensions directory recursively
Collection<File> extFiles = FileUtils.listFiles(extDir, new String[]{"xpi"}, true);
for (File extFile : extFiles) {
profile.addExtension(extFile);
}
} catch (IOException e) {
throw new FailureException("Unable to load Firefox extensions", e);
}
/*
* Hack to prevent FireBug from opening its Release Notes tab breaking our tests. With this property set it
* will only open that tab when FireBug version 301 is released. :-)
*/
profile.setPreference("extensions.firebug.currentVersion", "300");
if (enableFirebugDebugTabs()) {
// Firebug properties from http://getfirebug.com/wiki/index.php/Firebug_Preferences
profile.setPreference("extensions.firebug.script.enableSites", "true");
profile.setPreference("extensions.firebug.console.enableSites", "true");
}
}
示例4: createFirefoxBrowser
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
private void createFirefoxBrowser(DesiredCapabilities capabilities) throws MalformedURLException {
FirefoxProfile profile = new FirefoxProfile();
// This flag avoids granting the access to the camera
profile.setPreference("media.navigator.permission.disabled", true);
// This flag force to use fake user media (synthetic video of multiple color)
profile.setPreference("media.navigator.streams.fake", true);
// This allows to load pages with self-signed certificates
capabilities.setCapability("acceptInsecureCerts", true);
profile.setAcceptUntrustedCertificates(true);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
// Firefox extensions
if (extensions != null && !extensions.isEmpty()) {
for (Map<String, String> extension : extensions) {
InputStream is = getExtensionAsInputStream(extension.values().iterator().next());
if (is != null) {
try {
File xpi = File.createTempFile(extension.keySet().iterator().next(), ".xpi");
FileUtils.copyInputStreamToFile(is, xpi);
profile.addExtension(xpi);
} catch (Throwable t) {
log.error("Error loading Firefox extension {} ({} : {})", extension, t.getClass(),
t.getMessage());
}
}
}
}
createDriver(capabilities, profile);
}
示例5: getFirefoxProfile
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
private static FirefoxProfile getFirefoxProfile(final String username, final String password) {
FirefoxProfile ffProfile = new FirefoxProfile();
// Authenication Hack for Firefox
if (username != null && password != null) {
ffProfile.setPreference("network.http.phishy-userpass-length", 255);
}
String useProxy = SeleniumProperties.getProperty(SeleniumProperties.ENVIROMENT_USEPROXY);
if (useProxy != null && useProxy.equals("true")) {
int proxyType = new Integer(SeleniumProperties.getProperty(SeleniumProperties.NETWORK_PROXY_TYPE)).intValue();
String proxyHttp = SeleniumProperties.getProperty(SeleniumProperties.NETWORK_PROXY_HTTP);
int proxyPort = new Integer(SeleniumProperties.getProperty(SeleniumProperties.NETWORK_PROXY_HTTP_PORT)).intValue();
String ssl = SeleniumProperties.getProperty(SeleniumProperties.NETWORK_PROXY_SSL);
int sslPort = new Integer(SeleniumProperties.getProperty(SeleniumProperties.NETWORK_PROXY_SSL_PORT)).intValue();
ffProfile.setPreference("network.proxy.type", proxyType);
ffProfile.setPreference("network.proxy.http", proxyHttp);
ffProfile.setPreference("network.proxy.http_port", proxyPort);
ffProfile.setPreference("network.proxy.ssl", ssl);
ffProfile.setPreference("network.proxy.ssl_port", sslPort);
}
ffProfile.setPreference("browser.download.folderList", 2);
ffProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/plain");
ffProfile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
try {
ffProfile.addExtension(new File(baseDriverPath + "/firebug-2.0.4.xpi"));
}
catch (IOException e) {
// Add-On geht nicht, das ist aber doof .. trotzdem nicht schlimm
System.err.println("Firebug-Plugin konnte nicht geladen werden. Mache weiter ...");
}
return ffProfile;
}
示例6: getFireFoxProfile
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
/**
* Méthode getFireFoxProfile.
* @return
* @throws UtilitaireException
*/
private static FirefoxProfile getFireFoxProfile() throws UtilitaireException {
FirefoxProfile profile = new FirefoxProfile();
boolean extensions = Boolean.valueOf(PropsUtils.getProperties().getProperty(Saladium.EXTENSION_AVAILABLE, "false"));
if (extensions) {
profile.addExtension(new File(PropsUtils.getProperties().getProperty(Saladium.EXTENSION_FIREBUG)));
profile.addExtension(new File(PropsUtils.getProperties().getProperty(Saladium.EXTENSION_WEBDEVELOPER)));
}
String prop = PropsUtils.getProperties().getProperty(Saladium.DOWNLOAD_DIR);
if (prop != null && !prop.isEmpty()) {
// crée le répertoire s'il n'existe pas
StringBuilder filePath = new StringBuilder(
PropsUtils.getProperties().getProperty(Saladium.DOWNLOAD_DIR));
File directory = new File(filePath.toString());
if (!directory.exists()) {
try {
FileUtils.forceMkdir(directory);
} catch (IOException e) {
throw new UtilitaireException("Impossible de créer le répertoire " + filePath, e);
}
}
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", PropsUtils.getProperties().getProperty(Saladium.DOWNLOAD_DIR));
profile.setPreference("browser.download.defaultFolder", PropsUtils.getProperties().getProperty(Saladium.DOWNLOAD_DIR));
profile.setPreference("browser.download.lastDir", PropsUtils.getProperties().getProperty(Saladium.DOWNLOAD_DIR));
profile.setPreference("browser.download.panel.shown", false);
profile.setPreference("browser.download.alertOnEXEOpen", false);
// profile.setPreference("network.proxy.autoconfig_url", "");
// profile.setPreference("browser.download.show_plugins_in_list", false);
profile
.setPreference(
"browser.helperApps.neverAsk.openFile",
"application/octet-stream;application/csv;text/csv;application/pdf;image/png;image/jpeg;text/plain;application/x-msexcel;application/excel;application/x-excel;application/excel;application/x-excel;application/excel;application/vnd.ms-excel;application/x-excel;application/x-msexcel");
profile
.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/octet-stream;application/csv;text/csv;application/pdf;image/png;image/jpeg;text/plain;application/x-msexcel;application/excel;application/x-excel;application/excel;application/x-excel;application/excel;application/vnd.ms-excel;application/x-excel;application/x-msexcel");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
}
// profile.setPreference("extensions.xpiState", "");
// firefoxProfile.setPreference("browser.private.browsing.autostart",true);
// firefoxProfile.setEnableNativeEvents(true);
return profile;
}
示例7: getOptions
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
@Override
public MutableCapabilities getOptions(Parameter parameter,
Optional<Object> testInstance)
throws IOException, IllegalAccessException {
FirefoxOptions firefoxOptions = new FirefoxOptions();
// @Arguments
Arguments arguments = parameter.getAnnotation(Arguments.class);
if (arguments != null) {
stream(arguments.value()).forEach(firefoxOptions::addArguments);
}
// @Extensions
Extensions extensions = parameter.getAnnotation(Extensions.class);
if (extensions != null) {
for (String extension : extensions.value()) {
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(getExtension(extension));
firefoxOptions.setProfile(firefoxProfile);
}
}
// @Binary
Binary binary = parameter.getAnnotation(Binary.class);
if (binary != null) {
firefoxOptions.setBinary(binary.value());
}
// @Preferences
managePreferences(parameter, firefoxOptions);
// @Options
Object optionsFromAnnotatedField = annotationsReader
.getOptionsFromAnnotatedField(testInstance, Options.class);
if (optionsFromAnnotatedField != null) {
firefoxOptions = ((FirefoxOptions) optionsFromAnnotatedField)
.merge(firefoxOptions);
}
return firefoxOptions;
}
示例8: getWebDriver
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
public static WebDriver getWebDriver() {
if (INSTANCE == null || hasQuit(INSTANCE) || INSTANCE.getWindowHandles().isEmpty()) {
// create chrome profile
//ChromeOptions options = new ChromeOptions();
//options.addExtensions(new File("adblock.crx"));
FirefoxProfile profile = new FirefoxProfile();
// install adblock plus
File tmpFile = new File("adblock.xpi");
try {
InputStream inputStream = SeleniumBrowser.class.getResourceAsStream("/adblock_firefox.xpi");
FileUtils.copyInputStreamToFile(inputStream, tmpFile);
profile.addExtension(tmpFile);
} catch (IOException ex) {
Logger.getLogger(EvaluationGui.class.getName()).log(Level.SEVERE, null, ex);
}
// disable local and session storage
// some websites (e.g. stackoverflow) use those storages in addition
// to session cookies
profile.setPreference("dom.storage.enabled", false);
// start new Firefox instance
INSTANCE = new FirefoxDriver(profile);
// screen size
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
width = width > 1440 ? 1440 : width;
height = height > 900 ? 900 : height;
INSTANCE.manage().window().setPosition(new Point(0,0));
INSTANCE.manage().window().setSize(new Dimension(width, height));
tmpFile.delete();
}
return INSTANCE;
}
示例9: addExtension
import org.openqa.selenium.firefox.FirefoxProfile; //导入方法依赖的package包/类
/**
* Adds the Firefox extension collecting JS errors to the profile what allows later use of {@link #readErrors(WebDriver)}.
* <p>
* Example:<br>
* <pre><code>
* final FirefoxProfile profile = new FirefoxProfile();
* JavaScriptError.addExtension(profile);
* final WebDriver driver = new FirefoxDriver(profile);
* </code></pre>
* @param ffProfile the Firefox profile to which the extension should be added.
* @throws IOException in case of problem
*/
public static void addExtension(final FirefoxProfile ffProfile) throws IOException {
ffProfile.addExtension(JavaScriptError.class, "JSErrorCollector.xpi");
}