Search in sources :

Example 1 with ConfigurationException

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

the class SauceLabsDriverFactory method uploadFile.

/**
 * Upload application to saucelabs server
 * @param targetAppPath
 * @param serverURL
 * @return
 * @throws IOException
 * @throws AuthenticationException
 */
protected static boolean uploadFile(String targetAppPath) throws IOException, AuthenticationException {
    // extract user name and password from getWebDriverGrid
    Matcher matcher = REG_USER_PASSWORD.matcher(SeleniumTestsContextManager.getThreadContext().getWebDriverGrid().get(0));
    String user;
    String password;
    if (matcher.matches()) {
        user = matcher.group(1);
        password = matcher.group(2);
    } else {
        throw new ConfigurationException("getWebDriverGrid variable does not have the right format for connecting to sauceLabs");
    }
    FileEntity entity = new FileEntity(new File(targetAppPath));
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, password);
    HttpPost request = new HttpPost(String.format(SAUCE_UPLOAD_URL, user, new File(targetAppPath).getName()));
    request.setEntity(entity);
    request.addHeader(new BasicScheme().authenticate(creds, request, null));
    request.addHeader("Content-Type", "application/octet-stream");
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        CloseableHttpResponse response = client.execute(request);
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new ConfigurationException("Application file upload failed: " + response.getStatusLine().getReasonPhrase());
        }
    }
    return true;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicScheme(org.apache.http.impl.auth.BasicScheme) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) FileEntity(org.apache.http.entity.FileEntity) Matcher(java.util.regex.Matcher) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) File(java.io.File) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with ConfigurationException

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

the class CustomTestNGCucumberRunner method provideScenarios.

/**
 * @return returns the cucumber scenarios as a two dimensional array of {@link PickleEventWrapper}
 * scenarios combined with their {@link CucumberFeatureWrapper} feature.
 */
public Object[][] provideScenarios() {
    try {
        List<Object[]> scenarios = new ArrayList<>();
        List<CucumberFeature> features = getFeatures();
        for (CucumberFeature feature : features) {
            for (PickleEvent pickle : feature.getPickles()) {
                if (filters.matchesFilters(pickle)) {
                    ScenarioDefinition scenario = getScenarioDefinitionFromPickle(feature.getGherkinFeature().getFeature(), pickle);
                    scenarios.add(new Object[] { new CucumberScenarioWrapper(pickle, scenario) });
                }
            }
        }
        // no scenario found, search among feature name and feature file name
        if (scenarios.isEmpty()) {
            scenarios.addAll(provideScenariosFromFeatureFiles(features));
        }
        return scenarios.toArray(new Object[][] {});
    } catch (CucumberException e) {
        throw new ConfigurationException("Error while providing cucumber scenario", e);
    }
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ScenarioDefinition(gherkin.ast.ScenarioDefinition) ArrayList(java.util.ArrayList) PickleEvent(gherkin.events.PickleEvent) CucumberException(cucumber.runtime.CucumberException)

Example 3 with ConfigurationException

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

the class SeleniumTestPlan method getDatasetFile.

private File getDatasetFile(Method testMethod) {
    File csvDatasetFile = Paths.get(robotConfig().getApplicationDataPath(), "dataset", robotConfig().getTestEnv(), testMethod.getName() + ".csv").toFile();
    File xlsxDatasetFile = Paths.get(robotConfig().getApplicationDataPath(), "dataset", robotConfig().getTestEnv(), testMethod.getName() + ".xlsx").toFile();
    if (csvDatasetFile.exists()) {
        return csvDatasetFile;
    } else if (xlsxDatasetFile.exists()) {
        return xlsxDatasetFile;
    } else {
        throw new ConfigurationException(String.format("Dataset file %s or %s does not exist", csvDatasetFile, xlsxDatasetFile));
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) File(java.io.File)

Example 4 with ConfigurationException

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

the class SeleniumTestsContext method setPageLoadStrategy.

public void setPageLoadStrategy(String strategy) {
    if (strategy != null) {
        PageLoadStrategy pls = PageLoadStrategy.fromString(strategy);
        if (pls == null) {
            throw new ConfigurationException("PageLoadStrategy values are 'eager', 'normal' (default one) and 'none'");
        }
        setAttribute(PAGE_LOAD_STRATEGY, pls);
    } else {
        setAttribute(PAGE_LOAD_STRATEGY, DEFAULT_PAGE_LOAD_STRATEGY);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) PageLoadStrategy(org.openqa.selenium.PageLoadStrategy)

Example 5 with ConfigurationException

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

the class SeleniumTestsContext method updatePlatformVersion.

/**
 * From platform name, in case of Desktop platform, do nothing and in case of mobile, extract OS version from name
 * as platformName will be 'Android 5.0' for example
 *
 * @throws ConfigurationException 	in mobile, if version is not present
 */
private void updatePlatformVersion() {
    try {
        Platform currentPlatform = Platform.fromString(getPlatform());
        if (!(currentPlatform.is(Platform.WINDOWS) || currentPlatform.is(Platform.MAC) || currentPlatform.is(Platform.UNIX) || currentPlatform.is(Platform.ANY) && getRunMode() == DriverMode.GRID)) {
            throw new WebDriverException("");
        }
    } catch (WebDriverException e) {
        if (getPlatform().toLowerCase().startsWith("android") || getPlatform().toLowerCase().startsWith("ios")) {
            String[] pfVersion = getPlatform().split(" ", 2);
            try {
                setPlatform(pfVersion[0]);
                setMobilePlatformVersion(pfVersion[1]);
            } catch (IndexOutOfBoundsException x) {
                setMobilePlatformVersion(null);
                logger.warn("For mobile platform, platform name should contain version. Ex: 'Android 5.0' or 'iOS 9.1'. Else, first found device is used");
            }
        } else {
            throw new ConfigurationException(String.format("Platform %s has not been recognized as a valid platform", getPlatform()));
        }
    }
}
Also used : Platform(org.openqa.selenium.Platform) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

ConfigurationException (com.seleniumtests.customexception.ConfigurationException)66 ArrayList (java.util.ArrayList)19 File (java.io.File)18 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)13 Matcher (java.util.regex.Matcher)9 List (java.util.List)8 UnirestException (kong.unirest.UnirestException)8 GenericTest (com.seleniumtests.GenericTest)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ScenarioException (com.seleniumtests.customexception.ScenarioException)5 BrowserType (com.seleniumtests.driver.BrowserType)5 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 Win32Exception (com.sun.jna.platform.win32.Win32Exception)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Files (java.nio.file.Files)4