当前位置: 首页>>代码示例>>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;未经允许,请勿转载。