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;
}
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);
}
}
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));
}
}
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);
}
}
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()));
}
}
}
Aggregations