當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。