Repository: bbc/wraith

Issue #546: Wraith latest mode failure 
Created: 2017-11-15T12:17:23Z
Hello!
I'm trying to use Wraith in history mode but I've quickly run into an issue. The history step works well, but trying to run latest errors out. Relevant part of the error log:
Config validated. No serious issues found.
SAVING IMAGES
ERROR: No such file or directory @ rb_sysopen - shots/home/1280_chrome_news_latest.png
WARN: Using fallback image instead
/Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1289:in `initialize': No such file or directory @ rb_sysopen - shots/home/1280_chrome_news_latest.png (Errno::ENOENT)

I checked out the code and poking around found that calling setup_folders(config) before save_images(config, true) in lib/wraith/cli.rb ~L159 seems to sort the issue (command runs and can see expected results in the generated gallery).
Now, this is a total stab in the dark and I have no idea about possible ramifications, but thought of letting you know!
To reproduce:

Install latest Wraith (4.2.1) via gem install wraith and sufficiently new Chrome on Mac for headless mode (note doubt this is related to Chrome, but I don't want to install Phantom since it's been mostly abandoned).
On an empty folder copy YAML config below.
Run wraith history history.yaml.
Run wraith latest history.yaml.

Expected: commands run without problems, gallery is created.
Actual: latest command crashes, no gallery created.
Hope it helps.
Juan
ps: if adding that line of code is the right fix let me know and I'll send a PR over.

Issue checklist:

 I have validated my config file against YAML Validator to make sure it is valid YAML.
 I have run the wraith info command and pasted the output below:

DEBUG: #################################################
DEBUG:   Command run:        info
DEBUG:   Wraith version:     4.2.1
DEBUG:   Ruby version:       ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
DEBUG:   ImageMagick:        Version: ImageMagick 7.0.7-11 Q16 x86_64 2017-11-12 http://www.imagemagick.org
DEBUG:   PhantomJS version:  PhantomJS not installed
DEBUG:   chromedriver version:  ChromeDriver 2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2)
DEBUG:   CasperJS version:   Fatal: Did you install phantomjs?
DEBUG: #################################################


 I have run the command in verbose mode (by adding verbose: true to my config) and pasted the output below:

DEBUG: #################################################
DEBUG:   Command run:        latest history.yaml
DEBUG:   Wraith version:     4.2.1
DEBUG:   Ruby version:       ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
DEBUG:   ImageMagick:        Version: ImageMagick 7.0.7-11 Q16 x86_64 2017-11-12 http://www.imagemagick.org
DEBUG:   PhantomJS version:  PhantomJS not installed
DEBUG:   chromedriver version:  ChromeDriver 2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2)
DEBUG:   CasperJS version:   Fatal: Did you install phantomjs?
DEBUG: #################################################
Config validated. No serious issues found.
SAVING IMAGES
ERROR: No such file or directory @ rb_sysopen - shots/home/1280_chrome_news_latest.png
WARN: Using fallback image instead
/Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1289:in `initialize': No such file or directory @ rb_sysopen - shots/home/1280_chrome_news_latest.png (Errno::ENOENT)
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1289:in `open'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1289:in `block in copy_file'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1288:in `open'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1288:in `copy_file'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:429:in `copy_file'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:356:in `block in cp'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1460:in `block in fu_each_src_dest'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1476:in `fu_each_src_dest0'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:1458:in `fu_each_src_dest'
	from /Users/juan/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/fileutils.rb:355:in `cp'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/wraith-4.2.1/lib/wraith/save_images.rb:169:in `create_invalid_image'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/wraith-4.2.1/lib/wraith/save_images.rb:88:in `rescue in block in parallel_task'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/wraith-4.2.1/lib/wraith/save_images.rb:79:in `block in parallel_task'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/parallel-1.12.0/lib/parallel.rb:486:in `call_with_index'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/parallel-1.12.0/lib/parallel.rb:342:in `block (2 levels) in work_in_threads'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/parallel-1.12.0/lib/parallel.rb:495:in `with_instrumentation'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/parallel-1.12.0/lib/parallel.rb:341:in `block in work_in_threads'
	from /Users/juan/.rvm/gems/ruby-2.4.1/gems/parallel-1.12.0/lib/parallel.rb:206:in `block (2 levels) in in_threads'


 I have pasted the contents of my config file below:

##############################################################
##############################################################
# This is an example configuration provided by Wraith.
# Feel free to amend for your own requirements.
# ---
# This particular config is intended to demonstrate how
# to use Wraith in 'history' mode, which is best suited to
# making sure your site's appearance remains consistent over
# time.
#
# `wraith history history.yaml` # generate base screenshots
# `wraith latest history.yaml`  # take new shots and compare
#
##############################################################
##############################################################

# (required) The engine to run Wraith with. Examples: 'phantomjs', 'casperjs', 'slimerjs'
browser: "chrome"

# (required) The domain to take screenshots of.
domains:
  news: "http://www.bbc.com/news"

# (required) The paths to capture. This particular config is using casperjs, so we can take screenshots of selectors rather than the entire page.
paths:
  home: /

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
# before_capture: 'javascript/wait--casper.js'

# (required) Screen widths (and optional height) to resize the browser to before taking the screenshot.
screen_widths:
  - 1280

# (optional) Resize to each screen width (efficient), or reload at each screen width (costly). Default: 'reload'
resize_or_reload: 'reload'

# (required for history mode, otherwise optional) The directory that your base screenshots will be stored in.
history_dir: 'shots_history'

# (required) The directory that your latest screenshots will be stored in
directory: 'shots'

# (required) Amount of fuzz ImageMagick will use when comparing images. A higher fuzz makes the comparison less strict.
fuzz: '20%'

# (optional) The maximum acceptable level of difference (in %) between two images before Wraith reports a failure. Default: 0
threshold: 5

# (optional) Specify the template (and generated thumbnail sizes) for the gallery output.
gallery:
  template: 'slideshow_template' # Examples: 'basic_template' (default), 'slideshow_template'
  thumb_width:  200
  thumb_height: 200

# (optional) Choose which results are displayed in the gallery, and in what order. Default: alphanumeric
# Options:
#   alphanumeric - all paths (with or without a difference) are shown, sorted by path
#   diffs_first - all paths (with or without a difference) are shown, sorted by difference size (largest first)
#   diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
# Note: different screen widths are always grouped together.
mode: diffs_first

# (optional) Choose to run Wraith in verbose mode, for easier debugging. Default: false
verbose: true

# (optional) Color to highlight the image diff. Default: 'blue'
highlight_color: red

# (optional) Parameters to pass to Phantom/Casper command line. Default: '--ignore-ssl-errors=true --ssl-protocol=tlsv1'
phantomjs_options: ''

Duplicate issue #555: 'Latest' command is missing creating the directory structure
Created: 2018-01-23T08:00:33Z
https://github.com/BBC-News/wraith/blob/df0abb4ffccded412d118f04988443ea76fa1479/lib/wraith/cli.rb#L158
  desc "latest [config_name]", "Capture new shots to compare with baseline"
  def latest(config)
    within_acceptable_limits do
      logger.info Wraith::Validate.new(config).validate("latest")
      reset_shots(config)
+      setup_folders(config)
      save_images(config, true)
      copy_base_images(config)
      crop_images(config)
      compare_images(config)
      generate_thumbnails(config)
      generate_gallery(config)
    end
  end

Closing comment (2018-04-29T01:06:15Z): This looks like a duplicate of #546.