@Test public void testErrorsGeneration() throws IOException { when(assetService.saveScreenshot(any(), anyString())).thenAnswer(call -> "http: ); List<Feature> features = CucumberReportUtil.parseReportJson(TestUtil.loadUtf8ResourceAsString("reports/tests/report.json")); List<String> stepDefinitions = StepDefinitionUtil.parseStepDefinitionsJson(TestUtil.loadUtf8ResourceAsString("reports/tests/stepDefinitions.json")); List<ExecutedScenario> executedScenarios = cut.extractExecutedScenarios(features, stepDefinitions, "http: try (AutoCloseableSoftAssertions asserts = new AutoCloseableSoftAssertions()) { asserts.assertThat(executedScenarios).hasSize(18); asserts.assertThat(executedScenarios.stream().flatMap(e -> e.getErrors().stream())).hasSize(13); { final ExecutedScenario executedScenario = executedScenarios.get(0); asserts.assertThat(executedScenario.getRun()).isNull(); asserts.assertThat(executedScenario.getFeatureFile()).isEqualTo(FEATURE_1_FILE); asserts.assertThat(executedScenario.getFeatureName()).isEqualTo(FEATURE_1_NAME); asserts.assertThat(executedScenario.getSeverity()).isEqualTo("sanity-check"); asserts.assertThat(executedScenario.getName()).isEqualTo("Functionality 111: Fail with two errors"); asserts.assertThat(executedScenario.getCucumberId()).isEqualTo("feature-1;fail-with-two-errors"); asserts.assertThat(executedScenario.getLine()).isEqualTo(7); asserts.assertThat(executedScenario.getContent()).isEqualTo("" + "8:passed:123000000:Given A step that works\n" + "9:failed:123000000:Then A step number 1 that fails with error \"string parameter 1\"\n" + "10:failed:123000000:And A step number 2 that fails with error \"string parameter 2\"\n" + "100000:passed:123000000:@After TestGlue.after(Scenario)"); asserts.assertThat(executedScenario.getScreenshotUrl()).isEqualTo("http: asserts.assertThat(executedScenario.getVideoUrl()).isEqualTo("http: { Error error = get(executedScenario.getErrors(), 0); asserts.assertThat(error.getId()).isNull(); asserts.assertThat(error.getStep()).isEqualTo("A step number 1 that fails with error \"string parameter 1\""); asserts.assertThat(error.getStepDefinition()).isEqualTo(STEP_DEF_ERROR); asserts.assertThat(error.getStepLine()).isEqualTo(9); asserts.assertThat(error.getException()).contains("java.lang.RuntimeException: Error message string parameter 1\n"); asserts.assertThat(error.getException()).contains("at ✽.Then A step number 1 that fails with error \"string parameter 1\"(ara/test/features/feature1.feature:9)\n"); } { Error error = get(executedScenario.getErrors(), 1); asserts.assertThat(error.getId()).isNull(); asserts.assertThat(error.getStep()).isEqualTo("A step number 2 that fails with error \"string parameter 2\""); asserts.assertThat(error.getStepDefinition()).isEqualTo(STEP_DEF_ERROR); asserts.assertThat(error.getStepLine()).isEqualTo(10); asserts.assertThat(error.getException()).contains("java.lang.RuntimeException: Error message string parameter 2\n"); asserts.assertThat(error.getException()).contains("\tat ✽.And A step number 2 that fails with error \"string parameter 2\"(ara/test/features/feature1.feature:10)\n"); } } { final ExecutedScenario executedScenario = executedScenarios.get(1); asserts.assertThat(executedScenario.getErrors()).isEmpty(); } { final ExecutedScenario executedScenario = executedScenarios.get(2); asserts.assertThat(executedScenario.getRun()).isNull(); asserts.assertThat(executedScenario.getFeatureFile()).isEqualTo(FEATURE_1_FILE); asserts.assertThat(executedScenario.getFeatureName()).isEqualTo(FEATURE_1_NAME); asserts.assertThat(executedScenario.getSeverity()).isEqualTo("high"); asserts.assertThat(executedScenario.getName()).isEqualTo("Functionality 113: Fail with name example 1"); asserts.assertThat(executedScenario.getLine()).isEqualTo(22); asserts.assertThat(executedScenario.getContent()).isEqualTo("" + "18:failed:123000000:When A step number 3 that fails with error \"example 1\"\n" + "100000:passed:123000000:@After TestGlue.after(Scenario)"); asserts.assertThat(executedScenario.getScreenshotUrl()).isEqualTo("http: asserts.assertThat(executedScenario.getVideoUrl()).isEqualTo("http: { Error error = get(executedScenario.getErrors(), 0); asserts.assertThat(error.getId()).isNull(); asserts.assertThat(error.getStep()).isEqualTo("A step number 3 that fails with error \"example 1\""); asserts.assertThat(error.getStepDefinition()).isEqualTo(STEP_DEF_ERROR); asserts.assertThat(error.getStepLine()).isEqualTo(18); asserts.assertThat(error.getException()).contains("java.lang.RuntimeException: Error message example 1\n"); asserts.assertThat(error.getException()).contains("\tat ✽.When A step number 3 that fails with error \"example 1\"(ara/test/features/feature1.feature:18)\n"); } } { final ExecutedScenario executedScenario = executedScenarios.get(3); asserts.assertThat(executedScenario.getRun()).isNull(); asserts.assertThat(executedScenario.getFeatureFile()).isEqualTo(FEATURE_1_FILE); asserts.assertThat(executedScenario.getFeatureName()).isEqualTo(FEATURE_1_NAME); asserts.assertThat(executedScenario.getSeverity()).isEqualTo("high"); asserts.assertThat(executedScenario.getName()).isEqualTo("Functionality 113: Fail with name example 2"); asserts.assertThat(executedScenario.getLine()).isEqualTo(23); asserts.assertThat(executedScenario.getContent()).isEqualTo("" + "18:failed:123000000:When A step number 3 that fails with error \"example 2\"\n" + "100000:passed:123000000:@After TestGlue.after(Scenario)"); asserts.assertThat(executedScenario.getScreenshotUrl()).isEqualTo("http: asserts.assertThat(executedScenario.getVideoUrl()).isEqualTo("http: { Error error = get(executedScenario.getErrors(), 0); asserts.assertThat(error.getId()).isNull(); asserts.assertThat(error.getStep()).isEqualTo("A step number 3 that fails with error \"example 2\""); asserts.assertThat(error.getStepDefinition()).isEqualTo(STEP_DEF_ERROR); asserts.assertThat(error.getStepLine()).isEqualTo(18); asserts.assertThat(error.getException()).contains("java.lang.RuntimeException: Error message example 2\n"); asserts.assertThat(error.getException()).contains("\tat ✽.When A step number 3 that fails with error \"example 2\"(ara/test/features/feature1.feature:18)\n"); } } { final ExecutedScenario executedScenario = executedScenarios.get(4); asserts.assertThat(executedScenario.getRun()).isNull(); asserts.assertThat(executedScenario.getFeatureFile()).isEqualTo("ara/test/features/feature2.feature"); asserts.assertThat(executedScenario.getFeatureName()).isEqualTo("Feature 2"); asserts.assertThat(executedScenario.getSeverity()).isEqualTo("high"); asserts.assertThat(executedScenario.getName()).isEqualTo("Fail before it"); asserts.assertThat(executedScenario.getLine()).isEqualTo(8); String begin1 = "" + "-100000:failed:123000000:@Before TestGlue.failOnBefore()\n" + "-99999:passed:123000000:@Before TestGlue.anotherBeforeHook()"; String begin2 = "" + "-100000:passed:123000000:@Before TestGlue.anotherBeforeHook()\n" + "-99999:failed:123000000:@Before TestGlue.failOnBefore()"; String end = "\n" + "9:skipped:0:Given A step that works\n" + "100000:passed:123000000:@After TestGlue.after(Scenario)"; asserts.assertThat(executedScenario.getContent()).isIn(begin1 + end, begin2 + end); asserts.assertThat(executedScenario.getScreenshotUrl()).isEqualTo("http: asserts.assertThat(executedScenario.getVideoUrl()).isEqualTo("http: { Error error = get(executedScenario.getErrors(), 0); asserts.assertThat(error.getId()).isNull(); asserts.assertThat(error.getStep()).isEqualTo("@Before"); asserts.assertThat(error.getStepDefinition()).isEqualTo("TestGlue.failOnBefore()"); asserts.assertThat(error.getStepLine()).isIn(-100000, -99999); asserts.assertThat(error.getException()).startsWith("" + "java.lang.RuntimeException: This scenario fails on before\n" + "\tat ara.test.TestGlue.failOnBefore("); } } { final ExecutedScenario executedScenario = executedScenarios.get(5); asserts.assertThat(executedScenario.getRun()).isNull(); asserts.assertThat(executedScenario.getFeatureFile()).isEqualTo("ara/test/features/feature2.feature"); asserts.assertThat(executedScenario.getFeatureName()).isEqualTo("Feature 2"); asserts.assertThat(executedScenario.getFeatureTags()).isEqualTo("@feature-2-tag"); asserts.assertThat(executedScenario.getTags()).isEqualTo("@add-structured-embeddings @severity-medium"); asserts.assertThat(executedScenario.getSeverity()).isEqualTo("medium"); asserts.assertThat(executedScenario.getName()).isEqualTo("Table step"); asserts.assertThat(executedScenario.getLine()).isEqualTo(12); String begin = "" + "13:passed:123000000:Given These values are true:\n" + "14:passed:| Value 1 | 1 |\n" + "15:passed:| Another value | 42 |\n" + "16:failed:123000000:And A step number 4 that fails with error \"string parameter 4\""; String end1 = "\n" + "100000:passed:123000000:@After TestGlue.after(Scenario)\n" + "100001:passed:123000000:@After TestGlue.addStructuredEmbeddings(Scenario)"; String end2 = "\n" + "100000:passed:123000000:@After TestGlue.addStructuredEmbeddings(Scenario)\n" + "100001:passed:123000000:@After TestGlue.after(Scenario)"; asserts.assertThat(executedScenario.getContent()).isIn(begin + end1, begin + end2); asserts.assertThat(executedScenario.getScreenshotUrl()).isEqualTo("screenshot.com"); asserts.assertThat(executedScenario.getVideoUrl()).isEqualTo("video.com"); asserts.assertThat(executedScenario.getLogsUrl()).isEqualTo("logs.com"); asserts.assertThat(executedScenario.getHttpRequestsUrl()).isEqualTo("http-requests.com"); asserts.assertThat(executedScenario.getJavaScriptErrorsUrl()).isEqualTo("java-script-errors.com"); asserts.assertThat(executedScenario.getStartDateTime()).isEqualTo(theDate()); asserts.assertThat(executedScenario.getCucumberReportUrl()).isEqualTo("http: { Error error = get(executedScenario.getErrors(), 0); asserts.assertThat(error.getId()).isNull(); asserts.assertThat(error.getStep()).isEqualTo("A step number 4 that fails with error \"string parameter 4\""); asserts.assertThat(error.getStepDefinition()).isEqualTo(STEP_DEF_ERROR); asserts.assertThat(error.getStepLine()).isEqualTo(16); asserts.assertThat(error.getException()).contains("java.lang.RuntimeException: Error message string parameter 4\n"); asserts.assertThat(error.getException()).contains("\tat ✽.And A step number 4 that fails with error \"string parameter 4\"(ara/test/features/feature2.feature:16)\n"); } } { final ExecutedScenario executedScenario = executedScenarios.get(6); asserts.assertThat(executedScenario.getName()).isEqualTo("Fail after it"); { Error error = get(executedScenario.getErrors(), 0); asserts.assertThat(error.getStep()).isEqualTo("@After"); asserts.assertThat(error.getStepDefinition()).isEqualTo("TestGlue.failOnAfter()"); asserts.assertThat(error.getStepLine()).isIn(100000, 100001); } } asserts.assertThat(executedScenarios.get(7).getLine()).isEqualTo(6); asserts.assertThat(executedScenarios.get(8).getLine()).isEqualTo(11); asserts.assertThat(executedScenarios.get(9).getLine()).isEqualTo(21); asserts.assertThat(executedScenarios.get(10).getLine()).isEqualTo(22); asserts.assertThat(executedScenarios.get(15).getContent()).isEqualTo("" + "-100000:passed:123000000:@Before TestGlue.anotherBeforeHook()\n" + "0:element:Background:\n" + "6:passed:123000000:Given A step that works\n" + "7:failed:123000000:And A step number 1 that fails with error \"bad-background\"\n" + "0:element:Scenario:\n" + "11:passed:123000000:Given A step that works\n" + "100000:passed:123000000:@After TestGlue.after(Scenario)"); } }
public List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl) { final List<ExecutedScenario> executedScenarios = new ArrayList<>(); ExecutedScenario lastBackground = null; for (Feature feature : features) { for (Element element : feature.getElements()) { if (element.isBackground()) { lastBackground = extractBackground(stepDefinitions, element); } else if (element.isScenario()) { executedScenarios.add(extractExecutedScenario(stepDefinitions, feature, element, runJobUrl, lastBackground)); lastBackground = null; } } lastBackground = null; } return executedScenarios; }
ExecutedScenarioExtractorService { public List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl) { final List<ExecutedScenario> executedScenarios = new ArrayList<>(); ExecutedScenario lastBackground = null; for (Feature feature : features) { for (Element element : feature.getElements()) { if (element.isBackground()) { lastBackground = extractBackground(stepDefinitions, element); } else if (element.isScenario()) { executedScenarios.add(extractExecutedScenario(stepDefinitions, feature, element, runJobUrl, lastBackground)); lastBackground = null; } } lastBackground = null; } return executedScenarios; } }
ExecutedScenarioExtractorService { public List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl) { final List<ExecutedScenario> executedScenarios = new ArrayList<>(); ExecutedScenario lastBackground = null; for (Feature feature : features) { for (Element element : feature.getElements()) { if (element.isBackground()) { lastBackground = extractBackground(stepDefinitions, element); } else if (element.isScenario()) { executedScenarios.add(extractExecutedScenario(stepDefinitions, feature, element, runJobUrl, lastBackground)); lastBackground = null; } } lastBackground = null; } return executedScenarios; }  }
ExecutedScenarioExtractorService { public List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl) { final List<ExecutedScenario> executedScenarios = new ArrayList<>(); ExecutedScenario lastBackground = null; for (Feature feature : features) { for (Element element : feature.getElements()) { if (element.isBackground()) { lastBackground = extractBackground(stepDefinitions, element); } else if (element.isScenario()) { executedScenarios.add(extractExecutedScenario(stepDefinitions, feature, element, runJobUrl, lastBackground)); lastBackground = null; } } lastBackground = null; } return executedScenarios; }  List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl); }
ExecutedScenarioExtractorService { public List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl) { final List<ExecutedScenario> executedScenarios = new ArrayList<>(); ExecutedScenario lastBackground = null; for (Feature feature : features) { for (Element element : feature.getElements()) { if (element.isBackground()) { lastBackground = extractBackground(stepDefinitions, element); } else if (element.isScenario()) { executedScenarios.add(extractExecutedScenario(stepDefinitions, feature, element, runJobUrl, lastBackground)); lastBackground = null; } } lastBackground = null; } return executedScenarios; }  List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl);  }