cucumber.runtime.CucumberException Java Examples
The following examples show how to use
cucumber.runtime.CucumberException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CucumberRunner.java From bdt with Apache License 2.0 | 6 votes |
/** * @return returns the cucumber scenarios as a two dimensional array of {@link PickleEventWrapper} * scenarios combined with their {@link CucumberFeatureWrapper} feature. */ public Object[][] provideScenarios() { try { List<Object[]> scenarios = new ArrayList<>(); List<CucumberFeature> features = getFeatures(); for (CucumberFeature feature : features) { for (PickleEvent pickle : feature.getPickles()) { if (filters.matchesFilters(pickle)) { scenarios.add(new Object[]{new PickleEventWrapperImpl(pickle), new CucumberFeatureWrapperImpl(feature)}); } } } return scenarios.toArray(new Object[][]{}); } catch (CucumberException e) { return new Object[][]{new Object[]{new CucumberExceptionWrapper(e), null}}; } }
Example #2
Source File: CucumberReporter.java From bdt with Apache License 2.0 | 6 votes |
private double getTotalDuration(NodeList testCaseNodes) { double totalDuration = 0; for (int i = 0; i < testCaseNodes.getLength(); i++) { try { String duration = "0"; Node durationms = testCaseNodes.item(i).getAttributes().getNamedItem("duration-ms"); if (durationms != null) { duration = durationms.getNodeValue(); } totalDuration += Double.parseDouble(duration); } catch (NumberFormatException e) { throw new CucumberException(e); } } return totalDuration; }
Example #3
Source File: HtmlFormatter.java From scott with MIT License | 5 votes |
private void writeBytesAndClose(byte[] buf, OutputStream out) { try { out.write(buf); } catch (IOException e) { throw new CucumberException("Unable to write to report file item: ", e); } }
Example #4
Source File: PickleStepDefinitionMatch.java From bdt with Apache License 2.0 | 5 votes |
private CucumberException arityMismatch(int parameterCount) { List<String> arguments = createArgumentsForErrorMessage(); return new CucumberException(String.format( "Step [%s] is defined with %s parameters at '%s'.\n" + "However, the gherkin step has %s arguments%sStep text: %s", stepDefinition.getPattern(), parameterCount, stepDefinition.getLocation(true), arguments.size(), formatArguments(arguments), step.getText() )); }
Example #5
Source File: PickleStepDefinitionMatch.java From bdt with Apache License 2.0 | 5 votes |
private CucumberException couldNotConvertArguments(Exception e) { return new CucumberException(String.format( "Could not convert arguments for step [%s] defined at '%s'.\n" + "The details are in the stacktrace below.", stepDefinition.getPattern(), stepDefinition.getLocation(true) ), e); }
Example #6
Source File: PickleStepDefinitionMatch.java From bdt with Apache License 2.0 | 5 votes |
private CucumberException registerTypeInConfiguration(Exception e) { return new CucumberException(String.format("" + "Could not convert arguments for step [%s] defined at '%s'.\n" + "It appears you did not register a data table type. The details are in the stacktrace below.", //TODO: Add doc URL stepDefinition.getPattern(), stepDefinition.getLocation(true) ), e); }
Example #7
Source File: TestCaseResultListener.java From bdt with Apache License 2.0 | 5 votes |
Throwable getError() { if (result == null) { return null; } switch (result.getStatus()) { case FAILED: case AMBIGUOUS: return result.getError(); case PENDING: if (strict) { return result.getError(); } else { return new SkipException(result.getErrorMessage(), result.getError()); } case UNDEFINED: if (strict) { return new CucumberException(UNDEFINED_MESSAGE); } else { return new SkipException(UNDEFINED_MESSAGE); } case SKIPPED: Throwable error = result.getError(); if (error != null) { if (error instanceof SkipException) { return error; } else { return new SkipException(result.getErrorMessage(), error); } } else { return new SkipException(SKIPPED_MESSAGE); } case PASSED: return null; default: throw new IllegalStateException("Unexpected result status: " + result.getStatus()); } }
Example #8
Source File: AllureReporter.java From allure-cucumberjvm with Apache License 2.0 | 5 votes |
private Step extractStep(StepDefinitionMatch match) { try { Field step = match.getClass().getDeclaredField("step"); step.setAccessible(true); return (Step) step.get(match); } catch (ReflectiveOperationException e) { //shouldn't ever happen LOG.error(e.getMessage(), e); throw new CucumberException(e); } }
Example #9
Source File: HtmlFormatter.java From scott with MIT License | 5 votes |
private OutputStream reportFileOutputStream(String fileName) { try { return new URLOutputStream(new URL(htmlReportDir, fileName)); } catch (IOException e) { throw new CucumberException(e); } }
Example #10
Source File: HtmlFormatter.java From scott with MIT License | 5 votes |
private NiceAppendable jsOut() { if (jsOut == null) { try { jsOut = new NiceAppendable(new OutputStreamWriter(reportFileOutputStream(JS_REPORT_FILENAME), "UTF-8")); } catch (IOException e) { throw new CucumberException(e); } } return jsOut; }
Example #11
Source File: PerfRuntimeOptions.java From cucumber-performance with MIT License | 5 votes |
public void addPluginName(String name, boolean isAddPlugin) { if (PluginFactory.isFormatterName(name)) { formatterNames.addName(name, isAddPlugin); } else if (PluginFactory.isDisplayName(name)) { displayNames.addName(name, isAddPlugin); } else if (PluginFactory.isSummaryPrinterName(name)) { summaryPrinterNames.addName(name, isAddPlugin); } else { throw new CucumberException("Unrecognized plugin: " + name); } }
Example #12
Source File: HtmlFormatter.java From scott with MIT License | 5 votes |
private void writeStreamAndClose(InputStream in, OutputStream out) { byte[] buffer = new byte[16 * 1024]; try { int len = in.read(buffer); while (len != -1) { out.write(buffer, 0, len); len = in.read(buffer); } out.close(); } catch (IOException e) { throw new CucumberException("Unable to write to report file item: ", e); } }
Example #13
Source File: HtmlFormatter.java From scott with MIT License | 5 votes |
private void copyReportFiles() { for (String textAsset : TEXT_ASSETS) { InputStream textAssetStream = getClass().getResourceAsStream(textAsset); if (textAssetStream == null) { throw new CucumberException("Couldn't find " + textAsset + ". Is cucumber-html on your classpath? Make sure you have the right version."); } String baseName = new File(textAsset).getName(); writeStreamAndClose(textAssetStream, reportFileOutputStream(baseName)); } }
Example #14
Source File: AwaitConditionMatcher.java From cukes with Apache License 2.0 | 5 votes |
@Override protected boolean matchesSafely(Response response) { if (awaitCondition.getSuccessMatcher() != null && awaitCondition.getSuccessMatcher().matches(response)) { return true; } if (awaitCondition.getFailureMatcher() != null && awaitCondition.getFailureMatcher().matches(response)) { throw new CucumberException("Expected successful response but was failed."); } return false; }
Example #15
Source File: EntityFacade.java From cukes with Apache License 2.0 | 5 votes |
private String toString(Object value) throws NamingException { try { if (value instanceof byte[]) { return new String((byte[]) value, "UTF-8"); } else if (value instanceof char[]) { return new String((char[]) value); } else if (value.getClass().isArray()) { return ArrayUtils.toString(value); } return value.toString(); } catch (UnsupportedEncodingException e) { throw new CucumberException("Failed to convert value to string", e); } }
Example #16
Source File: PickleStepDefinitionMatch.java From NoraUi with GNU Affero General Public License v3.0 | 5 votes |
private CucumberException registerTypeInConfiguration(Exception e) { return new CucumberException( String.format("" + "Could not convert arguments for step [%s] defined at '%s'.\n" + "It appears you did not register a data table type. The details are in the stacktrace below.", // TODO: // Add // doc // URL stepDefinition.getPattern(), stepDefinition.getLocation(true)), e); }
Example #17
Source File: StepUtils.java From allure-java with Apache License 2.0 | 5 votes |
protected Step extractStep(final StepDefinitionMatch match) { try { final Field step = match.getClass().getDeclaredField("step"); step.setAccessible(true); return (Step) step.get(match); } catch (ReflectiveOperationException e) { //shouldn't ever happen LOG.error(e.getMessage(), e); throw new CucumberException(e); } }
Example #18
Source File: ExtentCucumberAdapter.java From extentreports-cucumber4-adapter with Apache License 2.0 | 5 votes |
private URL toUrl(String fileName) { try { URL url = Paths.get(screenshotDir, fileName).toUri().toURL(); return url; } catch (IOException e) { throw new CucumberException(e); } }
Example #19
Source File: ExtentCucumberAdapter.java From extentreports-cucumber4-adapter with Apache License 2.0 | 5 votes |
private static OutputStream createReportFileOutputStream(URL url) { try { return new URLOutputStream(url); } catch (IOException e) { throw new CucumberException(e); } }
Example #20
Source File: CucumberReporter.java From bdt with Apache License 2.0 | 4 votes |
private void finishReport() { try { // TestNG results.setAttribute("total", String.valueOf(getElementsCountByAttribute(suite, "status", ".*"))); results.setAttribute("passed", String.valueOf(getElementsCountByAttribute(suite, "status", "PASS"))); results.setAttribute("failed", String.valueOf(getElementsCountByAttribute(suite, "status", "FAIL"))); results.setAttribute("skipped", String.valueOf(getElementsCountByAttribute(suite, "status", "SKIP"))); suite.setAttribute("name", CucumberReporter.class.getName()); suite.setAttribute("duration-ms", String.valueOf(getTotalDuration(suite.getElementsByTagName("test-method")))); test.setAttribute("name", CucumberReporter.class.getName()); test.setAttribute("duration-ms", String.valueOf(getTotalDuration(suite.getElementsByTagName("test-method")))); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult streamResult = new StreamResult(writer); DOMSource domSource = new DOMSource(document); transformer.transform(domSource, streamResult); closeQuietly(writer); // JUnit // set up a transformer jUnitSuite.setAttribute("name", callerClass + "." + TestSourcesModelUtil.INSTANCE.getTestSourcesModel().getFeatureName(TestMethod.currentFeatureFile)); jUnitSuite.setAttribute("failures", String.valueOf(jUnitSuite.getElementsByTagName("failure").getLength())); jUnitSuite.setAttribute("skipped", String.valueOf(jUnitSuite.getElementsByTagName("skipped").getLength())); jUnitSuite.setAttribute("time", sumTimes(jUnitSuite.getElementsByTagName("testcase"))); jUnitSuite.setAttribute("tests", String.valueOf(getElementsCountByAttribute(suite, STATUS, ".*"))); jUnitSuite.setAttribute("errors", String.valueOf(getElementsCountByAttribute(suite, STATUS, "FAIL"))); jUnitSuite.setAttribute("timestamp", new java.util.Date().toString()); jUnitSuite.setAttribute("time", String.valueOf(BigDecimal.valueOf(getTotalDurationMs(suite.getElementsByTagName("test-method"))).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue())); if (jUnitSuite.getElementsByTagName("testcase").getLength() == 0) { addDummyTestCase(); // to avoid failed Jenkins jobs } TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(writerJunit); DOMSource source = new DOMSource(jUnitDocument); trans.transform(source, result); closeQuietly(writerJunit); } catch (TransformerException e) { throw new CucumberException("Error transforming report.", e); } }
Example #21
Source File: PickleStepDefinitionMatch.java From NoraUi with GNU Affero General Public License v3.0 | 4 votes |
private CucumberException arityMismatch(int parameterCount) { List<String> arguments = createArgumentsForErrorMessage(); return new CucumberException(String.format("Step [%s] is defined with %s parameters at '%s'.\n" + "However, the gherkin step has %s arguments%sStep text: %s", stepDefinition.getPattern(), parameterCount, stepDefinition.getLocation(true), arguments.size(), formatArguments(arguments), step.getText())); }
Example #22
Source File: PickleStepDefinitionMatch.java From NoraUi with GNU Affero General Public License v3.0 | 4 votes |
private CucumberException couldNotConvertArguments(Exception e) { return new CucumberException(String.format("Could not convert arguments for step [%s] defined at '%s'.\n" + "The details are in the stacktrace below.", stepDefinition.getPattern(), stepDefinition.getLocation(true)), e); }
Example #23
Source File: CucumberExceptionWrapper.java From bdt with Apache License 2.0 | 4 votes |
CucumberExceptionWrapper(CucumberException e) { this.exception = e; }