use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class IDesktopCapabilityFactory method prepareBinaryAndDriver.
/**
* In local mode, select the right browser info, depending on type, version and binary
* If several version are available, the highest is selected. This means that if betaVersion option is selected, we will get the beta browser.
*
* @param browserType the browser to select (chrome, firefox, ...)
* @param binPath the browser binary to start, if specifically set by user through option. Else, installed browser will be used
* @param driverPath user defined driver. if null, default driver will be selected depending on browser and version
* @param version user defined version if user needs to start a specific version of the browser and this version is installed
* @return
*/
private BrowserInfo prepareBinaryAndDriver(final BrowserType browserType, final String binPath, final String driverPath, final String version) {
// automatic list from OS + binary added as launch option (see SeleniumTestsContext.updateInstalledBrowsers())
List<BrowserInfo> browserInfos = OSUtility.getInstalledBrowsersWithVersion(webDriverConfig.getBetaBrowser()).get(browserType);
if (version != null) {
selectedBrowserInfo = BrowserInfo.getInfoFromVersion(version, browserInfos);
} else if (binPath != null) {
selectedBrowserInfo = BrowserInfo.getInfoFromBinary(binPath, browserInfos);
logger.info("Using user defined browser binary from: " + selectedBrowserInfo.getPath());
} else {
for (BrowserInfo browser : browserInfos) {
if (webDriverConfig.getBetaBrowser().equals(browser.getBeta())) {
selectedBrowserInfo = browser;
}
}
}
if (selectedBrowserInfo == null) {
throw new ConfigurationException(String.format("Browser %s %s is not available", webDriverConfig.getBrowserType(), webDriverConfig.getBetaBrowser() ? "beta" : ""));
}
// in case of legacy firefox driverFileName is null
String newDriverPath = new DriverExtractor().extractDriver(selectedBrowserInfo.getDriverFileName());
if (driverPath != null) {
newDriverPath = driverPath;
logger.info("using user defined driver from: " + driverPath);
}
if (newDriverPath != null) {
System.setProperty(getDriverExeProperty(), newDriverPath);
if (!OSUtility.isWindows() && !new File(newDriverPath).setExecutable(true)) {
logger.error(String.format("Error setting executable on driver %s", newDriverPath));
}
}
return selectedBrowserInfo;
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class IDesktopCapabilityFactory method configureProxyCap.
/**
* Add proxy capability
* If network capture is enabled, start browsermob proxy and set it into browser
* @param capability
*/
private void configureProxyCap(MutableCapabilities capability) {
Proxy proxy = webDriverConfig.getProxy();
if (webDriverConfig.getCaptureNetwork()) {
if (webDriverConfig.getWebProxyType() != ProxyType.DIRECT && webDriverConfig.getWebProxyType() != ProxyType.MANUAL) {
throw new ConfigurationException("PAC/AUTODETECT/SYSTEM proxy cannot be used with browsermob proxy");
}
BrowserMobProxy mobProxy = new BrowserMobProxyServer();
if (webDriverConfig.getWebProxyType() == ProxyType.MANUAL) {
mobProxy.setChainedProxy(new InetSocketAddress(webDriverConfig.getWebProxyAddress(), webDriverConfig.getWebProxyPort()));
if (webDriverConfig.getWebProxyLogin() != null && webDriverConfig.getWebProxyPassword() != null) {
mobProxy.chainedProxyAuthorization(webDriverConfig.getWebProxyLogin(), webDriverConfig.getWebProxyPassword(), AuthType.BASIC);
}
}
mobProxy.setTrustAllServers(true);
mobProxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_HEADERS);
mobProxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(mobProxy);
capability.setCapability(CapabilityType.PROXY, seleniumProxy);
webDriverConfig.setBrowserMobProxy(mobProxy);
} else {
capability.setCapability(CapabilityType.PROXY, proxy);
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method addCurrentTestStepToTestCase.
/**
* Add the current test case (should have been previously created) to this test session
*/
public void addCurrentTestStepToTestCase(Integer testStepId, Integer testCaseInSessionId) {
if (testStepId == null || testCaseInSessionId == null) {
throw new ConfigurationException("Test step and Test case in session must be previously created");
}
try {
// get list of tests associated to this session
List<String> testSteps = getStepListFromTestCase(testCaseInSessionId);
if (!testSteps.contains(testStepId.toString())) {
testSteps.add(testStepId.toString());
}
addTestStepsToTestCases(testSteps, testCaseInSessionId);
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot add test step to test case", e);
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method createSnapshot.
/**
* Create snapshot on server that will be used to show differences between 2 versions of the application
*/
public Integer createSnapshot(Snapshot snapshot, Integer sessionId, Integer testCaseInSessionId, Integer stepResultId) {
if (!active) {
return null;
}
if (sessionId == null) {
throw new ConfigurationException("Session must be previously recorded");
}
if (testCaseInSessionId == null) {
throw new ConfigurationException("TestCaseInSession must be previously recorded");
}
checkStepResult(stepResultId);
if (snapshot == null || snapshot.getScreenshot() == null || snapshot.getScreenshot().getFullImagePath() == null) {
throw new SeleniumRobotServerException("Provided snapshot does not exist");
}
String snapshotName = snapshot.getName().length() > MAX_SNAPSHOT_NAME_LENGHT ? snapshot.getName().substring(0, MAX_SNAPSHOT_NAME_LENGHT) : snapshot.getName();
try {
File pictureFile = new File(snapshot.getScreenshot().getFullImagePath());
JSONObject snapshotJson = getJSonResponse(buildPostRequest(url + SNAPSHOT_API_URL).field("stepResult", stepResultId).field("sessionId", sessionUUID).field(FIELD_TEST_CASE, testCaseInSessionId.toString()).field(FIELD_IMAGE, pictureFile).field(FIELD_NAME, snapshotName).field("compare", snapshot.getCheckSnapshot().getName()).field("diffTolerance", String.valueOf(snapshot.getCheckSnapshot().getErrorThreshold())));
return snapshotJson.getInt("id");
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot create test snapshot", e);
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class ConfigReader method readConfig.
public Map<String, TestVariable> readConfig(InputStream iniFileStream, String environment) {
Map<String, TestVariable> testConfig = new HashMap<>();
try {
Ini ini = new Ini();
Config conf = ini.getConfig();
conf.setGlobalSection(true);
conf.setGlobalSectionName(GLOBAL_SECTION_NAME);
conf.setFileEncoding(StandardCharsets.UTF_8);
ini.setConfig(conf);
ini.load(iniFileStream);
Set<Entry<String, Section>> sections = ini.entrySet();
// first get global options
testConfig = getGlobalOptions(testConfig, sections);
// then overwrite global options with local ones
testConfig = getLocalOptions(testConfig, sections, environment);
return testConfig;
} catch (InvalidFileFormatException e) {
throw new ConfigurationException("Invalid ini/properties file: " + iniFileStream + ", check there is no BOM for encoding");
} catch (IOException e) {
throw new ConfigurationException(String.format("File does not exist %s: %s", iniFileStream, e.getMessage()));
}
}
Aggregations