Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2499: Improve auto-screenshot on error in report #2493

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Loading