Example usage for org.openqa.selenium.remote RemoteWebDriver getCapabilities

List of usage examples for org.openqa.selenium.remote RemoteWebDriver getCapabilities

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver getCapabilities.

Prototype

@Override
    public Capabilities getCapabilities() 

Source Link

Usage

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.TestReusableRemoteWebDriver.java

License:Apache License

@Test
public void whenBrowserIsCreatedThenCouldBeReused(@Drone @Reusable RemoteWebDriver driver)
        throws UnableReuseSessionException {

    driver.navigate().to(SERVER_URL.toString());

    new AugmentingEnhancer().deenhance(driver, Reusable.class); // without deenhancing we can't serialize capabilities

    Capabilities reusedCapabilities = serializeDeserialize(
            ReusedSession.createReusableCapabilities(driver.getCapabilities()));
    SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString()));

    RemoteWebDriver reusedDriver = ReusableRemoteWebDriver.fromReusedSession(HUB_URL, reusedCapabilities,
            reusedSessionId);//from   w  w w .  jav a 2  s .  com
    reusedDriver.navigate().to(HUB_URL.toString());
}

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.TestReusableRemoteWebDriver.java

License:Apache License

@Test
public void whenBrowserIsCreatedAndQuitAndTriedToReuseThenItShouldThrowException(
        @Drone @Reusable RemoteWebDriver driver) {

    driver.navigate().to(SERVER_URL.toString());
    new AugmentingEnhancer().deenhance(driver, Reusable.class); // without deenhancing we can't serialize capabilities
    Capabilities reusedCapabilities = serializeDeserialize(
            ReusedSession.createReusableCapabilities(driver.getCapabilities()));
    SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString()));
    driver.quit();/*from  ww w. j  a v  a2  s.c  o m*/

    try {
        ReusableRemoteWebDriver.fromReusedSession(HUB_URL, reusedCapabilities, reusedSessionId);
        fail("Original driver had quited before, so session should not be reusable");
    } catch (UnableReuseSessionException e) {
        // exception should be thrown
    }
}

From source file:org.jboss.arquillian.drone.webdriver.factory.RemoteWebDriverFactory.java

License:Apache License

@Override
public void destroyInstance(RemoteWebDriver instance) {
    if (instance.getSessionId() == null) {
        log.warning("The driver has been already destroyed and can't be destroyed again.");
        return;//from w  ww .  ja v  a 2 s .c o  m
    }

    InitializationParameter param = initParams.get().remove(instance.getSessionId());

    if (param != null) {
        ReusedSession session = new ReusedSession(instance.getSessionId(), instance.getCapabilities());
        sessionStore.get().store(param, session);
        persistEvent.fire(new PersistReusedSessionsEvent());
    } else {
        instance.quit();
    }

}

From source file:org.keycloak.testsuite.drone.KeycloakDronePostSetup.java

License:Apache License

public void configureWebDriver(@Observes AfterDroneEnhanced event, DroneContext droneContext) {
    DronePoint<?> dronePoint = event.getDronePoint();
    Object drone = droneContext.get(dronePoint).getInstance();

    if (drone instanceof RemoteWebDriver) {
        RemoteWebDriver remoteWebDriver = (RemoteWebDriver) drone;
        log.infof("Detected browser: %s %s", remoteWebDriver.getCapabilities().getBrowserName(),
                remoteWebDriver.getCapabilities().getVersion());
    }/*from   ww  w .  jav a  2  s.  c om*/

    if (drone instanceof WebDriver && !(drone instanceof AppiumDriver)) {
        WebDriver webDriver = (WebDriver) drone;
        configureDriverSettings(webDriver);
    } else {
        log.warn("Drone is not instanceof WebDriver for a desktop browser! Drone is " + drone);
    }

    if (drone instanceof GrapheneProxyInstance) {
        GrapheneProxyInstance droneProxy = (GrapheneProxyInstance) drone;
        if (drone instanceof HtmlUnitDriver) {
            droneProxy.registerInterceptor(new HtmlUnitInterceptor());
        }
    } else {
        log.warn("Drone is not instanceof GrapheneProxyInstance! Drone is " + drone);
    }
}

From source file:org.mousephenotype.www.testing.model.TestUtils.java

License:Apache License

/**
 * Given an initialized <code>WebDriver</code> instance and a selenium URL,
 * prints the test environment for the test associated with <code>driver<code>.
 * @param driver the initialized <code>WebDriver</code> instance
 * @param seleniumUrl the Selenium URL//from   w w  w.  j av a  2 s. com
 */
public static void printTestEnvironment(WebDriver driver, String seleniumUrl) {
    String browserName = "<Unknown>";
    String version = "<Unknown>";
    String platform = "<Unknown>";
    if (driver instanceof RemoteWebDriver) {
        RemoteWebDriver remoteWebDriver = (RemoteWebDriver) driver;
        browserName = remoteWebDriver.getCapabilities().getBrowserName();
        version = remoteWebDriver.getCapabilities().getVersion();
        platform = remoteWebDriver.getCapabilities().getPlatform().name();
    }

    System.out.println("\nTESTING AGAINST " + browserName + " version " + version + " on platform " + platform);
    System.out.println("seleniumUrl: " + seleniumUrl);
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

License:Open Source License

/**
 * @param driver -- can be null to use the last used WebDriver session.
 * @return String of browser name or null if there is no WebDriver session.
 * @see SelectBrowser#BROWSER_NAME_CHROME
 * @see SelectBrowser#BROWSER_NAME_FIREFOX
 * @see SelectBrowser#BROWSER_NAME_HTMLUNIT
 * @see SelectBrowser#BROWSER_NAME_IE/*from w w  w  .  j  ava2  s  .  com*/
 * @see SelectBrowser#BROWSER_NAME_SAFARI
 */
public static String getBrowserName(WebDriver driver) {
    if (driver == null)
        driver = getWebDriver();
    if (driver instanceof FirefoxDriver)
        return SelectBrowser.BROWSER_NAME_FIREFOX;
    if (driver instanceof ChromeDriver)
        return SelectBrowser.BROWSER_NAME_CHROME;
    if (driver instanceof InternetExplorerDriver)
        return SelectBrowser.BROWSER_NAME_IE;
    if (driver instanceof SafariDriver)
        return SelectBrowser.BROWSER_NAME_SAFARI;
    if (driver instanceof HtmlUnitDriver)
        return SelectBrowser.BROWSER_NAME_HTMLUNIT;
    if (driver instanceof RemoteWebDriver) {
        RemoteWebDriver rdriver = (RemoteWebDriver) driver;
        try {
            return rdriver.getCapabilities().getBrowserName();
        } catch (NullPointerException ignore) {
        }
    }
    return null;
}

From source file:org.testeditor.fixture.web.WebDriverFixture.java

License:Open Source License

private void logBrowserVersion(Capabilities capabilities, RemoteWebDriver remoteDriver) {
    String browserName = capabilities.getBrowserName();
    String version = remoteDriver.getCapabilities().getVersion();
    logger.debug("Browser \"{}\" has version \"{}\".", browserName, version);
}