use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class IniHelper method readIniFile.
/**
* @author Sophie
* @param fileToRead
* file where are the targeted data
* @param hashMapToComplete
* hashMap we want to fill
* @return the HashMap completed with data from the file
*/
public static Map<String, Map<String, String>> readIniFile(File fileToRead, Map<String, Map<String, String>> hashMapToComplete) {
try {
Ini ini = new Ini();
Config conf = ini.getConfig();
conf.setGlobalSection(true);
conf.setFileEncoding(StandardCharsets.UTF_8);
ini.setConfig(conf);
ini.load(fileToRead);
Set<Entry<String, Section>> sections = ini.entrySet();
for (Entry<String, Section> section : sections) {
Map<String, String> inter = new HashMap<>();
String actualSection = section.getKey();
if (hashMapToComplete.containsKey(actualSection)) {
// recup datas already read
inter.putAll(hashMapToComplete.get(actualSection));
}
for (Entry<String, String> sectionOption : section.getValue().entrySet()) {
inter.put(sectionOption.getKey(), sectionOption.getValue());
}
hashMapToComplete.put(actualSection, inter);
}
} catch (InvalidFileFormatException | NullPointerException e) {
throw new ConfigurationException("Invalid file: " + fileToRead);
} catch (IOException e) {
throw new ConfigurationException(String.format("File does not exist %s: %s", fileToRead, e.getMessage()));
}
return hashMapToComplete;
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class UiElement method findElementByPosition.
private void findElementByPosition() {
// search the fields with label
Label labelRightOf = null;
Label labelLeftOf = null;
Label labelAbove = null;
Label labelBelow = null;
Label labelText = null;
if (by.getRightOf() != null) {
for (Label lbl : labelsPerPage.get(origin)) {
if (by.getRightOf().matcher(lbl.getText().trim()).matches()) {
labelRightOf = lbl;
break;
}
}
}
if (by.getLeftOf() != null) {
for (Label lbl : labelsPerPage.get(origin)) {
if (by.getLeftOf().matcher(lbl.getText().trim()).matches()) {
labelLeftOf = lbl;
break;
}
}
}
if (by.getAbove() != null) {
for (Label lbl : labelsPerPage.get(origin)) {
if (by.getAbove().matcher(lbl.getText().trim()).matches()) {
labelAbove = lbl;
break;
}
}
}
if (by.getBelow() != null) {
for (Label lbl : labelsPerPage.get(origin)) {
if (by.getBelow().matcher(lbl.getText().trim()).matches()) {
labelBelow = lbl;
break;
}
}
}
if (by.getText() != null) {
for (Label lbl : labelsPerPage.get(origin)) {
if (by.getText().matcher(lbl.getText().trim()).matches()) {
labelText = lbl;
break;
}
}
}
if (labelLeftOf == null && labelRightOf == null && labelText == null && labelAbove == null && labelBelow == null) {
throw new ConfigurationException(String.format("No label could be found matching search criteria [%s]", by));
}
for (Field field : fieldsPerPage.get(origin)) {
if (ElementType.fromClassName(field.getClassName()) == elementType && // only use raw fields
field.getRelatedField() == null && (labelText == null || labelText.isInside(field)) && (labelRightOf == null || labelRightOf.isFieldRightOf(field)) && (labelLeftOf == null || labelLeftOf.isFieldLeftOf(field)) && (labelAbove == null || labelAbove.isFieldAbove(field)) && (labelBelow == null || labelBelow.isFieldBelow(field))) {
detectedObjectRectangle = field.getRectangle();
return;
}
}
throw new ConfigurationException(String.format("No field could be found matching search criteria [%s]", by));
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class OSUtilityWindows method discoverInstalledBrowsersWithVersion.
@Override
public Map<BrowserType, List<BrowserInfo>> discoverInstalledBrowsersWithVersion(boolean discoverBetaBrowsers) {
Map<BrowserType, List<BrowserInfo>> browserList = new EnumMap<>(BrowserType.class);
browserList.put(BrowserType.HTMLUNIT, Arrays.asList(new BrowserInfo(BrowserType.HTMLUNIT, BrowserInfo.LATEST_VERSION, null)));
browserList.put(BrowserType.PHANTOMJS, Arrays.asList(new BrowserInfo(BrowserType.PHANTOMJS, BrowserInfo.LATEST_VERSION, null)));
// look for Firefox
try {
browserList.put(BrowserType.FIREFOX, new ArrayList<>());
for (String firefoxPath : searchFirefoxVersions()) {
String version = getFirefoxVersion(firefoxPath);
try {
browserList.get(BrowserType.FIREFOX).add(new BrowserInfo(BrowserType.FIREFOX, extractFirefoxVersion(version), firefoxPath));
} catch (ConfigurationException e) {
// ignore
}
}
} catch (IndexOutOfBoundsException e) {
// ignore
}
// look for chrome
try {
browserList.put(BrowserType.CHROME, new ArrayList<>());
// main chrome version
String chromePath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeHTML\\shell\\open\\command", "");
chromePath = chromePath.split(EXE_EXT_QUOTE)[0].replace("\"", "") + ".exe";
String version = getWindowsChromeVersion(chromePath);
browserList.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, extractChromeVersion("Google Chrome " + version), false, chromePath));
} catch (Win32Exception | ConfigurationException e) {
logger.warn("Error searching chrome installations: " + e.getMessage());
}
try {
// beta chrome version
String chromeBetaPath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeBHTML\\shell\\open\\command", "");
chromeBetaPath = chromeBetaPath.split(EXE_EXT_QUOTE)[0].replace("\"", "") + ".exe";
String versionBeta;
versionBeta = getWindowsBetaChromeVersion(chromeBetaPath);
browserList.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, extractChromeVersion("Google Chrome " + versionBeta), true, chromeBetaPath));
} catch (Win32Exception | ConfigurationException e) {
logger.warn("Error searching Beta chrome installations: " + e.getMessage());
}
// look for ie
try {
Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE", "");
String version = getIeVersionFromRegistry();
browserList.put(BrowserType.INTERNET_EXPLORER, Arrays.asList(new BrowserInfo(BrowserType.INTERNET_EXPLORER, extractIEVersion(version), null)));
} catch (Win32Exception | ConfigurationException e) {
logger.warn("Error searching Internet explorer installations: " + e.getMessage());
}
// look for edge chromium
try {
browserList.put(BrowserType.EDGE, new ArrayList<>());
String edgePath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Microsoft Edge", "InstallLocation");
String version = getWindowsEdgeVersion(edgePath);
if (version != null && !version.isEmpty()) {
browserList.get(BrowserType.EDGE).add(new BrowserInfo(BrowserType.EDGE, extractEdgeVersion(version), false, Paths.get(edgePath, MSEDGE_EXE).toString()));
}
} catch (Win32Exception | ConfigurationException e) {
logger.warn("Error searching Edge chromium installations: " + e.getMessage());
}
try {
// beta edge version
String edgePathBeta = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Microsoft Edge Beta", "InstallLocation");
String versionBeta = getWindowsBetaEdgeVersion(edgePathBeta);
if (versionBeta != null && !versionBeta.isEmpty()) {
browserList.get(BrowserType.EDGE).add(new BrowserInfo(BrowserType.EDGE, extractEdgeVersion(versionBeta), true, Paths.get(edgePathBeta, MSEDGE_EXE).toString()));
}
} catch (Win32Exception | ConfigurationException e) {
logger.warn("Error searching Beta Edge chromium installations: " + e.getMessage());
}
return browserList;
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class TestLocalAppiumLauncher method testAppiumStartup.
@Test(groups = { "it" })
public void testAppiumStartup() {
try {
LocalAppiumLauncher appium = new LocalAppiumLauncher();
appium.startAppium();
appium.stopAppium();
} catch (ConfigurationException e) {
throw new SkipException("Test skipped, appium not correctly configured", e);
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class TestWebUiDriver method testLocalAndroidDriver.
@Test(groups = { "it" })
public void testLocalAndroidDriver() throws Exception {
whenNew(AdbWrapper.class).withNoArguments().thenReturn(adbWrapper);
List<MobileDevice> deviceList = new ArrayList<>();
deviceList.add(new MobileDevice("IPhone 6", "0000", "ios", "10.2", new ArrayList<>()));
deviceList.add(new MobileDevice("Nexus 5", "1234", "android", "5.0", new ArrayList<>()));
deviceList.add(new MobileDevice("Nexus 7", "1235", "android", "6.0", new ArrayList<>()));
when(adbWrapper.getDeviceList()).thenReturn(deviceList);
whenNew(AndroidDriver.class).withAnyArguments().thenReturn(androidDriver);
when(androidDriver.manage()).thenReturn(driverOptions);
when(androidDriver.getCapabilities()).thenReturn(DesiredCapabilities.chrome());
when(driverOptions.timeouts()).thenReturn(timeouts);
SeleniumTestsContextManager.getThreadContext().setRunMode("local");
SeleniumTestsContextManager.getThreadContext().setPlatform("android");
SeleniumTestsContextManager.getThreadContext().setMobilePlatformVersion("5.0");
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APPIUM_APP_ANDROID);
PowerMockito.mockStatic(AppiumLauncherFactory.class);
LocalAppiumLauncher appiumLauncher;
try {
appiumLauncher = spy(new LocalAppiumLauncher());
when(AppiumLauncherFactory.getInstance()).thenReturn(appiumLauncher);
WebUIDriver.getWebDriver(true);
} catch (ConfigurationException e) {
throw new SkipException("Test skipped, appium not correctly configured", e);
}
PowerMockito.verifyNew(AndroidDriver.class).withArguments(any(URL.class), any(Capabilities.class));
verify(appiumLauncher).stopAppium();
}
Aggregations