use of com.seleniumtests.customexception.CustomSeleniumTestsException in project seleniumRobot by bhecquet.
the class CustomTestNGCucumberRunner method initCucumberOptions.
private void initCucumberOptions() throws URISyntaxException {
String cucumberPkg = SeleniumTestsContextManager.getGlobalContext().getCucmberPkg();
if (cucumberPkg == null) {
throw new CustomSeleniumTestsException("'cucumberPackage' parameter is not set in test NG XML file (inside <suite> tag), " + "set it to the root package where cucumber implementation resides");
}
RuntimeOptionsBuilder builder = new RuntimeOptionsBuilder();
// add cucumber implementation classes
builder.addGlue(new URI("classpath:" + cucumberPkg.replace(".", "/")));
if (!cucumberPkg.startsWith("com.seleniumtests")) {
builder.addGlue(new URI("classpath:com/seleniumtests/core/runner/cucumber"));
}
// correct issue #243: as we write to log files, colors cannot be rendered in text files
builder.setMonochrome().addFeature(FeatureWithLines.parse(SeleniumTestsContextManager.getFeaturePath())).addTagFilter(SeleniumTestsContextManager.getThreadContext().getCucumberTags().replace(" AND ", // for compatibility with old format
" and "));
for (String cucumberTest : SeleniumTestsContextManager.getThreadContext().getCucumberTests()) {
builder.addNameFilter(Pattern.compile(cucumberTest.replace("??", // Handle special regex character '?' as we
"\\?\\?")));
}
runtimeOptions = builder.build();
runtimeOptions.addUndefinedStepsPrinterIfSummaryNotDefined();
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
BackendModuleBackendSupplier backendSupplier = new BackendModuleBackendSupplier(resourceLoader, classFinder, runtimeOptions);
bus = new TimeServiceEventBus(TimeService.SYSTEM);
plugins = new Plugins(classLoader, new PluginFactory(), runtimeOptions);
FeatureLoader featureLoader = new FeatureLoader(resourceLoader);
filters = new Filters(runtimeOptions);
this.runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, bus, backendSupplier);
featureSupplier = new FeaturePathFeatureSupplier(featureLoader, runtimeOptions);
}
use of com.seleniumtests.customexception.CustomSeleniumTestsException in project seleniumRobot by bhecquet.
the class SelectList method searchRelevantImplementation.
private static List<Class<? extends ISelectList>> searchRelevantImplementation() {
List<Class<? extends ISelectList>> selectImplementations = new ArrayList<>();
// load via SPI other Select implementations
ServiceLoader<ISelectList> selectLoader = ServiceLoader.load(ISelectList.class);
Iterator<ISelectList> selectsIterator = selectLoader.iterator();
while (selectsIterator.hasNext()) {
ISelectList selectClass = selectsIterator.next();
selectImplementations.add(selectClass.getClass());
}
if (selectImplementations.isEmpty()) {
throw new CustomSeleniumTestsException("Could not get list of Select classes");
}
return selectImplementations;
}
use of com.seleniumtests.customexception.CustomSeleniumTestsException in project seleniumRobot by bhecquet.
the class CSVHelper method getDataFromCSVFile.
/**
* Reads data from csv file.
* class : null => filename : entire path of file
* class : this.getClass(), filename : the filename will be search in the same directory of the class
*
* @param clazz
* @param filename
* @param filter
* @param readHeaders
* @param delimiter
* @param supportDPFilter
* @return
*/
public static Iterator<Object[]> getDataFromCSVFile(final Class<?> clazz, final String filename, Filter filter, final boolean readHeaders, final String delimiter, final boolean supportDPFilter) {
Filter newFilter = filter;
try (InputStream is = (clazz != null) ? clazz.getResourceAsStream(filename) : new FileInputStream(filename)) {
if (is == null) {
return new ArrayList<Object[]>().iterator();
}
// Get the sheet
String[][] csvData = read(is, delimiter);
if (csvData == null) {
return new ArrayList<Object[]>().iterator();
}
List<Object[]> sheetData = new ArrayList<>();
if (readHeaders) {
List<Object> rowData = new ArrayList<>();
for (int j = 0; j < csvData[0].length; j++) {
rowData.add(csvData[0][j]);
}
sheetData.add(rowData.toArray(new Object[rowData.size()]));
}
// Check for blank rows first
// First row is the header
StringBuilder sbBlank = new StringBuilder();
if (sbBlank.length() > 0) {
sbBlank.deleteCharAt(sbBlank.length() - 1);
throw new CustomSeleniumTestsException("Blank TestTitle found on Row(s) " + sbBlank.toString() + ".");
}
// Support include tags and exclude tags
if (supportDPFilter) {
Filter dpFilter = SpreadSheetHelper.getDPFilter();
if (dpFilter != null) {
if (newFilter == null) {
newFilter = dpFilter;
} else {
newFilter = Filter.and(newFilter, dpFilter);
}
}
}
// The first row is the header data
for (int i = 1; i < csvData.length; i++) {
Map<String, Object> rowDataMap = new HashMap<>();
List<Object> rowData = new ArrayList<>();
// Create the mapping between headers and column data
for (int j = 0; j < csvData[i].length; j++) {
rowDataMap.put(csvData[0][j], csvData[i][j]);
}
for (int j = 0; j < csvData[0].length; j++) {
// expected.
if (csvData[i].length > j) {
rowData.add(csvData[i][j]);
} else {
rowData.add(null);
}
}
// To support include tags and exclude tags
if (supportDPFilter) {
SpreadSheetHelper.formatDPTags(rowDataMap);
}
if (newFilter == null || newFilter.match(rowDataMap)) {
sheetData.add(rowData.toArray(new Object[rowData.size()]));
}
}
if ((!readHeaders && sheetData.isEmpty()) || (readHeaders && sheetData.size() <= 1)) {
logger.warn("No matching data found on csv file: " + filename + " with filter criteria: " + newFilter.toString());
}
return sheetData.iterator();
} catch (Exception e) {
throw new DatasetException(e.getMessage());
}
}
use of com.seleniumtests.customexception.CustomSeleniumTestsException in project seleniumRobot by bhecquet.
the class ReporterControler method updateTestSteps.
/**
* Add configurations methods to list of test steps so that they can be used by reporters
* @param suites List of test suite to parse
* @param currentTestResult When we generate temp results, we get a current test result so that we do not wait test2 to be executed to get test1 displayed in report
*/
private Map<ITestContext, Set<ITestResult>> updateTestSteps(List<ISuite> suites, ITestResult currentTestResult) {
Map<ITestContext, Set<ITestResult>> allResultSet = new LinkedHashMap<>();
for (ISuite suite : suites) {
Field testRunnersField;
List<TestRunner> testContexts;
try {
testRunnersField = SuiteRunner.class.getDeclaredField("testRunners");
testRunnersField.setAccessible(true);
testContexts = (List<TestRunner>) testRunnersField.get(suite);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | ClassCastException e) {
throw new CustomSeleniumTestsException("TestNG may have changed");
}
// If at least one test (not a test method, but a TestNG test) is finished, suite contains its results
for (String suiteString : suite.getResults().keySet()) {
ISuiteResult suiteResult = suite.getResults().get(suiteString);
Set<ITestResult> resultSet = new HashSet<>();
resultSet.addAll(suiteResult.getTestContext().getFailedTests().getAllResults());
resultSet.addAll(suiteResult.getTestContext().getPassedTests().getAllResults());
resultSet.addAll(suiteResult.getTestContext().getSkippedTests().getAllResults());
allResultSet.put(suiteResult.getTestContext(), resultSet);
}
// complete the suite result with remaining, currently running tests
for (TestRunner testContext : testContexts) {
if (allResultSet.containsKey(testContext)) {
continue;
}
Set<ITestResult> resultSet = removeUnecessaryResults(testContext, currentTestResult);
allResultSet.put(testContext, resultSet);
}
for (Set<ITestResult> resultSet : allResultSet.values()) {
for (ITestResult testResult : resultSet) {
List<TestStep> testSteps = getAllTestSteps(testResult);
Long testDuration = 0L;
synchronized (testSteps) {
for (TestStep step : testSteps) {
testDuration += step.getDuration();
}
}
testResult.setEndMillis(testResult.getStartMillis() + testDuration);
}
}
}
return allResultSet;
}
use of com.seleniumtests.customexception.CustomSeleniumTestsException in project seleniumRobot by bhecquet.
the class PageObject method open.
private void open(final String url) {
setUrl(url);
try {
// Navigate to app URL for browser test
if (SeleniumTestsContextManager.isWebTest()) {
setWindowToRequestedSize();
driver.navigate().to(url);
}
} catch (UnreachableBrowserException e) {
// recreate the driver without recreating the enclosing WebUiDriver
driver = WebUIDriver.getWebUIDriver(false).createWebDriver();
if (SeleniumTestsContextManager.isWebTest()) {
setWindowToRequestedSize();
driver.navigate().to(url);
}
} catch (UnsupportedCommandException e) {
logger.error("get UnsupportedCommandException, retry");
// recreate the driver without recreating the enclosing WebUiDriver
driver = WebUIDriver.getWebUIDriver(false).createWebDriver();
if (SeleniumTestsContextManager.isWebTest()) {
setWindowToRequestedSize();
driver.navigate().to(url);
}
} catch (org.openqa.selenium.TimeoutException ex) {
logger.error("got time out when loading " + url + ", ignored");
} catch (org.openqa.selenium.UnhandledAlertException ex) {
logger.error("got UnhandledAlertException, retry");
driver.navigate().to(url);
} catch (WebDriverException e) {
internalLogger.error(e);
throw new CustomSeleniumTestsException(e);
}
}
Aggregations