本文整理汇总了Java中org.openqa.selenium.remote.DesiredCapabilities.chrome方法的典型用法代码示例。如果您正苦于以下问题:Java DesiredCapabilities.chrome方法的具体用法?Java DesiredCapabilities.chrome怎么用?Java DesiredCapabilities.chrome使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.remote.DesiredCapabilities
的用法示例。
在下文中一共展示了DesiredCapabilities.chrome方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的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);
}
示例2: newDriverForTest
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
private WebDriver newDriverForTest() {
ChromeOptions theOptions = new ChromeOptions();
theOptions.addArguments("headless");
theOptions.addArguments("disable-gpu");
LoggingPreferences theLoggingPreferences = new LoggingPreferences();
theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);
DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);
return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
示例3: createDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
/**
* Создание instance google chrome эмулирующего работу на мобильном устройстве (по умолчанию nexus 5)
* Мобильное устройство может быть задано через системные переменные
*
* @param capabilities настройки Chrome браузера
* @return возвращает новый instance Chrome драйера
*/
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
log.info("---------------run CustomMobileDriver---------------------");
String mobileDeviceName = loadSystemPropertyOrDefault("device", "Nexus 5");
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", mobileDeviceName);
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
desiredCapabilities.setBrowserName(desiredCapabilities.chrome().getBrowserName());
return new ChromeDriver(desiredCapabilities);
}
示例4: testDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
@Test
public void testDriver() throws IOException {
WebDriver driver = new RemoteWebDriver(toUrl("http://localhost:9515"), DesiredCapabilities.chrome());
driver.get(URL2);
String response = driver.getPageSource();
Document doc = Jsoup.connect(URL2).ignoreContentType(true).get();
Elements scriptTags = doc.select("body");
// get All functions
try {
String result = (String) engine.eval(response);
} catch (ScriptException e) {
e.printStackTrace();
}
log.info("PageSource " + response);
driver.quit();
}
示例5: getWebDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
@Override
public WebDriver getWebDriver()
{
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.2.27");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
return new ChromeDriver(capabilities);
}
示例6: generateGoogleChromeDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
/**
* Generates a chrome webdriver.
*
* @param headlessMode
* Enable headless mode ?
* @return
* A chrome webdriver
* @throws TechnicalException
* if an error occured when Webdriver setExecutable to true.
*/
private WebDriver generateGoogleChromeDriver(boolean headlessMode) throws TechnicalException {
final String pathWebdriver = DriverFactory.getPath(Driver.CHROME);
if (!new File(pathWebdriver).setExecutable(true)) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
}
logger.info("Generating Chrome driver ({}) ...", pathWebdriver);
System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);
final ChromeOptions chromeOptions = new ChromeOptions();
final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
setLoggingLevel(capabilities);
if (Context.isHeadless()) {
chromeOptions.addArguments("--headless");
}
// Proxy configuration
if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
}
setChromeOptions(capabilities, chromeOptions);
String withWhitelistedIps = Context.getWebdriversProperties("withWhitelistedIps");
if (withWhitelistedIps != null && !"".equals(withWhitelistedIps)) {
ChromeDriverService service = new ChromeDriverService.Builder().withWhitelistedIps(withWhitelistedIps).withVerbose(false).build();
return new ChromeDriver(service, capabilities);
} else {
return new ChromeDriver(capabilities);
}
}
示例7: createBrowserSession
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
private static WebDriver createBrowserSession() throws MalformedURLException {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setJavascriptEnabled(true);
LoggingPreferences logPreferences = new LoggingPreferences();
logPreferences.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPreferences);
return new RemoteWebDriver(
new URL("http://" + runtime.getContainer("selenium-chrome").getIp() + ":4444/wd/hub"),
capabilities
);
}
示例8: capabilitiesAndroid
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
private static DesiredCapabilities capabilitiesAndroid() {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Google Nexus 5");
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
return capabilities;
}
示例9: capabilitiesiPhone
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
private static DesiredCapabilities capabilitiesiPhone() {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Apple iPhone 6");
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
return capabilities;
}
示例10: capabilitiesiPad
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
private static DesiredCapabilities capabilitiesiPad() {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Apple iPad");
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
return capabilities;
}
示例11: DebateFetcher
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
public DebateFetcher(String chromeDriverFile)
throws IOException
{
service = new ChromeDriverService.Builder()
.usingDriverExecutable(
new File(chromeDriverFile))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY", ":20")).build();
service.start();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
driver = new RemoteWebDriver(service.getUrl(), capabilities);
}
示例12: initChromeDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
private WebDriver initChromeDriver(String appURL) {
System.out.println("Launching google chrome with new profile..");
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome () ;
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
ChromeDriver driver = new ChromeDriver(handlSSLErr);
driver.manage().window().maximize();
driver.navigate().to(appURL);
return new WebDriverProxy().protect(driver);
}
示例13: getChromeDriver
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
public static WebDriver getChromeDriver()
{
String path = "src/test/resources/chromedriver";
System.setProperty("webdriver.chrome.driver", path);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("networkConnectionEnabled", true);
capabilities.setCapability("browserConnectionEnabled", true);
return new ChromeDriver(capabilities);
}
示例14: chrome
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
public Builder chrome() {
this.browserCaps = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("'--start-maximized", "--window-size=1360,1020");
this.browserCaps.setCapability(ChromeOptions.CAPABILITY, options);
this.browserCaps.setCapability("enableVNC", true);
return this;
}
示例15: setUp
import org.openqa.selenium.remote.DesiredCapabilities; //导入方法依赖的package包/类
@BeforeTest
public void setUp() throws MalformedURLException {
driver = new RemoteWebDriver(new URL("http://localhost:9515"), DesiredCapabilities.chrome());
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}