Search in sources :

Example 56 with ConfigurationException

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;
}
Also used : Ini(org.ini4j.Ini) HashMap(java.util.HashMap) Config(org.ini4j.Config) IOException(java.io.IOException) Section(org.ini4j.Profile.Section) InvalidFileFormatException(org.ini4j.InvalidFileFormatException) Entry(java.util.Map.Entry) ConfigurationException(com.seleniumtests.customexception.ConfigurationException)

Example 57 with ConfigurationException

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));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Label(com.seleniumtests.connectors.selenium.fielddetector.Label)

Example 58 with ConfigurationException

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;
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) Win32Exception(com.sun.jna.platform.win32.Win32Exception)

Example 59 with ConfigurationException

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);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) LocalAppiumLauncher(com.seleniumtests.browserfactory.mobile.LocalAppiumLauncher) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 60 with ConfigurationException

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();
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) LocalAppiumLauncher(com.seleniumtests.browserfactory.mobile.LocalAppiumLauncher) SkipException(org.testng.SkipException) AndroidDriver(io.appium.java_client.android.AndroidDriver) URL(java.net.URL) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

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