Cucumber Embed for Screenshots Not Linking to Screenshot

Cucumber embed for screenshots not linking to screenshot

Aslak:

Try this:

After do |scenario|
if scenario.failed?
encoded_img = @browser.driver.screenshot_as(:base64)
embed("data:image/png;base64,#{encoded_img}",'image/png')
end
end

Aslak

Adam:

Aslak was able to see the embedded
image in the file that I emailed him,
while I was still unable to do so in
IE 8. I tried it out in Firefox 3.6
and the image appears as expected.
The problem may have originally been
with the embedding method itself (or
rather, my use of it), but using
Aslak's base64 solution it only fails
to work in the Internet Explorer
browser.

Aslak:

I believe Base64-encoding of images in
HTML pages [1] works in all decent
browsers (sorry, IE is not one of
them). However, it should work in
IE:
http://dean.edwards.name/weblog/2005/06/base64-ie/
(but maybe they broke it in IE8, or
maybe it only works with gifs, or
maybe IE needs a special kind of
base64 encoding, or maybe you should
just ditch IE)

If being able to read cucumber html
reports with screenshots in IE is
really important to you, you could
always write each image to disk:

 png = @browser.driver.screenshot_as(:png)
path = (0..16).to_a.map{|a| rand(16).to_s(16)}.join + '.png' # Or use some GUID library to make a unique filename - scenario names are not guaranteed to be unique.
File.open(path, 'wb') {|io| io.write(png)}
embed(path, 'image/png')

Obviously you have to make sure the
relative path you pass to embed is
right (depending on where you write
the html itself)

[1]
http://en.wikipedia.org/wiki/Data_URI_scheme

HTH, Aslak

cucumber hook scenario.embed always create screenshot at project root

@mpkorstanje - he is rightly pointed about it

As per his comment:

Use OutputType.BYTES and send the bytes directly to scenario.embed and write them directly to the screenshot file

But my issue was I am using mkolisnyk package and when I am using @AfterSuite annotation of it, it creating fail file images over root folder. seems bug in mkolisnyk package.

Mixing AfterSuite of testng and @ExtendedCucumberOptions of mkolisnyk works for me

How to attach/embed captured screenshots during custom softAssertion into Cucumber Report?

You attach scenarios to the report by using scenario.attach. This means you'll have to setup some plumbing to get the scenario into the assertion.

public class CustomSoftAssertion extends SoftAssertions {

private final Scenario scenario;

public CustomSoftAssertion(Scenario scenario) {
this.scenario = scenario;
}

@Override
public void onAssertionErrorCollected(AssertionError assertionError) {
// take screenshot and use the scenario object to attach it to the report
scenario.attach(....)
}
}

private CustomSoftAssertion softAssertion;

@Before
public void setup(Scenario scenario){
softAssertion = new CustomSoftAssertion(scenario);
}

@After // Or @AfterStep
public void assertAll(){
softAssertion.assertAll();
}

@Given("example")
public void example(){
softAssertion.assertThat(isLogin).isTrue();
}

Unable to attach screen shot to cucumber JVM report

Can you check the screenshot are embedded on the After Hooks steps on the html report?, This 5.3.0 version is attaching the screenshot at Hooks step as we have our logic in @After hooks. I also first struggled and later noticed this.

Captured screenshots are attached to local cucumber reports, but not to Jenkins report

Well, there was nothing wrong. The screenshots were showing just fine, in the After collapsed tab which I didnt open until now.



Related Topics



Leave a reply



Submit