Search in sources :

Example 41 with ConfigurationException

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

the class ConfigReader method readConfig.

/**
 * read configuration from default config file (env.ini or config.ini)
 * read any other provided configuration files (through loadIni parameter)
 * @return
 */
public Map<String, TestVariable> readConfig() {
    Map<String, TestVariable> variables = new HashMap<>();
    try (InputStream iniFileStream = FileUtils.openInputStream(getConfigFile())) {
        variables.putAll(readConfig(iniFileStream, testEnv));
    } catch (NullPointerException e) {
        logger.warn("config file is null, check config path has been set using 'SeleniumTestsContextManager.generateApplicationPath()'");
        return variables;
    } catch (IOException e1) {
        logger.warn("no valid config.ini file for this application");
        return variables;
    }
    // read additional files
    if (iniFiles != null) {
        for (String fileName : iniFiles.split(",")) {
            fileName = fileName.trim();
            File currentConfFile = Paths.get(SeleniumTestsContextManager.getConfigPath(), fileName).toFile();
            logger.info("reading file " + currentConfFile.getAbsolutePath());
            try (InputStream iniFileStream = FileUtils.openInputStream(currentConfFile)) {
                variables.putAll(readConfig(iniFileStream, testEnv));
            } catch (IOException e) {
                throw new ConfigurationException(String.format("File %s does not exist in data/<app>/config folder", fileName));
            }
        }
    }
    return variables;
}
Also used : HashMap(java.util.HashMap) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) InputStream(java.io.InputStream) TestVariable(com.seleniumtests.core.TestVariable) IOException(java.io.IOException) File(java.io.File)

Example 42 with ConfigurationException

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

the class SeleniumRobotTestListener method logLastStep.

/**
 * On test end, will take a snap shot and store it
 */
private void logLastStep(ITestResult testResult) {
    // finalize manual steps if we use this mode
    try {
        TestTasks.addStep(null);
    } catch (ConfigurationException e) {
    // no problem as it's to close the previous manual step
    }
    TestStep tearDownStep = new TestStep(TestStepManager.LAST_STEP_NAME, testResult, new ArrayList<>(), true);
    scenarioLogger.logTestInfo(TestStepManager.LAST_STATE_NAME, new MultipleInfo(TestStepManager.LAST_STATE_NAME));
    // add step to video
    VideoRecorder videoRecorder = WebUIDriver.getThreadVideoRecorder();
    if (videoRecorder != null) {
        CustomEventFiringWebDriver.displayStepOnScreen(tearDownStep.getName(), SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), videoRecorder);
    }
    TestStepManager.setCurrentRootTestStep(tearDownStep);
    if (testResult.isSuccess()) {
        scenarioLogger.log("Test is OK");
    } else if (testResult.getStatus() == ITestResult.FAILURE) {
        // issue #289: allow retry in case SO_TIMEOUT is raised
        if (SeleniumTestsContextManager.getThreadContext().getRunMode() != DriverMode.LOCAL && testResult.getThrowable() != null && testResult.getThrowable() instanceof WebDriverException && testResult.getThrowable().getMessage().contains("SO_TIMEOUT")) {
            logger.info("Test is retried due to SO_TIMEOUT");
            increaseMaxRetry();
        }
        String error = testResult.getThrowable() != null ? ExceptionUtility.getExceptionMessage(testResult.getThrowable()) : "no error found";
        scenarioLogger.log("Test is KO with error: " + error);
    } else {
        scenarioLogger.log("Test has not started or has been skipped");
    }
    logThrowableToTestEndStep(testResult);
    WebUIDriver.logFinalDriversState(testResult);
    tearDownStep.updateDuration();
    TestStepManager.logTestStep(tearDownStep);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) WebDriverException(org.openqa.selenium.WebDriverException)

Example 43 with ConfigurationException

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

the class Fixture method scanForElements.

/**
 * Search for all Elements in test code
 * @return
 */
public static Map<String, Field> scanForElements(String cucumberPkg) {
    try {
        if (cucumberPkg == null) {
            throw new ConfigurationException("'cucumberPackage' parameter is not set in test NG XML file (inside <suite> tag), " + "set it to the root package where cucumber implementation resides");
        }
        Map<String, Field> allFields = new HashMap<>();
        ImmutableSet<ClassInfo> infos = ClassPath.from(Fixture.class.getClassLoader()).getTopLevelClassesRecursive(cucumberPkg);
        for (ClassInfo info : infos) {
            // ReportPortalService try to initialize something which prevent cucumber from analyzing properly
            if ("com.seleniumtests.connectors.tms.reportportal.ReportPortalService".equals(info.getName())) {
                continue;
            }
            for (Field field : Class.forName(info.getName()).getDeclaredFields()) {
                if (Element.class.isAssignableFrom(field.getType()) && Modifier.isStatic(field.getModifiers())) {
                    field.setAccessible(true);
                    allFields.put(String.format("%s.%s", info.getSimpleName(), field.getName()), field);
                    allFields.put(field.getName(), field);
                }
            }
        }
        return allFields;
    } catch (IOException | SecurityException | ClassNotFoundException | IllegalArgumentException e) {
        throw new ConfigurationException(String.format("Cannot search elements in %s", cucumberPkg), e);
    }
}
Also used : HashMap(java.util.HashMap) Element(com.seleniumtests.uipage.htmlelements.Element) IOException(java.io.IOException) Field(java.lang.reflect.Field) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 44 with ConfigurationException

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

the class EWSClient method findFolder.

/**
 * search a folder in mailbox
 * @param folderName
 * @return
 * @throws Exception
 */
private FolderId findFolder(String folderName) throws Exception {
    if (folders.containsKey(folderName)) {
        return folders.get(folderName);
    }
    if (folderName.equals(WellKnownFolderName.Inbox.name())) {
        FolderId fId = new FolderId(WellKnownFolderName.Inbox, mb);
        folders.put(folderName, fId);
        return fId;
    }
    // search folder
    FolderView view = new FolderView(100);
    view.setPropertySet(new PropertySet(BasePropertySet.IdOnly));
    view.getPropertySet().add(FolderSchema.DisplayName);
    view.setTraversal(FolderTraversal.Deep);
    FindFoldersResults findFolderResults = service.findFolders(rootFolderId, view);
    for (Folder f : findFolderResults) {
        if (f.getDisplayName().equals(folderName)) {
            folders.put(folderName, f.getId());
            return f.getId();
        }
    }
    throw new ConfigurationException("folder " + folderName + " does not exist for this account");
}
Also used : FolderView(microsoft.exchange.webservices.data.search.FolderView) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) FindFoldersResults(microsoft.exchange.webservices.data.search.FindFoldersResults) BasePropertySet(microsoft.exchange.webservices.data.core.enumeration.property.BasePropertySet) PropertySet(microsoft.exchange.webservices.data.core.PropertySet) FolderId(microsoft.exchange.webservices.data.property.complex.FolderId) Folder(microsoft.exchange.webservices.data.core.service.folder.Folder)

Example 45 with ConfigurationException

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

the class EWSClient method getEmails.

/**
 * get list of all emails in folder
 *
 * @param folderName		folder to read
 * @param firstMessageTime	date from which we should get messages
 * @throws MessagingException
 * @throws IOException
 */
@Override
public List<Email> getEmails(String folderName, int firstMessageIndex, LocalDateTime firstMessageTime) throws Exception {
    if (folderName == null) {
        throw new ConfigurationException("folder should not be empty");
    }
    FolderId folderId = findFolder(folderName);
    Folder folder = Folder.bind(service, folderId);
    List<Email> emails = new ArrayList<>();
    List<Item> preFilteredItems;
    // filter messages
    if (searchMode == SearchMode.BY_INDEX || firstMessageTime == null) {
        lastMessageIndex = folder.getTotalCount();
        preFilteredItems = service.findItems(folderId, new ItemView(lastMessageIndex - firstMessageIndex + 1)).getItems();
    } else {
        SearchFilter.SearchFilterCollection filter = new SearchFilter.SearchFilterCollection();
        filter.add(new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, Date.from(firstMessageTime.plusHours(timeOffset).atZone(ZoneId.systemDefault()).toInstant())));
        preFilteredItems = service.findItems(folderId, filter, new ItemView(lastMessageIndex)).getItems();
    }
    for (Item item : preFilteredItems) {
        item.load();
        List<String> attachments = new ArrayList<>();
        for (Attachment att : item.getAttachments()) {
            attachments.add(att.getName());
        }
        emails.add(new Email(item.getSubject(), item.getBody().toString(), "", item.getDateTimeReceived().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), attachments));
    }
    return emails;
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(microsoft.exchange.webservices.data.search.filter.SearchFilter) Attachment(microsoft.exchange.webservices.data.property.complex.Attachment) FolderId(microsoft.exchange.webservices.data.property.complex.FolderId) Folder(microsoft.exchange.webservices.data.core.service.folder.Folder) Item(microsoft.exchange.webservices.data.core.service.item.Item) ItemView(microsoft.exchange.webservices.data.search.ItemView) ConfigurationException(com.seleniumtests.customexception.ConfigurationException)

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