Search in sources :

Example 1 with CustomSeleniumTestsException

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);
}
Also used : BackendModuleBackendSupplier(cucumber.runtime.BackendModuleBackendSupplier) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) URI(java.net.URI) TimeServiceEventBus(cucumber.runner.TimeServiceEventBus) ThreadLocalRunnerSupplier(cucumber.runner.ThreadLocalRunnerSupplier) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) Filters(cucumber.runtime.filter.Filters) FeaturePathFeatureSupplier(cucumber.runtime.FeaturePathFeatureSupplier) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ClassFinder(cucumber.runtime.ClassFinder) PluginFactory(cucumber.runtime.formatter.PluginFactory) FeatureLoader(cucumber.runtime.model.FeatureLoader) Plugins(cucumber.runtime.formatter.Plugins)

Example 2 with CustomSeleniumTestsException

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;
}
Also used : ISelectList(com.seleniumtests.uipage.htmlelements.select.ISelectList) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) ArrayList(java.util.ArrayList)

Example 3 with CustomSeleniumTestsException

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());
    }
}
Also used : HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) DatasetException(com.seleniumtests.customexception.DatasetException) DatasetException(com.seleniumtests.customexception.DatasetException) Filter(com.seleniumtests.core.Filter)

Example 4 with CustomSeleniumTestsException

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;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) ITestResult(org.testng.ITestResult) TestRunner(org.testng.TestRunner) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) ISuiteResult(org.testng.ISuiteResult) LinkedHashMap(java.util.LinkedHashMap) Field(java.lang.reflect.Field) ISuite(org.testng.ISuite) ITestContext(org.testng.ITestContext) SuiteRunner(org.testng.SuiteRunner) HashSet(java.util.HashSet)

Example 5 with CustomSeleniumTestsException

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);
    }
}
Also used : UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) TimeoutException(org.openqa.selenium.TimeoutException) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

CustomSeleniumTestsException (com.seleniumtests.customexception.CustomSeleniumTestsException)9 IOException (java.io.IOException)4 WebDriverException (org.openqa.selenium.WebDriverException)4 ScenarioException (com.seleniumtests.customexception.ScenarioException)3 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3 TimeoutException (org.openqa.selenium.TimeoutException)3 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 UnhandledAlertException (org.openqa.selenium.UnhandledAlertException)2 UnsupportedCommandException (org.openqa.selenium.UnsupportedCommandException)2 UnreachableBrowserException (org.openqa.selenium.remote.UnreachableBrowserException)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Filter (com.seleniumtests.core.Filter)1 DatasetException (com.seleniumtests.customexception.DatasetException)1 NotCurrentPageException (com.seleniumtests.customexception.NotCurrentPageException)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1