org.openqa.selenium.Capabilities Java Examples

The following examples show how to use org.openqa.selenium.Capabilities. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebDriverFactory.java    From vividus with Apache License 2.0 7 votes vote down vote up
@Override
public WebDriver getRemoteWebDriver(DesiredCapabilities desiredCapabilities)
{
    DesiredCapabilities mergedDesiredCapabilities = getWebDriverCapabilities(false, desiredCapabilities);
    WebDriverType webDriverType = WebDriverManager.detectType(mergedDesiredCapabilities);

    Capabilities capabilities = mergedDesiredCapabilities;
    if (webDriverType != null)
    {
        webDriverType.prepareCapabilities(mergedDesiredCapabilities);
        if (webDriverType == WebDriverType.CHROME)
        {
            WebDriverConfiguration configuration = getWebDriverConfiguration(webDriverType, false);
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments(configuration.getCommandLineArguments());
            configuration.getExperimentalOptions().forEach(chromeOptions::setExperimentalOption);
            capabilities = chromeOptions.merge(mergedDesiredCapabilities);
        }
    }
    return createWebDriver(remoteWebDriverFactory.getRemoteWebDriver(remoteDriverUrl, capabilities));
}
 
Example #2
Source File: DefaultSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getDescription(WebDriver instance, Capabilities capabilities) {
  DesiredCapabilities caps = new DesiredCapabilities(capabilities.asMap());
  caps.setJavascriptEnabled(instance instanceof JavascriptExecutor);
  if (instance instanceof TakesScreenshot) {
    caps.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
  }
  if (instance instanceof LocationContext) {
    caps.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
  }
  if (instance instanceof ApplicationCache) {
    caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
  }
  if (instance instanceof NetworkConnection) {
    caps.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
  }
  if (instance instanceof WebStorage) {
    caps.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);
  }
  if (instance instanceof Rotatable) {
    caps.setCapability(CapabilityType.ROTATABLE, true);
  }
  if (instance instanceof HasTouchScreen) {
    caps.setCapability(CapabilityType.HAS_TOUCHSCREEN, true);
  }
  return caps.asMap();
}
 
Example #3
Source File: LocalNode.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
public NodeStatus getStatus() {
  Map<Capabilities, Integer> stereotypes = factories.stream()
    .collect(groupingBy(SessionSlot::getStereotype, summingInt(caps -> 1)));

  ImmutableSet<NodeStatus.Active> activeSessions = currentSessions.asMap().values().stream()
    .map(slot -> new NodeStatus.Active(
      slot.getStereotype(),
      slot.getSession().getId(),
      slot.getSession().getCapabilities()))
    .collect(toImmutableSet());

  return new NodeStatus(
    getId(),
    externalUri,
    maxSessionCount,
    stereotypes,
    activeSessions,
    registrationSecret);
}
 
Example #4
Source File: InternetExplorerDriverHandler.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        InternetExplorerOptions internetExplorerOptions = (InternetExplorerOptions) getOptions(
                parameter, testInstance);
        if (capabilities.isPresent()) {
            internetExplorerOptions.merge(capabilities.get());
        }
        object = new InternetExplorerDriver(internetExplorerOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #5
Source File: InternetExplorerDriverConfigTest.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreateInternetExplorerAndStartService() throws Exception {
    InternetExplorerDriver mockInternetExplorerDriver = mock(InternetExplorerDriver.class);
    whenNew(InternetExplorerDriver.class).withParameterTypes(InternetExplorerDriverService.class, Capabilities.class).withArguments(isA(InternetExplorerDriverService.class), isA(Capabilities.class)).thenReturn(mockInternetExplorerDriver);
    InternetExplorerDriverService.Builder mockServiceBuilder = mock(InternetExplorerDriverService.Builder.class);
    whenNew(InternetExplorerDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder);
    when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder);
    InternetExplorerDriverService mockService = mock(InternetExplorerDriverService.class);
    when(mockServiceBuilder.build()).thenReturn(mockService);

    final InternetExplorerDriver browser = config.createBrowser();

    assertThat(browser, is(mockInternetExplorerDriver));
    verifyNew(InternetExplorerDriver.class, times(1)).withArguments(isA(InternetExplorerDriverService.class), isA(Capabilities.class));
    verify(mockServiceBuilder, times(1)).build();
    assertThat(config.getServices().size(), is(1));
    assertThat(config.getServices().values(), hasItem(mockService));
}
 
Example #6
Source File: RemoteWebDriver.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
  Capabilities caps = getCapabilities();
  if (caps == null) {
    return super.toString();
  }

  // w3c name first
  Object platform = caps.getCapability(PLATFORM_NAME);
  if (!(platform instanceof String)) {
    platform = caps.getCapability(PLATFORM);
  }
  if (platform == null) {
    platform = "unknown";
  }

  return String.format(
      "%s: %s on %s (%s)",
      getClass().getSimpleName(),
      caps.getBrowserName(),
      platform,
      getSessionId());
}
 
Example #7
Source File: JsonTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldParseCapabilitiesWithLoggingPreferences() {
  String caps = String.format(
      "{\"%s\": {" +
      "\"browser\": \"WARNING\"," +
      "\"client\": \"DEBUG\", " +
      "\"driver\": \"ALL\", " +
      "\"server\": \"OFF\"}}",
      CapabilityType.LOGGING_PREFS);

  Capabilities converted = new Json().toType(caps, Capabilities.class);

  LoggingPreferences lp =
      (LoggingPreferences) converted.getCapability(CapabilityType.LOGGING_PREFS);
  assertThat(lp).isNotNull();
  assertThat(lp.getLevel(BROWSER)).isEqualTo(WARNING);
  assertThat(lp.getLevel(CLIENT)).isEqualTo(FINE);
  assertThat(lp.getLevel(DRIVER)).isEqualTo(ALL);
  assertThat(lp.getLevel(SERVER)).isEqualTo(OFF);
}
 
Example #8
Source File: SyntheticNewSessionPayloadTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldExpandAllW3CMatchesToFirstMatchesAndRemoveAlwaysMatchIfSynthesizingAPayload() {
  Map<String, Object> payload = ImmutableMap.of(
    // OSS capabilities request a chrome webdriver
    "desiredCapabilities", ImmutableMap.of("browserName", "chrome"),
    // Yet the w3c ones ask for IE and edge
    "capabilities", ImmutableMap.of(
          "alwaysMatch", ImmutableMap.of("se:cake", "cheese"),
          "firstMatch", Arrays.asList(
            ImmutableMap.of("browserName", "edge"),
            ImmutableMap.of("browserName", "cheese"))));

  try (NewSessionPayload newSession = NewSessionPayload.create(payload)) {
    List<Capabilities> allCaps = newSession.stream().collect(toList());

    assertThat(allCaps).containsExactlyInAnyOrder(
        new ImmutableCapabilities("browserName", "cheese", "se:cake", "cheese"),
        new ImmutableCapabilities("browserName", "chrome"),
        new ImmutableCapabilities("browserName", "edge", "se:cake", "cheese"));
  }
}
 
Example #9
Source File: SeleniumGridWithCapabilitiesDriverFactoryFactoryBase.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
protected BiFunction<URL, Capabilities, RemoteWebDriver> getRemoteWebDriverConstructor() {
    if (webDriverConstructor == null) {
        if (isPropertySet(SELENIUM_DRIVER_CLASS)) {
            String driverClass = getProperty(SELENIUM_DRIVER_CLASS);
            try {
                Class<?> clazz = Class.forName(driverClass);
                if (RemoteWebDriver.class.isAssignableFrom(clazz)) {
                    Class<? extends RemoteWebDriver> rmd = (Class<? extends RemoteWebDriver>) clazz;
                    webDriverConstructor = new LambdaMetaHelper().getConstructor(rmd, URL.class, Capabilities.class);
                } else {
                    throw new IllegalArgumentException(driverClass + " does not implement RemoteWebDiver");
                }
            } catch (Exception e) {
                throw new IllegalArgumentException("Unable to create RemoteWebDriver using: " + driverClass, e);
            }
        } else {
            webDriverConstructor = RemoteWebDriver::new;
        }
    }

    return webDriverConstructor;
}
 
Example #10
Source File: CapabilitiesComparatorTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPickCorrectBrowser() {
  Capabilities chrome = new DesiredCapabilities(BrowserType.CHROME, "10", Platform.ANY);
  Capabilities firefox = new DesiredCapabilities(BrowserType.FIREFOX, "10", Platform.ANY);
  Capabilities opera = new DesiredCapabilities(BrowserType.OPERA_BLINK, "10", Platform.ANY);
  List<Capabilities> list = asList(chrome, firefox, opera);

  DesiredCapabilities desired = new DesiredCapabilities();

  desired.setBrowserName(BrowserType.CHROME);
  assertThat(getBestMatch(desired, list)).isEqualTo(chrome);

  desired.setBrowserName(BrowserType.FIREFOX);
  assertThat(getBestMatch(desired, list)).isEqualTo(firefox);

  desired.setBrowserName(BrowserType.OPERA_BLINK);
  assertThat(getBestMatch(desired, list)).isEqualTo(opera);
}
 
Example #11
Source File: VividusWebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
private void runCreateTest(boolean remoteExecution, String browserName) throws Exception
{
    vividusWebDriverFactory.setRemoteExecution(remoteExecution);
    vividusWebDriverFactory.setWebDriverEventListeners(List.of(webDriverEventListener));

    when(bddRunContext.getRunningStory()).thenReturn(createRunningStory(browserName));
    EventFiringWebDriver eventFiringWebDriver = mock(EventFiringWebDriver.class);
    PowerMockito.whenNew(EventFiringWebDriver.class).withArguments(driver).thenReturn(eventFiringWebDriver);
    Options options = mock(Options.class);
    when(eventFiringWebDriver.manage()).thenReturn(options);
    Window window = mock(Window.class);
    when(options.window()).thenReturn(window);
    when(eventFiringWebDriver.getCapabilities()).thenReturn(mock(Capabilities.class));
    BrowserWindowSize windowSize = new BrowserWindowSize("1920x1080");
    when(browserWindowSizeProvider.getBrowserWindowSize(remoteExecution))
            .thenReturn(windowSize);
    VividusWebDriver vividusWebDriver = vividusWebDriverFactory.create();
    assertEquals(eventFiringWebDriver, vividusWebDriver.getWrappedDriver());
    verify(eventFiringWebDriver).register(webDriverEventListener);
    assertEquals(remoteExecution, vividusWebDriver.isRemote());
    verify(webDriverManagerContext).reset(WebDriverManagerParameter.DESIRED_CAPABILITIES);
    verify(webDriverManager).resize(eventFiringWebDriver, windowSize);
}
 
Example #12
Source File: Host.java    From selenium with Apache License 2.0 6 votes vote down vote up
public DistributorStatus.NodeSummary asSummary() {
  Map<Capabilities, Integer> stereotypes = new HashMap<>();
  Map<Capabilities, Integer> used = new HashMap<>();

  slots.forEach(slot -> {
    stereotypes.compute(slot.getStereotype(), (key, curr) -> curr == null ? 1 : curr + 1);
    if (slot.getStatus() != AVAILABLE) {
      used.compute(slot.getStereotype(), (key, curr) -> curr == null ? 1 : curr + 1);
    }
  });

  return new DistributorStatus.NodeSummary(
      nodeId,
      uri,
      getHostStatus() == UP,
      maxSessionCount,
      stereotypes,
      used);
}
 
Example #13
Source File: Device.java    From coteafs-appium with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private D init(final URL url, final Capabilities capability) {
    LOG.trace("Initializing driver...");
    final TypeToken<D> token = new TypeToken<D>(getClass()) {
        private static final long serialVersionUID = 1562415938665085306L;
    };
    final Class<D> cls = (Class<D>) token.getRawType();
    final Class<?>[] argTypes = new Class<?>[] { URL.class, Capabilities.class };
    try {
        final Constructor<D> ctor = cls.getDeclaredConstructor(argTypes);
        return ctor.newInstance(url, capability);
    } catch (final NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        fail(DeviceDriverInitializationFailedError.class, "Error occured while initializing device driver.", e);
    }
    return null;
}
 
Example #14
Source File: DefaultSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
private DefaultSession(
    final DriverFactory factory,
    TemporaryFilesystem tempFs,
    final Capabilities capabilities) {
  this.knownElements = new KnownElements();
  this.tempFs = tempFs;
  final BrowserCreator browserCreator = new BrowserCreator(factory, capabilities);

  // Ensure that the browser is created on the single thread.
  EventFiringWebDriver initialDriver = browserCreator.call();

  if (!isQuietModeEnabled(browserCreator, capabilities)) {
    // Memo to self; this is not a constructor escape of "this" - probably ;)
    initialDriver.register(new SnapshotScreenListener(this));
  }

  this.driver = initialDriver;
  this.capabilities = browserCreator.getCapabilityDescription();
  this.sessionId = browserCreator.getSessionId();
}
 
Example #15
Source File: RemoteDriverHandler.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
private void resolveOtherThanDocker(Optional<Object> testInstance)
        throws IllegalAccessException, MalformedURLException {
    Optional<Capabilities> capabilities = annotationsReader
            .getCapabilities(parameter, testInstance);

    Optional<URL> url;
    if (browser != null && browser.getUrl() != null
            && !browser.getUrl().isEmpty()) {
        url = Optional.of(new URL(browser.getUrl()));
        capabilities = Optional.of(new DesiredCapabilities(
                browser.getType(), browser.getVersion(), ANY));
    } else {
        url = annotationsReader.getUrl(parameter, testInstance,
                config.getSeleniumServerUrl());
    }

    if (url.isPresent() && capabilities.isPresent()) {
        object = resolveRemote(url.get(), capabilities.get());
    } else {
        object = resolveGeneric();
    }
}
 
Example #16
Source File: SyntheticNewSessionPayloadTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDoNothingIfCapabilitiesArePresentButLeftEmpty() {
  Map<String, Object> empty = ImmutableMap.of(
      "desiredCapabilities", emptyMap(),
      "capabilities", emptyMap());

  List<Capabilities> allCaps = getCapabilities(empty);

  assertThat(allCaps).containsExactly(new ImmutableCapabilities());
}
 
Example #17
Source File: UiDriverFactory.java    From qaf with MIT License 5 votes vote down vote up
private static void onInitializationFailure(Capabilities desiredCapabilities, Throwable e,
		Collection<QAFWebDriverCommandListener> listners) {
	if ((listners != null) && !listners.isEmpty()) {
		for (QAFWebDriverCommandListener listener : listners) {
			listener.onInitializationFailure(desiredCapabilities, e);
		}
	}

}
 
Example #18
Source File: ThreadLocalSingleWebDriverPool.java    From webdriver-factory with Apache License 2.0 5 votes vote down vote up
private synchronized void createNewDriver(Capabilities capabilities, URL hub) {
  String newKey = createKey(capabilities, hub);
  WebDriver driver = newDriver(hub, capabilities);
  driverToKeyMap.put(driver, newKey);
  driverToThread.put(driver, Thread.currentThread());
  tlDriver.set(driver);
}
 
Example #19
Source File: FirefoxDriverTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canSetProfileInCapabilities() {
  FirefoxProfile profile = new FirefoxProfile();
  profile.setPreference("browser.startup.page", 1);
  profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage);

  Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.PROFILE, profile);

  localDriver = new FirefoxDriver(caps);
  wait.until($ -> "XHTML Test Page".equals(localDriver.getTitle()));
}
 
Example #20
Source File: AugmenterTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() {
  Capabilities caps = new ImmutableCapabilities("magic.numbers", false);
  WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps);

  WebDriver returned = getAugmenter()
    .addDriverAugmentation("magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42)
    .augment(driver);

  assertThat(returned).isSameAs(driver);
  assertThat(returned).isNotInstanceOf(HasMagicNumbers.class);
}
 
Example #21
Source File: GridUtility.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Get a driver with desired capabilities from specified Selenium Grid hub.
 * 
 * @param remoteAddress Grid hub from which to obtain the driver
 * @param desiredCapabilities desired capabilities for the driver
 * @return driver object (may be 'null')
 */
public static WebDriver getDriver(URL remoteAddress, Capabilities desiredCapabilities) {
    Objects.requireNonNull(remoteAddress, "[remoteAddress] must be non-null");
    if (isHubActive(remoteAddress)) {
        return new RemoteWebDriver(remoteAddress, desiredCapabilities);
    } else {
        throw new IllegalStateException("No Selenium Grid instance was found at " + remoteAddress);
    }
}
 
Example #22
Source File: UiDriverFactory.java    From Quantum with MIT License 5 votes vote down vote up
private static WebDriver getDriverProxyObj(Class<? extends WebDriver> of, Capabilities capabilities, URL url,
		Factory factory) {
	try {
		// give it first try
		// Constructor<? extends WebDriver> constructor =
		// of.getConstructor(HttpCommandExecutor.class,
		// Capabilities.class);
		Constructor<? extends WebDriver> constructor = of.getConstructor(URL.class, Factory.class,
				Capabilities.class);
		return constructor.newInstance(url, factory, capabilities);
	} catch (Exception ex) {
		return null;
	}
}
 
Example #23
Source File: SaucelabsWebDriver.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @param username 
 * @param accessKey
 * @param desiredCapabilities
 * @throws MalformedURLException
 */
public SaucelabsWebDriver(String username, String accessKey, Capabilities desiredCapabilities) throws MalformedURLException {
	super(new URL("http://" + username + ":" + accessKey
			+ "@ondemand.saucelabs.com:80/wd/hub"), desiredCapabilities);
	this.username = username;
	this.accessKey = accessKey;
	this.desiredCapabilities = desiredCapabilities;
}
 
Example #24
Source File: UiDriverFactory.java    From qaf with MIT License 5 votes vote down vote up
private Browsers(Capabilities desiredCapabilities, Class<? extends WebDriver> driver) {
	this(desiredCapabilities);
	if (null == driverCls) {
		// not overridden by extra capability
		driverCls = driver;
	}
}
 
Example #25
Source File: RemoteDriverConfigTest.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateRemoteDriver() throws Exception {
	config.setSeleniumGridUrl("http://my.awesomegrid.com");
    RemoteWebDriver mockRemoteWebDriver = Mockito.mock(RemoteWebDriver.class);
    whenNew(RemoteWebDriver.class)
        .withParameterTypes(URL.class, Capabilities.class)
        .withArguments(isA(URL.class), isA(Capabilities.class))
        .thenReturn(mockRemoteWebDriver);

    final RemoteWebDriver browser = config.createBrowser();

    assertThat(browser, is(mockRemoteWebDriver));
    verifyNew(RemoteWebDriver.class, times(1)).withArguments(isA(URL.class), isA(Capabilities.class));
}
 
Example #26
Source File: OneShotNode.java    From selenium with Apache License 2.0 5 votes vote down vote up
public static Node create(Config config) {
  LoggingOptions loggingOptions = new LoggingOptions(config);
  EventBusOptions eventOptions = new EventBusOptions(config);
  BaseServerOptions serverOptions = new BaseServerOptions(config);
  NodeOptions nodeOptions = new NodeOptions(config);

  Map<String, Object> raw = new Json().toType(
    config.get("k8s", "stereotype")
      .orElseThrow(() -> new ConfigException("Unable to find node stereotype")),
    MAP_TYPE);

  Capabilities stereotype = new ImmutableCapabilities(raw);

  Optional<String> driverName = config.get("k8s", "driver_name").map(String::toLowerCase);

  // Find the webdriver info corresponding to the driver name
  WebDriverInfo driverInfo = StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false)
    .filter(info -> info.isSupporting(stereotype))
    .filter(info -> driverName.map(name -> name.equals(info.getDisplayName().toLowerCase())).orElse(true))
    .findFirst()
    .orElseThrow(() -> new ConfigException(
      "Unable to find matching driver for %s and %s", stereotype, driverName.orElse("any driver")));

  LOG.info(String.format("Creating one-shot node for %s with stereotype %s", driverInfo, stereotype));
  LOG.info("Grid URI is: " + nodeOptions.getPublicGridUri());

  return new OneShotNode(
    loggingOptions.getTracer(),
    eventOptions.getEventBus(),
    serverOptions.getRegistrationSecret(),
    UUID.randomUUID(),
    serverOptions.getExternalUri(),
    nodeOptions.getPublicGridUri().orElseThrow(() -> new ConfigException("Unable to determine public grid address")),
    stereotype,
    driverInfo);
}
 
Example #27
Source File: SafariOptions.java    From selenium with Apache License 2.0 5 votes vote down vote up
public SafariOptions(Capabilities source) {
  this();

  source.asMap().forEach((key, value)-> {
    if (CAPABILITY.equals(key) && value instanceof Map) {

      @SuppressWarnings("unchecked")
      Map<? extends String, ?> map = (Map<? extends String, ?>) value;
      options.putAll(map);
    } else if (value != null) {
      setCapability(key, value);
    }
  });
}
 
Example #28
Source File: FirefoxOptionsTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canInitFirefoxOptionsWithCapabilitiesThatContainFirefoxOptionsAsMap() {
  FirefoxProfile profile = new FirefoxProfile();
  Capabilities caps = new ImmutableCapabilities(
      FIREFOX_OPTIONS, ImmutableMap.of("profile", profile));

  FirefoxOptions options = new FirefoxOptions(caps);

  assertThat(options.getProfile()).isSameAs(profile);
}
 
Example #29
Source File: Augmenter.java    From selenium with Apache License 2.0 5 votes vote down vote up
public Augmentation(
  Predicate<Capabilities> whenMatches,
  Class<X> interfaceClass,
  BiFunction<Capabilities, ExecuteMethod, X> implementation) {
  this.whenMatches = Require.nonNull("Capabilities predicate", whenMatches);
  this.interfaceClass = Require.nonNull("Interface to implement", interfaceClass);
  this.implementation = Require.nonNull("Interface implementation", implementation);

  Require.precondition(
    interfaceClass.isInterface(),
    "%s must be an interface, not a concrete class",
    interfaceClass);
}
 
Example #30
Source File: DefaultSessionTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldClearTempFsWhenSessionCloses() {
  final DriverFactory factory = mock(DriverFactory.class);
  when(factory.newInstance(any(Capabilities.class))).thenReturn(mock(WebDriver.class));
  final TemporaryFilesystem tempFs = mock(TemporaryFilesystem.class);

  Session session = DefaultSession.createSession(
      factory, tempFs,
      new DesiredCapabilities(BrowserType.FIREFOX, "10", Platform.ANY));

  session.close();
  verify(tempFs).deleteTemporaryFiles();
  verify(tempFs).deleteBaseDir();
}