Skip to content

Commit

Permalink
Merge pull request #2493 from codehackerr/develop
Browse files Browse the repository at this point in the history
2499: Improve auto-screenshot on error in report
  • Loading branch information
ptrthomas authored Feb 2, 2024
2 parents fcc1ad3 + 481cead commit ccd7ee9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public String getEmbedFileName(ResourceType resourceType) {
return scenario.getUniqueId() + "_" + System.currentTimeMillis() + (extension == null ? "" : "." + extension);
}

public Embed saveToFileAndCreateEmbed(byte[] bytes, ResourceType resourceType) {
private Embed saveToFileAndCreateEmbed(byte[] bytes, ResourceType resourceType) {
File file = new File(featureRuntime.suite.reportDir + File.separator + getEmbedFileName(resourceType));
FileUtils.writeToFile(file, bytes);
return new Embed(file, resourceType);
Expand Down Expand Up @@ -465,6 +465,12 @@ public StepResult execute(Step step) {
error = stepResult.getError();
logError(error.getMessage());
}
if (engine.driver != null) {
engine.driver.onFailure(currentStepResult);
}
if (engine.robot != null) {
engine.robot.onFailure(currentStepResult);
}
} else {
boolean hidden = reportDisabled || (step.isPrefixStar() && !step.isPrint() && !engine.getConfig().isShowAllSteps());
currentStepResult.setHidden(hidden);
Expand All @@ -484,14 +490,6 @@ public StepResult execute(Step step) {
stopped = true;
}
}
if (stepResult.isFailed()) {
if (engine.driver != null) {
engine.driver.onFailure(currentStepResult);
}
if (engine.robot != null) {
engine.robot.onFailure(currentStepResult);
}
}
if (executed && !dryRun) {
featureRuntime.suite.hooks.forEach(h -> h.afterStep(currentStepResult, this));
}
Expand Down
5 changes: 5 additions & 0 deletions karate-junit5/src/test/java/karate/SampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.intuit.karate.junit5.Karate;

class SampleTest {
@Karate.Test
// Uncomment @ignore on embed.feature for development verification
Karate testScreenshotIsEmbeddedOnTheCorrectStepOnFailure() {
return Karate.run("embed").relativeTo(getClass());
}

@Karate.Test
Karate testSample() {
Expand Down
22 changes: 22 additions & 0 deletions karate-junit5/src/test/java/karate/embed.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: browser automation demo

Background:
* configure driver = { type: 'chrome' }
@ignore
Scenario: try to login to github and then do a google search
Simulates step failure for testing embedded screenshots. Remove @ignore for developement

Given driver 'https://github.com/login'
And input('#login_field', 'YYY')
And input('#password', 'world')
When submit().click("input[name=commit]")
Then match html('.flash-error') contains 'Bad username or password.'

Given driver 'https://google.com'
# And click('{}Accept all')
And input("[name=q][name=q]", 'karate dsl')
When submit().click("input[name=btnI]")
Then waitForUrl('https://github.com/karatelabs/karate')

Scenario: Dummy not to fail build
* print 'dummy'

0 comments on commit ccd7ee9

Please sign in to comment.