Search in sources :

Example 1 with DriverExceptions

use of com.seleniumtests.customexception.DriverExceptions in project seleniumRobot by bhecquet.

the class SauceLabsDriverFactory method createNativeDriver.

@Override
protected WebDriver createNativeDriver() {
    MutableCapabilities capabilities = createCapabilities();
    capabilities.merge(driverOptions);
    try {
        if (ANDROID_PLATFORM.equalsIgnoreCase(webDriverConfig.getPlatform())) {
            return new AndroidDriver<WebElement>(new URL(webDriverConfig.getHubUrl().get(0)), capabilities);
        } else if ("ios".equalsIgnoreCase(webDriverConfig.getPlatform())) {
            return new IOSDriver<WebElement>(new URL(webDriverConfig.getHubUrl().get(0)), capabilities);
        } else {
            return new RemoteWebDriver(new URL(webDriverConfig.getHubUrl().get(0)), capabilities);
        }
    } catch (MalformedURLException e) {
        throw new DriverExceptions("Error creating driver: " + e.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DriverExceptions(com.seleniumtests.customexception.DriverExceptions) MutableCapabilities(org.openqa.selenium.MutableCapabilities) AndroidDriver(io.appium.java_client.android.AndroidDriver) WebElement(org.openqa.selenium.WebElement) URL(java.net.URL)

Example 2 with DriverExceptions

use of com.seleniumtests.customexception.DriverExceptions in project seleniumRobot by bhecquet.

the class BrowserStackDriverFactory method createNativeDriver.

@Override
protected WebDriver createNativeDriver() {
    MutableCapabilities capabilities = createCapabilities();
    capabilities.merge(driverOptions);
    try {
        return new RemoteWebDriver(new URL(webDriverConfig.getHubUrl().get(0)), capabilities);
    } catch (MalformedURLException e) {
        throw new DriverExceptions("Error creating driver: " + e.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DriverExceptions(com.seleniumtests.customexception.DriverExceptions) MutableCapabilities(org.openqa.selenium.MutableCapabilities) URL(java.net.URL)

Example 3 with DriverExceptions

use of com.seleniumtests.customexception.DriverExceptions in project seleniumRobot by bhecquet.

the class HtmlElement method getUnderlyingElement.

/*
	 * Methods for mobile actions only
	 */
/**
 * findElement returns a EventFiringWebElement which is not compatible with
 * MobileElement Get the unerlying element and return it
 */
private WebElement getUnderlyingElement(WebElement localElement) {
    if (localElement.getClass().getName().contains("EventFiringWebElement")) {
        try {
            Method getWrappedElementMethod = localElement.getClass().getDeclaredMethod("getWrappedElement");
            getWrappedElementMethod.setAccessible(true);
            return (WebElement) getWrappedElementMethod.invoke(localElement);
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw new DriverExceptions("cannot get wrapped Element", e);
        }
    } else {
        return localElement;
    }
}
Also used : DriverExceptions(com.seleniumtests.customexception.DriverExceptions) Method(java.lang.reflect.Method) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with DriverExceptions

use of com.seleniumtests.customexception.DriverExceptions in project seleniumRobot by bhecquet.

the class AppiumDriverFactory method createNativeDriver.

@Override
protected WebDriver createNativeDriver() {
    // start appium
    appiumLauncher = AppiumLauncherFactory.getInstance();
    appiumLauncher.startAppium();
    try {
        MutableCapabilities capabilities = getMobileCapabilities();
        if (ANDROID_PLATORM.equalsIgnoreCase(webDriverConfig.getPlatform())) {
            extractAndroidDriver(capabilities);
            return new AndroidDriver<WebElement>(new URL(appiumLauncher.getAppiumServerUrl()), capabilities);
        } else if ("ios".equalsIgnoreCase(webDriverConfig.getPlatform())) {
            return new IOSDriver<WebElement>(new URL(appiumLauncher.getAppiumServerUrl()), capabilities);
        } else {
            throw new ConfigurationException(String.format("Platform %s is unknown for Appium tests", webDriverConfig.getPlatform()));
        }
    } catch (MalformedURLException e) {
        throw new DriverExceptions("Error creating driver: " + e.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) DriverExceptions(com.seleniumtests.customexception.DriverExceptions) MutableCapabilities(org.openqa.selenium.MutableCapabilities) AndroidDriver(io.appium.java_client.android.AndroidDriver) WebElement(org.openqa.selenium.WebElement) URL(java.net.URL)

Example 5 with DriverExceptions

use of com.seleniumtests.customexception.DriverExceptions in project seleniumRobot by bhecquet.

the class StubTestClass method testWithExceptionOnFirstExec.

/**
 * Test which fails only on first execution
 */
@Test(groups = "stub")
public void testWithExceptionOnFirstExec() {
    TestStep step1 = new TestStep("step 10", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    step1.addAction(new TestAction(String.format("played %d times", count), false, new ArrayList<>()));
    step1.addAction(new TestAction("click button", false, new ArrayList<>()));
    TestStepManager.logTestStep(step1);
    if (!failed) {
        failed = true;
        throw new DriverExceptions("some exception");
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) DriverExceptions(com.seleniumtests.customexception.DriverExceptions) ArrayList(java.util.ArrayList) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test)

Aggregations

DriverExceptions (com.seleniumtests.customexception.DriverExceptions)13 TestAction (com.seleniumtests.reporter.logger.TestAction)8 TestStep (com.seleniumtests.reporter.logger.TestStep)8 ArrayList (java.util.ArrayList)8 Test (org.testng.annotations.Test)8 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 MutableCapabilities (org.openqa.selenium.MutableCapabilities)3 WebElement (org.openqa.selenium.WebElement)3 AndroidDriver (io.appium.java_client.android.AndroidDriver)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Path (java.nio.file.Path)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1