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