当前位置: 首页>>代码示例>>Java>>正文


Java DesiredCapabilities类代码示例

本文整理汇总了Java中org.openqa.selenium.remote.DesiredCapabilities的典型用法代码示例。如果您正苦于以下问题:Java DesiredCapabilities类的具体用法?Java DesiredCapabilities怎么用?Java DesiredCapabilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DesiredCapabilities类属于org.openqa.selenium.remote包,在下文中一共展示了DesiredCapabilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setChromeOptions

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的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);
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:22,代码来源:DriverFactory.java

示例2: startApp

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
@Before
public void startApp() throws Exception {
	DesiredCapabilities capabilities = new DesiredCapabilities();

	Map<String, Object> baseState = new HashMap<>();
	baseState.put("type", "NATIVE");
	baseState.put("executable", APP);
	baseState.put("locator", "//Window");

	capabilities.setCapability("appdriver-basestate", baseState);

	Map<String, Object> options = new HashMap<>();
	options.put("closeOnQuit", true);

	capabilities.setCapability("appdriver-options", options);

	driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
}
 
开发者ID:MicroFocus,项目名称:SilkAppDriver,代码行数:19,代码来源:MultiWindowTests.java

示例3: getFirefoxDriver

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
public static WebDriver getFirefoxDriver()
            throws Exception
	{
        baseDir = new File(".").getPath();
        System.out.println("******** " + baseDir);

        String path = "src/test/resources/geckodriver";
        System.out.println("******** " + path);
		System.setProperty("webdriver.gecko.driver", path);

        DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
		capabilities.setCapability("marionette", true);
        capabilities.setCapability("networkConnectionEnabled", true);
        capabilities.setCapability("browserConnectionEnabled", true);


        WebDriver driver = new RemoteWebDriver(
                new URL("http://localhost:4444"),
                capabilities);

//		WebDriver driver = new MarionetteDriver(capabilities);

		return driver;
	}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:25,代码来源:SeleniumTestUtilities.java

示例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();
}
 
开发者ID:robevansuk,项目名称:delay-repay-bot,代码行数:23,代码来源:PhantomJSTest.java

示例5: runSequentialIndex

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
/**
 * Run a capability.
 */
private void runSequentialIndex(final WebDriver[] drivers, final boolean[] success, final int driverIndex, final DesiredCapabilities capability) {
	AbstractSequentialSeleniumTest seleniumTest = this;
	try {
		final WebDriver driver = getRemoteDriver(capability);
		drivers[driverIndex] = driver;
		seleniumTest = this.getClass().newInstance();
		cloneAndRun(seleniumTest, driver, capability);
		success[driverIndex] = true;
	} catch (final Exception e) {
		log.error("Unable to build the driver for requested capability, other tests are not interrupted : " + capability, e);
	} finally {
		cleanup();
		seleniumTest.cleanup();
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:19,代码来源:AbstractSequentialSeleniumTest.java

示例6: setUp

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
@Before
  public void setUp() throws Exception {
      File classpathRoot = new File(System.getProperty("user.dir"));
      File appDir = new File(classpathRoot, "/apps/");
      File app = new File(appDir.getCanonicalPath(), "Financius.v0.18.2.apk");
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("deviceName", ""); // device UID from adb
capabilities.setCapability("platformVersion", "6.0.1"); // android version
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.code44.finance"); // package name
capabilities.setCapability("appWaitActivity", "com.code44.finance.*"); // default activity

capabilities.setCapability("no-reset", "true"); 
capabilities.setCapability("full-reset", "false"); 
      driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  
  }
 
开发者ID:ark-konopacki,项目名称:appium_tutorial,代码行数:19,代码来源:BaseDriver.java

示例7: clickWithNativeEvents

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
public void clickWithNativeEvents() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(new JavaProfile(), caps, caps);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    element1.click();
    AssertJUnit.assertTrue(buttonClicked);
    buttonClicked = false;
    new Actions(driver).click().perform();
    AssertJUnit.assertTrue(buttonClicked);
    AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
    buttonMouseActions.setLength(0);
    new Actions(driver).contextClick().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)")
            || buttonMouseActions.toString().contains("released(3-popup)"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:JavaDriverTest.java

示例8: createRemoteDriver

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
private static WebDriver createRemoteDriver(String url, DesiredCapabilities caps, Boolean checkForProxy,
        Properties props) {
    try {
        if (isAppiumNative(url, caps.asMap())) {
            if (isAndroidNative(caps.asMap())) {
                return new io.appium.java_client.android.AndroidDriver(new URL(url), caps);
            } else if (isIOSNative(caps.asMap())) {
                return new io.appium.java_client.ios.IOSDriver(new URL(url), caps);
            }
        }
        if (url == null) {
            return new RemoteWebDriver(caps);
        }
        if (checkForProxy) {
            return new RemoteWebDriver(RemoteProxy.getProxyExecutor(new URL(url), props), caps);
        }
        return new RemoteWebDriver(new URL(url), caps);
    } catch (MalformedURLException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return null;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:23,代码来源:WebDriverFactory.java

示例9: dndWithCopy

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:DragAndDropTest.java

示例10: prepareThreads

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
/**
 * Prepare the thread instances.
 */
private Thread[] prepareThreads(final WebDriver[] drivers, final boolean[] success) { // NOPMD
	final Thread[] threads = new Thread[repeatedCapabilities.length]; // NOPMD -- thread
	for (int index = 0; index < repeatedCapabilities.length; index++) {
		final int driverIndex = index;
		final DesiredCapabilities capability = repeatedCapabilities[driverIndex];
		success[driverIndex] = false;
		try {
			final WebDriver driver = getRemoteDriver(capability);
			drivers[driverIndex] = driver;
			threads[driverIndex] = prepareThread(driver, driverIndex, success, capability);
		} catch (final Exception e) {
			log.error("Unable to connect the remote web driver, other tests are not interrupted : " + capability, e);
		} finally {
			cleanup();
		}
	}
	return threads;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:AbstractParallelSeleniumTest.java

示例11: 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);
}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:15,代码来源:BytecoderUnitTestRunner.java

示例12: generateHtmlUnitDriver

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
/**
 * Generates a htmlunit webdriver.
 *
 * @return
 *         A htmlunit webdriver
 */
private WebDriver generateHtmlUnitDriver() {
    logger.info("Generating HtmlUnit driver...");
    final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }
    return new HtmlUnitDriver(capabilities);
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:22,代码来源:DriverFactory.java

示例13: getCapabilities

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
public Capabilities getCapabilities() throws IOException {
  String capabilitiesFile = properties.getProperty("capabilities");

  Properties capsProps = new Properties();
  capsProps.load(SuiteConfiguration.class.getResourceAsStream(capabilitiesFile));

  DesiredCapabilities capabilities = new DesiredCapabilities();
  for (String name : capsProps.stringPropertyNames()) {
    String value = capsProps.getProperty(name);
    if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
      capabilities.setCapability(name, Boolean.valueOf(value));
    } else if (value.startsWith("file:")) {
      capabilities.setCapability(name, new File(".", value.substring(5)).getCanonicalFile().getAbsolutePath());
    } else {
      capabilities.setCapability(name, value);
    }
  }

  return capabilities;
}
 
开发者ID:barancev,项目名称:webdriver-junit5-archetype,代码行数:21,代码来源:SuiteConfiguration.java

示例14: get32IEDriver

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
public static WebDriver get32IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer32.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:9,代码来源:SeleniumTestUtilities.java

示例15: createIOSSafariDriver

import org.openqa.selenium.remote.DesiredCapabilities; //导入依赖的package包/类
/**
 * 启动ios的safari浏览器
 * 
 * @param noReset
 */
private void createIOSSafariDriver(Boolean noReset) {

	capabilities = new DesiredCapabilities();

	capabilities.setCapability("platformName", property.getProperty("platformName"));
	capabilities.setCapability("platformVersion", property.getProperty("platformVersion"));
	capabilities.setCapability("deviceName", property.getProperty("deviceName"));
	capabilities.setCapability("browserName", property.getProperty("browserName", "Safari"));
	capabilities.setCapability("autoAcceptAlerts", property.getProperty("autoAcceptAlerts", "True"));
	// debug时,等待时间调大点!!
	capabilities.setCapability("newCommandTimeout", property.getProperty("newCommandTimeout"));
	capabilities.setCapability("noReset", noReset); // 不卸载、不重装
	capabilities.setCapability("noSign", "true");
	// 重置输入法,并且设置可以中文输入
	capabilities.setCapability("unicodeKeyboard", "True");
	capabilities.setCapability("resetKeyboard", "True");

	try {
		driver = new IOSDriver<MobileElement>(new URL(property.getProperty("remote.address")), capabilities);
	} catch (Exception e) {
		e.printStackTrace();
		AssertUtil.fail("初始化对象失败,e = " + e.getMessage());
	}
}
 
开发者ID:quanqinle,项目名称:WebAndAppUITesting,代码行数:30,代码来源:DriverFactory.java


注:本文中的org.openqa.selenium.remote.DesiredCapabilities类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。