本文整理汇总了Java中org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption方法的典型用法代码示例。如果您正苦于以下问题:Java ChromeOptions.setExperimentalOption方法的具体用法?Java ChromeOptions.setExperimentalOption怎么用?Java ChromeOptions.setExperimentalOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.chrome.ChromeOptions
的用法示例。
在下文中一共展示了ChromeOptions.setExperimentalOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChromeDesiredCapabilities
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
private DesiredCapabilities getChromeDesiredCapabilities(Settings settings) {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//Added to avoid yellow warning in chrome 35
ChromeOptions options = new ChromeOptions();
// options.addArguments("test-type");
//For view pdf in chrome
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type", "--ignore-certificate-errors"));
if (settings.isHeadlessBrowser()) {
options.addArguments("headless");
}
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setPlatform(Platform.WINDOWS);
setAlertBehaviorCapabilities(capabilities);
setLoggingPrefs(capabilities);
setProxy(capabilities);
return capabilities;
}
示例2: setChromeOptions
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
/**
* Sets the target browser binary path in chromeOptions if it exists in configuration.
*
* @param capabilities
* The global DesiredCapabilities
*/
private void setChromeOptions(final DesiredCapabilities capabilities, ChromeOptions chromeOptions) {
// Set custom downloaded file path. When you check content of downloaded file by robot.
HashMap<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("download.default_directory", System.getProperty("user.dir") + File.separator + "downloadFiles");
chromeOptions.setExperimentalOption("prefs", chromePrefs);
// Set custom chromium (if you not use default chromium on your target device)
String targetBrowserBinaryPath = Context.getWebdriversProperties("targetBrowserBinaryPath");
if (targetBrowserBinaryPath != null && !"".equals(targetBrowserBinaryPath)) {
chromeOptions.setBinary(targetBrowserBinaryPath);
}
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
}
示例3: settingAllChromeProperties
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Test
public void settingAllChromeProperties() throws IOException {
// given
WebDriverProperties properties = new WebDriverProperties();
properties.setProperty("device", IPHONE_DEVICE);
properties.setProperty("userAgent", ANY_USER_AGENT);
properties.setProperty("viewportSize", "378x664");
properties.setProperty("pixelRatio", "3.0");
properties.setProperty("headless", "true");
// when
Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);
// then
// expected chrome options
ChromeOptions expectedChromeOptions = new ChromeOptions();
expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
Map<String, Object> expectedMobileEmulation = new HashMap<>();
Map<String, Object> expectedDeviceMetrics = new HashMap<>();
expectedDeviceMetrics.put("width", 378);
expectedDeviceMetrics.put("height", 664);
expectedDeviceMetrics.put(CAPABILITY_PIXEL_RATIO, 3.0);
expectedMobileEmulation.put("deviceMetrics", expectedDeviceMetrics);
expectedMobileEmulation.put(CAPABILITY_DEVICE_NAME, IPHONE_DEVICE);
expectedMobileEmulation.put(CAPABILITY_USER_AGENT, ANY_USER_AGENT);
expectedChromeOptions.setExperimentalOption("mobileEmulation", expectedMobileEmulation);
expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
expectedChromeOptions.addArguments("--disable-infobars");
expectedChromeOptions.addArguments("--headless", "--disable-gpu");
assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
}
示例4: notSettingDeviceMetrics
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Test
public void notSettingDeviceMetrics() throws IOException {
// given
WebDriverProperties properties = new WebDriverProperties();
properties.setProperty("device", IPHONE_DEVICE);
properties.setProperty("userAgent", ANY_USER_AGENT);
// when
Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);
// then
// expected chrome options
ChromeOptions expectedChromeOptions = new ChromeOptions();
Map<String, Object> expectedMobileEmulation = new HashMap<>();
expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
expectedMobileEmulation.put(CAPABILITY_DEVICE_NAME, IPHONE_DEVICE);
expectedMobileEmulation.put(CAPABILITY_USER_AGENT, ANY_USER_AGENT);
expectedChromeOptions.setExperimentalOption("mobileEmulation", expectedMobileEmulation);
expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
expectedChromeOptions.addArguments("--disable-infobars");
assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
}
示例5: createDriver
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
Map<String, Object> preferences = new Hashtable<>();
preferences.put("profile.default_content_settings.popups", 0);
preferences.put("download.prompt_for_download", "false");
String downloadsPath = System.getProperty("user.home") + "/Downloads";
preferences.put("download.default_directory", loadSystemPropertyOrDefault("fileDownloadPath", downloadsPath));
preferences.put("plugins.plugins_disabled", new String[]{
"Adobe Flash Player", "Chrome PDF Viewer"});
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return new ChromeDriver(capabilities);
}
示例6: initialise
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
/**
* Initialises the WebDriver (client).
*
* This method should be called once before each test to ensure that the session state doesn't bleed from one test
* to another (such as user being logged in).
*/
public void initialise() {
final ChromeOptions chromeOptions = new ChromeOptions();
final Map<String, Object> chromePrefs = new HashMap<>();
log.info("Setting WebDriver download directory to '{}'.", downloadDirectory);
chromePrefs.put("download.default_directory", downloadDirectory.toAbsolutePath().toString());
chromeOptions.setExperimentalOption("prefs", chromePrefs);
log.info("Configuring WebDriver to run in {} mode.", isHeadlessMode ? "headless" : "full, graphical");
if (isHeadlessMode) {
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("window-size=1920,1080");
}
webDriver = new RemoteWebDriver(webDriverServiceProvider.getUrl(), chromeOptions);
}
示例7: setUp
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
private ChromeDriver setUp(Properties properties) {
System.setProperty("webdriver.chrome.driver", properties.getProperty("webdriver.chrome.driver"));
String binaryPath = properties.getProperty(CHROME_DRIVER_BINARY_PATH);
if (binaryPath == null) {
throw new RuntimeException("Missing property : " + CHROME_DRIVER_BINARY_PATH);
}
Map<String, Object> prefs = new HashMap<>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.setBinary(binaryPath);
options.addArguments("--headless");
options.addArguments("--user-agent=" + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
return new ChromeDriver(options);
}
示例8: createDriver
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
public void createDriver(String pkg_name, String sn) {
if(this.driver == null) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("androidPackage", pkg_name);
// chromeOptions.setExperimentalOption("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
// chromeOptions.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
chromeOptions.setExperimentalOption("androidUseRunningApp", true);
chromeOptions.setExperimentalOption("androidDeviceSerial", sn);
// Map<String, Object> chromeOptions = new HashMap<String, Object>();
// chromeOptions.put("androidPackage", "com.eg.android.AlipayGphoneRC");
// chromeOptions.put("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
// capabilities.setCapability(CapabilityType., value);
if(ChromeService.getService() != null)
driver = new RobotRemoteWebDriver(ChromeService.getService().getUrl(), capabilities);
}
}
示例9: getCapabilities
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Override
public ChromeOptions getCapabilities() {
ChromeOptions chromeOptions = new ChromeOptions();
// useful defaults
chromeOptions.setCapability(
"chrome.switches",
singletonList("--no-default-browser-check"));
chromeOptions.setCapability(
"chrome.prefs",
ImmutableMap.of("profile.password_manager_enabled", "false"));
// Use Chrome's built in device emulators
if (Property.DEVICE.isSpecified()) {
chromeOptions.setExperimentalOption(
"mobileEmulation",
ImmutableMap.of("deviceName", Property.DEVICE.getValue()));
}
// Allow user to provide their own user directory, for custom chrome profiles
if (Property.CHROME_USER_DATA_DIR.isSpecified()) {
chromeOptions.addArguments(
"user-data-dir=" + Property.CHROME_USER_DATA_DIR.getValue());
}
chromeOptions.setHeadless(Property.HEADLESS.getBoolean());
return chromeOptions;
}
示例10: getCapability
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
public DesiredCapabilities getCapability(String testName)
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = initBaseCapabilities(capabilities, BrowserType.CHROME, testName);
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized", "--ignore-ssl-errors"));
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false);
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
if (Configuration.getBoolean(Configuration.Parameter.AUTO_DOWNLOAD))
{
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("download.prompt_for_download", false);
chromePrefs.put("download.default_directory", ReportContext.getArtifactsFolder().getAbsolutePath());
chromePrefs.put("plugins.always_open_pdf_externally", true);
options.setExperimentalOption("prefs", chromePrefs);
}
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return capabilities;
}
示例11: ChromeDesiredCapabilities
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
public ChromeDesiredCapabilities() {
super(BrowserType.ANDROID, "", Platform.ANDROID);
prefs = new HashMap<String, Object>();
options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
setCapability(ChromeOptions.CAPABILITY, options);
}
示例12: getChromeEmulatorCaps
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
private static DesiredCapabilities getChromeEmulatorCaps(DesiredCapabilities caps, String deviceName) {
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", deviceName);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
return caps;
}
示例13: getDesiredCapabilities
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
public static DesiredCapabilities getDesiredCapabilities() {
Map<String, Object> prefs = new HashMap<>();
DesiredCapabilities profile = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);
profile.setCapability("name", "chrome");
profile.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
profile.setCapability(ChromeOptions.CAPABILITY, options);
profile.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
return profile;
}
示例14: createChromeOptions
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
/**
* Create chrome options from passes locales
* @param locales comma-separated locales
* @return chrome options
*/
public static ChromeOptions createChromeOptions(String locales) {
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
if (locales !=null) {
HashMap<String, String> prefs = new HashMap<String, String>();
prefs.put("intl.accept_languages", locales);
options.setExperimentalOption("prefs", prefs);
}
return options;
}
示例15: beforeTest
import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@BeforeMethod
@Parameters({ "remoteURL", "baseURL", "OS", "browser",
"version", "internal" })
public void beforeTest(String remoteURL, String baseURL,
String OS, String browser, String version, String internal)
throws IOException {
this.testCase = new TestCase();
this.testCase.setExecutionEnvironment("{browser:"+browser+",browserVersion:"+version+",OperatingSystem:"+OS+"}");
this.testCase.setParentURL(baseURL);
this.testCase.setTestCaseId("KT"+testCaseCount++);
this.testCase.setScreenshotDirectory(log.getReportDirectory()+ File.separator + "images");
config = new WebDriverConfig();
config.setRemoteURL(remoteURL);
this.baseURL = baseURL;
config.setOS(OS);
config.setBrowserName(browser);
config.setBrowserVersion(version);
config.setIntenal(Boolean.parseBoolean(internal));
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--enable-strict-powerful-feature-restrictions");
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("profile.default_content_settings.geolocation", 2);
jsonObject.addProperty("profile.default_content_setting_values.notifications",2);
options.setExperimentalOption("prefs", jsonObject);
options.addArguments("--disable-notifications");
config.setChromeOptions(options);
driver = xRemoteWebDriver.getInstance(config, log);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(this.baseURL);
}