Package com.codeborne.selenide.impl

Source Code of com.codeborne.selenide.impl.Cleanup

package com.codeborne.selenide.impl;

import org.openqa.selenium.InvalidSelectorException;
import org.openqa.selenium.WebDriverException;

public class Cleanup {
  public static Cleanup of = new Cleanup();

  public String webdriverExceptionMessage(WebDriverException webDriverException) {
    return webdriverExceptionMessage(webDriverException.toString());
  }

  protected String webdriverExceptionMessage(String webDriverExceptionInfo) {
    return webDriverExceptionInfo == null || webDriverExceptionInfo.indexOf('\n') == -1 ?
        webDriverExceptionInfo :
        webDriverExceptionInfo
            .substring(0, webDriverExceptionInfo.indexOf('\n'))
            .replaceFirst("(.*)\\(WARNING: The server did not provide any stacktrace.*", "$1")
            .replaceFirst("org\\.openqa\\.selenium\\.(.*)", "$1")
            .trim();
  }

  public boolean isInvalidSelectorError(Throwable error) {
    return (error instanceof InvalidSelectorException) ||
        error.getMessage().contains("invalid or illegal string was specified") ||
        error.getMessage().contains("nvalid selector") ||
        error.getMessage().contains("is not a valid selector") ||
        error.getMessage().contains("SYNTAX_ERR") ||
        error.getCause() != null && error.getCause() != error && isInvalidSelectorError(error.getCause());
  }

  public InvalidSelectorException wrap(RuntimeException error) {
    return (error instanceof InvalidSelectorException) ?
        (InvalidSelectorException) error :
        new InvalidSelectorException("Invalid selector", error);
  }
}
TOP

Related Classes of com.codeborne.selenide.impl.Cleanup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.