當前位置: 首頁>>代碼示例>>Java>>正文


Java WebDriver類代碼示例

本文整理匯總了Java中org.openqa.selenium.WebDriver的典型用法代碼示例。如果您正苦於以下問題:Java WebDriver類的具體用法?Java WebDriver怎麽用?Java WebDriver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebDriver類屬於org.openqa.selenium包,在下文中一共展示了WebDriver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFirefoxDriver

import org.openqa.selenium.WebDriver; //導入依賴的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

示例2: checkEmulators

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
private static WebDriver checkEmulators(String browserName, DesiredCapabilities caps, ProjectSettings settings,
        Boolean isGrid, String remoteUrl) {
    Emulator emulator = settings.getEmulators().getEmulator(browserName);
    if (emulator != null) {
        switch (emulator.getType()) {
            case "Duplicate":
                return create(emulator.getDriver(), caps, settings, isGrid, remoteUrl);
            case "Emulator":
                if (emulator.getDriver().equals("Chrome")) {
                    return checkAndSetSize(
                            create(emulator.getDriver(), getChromeUAECaps(caps, emulator), settings, isGrid, remoteUrl),
                            emulator.getSize());
                } else {
                    return checkAndSetSize(
                            create(emulator.getDriver(), getFFUAECaps(caps, emulator), settings, isGrid, remoteUrl),
                            emulator.getSize());
                }
            case "Chrome Emulator":
                return create("Chrome", getChromeEmulatorCaps(caps, emulator.getDriver()), settings, isGrid, remoteUrl);
            case "Remote URL": {
                return createRemoteDriver(emulator.getRemoteUrl(), caps, settings.getDriverSettings().useProxy(), settings.getDriverSettings());
            }
        }
    }
    return null;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:27,代碼來源:WebDriverFactory.java

示例3: mockElement

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
/**
 * Create mocked {@link WebElement} object.
 * 
 * @param type element type
 * @param value element value
 * @param isCheckbox 'true' is checkbox is desired; otherwise 'false'
 * @return mocked WebElement object
 */
private static WebElement mockElement(String type, String value, boolean isCheckbox) {
    WebElement element = mock(WebElement.class, withSettings().extraInterfaces(WrapsDriver.class));
    when(element.getTagName()).thenReturn(type);
    if (isCheckbox) {
        when(element.getAttribute("type")).thenReturn("checkbox");
        when(element.getAttribute("value")).thenReturn("isSelected: " + value);
        when(element.isSelected()).thenReturn(Boolean.parseBoolean(value));
    } else {
        when(element.getAttribute("type")).thenReturn("text");
        when(element.getAttribute("value")).thenReturn(value);
        when(element.isSelected()).thenReturn(false);
    }

    WebDriver driver = mockDriver();
    when(((WrapsDriver) element).getWrappedDriver()).thenReturn(driver);
    return element;
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:26,代碼來源:ComponentContainerTest.java

示例4: create

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
@Override
public WebDriver create(final Map<String, Object> options) {
  new Initialization(() -> {
    beforeInitialization(options);

    final File workDirectory = getWorkDirectory(options);
    final String expectedVersion = (String) options.get(EXPECTED_VERSION);
    final boolean forceUpdate = Boolean.parseBoolean((String) options.get(FORCE_UPDATE));
    final File webDriverExecutable =
        new DownloadWebDriverExecutable(workDirectory, getWebDriverExecutableFromWorkDirectory,
            getLatestVersion, downloadExpectedVersion).get(expectedVersion, forceUpdate);
    new SystemPropertyWebDriverExecutableSetup(systemPropertyForExecutable, webDriverExecutable)
        .setup();
    webDriver = instantiateWebDriver(options);
    new WebDriverShutdownHook(webDriver).install();

    afterInitialization(options);
  }).initialize();
  return webDriver;
}
 
開發者ID:klaushauschild1984,項目名稱:selenium-toys,代碼行數:21,代碼來源:AbstractDownloadingWebDriverFactory.java

示例5: getElements

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
private <T extends TeasyElement> List<T> getElements(By locator, Function<WebDriver, List<WebElement>> condition, TeasyElementType type) {
    List<WebElement> webElements;
    try {
        webElements = fluentWait.waitFor(condition);
    } catch (AssertionError ignoredToReturnEmptyList) {
        return new ArrayList<>();
    }
    if (webElements == null) {
        return new ArrayList<>();
    }
    if (context == null) {
        return wrapList(webElements, locator, type);
    } else {
        return wrapList(context, webElements, locator, type);
    }
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:17,代碼來源:TeasyElementFinder.java

示例6: load

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
public void load(SeleniumAction... actions){
	WebDriver driver=null;
	try {
		driver=webDriverPool.get();
		WebDriver.Options manage = driver.manage();
		manage.window().maximize();
		for(SeleniumAction action:actions){
			action.execute(driver);
		}
	} catch (InterruptedException e) {
		e.printStackTrace();
		log.error("",e);
	}finally{
		if(driver!=null){
			webDriverPool.returnToPool(driver);
		}
	}
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:19,代碼來源:WebDriverManager.java

示例7: captureScreenshot

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
/**
 * This method captures a screenshot
 **/
public static void captureScreenshot(WebDriver driver, String screenshotName) {
	try {
		TakesScreenshot ts = (TakesScreenshot) driver;
		File source = ts.getScreenshotAs(OutputType.FILE);
		FileUtils.copyFile(source, new File(dirPath + "/ " + screenshotName
				+ "_" + strDateStamp

				+ ".png"));
		String ESCAPE_PROPERTY = "org.uncommons.reportng.escape-output";
		System.setProperty(ESCAPE_PROPERTY, "false");
		URL path = new File(dirPath + "/ " + screenshotName + "_"
				+ strDateStamp + ".png").toURI().toURL();
		String test = "<a href=" + path + "> click to open screenshot of "
				+ screenshotName + "</a>";
		Reporter.log(screenshotName + test + "<br>");
		Reporter.log("<br>");
	}

	catch (Exception e) {
		System.out.println("Exception while taking screenshot "
				+ e.getMessage());
	}
}
 
開發者ID:AnujDasari,項目名稱:Actitime-Framework,代碼行數:27,代碼來源:ReportNGReport.java

示例8: isAlertPresent

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
private boolean isAlertPresent(WebDriver Driver) {
    try {
        Driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.OFF, e.getMessage(), e);
        return false;
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:10,代碼來源:CommonMethods.java

示例9: getDriverUsingIf

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
public static WebDriver getDriverUsingIf(DesiredCapabilities desiredCapabilities) {
	if (desiredCapabilities == null) {
		throw new IllegalStateException("DesiredCapabilities are missing!");
	}

	final String browser = desiredCapabilities.getBrowserName();

	if (CHROME.equalsIgnoreCase(browser)) {
		return new ChromeDriver(desiredCapabilities);
	} else if (FIREFOX.equalsIgnoreCase(browser)) {
		return new FirefoxDriver(desiredCapabilities);
	} else if (browser.isEmpty()) {
		throw new IllegalStateException("'browser' capability is missing!");
	}

	throw new IllegalArgumentException(desiredCapabilities.getBrowserName() + " browser is not supported!");
}
 
開發者ID:sskorol,項目名稱:selenium-camp-17,代碼行數:18,代碼來源:Java7WebDriverFactory.java

示例10: apply

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
@Nullable
@Override
public Boolean apply(@Nullable WebDriver webDriver) {
    List<String> actualTexts = new ArrayList<>();
    errorElements = new ArrayList<>();
    boolean isCorrect = true;
    for (TeasyElement el : elements) {
        actualTexts.add(el.getText());
        if (!text.equals(el.getText())) {
            isCorrect = false;
            errorElements.add(el);
        }
    }
    return isCorrect;
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:16,代碼來源:ElementsHaveText.java

示例11: createDriver

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
@Override
public WebDriver createDriver(final Browser browser, final XmlConfig config) {
    final RemoteWebDriver driver = mock(RemoteWebDriver.class);
    when(driver.getScreenshotAs(OutputType.BYTES)).thenReturn(new byte[]{1, 2, 3});
    doReturn(new SessionId(randomAlphanumeric(14))).when(driver).getSessionId();
    return driver;
}
 
開發者ID:sskorol,項目名稱:webdriver-supplier,代碼行數:8,代碼來源:MockWDFactory.java

示例12: getChromeDriver

import org.openqa.selenium.WebDriver; //導入依賴的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);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:12,代碼來源:SeleniumTestUtilities.java

示例13: esperaCargaPaginaNoTexto

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
static public void esperaCargaPaginaNoTexto(WebDriver driver, String texto, int timeout)
{
	Boolean resultado = 
			(new WebDriverWait(driver, timeout)).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[contains(text(),'" + texto + "')]")));

	assertTrue(resultado);	
}
 
開發者ID:Arquisoft,項目名稱:dashboard1b,代碼行數:8,代碼來源:SeleniumUtils.java

示例14: canGetArtifact

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
/**
 * Determine if the specified driver is capable of taking screenshots.
 * 
 * @param optDriver optional web driver object
 * @param logger SLF4J logger object
 * @return 'true' if driver can take screenshots; otherwise 'false
 */
public static boolean canGetArtifact(Optional<WebDriver> optDriver, Logger logger) {
    if (optDriver.isPresent()) {
        WebDriver driver = optDriver.get();
        if (driver instanceof TakesScreenshot) {
            return true;
        } else {
            String message = "This driver is not capable of taking a screenshot.  If a screenshot is desired, use"
                    + " a WebDriver implementation that supports screenshots. For more information, see https://"
                    + "seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/TakesScreenshot.html";
            logger.warn(message);
        }
    }
    return false;
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:22,代碼來源:ScreenshotUtils.java

示例15: testEventListenerWithError

import org.openqa.selenium.WebDriver; //導入依賴的package包/類
@Test
public void testEventListenerWithError() {
    WebDriver webDriver = rule.getWebDriver();
    webDriver.get("https://github.com");
    WebElement searchInput = webDriver.findElement(By.cssSelector(".header-search-input"));
    searchInput.sendKeys("will", "test");
    searchInput.sendKeys(Keys.ENTER);
    String searchKeyword = webDriver.findElement(By.cssSelector(".header-search-input")).getAttribute("value");
    assertThat(searchKeyword, is("foooooo"));
}
 
開發者ID:willhaben,項目名稱:willtest,代碼行數:11,代碼來源:EventListenerExample.java


注:本文中的org.openqa.selenium.WebDriver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。