Repository: bbc/wraith

Issue #308: Wraith does not work for HTTPS urls
Created: 2015-11-05T11:21:01Z
Hi there,
I am trying out wraith for a site and unfortunately, it only generates empty images for a HTTPS site. Now, I have been looking at issues on Github and it seems that I have to put this setting in my config/component.yaml:
phantomjs_options: --ssl-protocol=tlsv1

However, it is still generating empty images.
When I try it with a non-HTTPS page, the screenshot is created as expected. So, I am guessing that this is related to HTTPS issue.
This is my config/component.yaml file for the HTTPS (non-working) version.
# Add as many domains as necessary. Key will act as a label
phantomjs_options: --ssl-protocol=tlsv1
domains:
  english: "https://www.viki.com"

# (optional) JavaScript file to execute before taking screenshot of every path.
# Can be used to reload current page with headers specified, or to dynamically
# AJAX in content, or all manner of other uses!
#before_capture: 'javascript/global.js'

# Type page URL paths below, here are a couple of examples
paths:
  home: /

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

# the maximum acceptable level of difference (in %) between two images.
# Wraith considers it a failure if an image diff goes above this threshold.
threshold: 5

# screen widths (and optional height) to resize the browser to before taking the screenshot
screen_widths:
  - 320
  - 600x768
  - 768
  - 1024
  - 1280

# the engine to run Wraith with.
browser:
  phantomjs: "casperjs"   # variant of PhantomJS that allows screenshots by element selector
  #phantomjs: "phantomjs" # PhantomJS, built on top of Webkit and JavascriptCore (like Safari)
  #slimerjs: "slimerjs"   # SlimerJS, built on top of Gecko and SpiderMonkey (like Firefox)

# the file in charge of taking the screenshot
snap_file: "javascript/casper.js"

# the directory that your base screenshots will be stored in
history_dir: 'shots_base'

# the directory that your latest screenshots will be stored in
directory: 'shots'

# choose how results are displayed in the gallery (default is `alphanumeric` if omitted)
# Different screen widths are always grouped together.
# 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)
mode: alphanumeric

Are there any sort of settings that I may have missed pertaining to HTTPS settings?
In case if it helps, my system informations are:
PhantomJS version 1.9.7
ImageMagick 6.9.2-5
CasperJS version 1.0.0
Mac OS X El Capitan Version 10.11.1
Thanks in advance for your help!

Duplicate issue #455: Couldn't get CasperJS to work with HTTPS with the command --ssl-protocol=tlsv1
Created: 2016-07-28T08:47:57Z
I am having trouble making Wraith to work with CasperJS on sites with HTTPS protocol. I do not have this problem when I am running test on sites with HTTP protocol but only HTTPS with CasperJS. PhantomJS works fine on both protocols. And yes, I do have this option on:
phantomjs_options: --ssl-protocol=tlsv1 --ignore-ssl-errors=yes

This is the error that I received running the above command.
DEBUG: #################################################
DEBUG:   Command run:        latest configs/history.yaml
DEBUG:   Wraith version:     3.2.0
DEBUG:   Ruby version:       ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin12.0]

DEBUG:   ImageMagick:        Version: ImageMagick 6.9.2-5 Q16 x86_64 2015-11-01 http://www.imagemagick.org

DEBUG:   PhantomJS version:  1.9.7

DEBUG:   CasperJS version:   1.0.0

DEBUG: #################################################
DEBUG: 
Config validated. No serious issues found.
SAVING IMAGES
DEBUG: casperjs --ssl-protocol=tlsv1 --ignore-ssl-errors=yes '/Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/javascript/casper.js' 'https://smackaho.st:3022/' '320x10000,600x10000,768x10000,1024x10000,1280x10000' 'shots_latest/home/MULTI_casperjs_english_latest.png' 'body' '/Users/viki/workspace/raynor/javascript/wait--casper.js' 'false'
CasperError: CasperJS couldn't find module /Users/viki/workspace/raynor/_helper.js

  /Users/viki/.rvm/gems/ruby-2.1.1/gems/casperjs-1.0.0/bin/bootstrap.js:126 in _require

  /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/javascript/casper.js:24 in requireRelative

  /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/javascript/casper.js:4

COPYING BASE IMAGES
Copying shots_base/home to shots_latest
CROPPING IMAGES
DEBUG: Cropping both images to 600x1500. (shots_latest/home/320x1500_phantomjs_english.png, shots_latest/home/600x768_phantomjs_english.png)
DEBUG: Cropping both images to 1280x1500. (shots_latest/home/1024x1500_phantomjs_english.png, shots_latest/home/1280x1500_phantomjs_english.png)
/Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/crop.rb:48:in `initialize': no implicit conversion of nil into String (TypeError)
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/crop.rb:48:in `open'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/crop.rb:48:in `image_dimensions'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/crop.rb:26:in `crop_if_necessary'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/crop.rb:19:in `block in crop_images'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:453:in `call'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:453:in `call_with_index'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:422:in `process_incoming_jobs'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:404:in `block in worker'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:395:in `fork'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:395:in `worker'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:386:in `block in create_workers'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:385:in `each'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:385:in `each_with_index'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:385:in `create_workers'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:327:in `work_in_processes'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:241:in `map'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/parallel-1.9.0/lib/parallel.rb:203:in `each'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/crop.rb:18:in `crop_images'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/cli.rb:98:in `block in crop_images'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/cli.rb:28:in `within_acceptable_limits'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/cli.rb:95:in `crop_images'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/cli.rb:173:in `block in latest'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/cli.rb:28:in `within_acceptable_limits'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/lib/wraith/cli.rb:168:in `latest'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/viki/.rvm/gems/ruby-2.1.1/gems/wraith-3.2.0/bin/wraith:5:in `<top (required)>'
    from /Users/viki/.rvm/gems/ruby-2.1.1/bin/wraith:23:in `load'
    from /Users/viki/.rvm/gems/ruby-2.1.1/bin/wraith:23:in `<main>'
    from /Users/viki/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
    from /Users/viki/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

When I exclude --ssl-protocol=tlsv1, the test runs normally and gallery is successfully generated but all of the screenshots taken is blank. Including --ssl-protocol=tlsv1 will give the error above.
This is my config/history.yaml file
##############################################################
##############################################################
# 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: "casperjs"

# (required) The domain to take screenshots of.
domains:
  english: "https://smackaho.st:3022"

# (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:
    path: /
    selector: 'body'

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil

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

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

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

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

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

# (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: --ssl-protocol=tlsv1 --ignore-ssl-errors=yes


This is run on history mode (wraith latest command). Is there a workaround for this in order to make CasperJS work properly with HTTPS sites? CasperJS gem is already deprecated and has never been updated for quite a while now. I have been using Wraith for quite some time and phantomJS mode works just fine for us. However, I wanna start using CasperJS for taking snapshots of components instead of whole sites. Thanks in advance for your help!

Closing comment (2016-11-30T09:54:04Z): Duplicate of #308.