Skip to content

Commit

Permalink
Merge pull request #8 from MicroFocus/jane_defect_last_line_without_star
Browse files Browse the repository at this point in the history
fix results not loading correctly issue - 'at star' is not the last line of error message
  • Loading branch information
bingyujin authored Nov 4, 2022
2 parents 6551744 + c309721 commit b88071d
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 28 deletions.
76 changes: 49 additions & 27 deletions src/main/java/com/microfocus/bdd/CucumberJvmHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,36 @@ public void setElement(Element element) {
errorMessage = child.getText();
String lastLine = findLastNonEmptyLine(errorMessage);
if (lastLine.startsWith("at ✽.")) {
int startOfFileLocation = lastLine.lastIndexOf("(");
failedStep = lastLine.substring(5, startOfFileLocation);
featureFile = lastLine.substring(startOfFileLocation + 1, lastLine.lastIndexOf(')'));
int lineNumIndex = featureFile.lastIndexOf(':');
failedLineNum = featureFile.substring(lineNumIndex + 1);
featureFile = featureFile.substring(0, lineNumIndex);
extractFeatureFilePath(lastLine);
} else {
element.getChild("system-out").ifPresent(out -> {
errorMessage = out.getText();
String failedLine = null;
int indexOfPeriod = 0;
for (String line: getLinesBottomUp(errorMessage)) {
if (line.startsWith("at ") && line.endsWith(")")) {
indexOfPeriod = line.indexOf('.');
if (indexOfPeriod != -1) {
failedLine = line;
break;
Optional<String> optionalString = findFirstStarLine(errorMessage);
if (optionalString.isPresent()) {
extractFeatureFilePath(optionalString.get());
} else {
element.getChild("system-out").ifPresent(out -> {
errorMessage = out.getText();
String failedLine = null;
int indexOfPeriod = 0;
for (String line : getLinesBottomUp(errorMessage)) {
if (line.startsWith("at ") && line.endsWith(")")) {
indexOfPeriod = line.indexOf('.');
if (indexOfPeriod != -1) {
failedLine = line;
break;
}
}
}
}
if (failedLine == null) {
return;
}
int startOfFileLocation = failedLine.lastIndexOf("(");
failedStep = failedLine.substring(indexOfPeriod + 1, startOfFileLocation);
featureFile = failedLine.substring(startOfFileLocation + 1, failedLine.lastIndexOf(')'));
int lineNumIndex = featureFile.lastIndexOf(':');
failedLineNum = featureFile.substring(lineNumIndex + 1);
featureFile = featureFile.substring(0, lineNumIndex);
});
if (failedLine == null) {
return;
}
int startOfFileLocation = failedLine.lastIndexOf("(");
failedStep = failedLine.substring(indexOfPeriod + 1, startOfFileLocation);
featureFile = failedLine.substring(startOfFileLocation + 1, failedLine.lastIndexOf(')'));
int lineNumIndex = featureFile.lastIndexOf(':');
failedLineNum = featureFile.substring(lineNumIndex + 1);
featureFile = featureFile.substring(0, lineNumIndex);
});
}
}
} else if (childName.equals("skipped")) {
isSkipped = true;
Expand All @@ -109,10 +109,32 @@ private String findLastNonEmptyLine(String message) {
return null;
}

private Optional<String> findFirstStarLine(String message) {
for (String line : getLines(message)) {
if (line.startsWith("at ✽.")) {
return Optional.of(line);
}
}
return Optional.empty();
}

private Iterable<String> getLinesBottomUp(String message) {
return () -> new LinesBottomUpIterator(message);
}

private Iterable<String> getLines(String message) {
return () -> new LinesIterator(message);
}

private void extractFeatureFilePath(String line) {
int startOfFileLocation = line.lastIndexOf("(");
failedStep = line.substring(5, startOfFileLocation);
featureFile = line.substring(startOfFileLocation + 1, line.lastIndexOf(')'));
int lineNumIndex = featureFile.lastIndexOf(':');
failedLineNum = featureFile.substring(lineNumIndex + 1);
featureFile = featureFile.substring(0, lineNumIndex);
}

@Override
public Optional<String> getFeatureName() {
String classname = element.getAttribute("classname");
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/microfocus/bdd/LinesIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* © Copyright [2021] Micro Focus or one of its affiliates.
* Licensed under Apache License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* http://www.apache.org/licenses/
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
package com.microfocus.bdd;

import java.util.Iterator;

class LinesIterator implements Iterator<String> {
private String string;

private int index = 0;

public LinesIterator(String string) {
this.string = string;
}

@Override
public boolean hasNext() {
return index < string.length();
}

@Override
public String next() {
int endIndexOfLine = string.indexOf('\n', index);
String nextLine = string.substring(index, endIndexOfLine).trim();
index = endIndexOfLine + 1;
return nextLine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public static List<Object[]> data() {
//2 discrete junit reports + 1 unrelated junit report
{Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/separate-test3/*.xml", "src/test/resources/features/*.feature", "separateResults/cucumber-jvm-final3.xml", "**/separateResults/standard-cucumber-jvm-final3.xml"},
//1 junit report + 2 feature files
{Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/separate-test4/junit.xml", "src/test/resources/features/separate_test4*.feature", "separateResults/cucumber-jvm-final4.xml", "**/separateResults/standard-cucumber-jvm-final4.xml"}
{Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/separate-test4/junit.xml", "src/test/resources/features/separate_test4*.feature", "separateResults/cucumber-jvm-final4.xml", "**/separateResults/standard-cucumber-jvm-final4.xml"},
//1 junit report + 3 feature files
{Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/separate-test5/junit.xml", "src/test/resources/features/MyAccount*.feature", "separateResults/cucumber-jvm-final5.xml", "**/separateResults/standard-cucumber-jvm-final5.xml"}

});

Expand Down
125 changes: 125 additions & 0 deletions src/test/resources/cucumber-jvm/separate-test5/junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="7" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="31" time="884.541">

<testcase classname="MyAccountFooterUIValidations" name="Verify Footer - Our Fees Hyperlink" time="172.683">
<failure message="Expected condition failed: waiting for com.hastings.automation.function.pageaction.webpageaction.ClickAction$1@149b6966 (tried for 30 second(s) with 200 milliseconds interval)" type="org.openqa.selenium.TimeoutException"><![CDATA[Given User logs into My Account with a policy...............................passed
When User clicks on "Our Fees" link in My Account Footer....................failed
Then User should be navigated to the respective footer page.................skipped
StackTrace:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for com.hastings.automation.function.pageaction.webpageaction.ClickAction$1@149b6966 (tried for 30 second(s) with 200 milliseconds interval)
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:263)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231)
at com.hastings.automation.function.pageaction.webpageaction.ClickAction.waitAndClickElement(ClickAction.java:45)
at com.hastings.automation.function.ui.pageobjects.digital.reactmyaccount.MaReactMarketingPreferenceOverlayPage.clickMarketingPreferenceCloseButton(MaReactMarketingPreferenceOverlayPage.java:68)
at com.hastings.automation.automationtest.bdd.definitions.stepdefinitions.digital.digitalsteps.MyAccountReactSteps.userClickOnFooterLink(MyAccountReactSteps.java:179)
at ✽.User clicks on "Our Fees" link in My Account Footer(classpath:src/test/resources/features/MyAccountFooterUIValidations.feature:8)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//img[@alt="Close"]"}
(Session info: headless chrome=104.0.5112.81)
For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'EGS2HSTMCSTAU02', ip: '10.100.51.151', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.2'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [0eff3e94bb4a19c40ab2338acfa32771, findElement {using=xpath, value=//img[@alt="Close"]}]
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 104.0.5112.81, chrome: {chromedriverVersion: 104.0.5112.79 (3cf3e8c8a07d..., userDataDir: C:\Users\AUTOMA~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:64453}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://egs2hstmcstau01.test.h..., se:cdpVersion: 104.0.5112.81, se:name: TemenosToReact_TestValidati..., setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 0eff3e94bb4a19c40ab2338acfa32771
at jdk.internal.reflect.GeneratedConstructorAccessor104.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:162)
at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:60)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:387)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:379)
at org.openqa.selenium.By$BaseW3CLocator.findElement(By.java:399)
at org.openqa.selenium.By$ByXPath.findElement(By.java:279)
at com.hastings.automation.function.ui.pageobjects.BasePage$ByProperty.findElement(BasePage.java:135)
at org.openqa.selenium.remote.ElementLocation$ElementFinder$1.findElement(ElementLocation.java:136)
at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:60)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:387)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:379)
at com.hastings.automation.function.pageaction.webpageaction.ReturnAction.waitAndReturnElement(ReturnAction.java:158)
at com.hastings.automation.function.pageaction.webpageaction.ReturnAction.waitAndReturnElement(ReturnAction.java:132)
at com.hastings.automation.function.pageaction.webpageaction.ReturnAction.waitAndReturnElement(ReturnAction.java:97)
at com.hastings.automation.function.pageaction.webpageaction.ClickAction$1.apply(ClickAction.java:49)
at com.hastings.automation.function.pageaction.webpageaction.ClickAction$1.apply(ClickAction.java:45)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at com.hastings.automation.function.pageaction.webpageaction.ClickAction.waitAndClickElement(ClickAction.java:45)
at com.hastings.automation.function.ui.pageobjects.digital.reactmyaccount.MaReactMarketingPreferenceOverlayPage.clickMarketingPreferenceCloseButton(MaReactMarketingPreferenceOverlayPage.java:68)
at com.hastings.automation.automationtest.bdd.definitions.stepdefinitions.digital.digitalsteps.MyAccountReactSteps.userClickOnFooterLink(MyAccountReactSteps.java:179)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
at io.cucumber.java.Invoker.invoke(Invoker.java:24)
at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
at io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29)
at io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66)
at io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63)
at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:85)
at io.cucumber.core.runner.TestStep.run(TestStep.java:57)
at io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51)
at io.cucumber.core.runner.TestCase.run(TestCase.java:84)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:75)
at io.cucumber.testng.TestNGCucumberRunner.lambda$runScenario$1(TestNGCucumberRunner.java:132)
at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:129)
at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:129)
at io.cucumber.testng.TestNGCucumberRunner.runScenario(TestNGCucumberRunner.java:129)
at com.hastings.automation.automationtest.bdd.testrunners.JenkinsCucumberBrowserRunner.scenario(JenkinsCucumberBrowserRunner.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:77)
at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:15)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
]]></failure>
</testcase>

<testcase classname="MyAccountHelpUIValidation" name="Verify Help page on My Account" time="38.92">
<system-out><![CDATA[Given User logs into My Account with a policy...............................passed
When User clicks on Help button.............................................passed
Then User should be directed to the Hastings Direct Help page...............passed
]]></system-out>
</testcase>

<testcase classname="MyAccount GoGreen Overlay Ui Validations" name="Verify the Help us go green modal overlay for postal document delivery in My Account" time="81.777">
<system-out><![CDATA[Given User logs into My Account with Postal document delivery method policy.passed
When User is on Dashboard screen for Go Green Modal.........................passed
Then User should be presented with Help us go green modal overlay...........passed
]]></system-out>
</testcase>

<testcase classname="MyAccountFooterUIValidations" name="Verify Footer - Important Information About Us Hyperlink" time="157.348">
<failure message="Expected condition failed: waiting for com.hastings.automation.function.pageaction.webpageaction.ClickAction$1@7b93d7e1 (tried for 30 second(s) with 200 milliseconds interval)" type="org.openqa.selenium.TimeoutException"><![CDATA[Given User login into My Account with Multi Product Policies................passed
When User clicks on "Important Information About Us" link in My Account Footer.failed
Then User should be navigated to the respective footer page.................skipped
StackTrace:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for com.hastings.automation.function.pageaction.webpageaction.ClickAction$1@7b93d7e1 (tried for 30 second(s) with 200 milliseconds interval)
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:263)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231)
at com.hastings.automation.function.pageaction.webpageaction.ClickAction.waitAndClickElement(ClickAction.java:45)
at com.hastings.automation.function.ui.pageobjects.digital.reactmyaccount.MaReactMarketingPreferenceOverlayPage.clickMarketingPreferenceCloseButton(MaReactMarketingPreferenceOverlayPage.java:68)
at com.hastings.automation.automationtest.bdd.definitions.stepdefinitions.digital.digitalsteps.MyAccountReactSteps.userClickOnFooterLink(MyAccountReactSteps.java:179)
at ✽.User clicks on "Important Information About Us" link in My Account Footer(classpath:src/test/resources/features/MyAccountFooterUIValidations.feature:51)
]]></failure>
</testcase>
</testsuite>
Loading

0 comments on commit b88071d

Please sign in to comment.