bbc / wraith

Wraith — A responsive screenshot comparison tool
http://bbc-news.github.io/wraith/
Apache License 2.0
4.83k stars 356 forks source link

Disabling Cookies and Javascript for CasperJS CSS selectors pages does not show the page #451

Closed rayferns closed 8 years ago

rayferns commented 8 years ago

I'm trying to disable some annoying cookies & javascript for a webpage that keeps popping up on the results gallery window. I thought I'd add the javascript\disable_javascript--casper.js file, that didn't work. So I created my own file: javascript\disable_javascript_and_cookies--casperjs.js with an extra line:

casper.cookiesEnabled = false;

This did not work either, not sure what is the best option. Please advise.

I managed to get this working for PhantomJS using the following commands:

    phantom.cookiesEnabled = false;
    phantom.settings.javascriptEnabled = false;

This works fine on snapped images, but not for CasperJS. Nothing loads up for CasperJS gallery images. Details below:

Any help appreciated.

Thanks,

Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

Issue checklist:

C:\VisualRegression>wraith capture configs\CSS_Selector_pages.yaml
DEBUG: #################################################
DEBUG:   Command run:        capture configs\CSS_Selector_pages.yaml
DEBUG:   Wraith version:     3.2.0
DEBUG:   Ruby version:       ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32]
DEBUG:   ImageMagick:        Version: ImageMagick 7.0.2-1 Q16 x64 2016-06-23 http://www.imagemagick.org
DEBUG:   PhantomJS version:  1.9.6
DEBUG:   CasperJS version:   1.1.1
DEBUG: #################################################
DEBUG:
Config validated. No serious issues found.
Creating Folders
SAVING IMAGES
DEBUG: casperjs --ssl-protocol=tlsv1 --ignore-ssl-errors=yes 'C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wraith-3.2.0/lib/wraith/javascript/casper.js' 'http://www.volkswagen.co.uk/find-a-retailer' '600x800,320x533,750x1334' 'Retailers_CSS_Selector_shots/Retailer/MULTI_casperjs_Live.png' '.grid-row' 'C:/VisualRegression/javascript/disable_javascript_and_cookies--casperjs' 'false'
DEBUG: casperjs --ssl-protocol=tlsv1 --ignore-ssl-errors=yes 'C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wraith-3.2.0/lib/wraith/javascript/casper.js' 'http://origin-vw03.vwcloud.co.uk/find-a-retailer' '600x800,320x533,750x1334' 'Retailers_CSS_Selector_shots/Retailer/MULTI_casperjs_Origin_VW03.png' '.grid-row' 'C:/VisualRegression/javascript/disable_javascript_and_cookies--casperjs' 'false'
CROPPING IMAGES
Process.fork is not supported by this Ruby
COMPARING IMAGES
Process.fork is not supported by this Ruby
GENERATING THUMBNAILS
Process.fork is not supported by this Ruby
GENERATING GALLERY
Gallery generated

View the gallery in your browser: file://C:/VisualRegression/Retailers_CSS_Selector_shots/gallery.html
#debug mode
verbose: true
#Headless browser option
browser:
  casperjs: "casperjs"
#  phantomjs: "phantomjs"

before_capture: 'javascript/wait--casper.js'

# Type the name of the directory that shots will be stored in
directory: 'Retailers_CSS_Selector_shots'

#As per https://github.com/BBC-News/wraith/issues/308 - to read in https urls
phantomjs_options: --ssl-protocol=tlsv1 --ignore-ssl-errors=yes

before_capture: 'javascript/wait--casper.js'

# Add only 2 domains, key will act as a label
domains:
  Live: "http://www.volkswagen.co.uk"
  Origin_VW03: "http://origin-vw03.vwcloud.co.uk"

#Type screen widths below, here are a couple of examples
screen_widths:
    - 600x800
    - 320x533
    - 750x1334

resize_or_reload: 'resize'
#resize_or_reload: 'reload'

#Type page URL paths below, here are a couple of examples
paths: 
    Retailer:
      path: /find-a-retailer
      selector: '.grid-row'
    # HomeHeader:
      # path: /
      # selector: '#header'
    # HomeFooter:
      # path: /
      # selector: '#footer'

before_capture: 'javascript/disable_javascript_and_cookies--casperjs'

#Amount of fuzz ImageMagick will use
fuzz: '50%'

#Set the number of days to keep the site spider file
spider_days:
  - 10

#Choose how results are displayed, by default alphanumeric. Different screen widths are always grouped.
#alphanumeric - all paths (with, and without, a difference) are shown, sorted by path
#diffs_first - all paths (with, and 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: diffs_first
mode: alphanumeric

threshold: 5

# Examples: 'basic_template' (default), 'slideshow_template'
gallery:
  template: 'basic_template' 
  thumb_width:  200
  thumb_height: 200

Javascript file:

'javascript/disable_javascript_and_cookies--casperjs'

// ######################################################
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (casper, ready) {
    // disable Cookies
    casper.cookiesEnabled = false;

    // disable JavaScript
    casper.options.pageSettings.javascriptEnabled = false;

    // reload the page without JS enabled
    casper.thenOpen(casper.page.url);
}
ChrisBAshton commented 8 years ago

You have two before_capture hooks in one YAML file - there should only be one

before_capture: 'javascript/wait--casper.js'

before_capture: 'javascript/disable_javascript_and_cookies--casperjs'

Regardless, you'd have to find a casper command which disables cookies (I'm not sure this exists, so consider switching to Phantom, where it does exist).

These links are relevant:

Good luck!

kentr commented 7 years ago

For anyone else who finds this, it appears that casper.options.pageSettings.javascriptEnabled = false; disables the critical CasperJS / PhantomJS functionality and causes the screenshot to fail.

See