Hi! Unfortunately there's no built-in support for such a requirement in `watir-rspec` nor `rspec` itself.
However, you can achieve that quite easily by creating your own `HtmlFormatter`. Easiest would be to extend `Watir::RSpec::HtmlFormatter` (https://github.com/watir/watir-rspec/blob/master/lib/watir/rspec/html_formatter.rb) and then override `example_passed` from `RSpec::Core::Formatters::HtmlFormatter` (https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/html_formatter.rb#L48-L52) and insert the links created during your specs from `@files_saved_during_example`. It seems to me that you need to create a different method for printing out the html than it is done currently by RSpec at `HtmlPrinter` (https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/html_printer.rb#L29-L32). Then, in your specs you just need to save the screenshot like this: browser.screenshot.save Watir::RSpec.file_path("uploaded.txt") # => this creates a unique file name and adds it to the `@files_saved_during_example` array as well. Also, refer to the code currently adding links to files created during failing specs to get some idea how it is done: https://github.com/watir/watir-rspec/blob/master/lib/watir/rspec/html_formatter.rb#L47-L51 And don't forget to use your own HtmlFormatter in spec_helper instead of Watir::RSpec::HtmlFormatter. The whole approach written above is not tested in practice, but seems to be doable in theory without monkey-patching, but using regular OO programming practices :) Jarmo Pertman ----- IT does really matter - http://itreallymatters.net On Friday, April 18, 2014 10:30:21 AM UTC+3, Arjen Ruiterkamp wrote: > > Hi Jarmo, thanks for replying > > I'll clarify a bit what I would like in my rspec report. > > I don't want to make a screenshot after *every *spec, just during some of > the specs which test Flot graphs (a Javascript library for displaying > graphs). > These Flot graphs are pretty hard to interact with using Watir-Webdriver > thus I want to add a screenshot to the report (or a link to the screenshot) > so our testers can quickly check if nothing weird is going on. > > So my (simplified) spec looks like this: > describe "do something once logged in" do > > it "should screenshot the flot graph" do > screenshot.save 'flot.png' > end > end > > Then the generated report should look like this: > > > <https://lh6.googleusercontent.com/-vsIEoAadNmE/U1DTkUF0yoI/AAAAAAAAACU/VzUQ0FuRcSM/s1600/rspec.png> > > > > > > > > > > > > > Hopefully this clears up my question. > > Is this possible with just watir-rspec or is some form of monkey patching > required? > > Regards, > Arjen > > On Tuesday, April 15, 2014 12:07:04 PM UTC+2, Arjen Ruiterkamp wrote: >> >> Hello, >> >> For some acceptance tests I want to include screenshots, which are made >> during my specs, to the report (thus not just for failing specs). >> The watir-rspec readme states: >> >> You can use Watir::RSpec.file_path to have links automatically in the >> html report to the files created during tests. >> >> uploaded_file_path = >> Watir::RSpec.file_path("uploaded.txt")File.open(uploaded_file_path, "w") >> {|file| file.write "Generated File Input"}file_field(:name => >> "upload-file").set uploaded_file_path >> >> Where do I put this code? When I put it in my spec_helper.rb, I get this >> error: undefined method `file_field' for main:Object (NoMethodError) >> Anyone has some ideas what I'm doing wrong? >> > -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected] --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
