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
Adam:Aslak
Aslak: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.
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_schemeHTH, 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
Rails: Before Process_Action Callback: Authenticate_User! Has Not Been Defined
Cucumber Re-Run Failed Scenarios Automatically with a Tag
Ruby Require 'File' Doesn't Work But Require './File' Does. Why
Get Route for Base Class of Sti Class in Rails
When Is The Enumerator::Yielder#Yield Method Useful
Difference Between Render and Yield in Rails
How to "Break" Out of a Case...While in Ruby
Actionmailer Pass Local Variables to The Erb Template
How to Test Helpers Blocks in Sinatra, Using Rspec
Monitor Multiple Rails Applications
How to Click on Specific Element in Canvas by Its Coordinates (Using Webdriver)
Escaping Strings for Ruby Sqlite Insert
Calling Module Method into Another Module in Ruby
Ruby: Parse Excel 95-2003 Files
Adding Bootstrap Icon to Button in Ruby on Rails
I Need to Go from HTML to Markdown, Any Suggestion
Do I Need to Install Passenger as a Regular Gem Even Though My App Uses Bundler