Java 类org.openqa.selenium.remote.RemoteWebDriver 实例源码

项目:Spring-Security-Third-Edition    文件:SeleniumTestUtilities.java   
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;
    }
项目:selenium-testng-template    文件:DownloadUtils.java   
public static final String download(RemoteWebDriver driver, String url) {
    String folder = DOWNLOAD_PATH + RandomStringUtils.randomAlphabetic(10);
    new File(folder).mkdirs();

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Cookie", getCookie(driver));
    byte[] data = HttpUtils.get(url, headers);
    try {
        String filename;
        String contentDisposition = headers.get("Content-Disposition");
        if (StringUtils.contains(contentDisposition, "=")) {
            filename = contentDisposition.substring(contentDisposition.indexOf("=") + 1);
        } else {
            filename = new URL(url).getPath();
            if (filename.contains("/")) {
                filename = filename.substring(filename.lastIndexOf("/") + 1);
            }
        }
        IOUtils.write(data, new FileOutputStream(folder + "/" + filename));
        return folder + "/" + filename;
    } catch (Exception e) {
        throw new RuntimeException("Download failed!", e);
    }
}
项目:delay-repay-bot    文件:PhantomJSTest.java   
@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();
}
项目:webdriver-supplier    文件:CoreTests.java   
@Test
public void shouldCreateRemoteDriverInstance() throws MalformedURLException {
    XmlConfig config = new XmlConfig(new HashMap<String, String>() {
        {
            put(BROWSER_NAME, "firefox");
            put(PLATFORM_NAME, "ANY");
            put(TEST_NAME, "shouldCreateRemoteDriverInstance");
        }
    });

    WebDriver driver = mock(RemoteWebDriver.class, RETURNS_DEEP_STUBS);
    WebDriverProvider spyFactory = spy(defaultFactory);
    Reflect spyReflectedDriver = spy(spyFactory.wrapDriver(firefox));

    doReturn(spyReflectedDriver).when(spyFactory).wrapDriver(firefox);
    doReturn(on(driver)).when(spyReflectedDriver).create(new URL(firefox.url()), firefox.configuration(config));

    assertThat(spyFactory.createDriver(firefox, config)).isInstanceOf(RemoteWebDriver.class);
}
项目:SilkAppDriver    文件:MultiWindowTests.java   
@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);
}
项目:SilkAppDriver    文件:WpfSampleAppTests.java   
@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", "//WPFWindow");

    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);
}
项目:Spring-Security-Third-Edition    文件:SeleniumTestUtilities.java   
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;
    }
项目:tdd-pingpong    文件:PageObject.java   
protected PageObject(RemoteWebDriver driver, String title, String urlTail) {
  this.driver = driver;
  this.title = title;
  this.urlRoot = "http://localhost:8080";
  this.urlTail = urlTail;
  this.url = urlRoot + urlTail;

  String message = String.format(
      "Expected to be on page with"
      + "title containing %s and"
      + "url containing %s but"
      + "title was %s and"
      + "url was %s",
          title, url, driver.getTitle(), driver.getCurrentUrl());
  assertTrue(message, isCurrentPage());
}
项目:Spring-Security-Third-Edition    文件:SeleniumTestUtilities.java   
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;
    }
项目:Cognizant-Intelligent-Test-Scripter    文件:WebDriverFactory.java   
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;
}
项目:mpay24-java    文件:TestToken.java   
@Test
public void testTokenPaymentWithout3DS() throws ParseException, PaymentException, InterruptedException {
    Token token = mpay24.token(getTestTokenRequest(null));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("0520");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    TimeUnit.SECONDS.sleep(1l);

    Payment response = mpay24.payment(getTestPaymentRequest(), getTokenPaymentType(token.getToken()));

    assertEquals("OK", response.getReturnCode());
    assertNotNull(response.getmPayTid());
}
项目:mpay24-java    文件:TestPaymentPanel.java   
@Test
public void testShoppingCartAmounts() throws PaymentException {
    Payment response = mpay24.paymentPage(getTestPaymentRequest(120.0, null), getTestShoppingCart());
    assertSuccessfullResponse(response);
    RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
    WebElement element = driver.findElementById("cart");
    assertEquals("Rabatt:", element.findElement(By.xpath("tfoot/tr[1]/th")).getText());
    assertEquals("-10,00", element.findElement(By.xpath("tfoot/tr[1]/td")).getText());

    assertEquals("Versandkosten:", element.findElement(By.xpath("tfoot/tr[2]/th")).getText());
    assertEquals("-5,00", element.findElement(By.xpath("tfoot/tr[2]/td")).getText());

    assertEquals("Zwischensumme:", element.findElement(By.xpath("tfoot/tr[3]/th")).getText());
    assertEquals("100,00", element.findElement(By.xpath("tfoot/tr[3]/td")).getText());

    assertEquals("20.00% USt.:", element.findElement(By.xpath("tfoot/tr[4]/th")).getText());
    assertEquals("20,00", element.findElement(By.xpath("tfoot/tr[4]/td")).getText());

    assertEquals("Gesamtpreis:", element.findElement(By.xpath("tfoot/tr[5]/th")).getText());
    assertEquals("EUR 120,00", element.findElement(By.xpath("tfoot/tr[5]/td")).getText());

}
项目:mpay24-java    文件:TestPaymentPanel.java   
@Test
public void testLanguageEnglish() throws PaymentException {
    Payment response = mpay24.paymentPage(getTestPaymentRequest(1.0, null, Language.EN), getTestShoppingCart(getTestShoppingCartItemList()));
    assertSuccessfullResponse(response);

    RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
    WebElement element = driver.findElementById("cart");
    assertEquals("No.", element.findElement(By.xpath("thead/tr[1]/th[1]")).getText());
    assertEquals("Prod. No.", element.findElement(By.xpath("thead/tr[1]/th[2]")).getText());
    assertEquals("Product Name", element.findElement(By.xpath("thead/tr[1]/th[3]")).getText());
    assertEquals("Amount ordered", element.findElement(By.xpath("thead/tr[1]/th[4]")).getText());
    assertEquals("Price/Item", element.findElement(By.xpath("thead/tr[1]/th[5]")).getText());
    assertEquals("Total", element.findElement(By.xpath("thead/tr[1]/th[6]")).getText());
    assertEquals("Discount:", element.findElement(By.xpath("tfoot/tr[1]/th")).getText());
    assertEquals("Shipping Costs:", element.findElement(By.xpath("tfoot/tr[2]/th")).getText());
    assertEquals("Subtotal:", element.findElement(By.xpath("tfoot/tr[3]/th")).getText());
    assertEquals("Order Total:", element.findElement(By.xpath("tfoot/tr[5]/th")).getText());
}
项目:mpay24-java    文件:TestPaymentPanel.java   
@Test
public void testShippingAddress() throws PaymentException {
    Payment response = mpay24.paymentPage(getTestPaymentRequest(), getCustomerWithAddress(null));
    assertSuccessfullResponse(response);

    RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
    driver.findElement(By.name("selCC|VISA")).click();
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.elementToBeClickable(By.id("cardnumber"))); 
    assertEquals("Testperson-de Approved", driver.findElement(By.name("BillingAddr/Name")).getAttribute("value"));
    assertEquals("Hellersbergstraße 14", driver.findElement(By.name("BillingAddr/Street")).getAttribute("value"));
    assertNotExistent(driver, By.name("BillingAddr/Street2"));
    assertEquals("41460", driver.findElement(By.name("BillingAddr/Zip")).getAttribute("value"));
    assertEquals("Neuss", driver.findElement(By.name("BillingAddr/City")).getAttribute("value"));
    assertEquals("Ankeborg", driver.findElement(By.name("BillingAddr/State")).getAttribute("value"));
    assertEquals("Deutschland", driver.findElement(By.name("BillingAddr/Country/@Code")).findElement(By.xpath("option[@selected='']")).getText());
}
项目:mpay24-java    文件:TestPaymentPanel.java   
@Test
public void testShippingAddressWithStreet2() throws PaymentException {
    Payment response = mpay24.paymentPage(getTestPaymentRequest(), getCustomerWithAddress("Coconut 3"));
    assertSuccessfullResponse(response);

    RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
    driver.findElement(By.name("selPAYPAL|PAYPAL")).click();
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.elementToBeClickable(By.name("BillingAddr/Street"))); 
    assertEquals("Testperson-de Approved", driver.findElement(By.name("BillingAddr/Name")).getAttribute("value"));
    assertEquals("Hellersbergstraße 14", driver.findElement(By.name("BillingAddr/Street")).getAttribute("value"));
    assertEquals("Coconut 3", driver.findElement(By.name("BillingAddr/Street2")).getAttribute("value"));
    assertEquals("41460", driver.findElement(By.name("BillingAddr/Zip")).getAttribute("value"));
    assertEquals("Neuss", driver.findElement(By.name("BillingAddr/City")).getAttribute("value"));
    assertEquals("Ankeborg", driver.findElement(By.name("BillingAddr/State")).getAttribute("value"));
    assertEquals("Deutschland", driver.findElement(By.name("BillingAddr/Country/@Code")).findElement(By.xpath("option[@selected='']")).getText());
}
项目:selenium-jupiter    文件:SeleniumExtension.java   
public SeleniumExtension() {
    handlerMap.put(ChromeDriver.class, ChromeDriverHandler.class);
    handlerMap.put(FirefoxDriver.class, FirefoxDriverHandler.class);
    handlerMap.put(EdgeDriver.class, EdgeDriverHandler.class);
    handlerMap.put(OperaDriver.class, OperaDriverHandler.class);
    handlerMap.put(SafariDriver.class, SafariDriverHandler.class);
    handlerMap.put(RemoteWebDriver.class, RemoteDriverHandler.class);
    handlerMap.put(AppiumDriver.class, AppiumDriverHandler.class);
    handlerMap.put(List.class, ListDriverHandler.class);
    handlerMap.put(PhantomJSDriver.class, OtherDriverHandler.class);

    templateHandlerMap.put("chrome", ChromeDriver.class);
    templateHandlerMap.put("firefox", FirefoxDriver.class);
    templateHandlerMap.put("edge", EdgeDriver.class);
    templateHandlerMap.put("opera", OperaDriver.class);
    templateHandlerMap.put("safari", SafariDriver.class);
    templateHandlerMap.put("appium", AppiumDriver.class);
    templateHandlerMap.put("phantomjs", PhantomJSDriver.class);
    templateHandlerMap.put("chrome-in-docker", RemoteWebDriver.class);
    templateHandlerMap.put("firefox-in-docker", RemoteWebDriver.class);
    templateHandlerMap.put("opera-in-docker", RemoteWebDriver.class);
}
项目:hippo    文件:WebDriverProvider.java   
/**
 * Initialises the WebDriver (client).
 *
 * This method should be called once before each test to ensure that the session state doesn't bleed from one test
 * to another (such as user being logged in).
 */
public void initialise() {

    final ChromeOptions chromeOptions = new ChromeOptions();

    final Map<String, Object> chromePrefs = new HashMap<>();
    log.info("Setting WebDriver download directory to '{}'.", downloadDirectory);
    chromePrefs.put("download.default_directory", downloadDirectory.toAbsolutePath().toString());

    chromeOptions.setExperimentalOption("prefs", chromePrefs);
    log.info("Configuring WebDriver to run in {} mode.", isHeadlessMode ? "headless" : "full, graphical");
    if (isHeadlessMode) {
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("window-size=1920,1080");
    }

    webDriver = new RemoteWebDriver(webDriverServiceProvider.getUrl(), chromeOptions);
}
项目:teasy    文件:BaseTeasyElement.java   
@Override
public <X> X getScreenshotAs(OutputType<X> target) {
    if (getWebDriver().getClass() == RemoteWebDriver.class) {
        WebDriver augmentedDriver = new Augmenter().augment(getWebDriver());
        return ((TakesScreenshot) augmentedDriver).getScreenshotAs(target);
    } else {
        return ((TakesScreenshot) getWebDriver()).getScreenshotAs(target);
    }
}
项目:teasy    文件:WebDriverDecorator.java   
@Override
public <X> X getScreenshotAs(final OutputType<X> target) throws WebDriverException {
    if (driver.getClass() == RemoteWebDriver.class) {
        WebDriver augmentedDriver = new Augmenter().augment(driver);
        return ((TakesScreenshot) augmentedDriver).getScreenshotAs(target);
    } else {
        return ((TakesScreenshot) driver).getScreenshotAs(target);
    }
}
项目:teasy    文件:ChromeConfigTest.java   
@Test
@NeedRestartDriver
public void chrome_config_test() {
    openPage("main.html", BasePage.class);
    WebDriver webDriver = ((FramesTransparentWebDriver) SeleniumHolder.getWebDriver()).getWrappedDriver();

    Assert.assertTrue(webDriver instanceof ChromeDriver);

    Assert.assertEquals(((RemoteWebDriver) webDriver).getCapabilities().getCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR), UnexpectedAlertBehaviour.IGNORE.toString());
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
/**
 * A helper method that enriches a {@link RemoteWebDriver} instance with the ability to route all browser
 * interaction requests directly to the node on which the session was created and route only the session termination
 * request to the hub.
 *
 * @param driver - A {@link RemoteWebDriver} instance.
 * @param hub    - A {@link Host} object that represents the Hub information.
 * @return - A {@link RemoteWebDriver} instance that is enriched with the ability to route all browser interactions
 * directly to the node.
 */
public static RemoteWebDriver enrichRemoteWebDriverToInteractDirectlyWithNode(RemoteWebDriver driver, Host hub) {
    if (hub == null) {
        return driver;
    }
    try {
        CommandExecutor grid = driver.getCommandExecutor();
        String sessionId = driver.getSessionId().toString();
        GridApiAssistant assistant = new GridApiAssistant(hub);

        Host nodeHost = assistant.getNodeDetailsForSession(sessionId);
        URL url = new URL(String.format("http://%s:%d/wd/hub", nodeHost.getIpAddress(), nodeHost.getPort()));
        CommandExecutor node = new HttpCommandExecutor(url);
        CommandCodec commandCodec = getCodec(grid, "commandCodec");
        ResponseCodec responseCodec = getCodec(grid, "responseCodec");
        setCodec(node, commandCodec, "commandCodec");
        setCodec(node, responseCodec, "responseCodec");
        appendListenerToWebDriver(driver, grid, node);
        LOG.info("Traffic will now be routed directly to the node.");
        LOG.warning(constructWarningMessage(hub));
    } catch (Exception e) {
        //Gobble exceptions
        LOG.warning("Unable to enrich the RemoteWebDriver instance. Root cause :" + e.getMessage()
            + ". Returning back the original instance that was passed, as is.");
    }
    return driver;
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
private static Host getHubInfo(RemoteWebDriver driver) {
    Host hub = null;
    CommandExecutor executor = driver.getCommandExecutor();
    if (executor instanceof HttpCommandExecutor) {
        URL url = ((HttpCommandExecutor) executor).getAddressOfRemoteServer();
        hub = new Host(url.getHost(), Integer.toString(url.getPort()));
    }
    return hub;
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
@SuppressWarnings("unchecked")
private static void appendListenerToWebDriver(RemoteWebDriver rwd, CommandExecutor grid, CommandExecutor node)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    CommandExecutor executor = new CustomCommandExecutor(grid, node);
    Class clazz = rwd.getClass();
    while (!RemoteWebDriver.class.equals(clazz)) {
        clazz = clazz.getSuperclass();
    }
    Method m = clazz.getDeclaredMethod("setCommandExecutor", CommandExecutor.class);
    m.setAccessible(true);
    m.invoke(rwd, executor);
}
项目:Selenium-Foundation    文件:GridUtility.java   
/**
 * Get the Selenium driver for the specified test class instance.
 * 
 * @return driver object (may be 'null')
 */
public static WebDriver getDriver() {
    SeleniumConfig config = SeleniumConfig.getConfig();
    GridServerParms hubParms = GridServerParms.getHubParms(config);
    if (isHubActive()) {
        return new RemoteWebDriver(hubParms.endpointUrl, config.getBrowserCaps());
    } else {
        throw new IllegalStateException("No Selenium Grid instance was found at " + hubParms.endpointUrl);
    }
}
项目:GitTalent    文件:GitTalentIntegrationTest.java   
@Test
public void testDeveloperTab() throws InterruptedException {
    RemoteWebDriver driver = chrome.getWebDriver();
    driver.get("http://gittalentbackend:8080/githubimport/developer/ldoguin");
    driver.get("http://gittalentbackend:8080/githubimport/status");
    while(driver.getPageSource().contains("false")) {
        Thread.sleep(1000);
        driver.navigate().refresh();
    };
    driver.get("http://gittalentfrontend/");
    WebElement myDynamicElement = (new WebDriverWait(driver, 20))
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/app-root/div/developers/div[1]/div[2]/div[1]/table/tbody/tr/td[2]")));
    Assert.assertTrue(myDynamicElement.getText().equals("ldoguin"));
}
项目:Selenium-Foundation    文件:GridUtility.java   
/**
 * Get the Selenium driver for the specified test class instance.
 * 
 * @return driver object (may be 'null')
 */
public static WebDriver getDriver() {
    SeleniumConfig config = SeleniumConfig.getConfig();
    GridServerParms hubParms = GridServerParms.getHubParms(config);
    if (isHubActive()) {
        return new RemoteWebDriver(hubParms.endpointUrl, config.getBrowserCaps());
    } else {
        throw new IllegalStateException("No Selenium Grid instance was found at " + hubParms.endpointUrl);
    }
}
项目:msa-cucumber-appium    文件:MobileApp.java   
public static MobileApp getInstance() throws Throwable {
    if (ourInstance == null) {
        ourInstance = new MobileApp();
        System.out.println("**********************Session id created********************** new session id : "+((RemoteWebDriver) driver.get()).getSessionId());
    }

    if(ourInstance != null &&  ((RemoteWebDriver) driver.get()).getSessionId() == null){
        ourInstance = new MobileApp();
        System.out.println("**********************Session id killed and new session created********************** new session id : "+((RemoteWebDriver) driver.get()).getSessionId());
    }

    return ourInstance;
}
项目:marathonv5    文件:JavaDriverTest.java   
public void succeedsWhenRequestingNonNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", false);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(!capabilities.is("nativeEvents"));
}
项目:marathonv5    文件:JavaDriverTest.java   
public void getSessions() {
    driver = new JavaDriver();
    JavaDriver driver1 = new JavaDriver();
    SessionId id1 = ((RemoteWebDriver) driver).getSessionId();
    SessionId id2 = driver1.getSessionId();
    AssertJUnit.assertFalse(id1.equals(id2));
}
项目:marathonv5    文件:JavaDriverCapabilitiesTest.java   
public void javaDriver() {
    driver = new JavaDriver();
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertEquals("java", capabilities.getBrowserName());
    AssertJUnit.assertEquals(true, capabilities.is("takesScreenshot"));
    AssertJUnit.assertEquals(false, capabilities.is("nativeEvents"));
}
项目:webdriver-supplier    文件:BaseListener.java   
private void injectSessionId(final ITestResult testResult) {
    ofNullable(DRIVER_CONTAINER.get())
            .map(t -> t._1)
            .filter(d -> d instanceof RemoteWebDriver)
            .map(d -> ((RemoteWebDriver) d).getSessionId())
            .ifPresent(id -> testResult.setAttribute("sessionId", id));
}
项目:webdriver-supplier    文件:MockWDFactory.java   
@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;
}
项目:cucumber-framework-java    文件:WebDriverThread.java   
private void instantiateWebDriver( DesiredCapabilities desiredCapabilities ) throws MalformedURLException
{

    System.out.println( String.format( "Current Operating System : {%s}"
            , operatingSystem ) );
    System.out.println( String.format( "Current System Architecture : {%s}"
            , systemArchitecture ) );
    System.out.println( String.format( "Current Browser : {%s}\n"
            , driverType ) );

    if( useRemoteWebDriver )
    {
        URL seleniumGridURL = new URL( System.getProperty( "gridURL" ) );
        System.out.println( "seleniumGridURL = " + seleniumGridURL );
        String desiredBrowserVersion = System.getProperty( "desiredBrowserVersion" );
        String desiredPlatform = System.getProperty( "desiredPlatform" );

        if( ( null != desiredPlatform ) && desiredPlatform.isEmpty() )
        {
            desiredCapabilities.setPlatform( Platform.valueOf( desiredPlatform ) );
        }

        if( null != desiredBrowserVersion && desiredBrowserVersion.isEmpty() )
        {
            desiredCapabilities.setVersion( desiredBrowserVersion );
        }
        driver = new RemoteWebDriver( seleniumGridURL, desiredCapabilities );

    } else
    {
        driver = selectedDriverType.getWebDriverObject( desiredCapabilities );
    }
}
项目:WebAndAppUITesting    文件:BaseOpt.java   
/**
 * 兼容循环执行时 不会重新加载构造方法的问题
 * 
 * @return
 */
public RemoteWebDriver getDriver() {
    if (driver == null || driver.getSessionId() == null) {
        driver = DriverFactory.getInstance().getDriver();
        wait = new WebDriverWait(driver, DRIVER_WAIT_TIMEOUT_IN_SECOND, 500);
    }
    return driver;
}
项目:SilkAppDriver    文件:ExceptionTests.java   
@Before
public void startApp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("app", APP);

    driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
}
项目:SilkAppDriver    文件:NotepadDemoTest.java   
@Before
public void startApp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("app", APP);

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

    driver.manage().timeouts().implicitlyWait(17, TimeUnit.SECONDS);

    String windowHandle = driver.getWindowHandle();
    assertNotNull(windowHandle);

    Point windowPosition = driver.manage().window().getPosition();
    assertNotNull(windowPosition);
}
项目:Query    文件:QueryTest.java   
private void initQueryObject() {
    Capabilities mockedCapabilities = mock(Capabilities.class);
    when(mockedCapabilities.getBrowserName()).thenReturn(BrowserType.GOOGLECHROME);
    when(mockedCapabilities.getPlatform()).thenReturn(Platform.YOSEMITE);

    RemoteWebDriver mockedWebDriver = mock(RemoteWebDriver.class);
    when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities);
    when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_FOR_DEFAULT);
    when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_LIST_FOR_DEFAULT);

    Query.initQueryObjects(mockedWebDriver);
}
项目:Query    文件:QueryTest.java   
private void initQueryObjectWithAppiumAndroid() {
    Capabilities mockedCapabilities = mock(Capabilities.class);
    when(mockedCapabilities.getBrowserName()).thenReturn("");
    when(mockedCapabilities.getPlatform()).thenReturn(Platform.fromString(MobilePlatform.ANDROID));
    when(mockedCapabilities.getCapability("automationName")).thenReturn("Appium");

    RemoteWebDriver mockedWebDriver = mock(AndroidDriver.class);
    when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities);
    when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_MOBILE_ELEMENT_FOR_DEFAULT);
    when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_MOBILE_ELEMENT_LIST_FOR_DEFAULT);

    Query.initQueryObjects(mockedWebDriver);
}
项目:argument-reasoning-comprehension-task    文件:DebateFetcher.java   
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);
}