org.openqa.selenium.UnsupportedCommandException Java Examples

The following examples show how to use org.openqa.selenium.UnsupportedCommandException. 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: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void elementClearOnNonClearableComponents() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    try {
        element1.clear();
        throw new MissingException(UnsupportedCommandException.class);
    } catch (UnsupportedCommandException e) {

    }
}
 
Example #2
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void isSelectedOnNonSelectableComponents() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("text-field"));
    try {
        element1.isSelected();
        throw new MissingException(UnsupportedCommandException.class);
    } catch (UnsupportedCommandException e) {

    }
}
 
Example #3
Source File: W3CHttpResponseCodecTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void decodingAnErrorWithoutAStacktraceIsDecodedProperlyForConformingImplementations() {
  Map<String, Object> error = new HashMap<>();
  error.put("error", "unsupported operation");  // 500
  error.put("message", "I like peas");
  error.put("stacktrace", "");
  Map<String, Object> data = new HashMap<>();
  data.put("value", error);

  HttpResponse response = createValidResponse(HTTP_INTERNAL_ERROR, data);

  Response decoded = new W3CHttpResponseCodec().decode(response);

  assertThat(decoded.getState()).isEqualTo("unsupported operation");
  assertThat(decoded.getStatus().intValue()).isEqualTo(METHOD_NOT_ALLOWED);

  assertThat(decoded.getValue()).isInstanceOf(UnsupportedCommandException.class);
  assertThat(((WebDriverException) decoded.getValue()).getMessage()).contains("I like peas");
}
 
Example #4
Source File: RemoteDriverFactory.java    From seleniumtestsframework with Apache License 2.0 6 votes vote down vote up
protected void setPageLoadTimeout(final long timeout, final BrowserType type) {
    switch (type) {

        case Chrome :
            try {
                driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
            } catch (UnsupportedCommandException e) {
                e.printStackTrace();
            }

            break;

        case FireFox :
        case InternetExplore :
            driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
            break;

        default :
    }
}
 
Example #5
Source File: W3CHttpResponseCodecTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void decodingAnErrorWithoutAStacktraceIsDecodedProperlyForNonCompliantImplementations() {
  Map<String, Object> error = new HashMap<>();
  error.put("error", "unsupported operation");  // 500
  error.put("message", "I like peas");
  error.put("stacktrace", "");

  HttpResponse response = createValidResponse(HTTP_INTERNAL_ERROR, error);

  Response decoded = new W3CHttpResponseCodec().decode(response);

  assertThat(decoded.getState()).isEqualTo("unsupported operation");
  assertThat(decoded.getStatus().intValue()).isEqualTo(METHOD_NOT_ALLOWED);

  assertThat(decoded.getValue()).isInstanceOf(UnsupportedCommandException.class);
  assertThat(((WebDriverException) decoded.getValue()).getMessage()).contains("I like peas");
}
 
Example #6
Source File: ErrorHandlerTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void testThrowsCorrectExceptionTypes() {
  assertThrowsCorrectExceptionType(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class);
  assertThrowsCorrectExceptionType(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class);
  assertThrowsCorrectExceptionType(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class);
  assertThrowsCorrectExceptionType(
      ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class);
  assertThrowsCorrectExceptionType(
      ErrorCodes.METHOD_NOT_ALLOWED, UnsupportedCommandException.class);
  assertThrowsCorrectExceptionType(
      ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class);
  assertThrowsCorrectExceptionType(
      ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class);
  assertThrowsCorrectExceptionType(
      ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class);
  assertThrowsCorrectExceptionType(
      ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class);
  assertThrowsCorrectExceptionType(ErrorCodes.INVALID_ELEMENT_COORDINATES,
      InvalidCoordinatesException.class);
}
 
Example #7
Source File: RemoteLogs.java    From selenium with Apache License 2.0 6 votes vote down vote up
private LogEntries getRemoteEntries(String logType) {
  Object raw = executeMethod.execute(DriverCommand.GET_LOG, ImmutableMap.of(TYPE_KEY, logType));
  if (!(raw instanceof List)) {
    throw new UnsupportedCommandException("malformed response to remote logs command");
  }
  @SuppressWarnings("unchecked")
  List<Map<String, Object>> rawList = (List<Map<String, Object>>) raw;
  List<LogEntry> remoteEntries = new ArrayList<>(rawList.size());

  for (Map<String, Object> obj : rawList) {
    remoteEntries.add(new LogEntry(LogLevelMapping.toLevel((String)obj.get(LEVEL)),
        (Long) obj.get(TIMESTAMP),
        (String) obj.get(MESSAGE)));
  }
  return new LogEntries(remoteEntries);
}
 
Example #8
Source File: TimeoutConfigurerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testSetTimeoutsWithExceptionAtScriptTimeoutSetting()
{
    Timeouts timeouts = mock(Timeouts.class);
    UnsupportedCommandException exception = new UnsupportedCommandException("asynctimeout");
    when(timeouts.setScriptTimeout(ASYNC_SCRIPT_TIMEOUT, ASYNC_SCRIPT_TIMEOUT_TIMEUNIT)).thenThrow(exception);
    timeoutConfigurer.configure(timeouts);
    verify(timeouts).pageLoadTimeout(PAGE_LOAD_TIMEOUT, PAGE_LOAD_TIMEOUT_TIMEUNIT);
}
 
Example #9
Source File: JsonHttpCommandHandler.java    From selenium with Apache License 2.0 5 votes vote down vote up
private Command decode(HttpRequest request) {
  UnsupportedCommandException lastException = null;
  for (CommandCodec<HttpRequest> codec : commandCodecs) {
    try {
      return codec.decode(request);
    } catch (UnsupportedCommandException e) {
      lastException = e;
    }
  }
  if (lastException != null) {
    throw lastException;
  }
  throw new UnsupportedOperationException("Cannot find command for: " + request.getUri());
}
 
Example #10
Source File: JsonHttpCommandCodecTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void treatsNullPathAsRoot_unrecognizedCommand() {
  codec.defineCommand("num", GET, "/");

  byte[] data = "{\"char\":\"水\"}".getBytes(UTF_8);
  HttpRequest request = new HttpRequest(POST, null);
  request.setHeader(CONTENT_TYPE, JSON_UTF_8.withoutParameters().toString());
  request.setHeader(CONTENT_LENGTH, String.valueOf(data.length));
  request.setContent(bytes(data));

  assertThatExceptionOfType(UnsupportedCommandException.class)
      .isThrownBy(() -> codec.decode(request));
}
 
Example #11
Source File: JsonHttpCommandCodecTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void treatsEmptyPathAsRoot_unrecognizedCommand() {
  codec.defineCommand("num", GET, "/");

  byte[] data = "{\"char\":\"水\"}".getBytes(UTF_8);
  HttpRequest request = new HttpRequest(POST, "");
  request.setHeader(CONTENT_TYPE, JSON_UTF_8.withoutParameters().toString());
  request.setHeader(CONTENT_LENGTH, String.valueOf(data.length));
  request.setContent(bytes(data));

  assertThatExceptionOfType(UnsupportedCommandException.class)
      .isThrownBy(() -> codec.decode(request));
}
 
Example #12
Source File: JsonHttpCommandCodecTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void throwsIfEncodedCommandHasNoMapping() {
  HttpRequest request = new HttpRequest(GET, "/foo/bar/baz");
  assertThatExceptionOfType(UnsupportedCommandException.class)
      .isThrownBy(() -> codec.decode(request))
      .withMessageStartingWith("GET /foo/bar/baz\n");
}
 
Example #13
Source File: JsonHttpCommandCodecTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void throwsIfCommandNameIsNotRecognized() {
  Command command = new Command(null, "garbage-command-name");
  assertThatExceptionOfType(UnsupportedCommandException.class)
      .isThrownBy(() -> codec.encode(command))
      .withMessageStartingWith(command.getName() + "\n");
}
 
Example #14
Source File: AbstractHttpCommandCodec.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public HttpRequest encode(Command command) {
  String name = aliases.getOrDefault(command.getName(), command.getName());
  CommandSpec spec = nameToSpec.get(name);
  if (spec == null) {
    throw new UnsupportedCommandException(command.getName());
  }
  Map<String, ?> parameters = amendParameters(command.getName(), command.getParameters());
  String uri = buildUri(name, command.getSessionId(), parameters, spec);

  HttpRequest request = new HttpRequest(spec.method, uri);

  if (HttpMethod.POST == spec.method) {

    String content = json.toJson(parameters);
    byte[] data = content.getBytes(UTF_8);

    request.setHeader(CONTENT_LENGTH, String.valueOf(data.length));
    request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString());
    request.setContent(bytes(data));
  }

  if (HttpMethod.GET == spec.method) {
    request.setHeader(CACHE_CONTROL, "no-cache");
  }

  return request;
}
 
Example #15
Source File: Actions.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void perform() {
  if (driver == null) {
    // One of the deprecated constructors was used. Fall back to the old way for now.
    fallBack.perform();
    return;
  }

  try {
    ((Interactive) driver).perform(sequences.values());
  } catch (ClassCastException | UnsupportedCommandException e) {
    // Fall back to the old way of doing things. Old Skool #ftw
    fallBack.perform();
  }
}
 
Example #16
Source File: SauceLabsDriverFactory.java    From seleniumtestsframework with Apache License 2.0 5 votes vote down vote up
protected void setPageLoadTimeout(final long timeout) {
    try {
        driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
    } catch (UnsupportedCommandException e) {
        // chromedriver does not support pageLoadTimeout
    }
}
 
Example #17
Source File: SideBarIT.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOverviewLayout() throws InterruptedException {
    this.setTestName(getClassname() + "-testOvervieLayout");
    this.getDriver();
    this.getAppController().openViewer(this.getDriver(), getTestDerivate());

    ImageViewerController controller = this.getViewerController();

    ToolBarController tbController = controller.getToolBarController();
    SideBarController sbController = controller.getSideBarController();

    tbController.pressButton(ToolBarController.BUTTON_ID_SIDEBAR_CONTROLL);
    tbController.clickElementById(ImageOverviewController.IMAGE_OVERVIEW_SELECTOR);

    int before = sbController.countThumbnails();

    try {
        sbController.dragAndDropByXpath("//div[contains(@class,'sidebar')]/span[@class='resizer']", 300, 0);
    } catch (UnsupportedCommandException e) {
        LOGGER.warn("Driver does not support Actions", e);
        return;
    }

    Thread.sleep(1000);
    int after = sbController.countThumbnails();

    Assert.assertEquals(2 * before, after);
}
 
Example #18
Source File: SideBarIT.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
/**
 * Ignored because https://github.com/mozilla/geckodriver/issues/233
 */
public void testSideBarResize() throws Exception {
    this.setTestName(getClassname() + "-testSideBarResize");
    this.getDriver();
    this.getAppController().openViewer(this.getDriver(), getTestDerivate());

    ImageViewerController controller = this.getViewerController();

    ToolBarController tbController = controller.getToolBarController();
    SideBarController sbController = controller.getSideBarController();

    tbController.pressButton(ToolBarController.BUTTON_ID_SIDEBAR_CONTROLL);
    tbController.clickElementById(ImageOverviewController.IMAGE_OVERVIEW_SELECTOR);

    int sbWidthStart = sbController.getSideBarWidth();

    try { // Firefox does not support actions so we just let the test pass.
        sbController.dragAndDropByXpath("//div[contains(@class,\"sidebar\")]/span[@class=\"resizer\"]", 50, 0);
    } catch (UnsupportedCommandException e) {
        LOGGER.warn("Driver does not support Actions", e);
        return;
    }
    int sbWidthEnd = sbController.getSideBarWidth();

    assertLess(sbWidthEnd, sbWidthStart, "Sidebar width schould be increased!");

}
 
Example #19
Source File: ReadBrowserLogs.java    From opentest with MIT License 5 votes vote down vote up
@Override
public void run() {
    this.waitForAsyncCallsToFinish();

    try {
        List<LogEntry> logEntries = driver.manage().logs().get("browser").getAll();
        this.writeOutput("entries", this.getActor().toJsArray(logEntries));
    } catch (UnsupportedCommandException exc) {
        // Some browsers don't implement the logging API. If so, we'll just
        // return an empty array.
        this.writeOutput("entries", this.getActor().toJsArray(new ArrayList()));
    }
}
 
Example #20
Source File: JListXTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void unsupportedPseudoElement() throws Throwable {
    driver = new JavaDriver();
    try {
        driver.findElement(By.cssSelector("#list-1::xth-item(21)"));
        throw new MissingException(UnsupportedCommandException.class);
    } catch (UnsupportedCommandException e) {

    }
}
 
Example #21
Source File: Frame.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Switch driver focus to the parent of the specified frame context element.
 * <p>
 * <b>NOTE</b> This method initially invokes {@code driver.switchTo().parentFrame()}. If that fails with
 * {@link UnsupportedCommandException}, it invokes {@code element.switchTo()} as a fallback.
 * 
 * @param element frame context element
 * @return parent search context
 */
public static SearchContext switchToParentFrame(final RobustWebElement element) {
    if (canSwitchToParentFrame) {
        try {
            return element.getWrappedDriver().switchTo().parentFrame();
        } catch (WebDriverException e) {
            if (Throwables.getRootCause(e) instanceof UnsupportedCommandException) {
                canSwitchToParentFrame = false;
            } else {
                throw e;
            }
        }
    }
    return element.switchTo();
}
 
Example #22
Source File: TimeoutConfigurerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testSetTimeoutsWithExceptionAtPageLoadTimeoutSetting()
{
    Timeouts timeouts = mock(Timeouts.class);
    UnsupportedCommandException exception = new UnsupportedCommandException("pagetimeout");
    when(timeouts.pageLoadTimeout(PAGE_LOAD_TIMEOUT, PAGE_LOAD_TIMEOUT_TIMEUNIT)).thenThrow(exception);
    timeoutConfigurer.configure(timeouts);
    verify(timeouts).setScriptTimeout(ASYNC_SCRIPT_TIMEOUT, ASYNC_SCRIPT_TIMEOUT_TIMEUNIT);
}
 
Example #23
Source File: CustomHttpCommandExecutor.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
public Response execute(Command command) throws IOException {
	if (command.getSessionId() == null) {
		if (QUIT.equals(command.getName())) {
			return new Response();
		}
		if (!GET_ALL_SESSIONS.equals(command.getName()) && !NEW_SESSION.equals(command.getName())) {
			throw new NoSuchSessionException("Session ID is null. Using WebDriver after calling quit()?");
		}
	}

	if (NEW_SESSION.equals(command.getName())) {
		if (commandCodec != null) {
			throw new SessionNotCreatedException("Session already exists");
		}
		ProtocolHandshake handshake = new ProtocolHandshake();
		log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true));
		ProtocolHandshake.Result result = handshake.createSession(client, command);
		dialect = result.getDialect();
		commandCodec = dialect.getCommandCodec();
		for (Map.Entry<String, CommandInfo> entry : additionalCommands.entrySet()) {
			defineCommand(entry.getKey(), entry.getValue());
		}
		responseCodec = dialect.getResponseCodec();
		log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false));
		return result.createResponse();
	}

	if (commandCodec == null || responseCodec == null) {
		throw new WebDriverException("No command or response codec has been defined. Unable to proceed");
	}

	HttpRequest httpRequest = commandCodec.encode(command);
	try {
		log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true));
		HttpResponse httpResponse = client.execute(httpRequest, true);
		log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false));

		Response response = responseCodec.decode(httpResponse);
		if (response.getSessionId() == null) {
			if (httpResponse.getTargetHost() != null) {
				response.setSessionId(HttpSessionId.getSessionId(httpResponse.getTargetHost()));
			} else {
				// Spam in the session id from the request
				response.setSessionId(command.getSessionId().toString());
			}
		}
		if (QUIT.equals(command.getName())) {
			client.close();
		}
		return response;
	} catch (UnsupportedCommandException e) {
		if (e.getMessage() == null || "".equals(e.getMessage())) {
			throw new UnsupportedOperationException(
					"No information from server. Command name was: " + command.getName(), e.getCause());
		}
		throw e;
	}
}
 
Example #24
Source File: AndroidDriverFactory.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
protected void setPageLoadTimeout(final long timeout) {
    try {
        driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
    } catch (UnsupportedCommandException e) {
    }
}
 
Example #25
Source File: HttpCommandExecutor.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public Response execute(Command command) throws IOException {
  if (command.getSessionId() == null) {
    if (QUIT.equals(command.getName())) {
      return new Response();
    }
    if (!GET_ALL_SESSIONS.equals(command.getName())
        && !NEW_SESSION.equals(command.getName())) {
      throw new NoSuchSessionException(
          "Session ID is null. Using WebDriver after calling quit()?");
    }
  }

  if (NEW_SESSION.equals(command.getName())) {
    if (commandCodec != null) {
      throw new SessionNotCreatedException("Session already exists");
    }
    ProtocolHandshake handshake = new ProtocolHandshake();
    log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true));
    ProtocolHandshake.Result result = handshake.createSession(client, command);
    Dialect dialect = result.getDialect();
    commandCodec = dialect.getCommandCodec();
    for (Map.Entry<String, CommandInfo> entry : additionalCommands.entrySet()) {
      defineCommand(entry.getKey(), entry.getValue());
    }
    responseCodec = dialect.getResponseCodec();
    log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false));
    return result.createResponse();
  }

  if (commandCodec == null || responseCodec == null) {
    throw new WebDriverException(
        "No command or response codec has been defined. Unable to proceed");
  }

  HttpRequest httpRequest = commandCodec.encode(command);
  try {
    log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true));
    HttpResponse httpResponse = client.execute(httpRequest);
    log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false));

    Response response = responseCodec.decode(httpResponse);
    if (response.getSessionId() == null) {
      if (httpResponse.getTargetHost() != null) {
        response.setSessionId(getSessionId(httpResponse.getTargetHost()).orElse(null));
      } else {
        // Spam in the session id from the request
        response.setSessionId(command.getSessionId().toString());
      }
    }
    if (QUIT.equals(command.getName())) {
      httpClientFactory.cleanupIdleClients();
    }
    return response;
  } catch (UnsupportedCommandException e) {
    if (e.getMessage() == null || "".equals(e.getMessage())) {
      throw new UnsupportedOperationException(
          "No information from server. Command name was: " + command.getName(),
          e.getCause());
    }
    throw e;
  }
}
 
Example #26
Source File: IPhoneDriverFactory.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
protected void setPageLoadTimeout(final long timeout) {
    try {
        driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
    } catch (UnsupportedCommandException e) {
    }
}
 
Example #27
Source File: ErrorHandlerTest.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Test
public void testStatusCodesRaisedBackToStatusMatches() {
  Map<Integer, Class<?>> exceptions = new HashMap<>();
  exceptions.put(ErrorCodes.NO_SUCH_SESSION, NoSuchSessionException.class);
  exceptions.put(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class);
  exceptions.put(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class);
  exceptions.put(ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class);
  exceptions.put(ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class);
  exceptions.put(ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class);
  exceptions.put(ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class);
  exceptions.put(ErrorCodes.UNHANDLED_ERROR, WebDriverException.class);
  exceptions.put(ErrorCodes.ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class);
  exceptions.put(ErrorCodes.JAVASCRIPT_ERROR, JavascriptException.class);
  exceptions.put(ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class);
  exceptions.put(ErrorCodes.TIMEOUT, TimeoutException.class);
  exceptions.put(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class);
  exceptions.put(ErrorCodes.INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class);
  exceptions.put(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class);
  exceptions.put(ErrorCodes.UNEXPECTED_ALERT_PRESENT, UnhandledAlertException.class);
  exceptions.put(ErrorCodes.NO_ALERT_PRESENT, NoAlertPresentException.class);
  exceptions.put(ErrorCodes.ASYNC_SCRIPT_TIMEOUT, ScriptTimeoutException.class);
  exceptions.put(ErrorCodes.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesException.class);
  exceptions.put(ErrorCodes.IME_NOT_AVAILABLE, ImeNotAvailableException.class);
  exceptions.put(ErrorCodes.IME_ENGINE_ACTIVATION_FAILED, ImeActivationFailedException.class);
  exceptions.put(ErrorCodes.INVALID_SELECTOR_ERROR, InvalidSelectorException.class);
  exceptions.put(ErrorCodes.SESSION_NOT_CREATED, SessionNotCreatedException.class);
  exceptions.put(ErrorCodes.MOVE_TARGET_OUT_OF_BOUNDS, MoveTargetOutOfBoundsException.class);
  exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR, InvalidSelectorException.class);
  exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR_RETURN_TYPER, InvalidSelectorException.class);

  for (Map.Entry<Integer, Class<?>> exception : exceptions.entrySet()) {
    assertThatExceptionOfType(WebDriverException.class)
        .isThrownBy(() -> handler.throwIfResponseFailed(createResponse(exception.getKey()), 123))
        .satisfies(e -> {
          assertThat(e.getClass().getSimpleName()).isEqualTo(exception.getValue().getSimpleName());

          // all of the special invalid selector exceptions are just mapped to the generic invalid selector
          int expected = e instanceof InvalidSelectorException
                         ? ErrorCodes.INVALID_SELECTOR_ERROR : exception.getKey();
          assertThat(new ErrorCodes().toStatusCode(e)).isEqualTo(expected);
        });
  }
}
 
Example #28
Source File: ChromeDriverFactory.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
protected void setPageLoadTimeout(final long timeout) {
    try {
        driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
    } catch (UnsupportedCommandException e) { }
}