Java Code Examples for org.openqa.selenium.remote.CapabilityType

The following examples show how to use org.openqa.selenium.remote.CapabilityType. These examples are extracted from open source projects. 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
@Test
// Tests that a platform of 'ANY' matches another otherwise non-matching OS
public void testOsMatchesAnyRequests() {
    String uuid = "testUuid";
    String browser = "firefox";
    String browserVersion = "25";
    String os = "ANY";
    Map<String,Object> map = new HashMap<>();
    map.put(CapabilityType.BROWSER_NAME,browser);
    map.put(CapabilityType.VERSION,browserVersion);
    map.put(CapabilityType.PLATFORM,os);
    AutomationRunRequest first = new AutomationRunRequest(uuid,null,browser,browserVersion,"linux");
    AutomationRunRequest second = AutomationRunRequest.requestFromCapabilities(map);
    Assert.assertTrue("Requests should be equal", first.matchesCapabilities(second));
    Assert.assertTrue("Requests should be equal", second.matchesCapabilities(first));
}
 
Example 2
Source Project: selenium   Source File: JsonOutputTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConvertAProxyCorrectly() {
  Proxy proxy = new Proxy();
  proxy.setHttpProxy("localhost:4444");

  MutableCapabilities caps = new DesiredCapabilities("foo", "1", Platform.LINUX);
  caps.setCapability(CapabilityType.PROXY, proxy);
  Map<String, ?> asMap = ImmutableMap.of("desiredCapabilities", caps);
  Command command = new Command(new SessionId("empty"), DriverCommand.NEW_SESSION, asMap);

  String json = convert(command.getParameters());

  JsonObject converted = new JsonParser().parse(json).getAsJsonObject();
  JsonObject capsAsMap = converted.get("desiredCapabilities").getAsJsonObject();

  assertThat(capsAsMap.get(CapabilityType.PROXY).getAsJsonObject().get("httpProxy").getAsString())
      .isEqualTo(proxy.getHttpProxy());
}
 
Example 3
Source Project: JYTB   Source File: BotWorker.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setChromeDriver() {
        ChromeOptions options = new ChromeOptions();
        List<String> chromeOptions = new ArrayList<>();
        LoggingPreferences logPrefs = new LoggingPreferences();

        chromeOptions.add(String.format("--proxy-server=%s", proxies.getCurrentProxyModel().getIp()));
        chromeOptions.add(String.format("--user-agent=%s", userAgent.randomUA()));
        chromeOptions.add("--mute-audio");

        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
        options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        options.addArguments(chromeOptions);
        options.setBinary(this.driverLocation);
        options.setHeadless(true);
//        options.setProxy(this.proxies.getCurrentProxy());
        options.setCapability("proxy", this.proxies.getCurrentProxy());

        this.webDriver = new ChromeDriver(options);
        Log.WINFO(this.workerName, this.workerColor, "Chrome Driver Set.");
    }
 
Example 4
@Test
// Test to make sure an in progress counts against the free node count
public void testRequestNewRunNotStarted() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    String runId = "runId";
    AutomationContext.getContext().addRun(new AutomationRunRequest(runId,10,"firefox"));
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID, nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"firefox");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("No nodes should be free since existing run hasn't started",0,freeThreads);
}
 
Example 5
Source Project: coteafs-selenium   Source File: Browser.java    License: Apache License 2.0 6 votes vote down vote up
private static WebDriver setupIeDriver() throws MalformedURLException {
    LOG.i("Setting up Internet Explorer driver...");
    setupDriver(iedriver());
    final InternetExplorerOptions ieOptions = new InternetExplorerOptions();
    ieOptions.destructivelyEnsureCleanSession();
    ieOptions.setCapability("requireWindowFocus", true);
    ieOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    final InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService();
    if (!OS.isWindows()) {
        Assert.fail("IE is not supported.");
    }
    if (appSetting().isHeadlessMode()) {
        LOG.w("IE does not support headless mode. Hence, ignoring the same...");
    }
    return new InternetExplorerDriver(ieService, ieOptions);
}
 
Example 6
@Test
public void usingAProxyToTrackNetworkTrafficStep2() {
    BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
    browserMobProxy.start();
    Proxy seleniumProxyConfiguration = ClientUtil.createSeleniumProxy(browserMobProxy);

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability(CapabilityType.PROXY, seleniumProxyConfiguration);
    driver = new FirefoxDriver(firefoxOptions);
    browserMobProxy.newHar();
    driver.get("https://www.google.co.uk");

    Har httpArchive = browserMobProxy.getHar();

    assertThat(getHTTPStatusCode("https://www.google.co.uk/", httpArchive))
            .isEqualTo(200);
}
 
Example 7
@Test
// Happy path that browsers matching shows correct free node count
 public void testRequestMatchingBrowsers() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,browser);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));

    Assert.assertEquals("Thread count should be correct due to matching browser", 10, freeThreads);
}
 
Example 8
Source Project: selenium   Source File: WebDriverServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void doesNotRedirectForNewSessionsRequestedViaCrossDomainRpc()
    throws IOException, ServletException {
  Map<String, Object> json = ImmutableMap.of(
      "method", "POST",
      "path", "/session",
      "data", ImmutableMap.of(
          "desiredCapabilities", ImmutableMap.of(
              CapabilityType.BROWSER_NAME, BrowserType.FIREFOX,
              CapabilityType.VERSION, true)));
  FakeHttpServletResponse response = sendCommand("POST", "/xdrpc", json);

  assertEquals(HttpServletResponse.SC_OK, response.getStatus());
  assertEquals("application/json; charset=utf-8",
               response.getHeader("content-type"));

  Map<String, Object> jsonResponse = this.json.toType(response.getBody(), MAP_TYPE);
  assertEquals(ErrorCodes.SUCCESS, ((Number) jsonResponse.get("status")).intValue());
  assertNotNull(jsonResponse.get("sessionId"));

  Map<?, ?> value = (Map<?, ?>) jsonResponse.get("value");
  // values: browsername, version, remote session id.
  assertEquals(value.toString(), 3, value.entrySet().size());
  assertEquals(BrowserType.FIREFOX, value.get(CapabilityType.BROWSER_NAME));
  assertTrue((Boolean) value.get(CapabilityType.VERSION));
}
 
Example 9
@Before
public void setUp() throws Exception {
    // set up appium
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Selendroid");

    capabilities.setCapability(CapabilityType.VERSION, "4.2.2");

    capabilities.setCapability("device", "Android");
    capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
    capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/SugarCRM.apk.zip");
    capabilities.setCapability("app-package", "com.sugarcrm.nomad");
    capabilities.setCapability("app-activity", "NomadActivity");

    driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    values = new ArrayList<>();
}
 
Example 10
@Test
// Tests that a node in the Terminated state without an instance id is still considered a valid resource
public void testRequestNodeTerminatedNoInstanceId() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),10);
    node.updateStatus(AutomationDynamicNode.STATUS.TERMINATED);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    proxy.setMaxNumberOfConcurrentTestSessions(5);
    Map<String,Object> config = new HashMap<>();
    proxy.setConfig(config);
    List<TestSlot> testSlots = new ArrayList<TestSlot>();
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,browser);
    testSlots.add(new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities));
    proxy.setTestSlots(testSlots);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    AutomationRequestMatcher requestMatcher = new AutomationRequestMatcher();
    int freeThreads = requestMatcher.getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("Node should be available since instance id was not on the node", 1, freeThreads);
}
 
Example 11
Source Project: cloud-personslist-scenario   Source File: UiTestBase.java    License: Apache License 2.0 6 votes vote down vote up
private static void setupFirefox() {
	final DesiredCapabilities capabilities = new DesiredCapabilities();
	final String proxyHost = System.getProperty("http.proxyHost");
	final String proxyPort = System.getProperty("http.proxyPort");
	if (proxyHost != null) {
		System.out
				.println("Configuring Firefox Selenium web driver with proxy "
						+ proxyHost
						+ (proxyPort == null ? "" : ":" + proxyPort)
						+ " (requires Firefox browser)");
		final Proxy proxy = new Proxy();
		final String proxyString = proxyHost
				+ (proxyPort == null ? "" : ":" + proxyPort);
		proxy.setHttpProxy(proxyString).setSslProxy(proxyString);
		proxy.setNoProxy("localhost");
		capabilities.setCapability(CapabilityType.PROXY, proxy);
	} else {
		System.out
				.println("Configuring Firefox Selenium web driver without proxy (requires Firefox browser)");
	}

	driver = new FirefoxDriver(capabilities);
	driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
 
Example 12
@Test
// Tests that for an old run, the in progress tests are counted
public void testOldRunInProgress() {
    String uuid = "testUuid";
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM,"linux");
    capabilities.put(CapabilityType.BROWSER_NAME,"chrome");
    capabilities.put(AutomationConstants.UUID,uuid);
    AutomationRunRequest request = new AutomationRunRequest(uuid,10,"chrome","23","linux", AutomationUtils.modifyDate(new Date(),-5,Calendar.MINUTE));
    runContext.addRun(request);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    testSlot.getNewSession(capabilities);
    int inProgressTests = 5;
    proxy.setMultipleTestSlots(testSlot,inProgressTests);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals("Free threads should reflect in progress test count",inProgressTests,freeThreads);
}
 
Example 13
Source Project: selenium   Source File: FirefoxDriverTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@NotYetImplemented(value = MARIONETTE, reason = "https://bugzilla.mozilla.org/show_bug.cgi?id=1415067")
public void testFirefoxCanNativelyClickOverlappingElements() {
  FirefoxOptions options = new FirefoxOptions();
  options.setCapability(CapabilityType.OVERLAPPING_CHECK_DISABLED, true);
  localDriver = new FirefoxDriver(options);
  localDriver.get(appServer.whereIs("click_tests/overlapping_elements.html"));
  localDriver.findElement(By.id("under")).click();
  assertThat(localDriver.findElement(By.id("log")).getText())
      .isEqualTo("Log:\n"
               + "mousedown in over (handled by over)\n"
               + "mousedown in over (handled by body)\n"
               + "mouseup in over (handled by over)\n"
               + "mouseup in over (handled by body)\n"
               + "click in over (handled by over)\n"
               + "click in over (handled by body)");
}
 
Example 14
Source Project: vividus   Source File: VividusWebDriverFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public VividusWebDriver create()
{
    VividusWebDriver vividusWebDriver = createVividusWebDriver(bddRunContext.getRunningStory());

    WebDriver webDriver;
    DesiredCapabilities desiredCapabilities = vividusWebDriver.getDesiredCapabilities();
    if (proxy.isStarted())
    {
        desiredCapabilities.setCapability(CapabilityType.PROXY, createSeleniumProxy(remoteExecution));
        desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    }
    if (remoteExecution)
    {
        webDriver = webDriverFactory.getRemoteWebDriver(desiredCapabilities);
        vividusWebDriver.setRemote(true);
    }
    else
    {
        webDriver = webDriverFactory.getWebDriver(desiredCapabilities);
    }

    EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(webDriver);
    webDriverEventListeners.forEach(eventFiringWebDriver::register);

    vividusWebDriver.setWebDriver(eventFiringWebDriver);
    webDriverManager.resize(vividusWebDriver.getWrappedDriver(),
            browserWindowSizeProvider.getBrowserWindowSize(remoteExecution));
    return vividusWebDriver;
}
 
Example 15
Source Project: selenium   Source File: PageLoadingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Ignore(IE)
@NotYetImplemented(value = SAFARI, reason = "does not support insecure SSL")
@NotYetImplemented(EDGE)
public void testShouldBeAbleToAccessPagesWithAnInsecureSslCertificate() {
  createNewDriver(new ImmutableCapabilities(
      CapabilityType.ACCEPT_INSECURE_CERTS, Boolean.TRUE));
  driver.get(appServer.whereIsSecure("simpleTest.html"));

  shortWait.until(titleIs("Hello WebDriver"));
}
 
Example 16
@Test
// Tests a request can be fulfilled when chrome nodes have to be spun up
public void testRequestCanFulfillSpinUpNodesChrome() throws IOException, ServletException{
    MockVmManager manageEc2 = new MockVmManager();
    MockRequestMatcher matcher = new MockRequestMatcher();
    matcher.setThreadsToReturn(0);
    MockAutomationTestRunServlet servlet = new MockAutomationTestRunServlet(null,false, manageEc2,matcher);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("uuid","testUuid");
    request.setParameter("browser","chrome");
    request.setParameter("threadCount","7");
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"chrome");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    servlet.setProxySet(proxySet);
    AutomationContext.getContext().setTotalNodeCount(50);
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.doGet(request, response);
    Assert.assertEquals("Hub should be able to fulfill request",
            HttpServletResponse.SC_CREATED,response.getStatusCode());
}
 
Example 17
Source Project: hsac-fitnesse-fixtures   Source File: DriverFactory.java    License: Apache License 2.0 5 votes vote down vote up
static void addDefaultCapabilities(MutableCapabilities capabilities) {
    Set<String> capabilityNames = capabilities.getCapabilityNames();
    if (capabilityNames.contains(CapabilityType.BROWSER_NAME)
            && !capabilityNames.contains(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR)) {
        capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
    }
}
 
Example 18
Source Project: qaf   Source File: QAFExtendedWebDriver.java    License: MIT License 5 votes vote down vote up
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
	Object takeScreenshot = getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT);
	if (null == takeScreenshot || (Boolean) takeScreenshot) {
		String base64Str = execute(DriverCommand.SCREENSHOT).getValue().toString();
		return target.convertFromBase64Png(base64Str);
	}
	return null;
}
 
Example 19
Source Project: akita   Source File: CustomDriverProvider.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Задает options для запуска Firefox драйвера
 * options можно передавать, как системную переменную, например -Doptions=--load-extension=my-custom-extension
 *
 * @return FirefoxOptions
 */
private FirefoxOptions getFirefoxDriverOptions(DesiredCapabilities capabilities) {
    log.info("---------------Firefox Driver---------------------");
    FirefoxOptions firefoxOptions = !options[0].equals("") ? new FirefoxOptions().addArguments(options) : new FirefoxOptions();
    capabilities.setVersion(loadSystemPropertyOrDefault(CapabilityType.BROWSER_VERSION, VERSION_LATEST));
    firefoxOptions.setHeadless(getHeadless());
    firefoxOptions.merge(capabilities);
    return firefoxOptions;
}
 
Example 20
@Test
public void shouldReturnFalseWithDefaultCapabilitiesNotMatch_2() {
    Map<String, Object> nodeCapabilities = nodeCapabilities();

    Map<String, Object> requestedCapabilities = requestedCapabilities();
    requestedCapabilities.put(CapabilityType.PLATFORM, Platform.VISTA);

    assertFalse(capabilityMatcher.matches(nodeCapabilities, requestedCapabilities));
}
 
Example 21
Source Project: vividus   Source File: WebDriverManagerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testIsMobileFalse()
{
    Map<String, Object> capabilities = Map.of(
            CapabilityType.PLATFORM_NAME, Platform.LINUX.toString(),
            BROWSER_TYPE, BrowserType.CHROME
    );
    mockWebDriverHavingCapabilities(capabilities);
    assertFalse(webDriverManager.isMobile());
}
 
Example 22
Source Project: vividus   Source File: WebDriverManagerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void shouldBeAndroidNativeApp()
{
    webDriverManager.setNativeApp(true);
    mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID));
    assertTrue(webDriverManager.isAndroidNativeApp());
}
 
Example 23
Source Project: vividus   Source File: WebDriverManagerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void shouldNotBeAndroidNativeAppAsItIsIOS()
{
    webDriverManager.setNativeApp(true);
    mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, MobilePlatform.IOS));
    assertFalse(webDriverManager.isAndroidNativeApp());
}
 
Example 24
Source Project: vividus   Source File: WebDriverManagerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void shouldBeIOSNativeApp()
{
    webDriverManager.setNativeApp(true);
    mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, MobilePlatform.IOS));
    assertTrue(webDriverManager.isIOSNativeApp());
}
 
Example 25
Source Project: Quantum   Source File: UiDriverFactory.java    License: MIT License 5 votes vote down vote up
private Browsers(DesiredCapabilities desiredCapabilities) {
	this.desiredCapabilities = desiredCapabilities;
	this.desiredCapabilities.setJavascriptEnabled(true);
	this.desiredCapabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
	this.desiredCapabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);

}
 
Example 26
Source Project: at.info-knowledge-base   Source File: InternetExplorerRemote.java    License: MIT License 5 votes vote down vote up
@BeforeMethod
public void setUpProxy() throws Exception {
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(CapabilityType.PROXY, getProxy());
    //or
    //capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
}
 
Example 27
Source Project: vividus   Source File: WebDriverManagerTests.java    License: Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("orientationProvider")
void testIsOrientation(ScreenOrientation actualOrientation, ScreenOrientation orientationToCheck, String platform)
{
    when(webDriverProvider.getUnwrapped(Rotatable.class)).thenReturn(mobileDriver);
    when(webDriverManagerContext.getParameter(WebDriverManagerParameter.ORIENTATION)).thenReturn(null);
    when(mobileDriver.getOrientation()).thenReturn(actualOrientation);
    mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, platform));
    assertEquals(actualOrientation == orientationToCheck, webDriverManager.isOrientation(orientationToCheck));
    verify(webDriverManagerContext).putParameter(WebDriverManagerParameter.ORIENTATION, actualOrientation);
}
 
Example 28
@Test
// Test to make sure an in progress run only counts against the free nodes if the in progress run's browser
// matches the requested browser
public void testRequestNewRunNotStartedDifferentBrowser() throws IOException, ServletException{
    String nonMatchingBrowser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    String runId = "runId";
    AutomationContext.getContext().addRun(new AutomationRunRequest(runId,10,"firefox"));
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy nonMatchingProxy = new MockRemoteProxy();
    nonMatchingProxy.setMaxNumberOfConcurrentTestSessions(50);
    nonMatchingProxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    nonMatchingProxy.setConfig(config);
    Map<String,Object> nonMatchingCapabilities = new HashMap<String,Object>();
    nonMatchingCapabilities.put(CapabilityType.BROWSER_NAME, nonMatchingBrowser);
    TestSlot nonMatchingTestSlot = new TestSlot(nonMatchingProxy, SeleniumProtocol.WebDriver,null,nonMatchingCapabilities);
    nonMatchingProxy.setMultipleTestSlots(nonMatchingTestSlot, 10);
    proxySet.add(nonMatchingProxy);
    String matchingBrowser = "chrome";

    MockRemoteProxy matchingProxy = new MockRemoteProxy();
    proxySet.add(matchingProxy);
    matchingProxy.setMaxNumberOfConcurrentTestSessions(50);
    matchingProxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    matchingProxy.setConfig(config);
    Map<String,Object> matchingCapabilities = new HashMap<String,Object>();
    matchingCapabilities.put(CapabilityType.BROWSER_NAME, matchingBrowser);
    TestSlot matchingTestSlot = new TestSlot(nonMatchingProxy, SeleniumProtocol.WebDriver,null,matchingCapabilities);
    matchingProxy.setMultipleTestSlots(matchingTestSlot, 10);

    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(matchingBrowser));
    Assert.assertEquals("Nodes should be free even though run is in progress as browsers do not match",10,freeThreads);
}
 
Example 29
@Test
// 5 firefox, 5 chrome slots, (10 node total) 5 in progress chrome tests, firefox should still show 5 free
public void testMultipleBrowsersInUse() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(10);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> nonMatchingCapabilities = new HashMap<String,Object>();
    nonMatchingCapabilities.put(CapabilityType.BROWSER_NAME, "chrome");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,nonMatchingCapabilities);
    testSlot.getNewSession(nonMatchingCapabilities);
    proxy.setMultipleTestSlots(testSlot, 5);
    proxySet.add(proxy);

    Map<String,Object> matchingCapabilities = new HashMap<String,Object>();
    matchingCapabilities.put(CapabilityType.BROWSER_NAME, browser);
    TestSlot testSlot2 = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,matchingCapabilities);
    proxy.setMultipleTestSlots(testSlot2, 5);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("No nodes should be free since existing run is still new",5,freeThreads);
}
 
Example 30
/**
 * Generates a AutomationRunRequest object from the capabilities passed in
 * @param capabilities
 * @return
 */
public static AutomationRunRequest requestFromCapabilities(Map<String,Object> capabilities) {
    String capabilityBrowser = (String)capabilities.get(CapabilityType.BROWSER_NAME);
    String capabilityBrowserVersion = null;
    if(capabilities.containsKey(CapabilityType.VERSION)) {
        capabilityBrowserVersion = (String)capabilities.get(CapabilityType.VERSION);
    }
    String capabilityOs = (String)capabilities.get(CapabilityType.PLATFORM);
    return new AutomationRunRequest(null,null,capabilityBrowser,capabilityBrowserVersion,capabilityOs);
}