Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cropping fails with TypeError #114

Closed
trodrigues opened this issue Mar 13, 2014 · 6 comments
Closed

Cropping fails with TypeError #114

trodrigues opened this issue Mar 13, 2014 · 6 comments
Labels

Comments

@trodrigues
Copy link

Running wraith capture config, I get the following after it goes through a bunch of "cropping images" messages:

/Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/crop.rb:45:in `initialize': can't convert nil into String (TypeError)
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/crop.rb:45:in `open'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/crop.rb:45:in `find_heights'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/crop.rb:24:in `compare_height'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/crop.rb:12:in `crop'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/crop.rb:32:in `crop_images'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/cli.rb:60:in `crop_images'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/lib/wraith/cli.rb:89:in `capture'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/wraith-1.1.4/bin/wraith:7:in `<top (required)>'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/bin/wraith:23:in `load'
        from /Users/trodrigues/.rbenv/versions/1.9.3-p429/bin/wraith:23:in `<main>'

My config looks like this:

#Headless browser option
browser:
  webkit: "phantomjs"
  # gecko: "slimerjs"

#If you want to have multiple snapping files, set the file name here
snap_file: "javascript/snap.js"

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

# Add only 2 domains, key will act as a label
domains:
  production: "https://www.contentful.com"
  development: "http://www.localdevelopmentdomain.com:8888"

#Type screen widths below, here are a couple of examples
screen_widths:
  - 320
  - 600
  - 768
  - 1024
  - 1280

#Type page URL paths below, here are a couple of examples
paths:
  home: /
  tour: /tour
  plans: /plans
  blog: /blog
  team: /team
  jobs: /jobs
  contact: /contact
  terms: /terms
  privacy: /privacy

# If you don't want to name the paths explicitly you can use a yaml
# collection as follows, and names will be derived by replacing / with _
#
# paths:
#  - /imghp
#  - /maps

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

#Set the number of days to keep the site spider file
spider_days:
  - 10
@sbelyea
Copy link
Contributor

sbelyea commented Mar 31, 2014

I think this is actually related to Issue #122 and looks like it was closed a few days ago. Don't believe the gem is updated, though.

@dblooman
Copy link
Contributor

I started a PR #123, but there is a better way of doing it. The bug is actually to do with Phantom, if the process dies or anything else goes wrong, it just skips over to the next image. This means the cropping occurs when there are an incorrect amount of images.
The solution is to find a folder where the image(s) are missing, then add a placeholder to prevent the whole process from failing. Simply raising as exception and moving on instead wouldn't work as the images would then be out of order when comparing.

@dblooman
Copy link
Contributor

dblooman commented Apr 7, 2014

This will be fixed by #112

@dblooman dblooman closed this as completed Apr 7, 2014
@trodrigues
Copy link
Author

Completely missed these notifications.

Yeah, I assumed this would be related to Phantom because I started using Slimer and the problem doesn't happen anymore. Need to give a try to the latest version with Phantom.

@sasanikolic90
Copy link

sasanikolic90 commented Mar 27, 2019

I am still experiencing this issue. Any idea why?

/Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:48:in "initialize": no implicit conversion of nil into String (TypeError)

@crs1138
Copy link

crs1138 commented Apr 1, 2019

Using chrome and having the same problems when running wraith latests history_config.yml.

$ wraith info
DEBUG: #################################################
DEBUG:   Command run:        info
DEBUG:   Wraith version:     4.2.3
DEBUG:   Ruby version:       ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
DEBUG:   ImageMagick:        Version: ImageMagick 7.0.8-12 Q16 x86_64 2018-09-23 https://imagemagick.org
DEBUG:   PhantomJS version:  2.1.1
DEBUG:   chromedriver version:  ChromeDriver 72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38)
DEBUG:   CasperJS version:   CasperJS not installed
DEBUG: #################################################

and my history_config.yml 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: "phantomjs"
# browser: "slimerjs"
browser: "chrome"

# (required) The domain to take screenshots of.
domains:
  acompalia: 'https://domain.com'

# (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: /
  esp_home: /es

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

# (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_postupdates'

# (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:  400
  thumb_height: 400

# (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) Color to highlight the image diff. Default: 'blue'
highlight_color: red

========
Results in…

Config validated. No serious issues found.
Creating Folders
SAVING IMAGES
COPYING BASE IMAGES
Copying shots_base/home to shots_postupdates
Copying shots_base/donate to shots_postupdates
Copying shots_base/volunteers to shots_postupdates
Copying shots_base/members to shots_postupdates
Copying shots_base/news to shots_postupdates
Copying shots_base/grief_support to shots_postupdates
Copying shots_base/esp_home to shots_postupdates
Copying shots_base/esp_donate to shots_postupdates
Copying shots_base/esp_volunteers to shots_postupdates
Copying shots_base/esp_members to shots_postupdates
Copying shots_base/esp_news to shots_postupdates
Copying shots_base/esp_grief_support to shots_postupdates
CROPPING IMAGES
/Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:48:in `initialize': no implicit conversion of nil into String (TypeError)
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:48:in `open'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:48:in `image_dimensions'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:26:in `crop_if_necessary'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:19:in `block in crop_images'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:486:in `call_with_index'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:455:in `process_incoming_jobs'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:437:in `block in worker'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:428:in `fork'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:428:in `worker'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:419:in `block in create_workers'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:418:in `each'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:418:in `each_with_index'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:418:in `create_workers'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:358:in `work_in_processes'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:264:in `map'
        from /Library/Ruby/Gems/2.3.0/gems/parallel-1.12.1/lib/parallel.rb:217:in `each'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/crop.rb:18:in `crop_images'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/cli.rb:87:in `block in crop_images'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/helpers/utilities.rb:4:in `within_acceptable_limits'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/cli.rb:84:in `crop_images'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/cli.rb:161:in `block in latest'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/helpers/utilities.rb:4:in `within_acceptable_limits'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/lib/wraith/cli.rb:155:in `latest'
        from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
        from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
        from /Library/Ruby/Gems/2.3.0/gems/wraith-4.2.3/bin/wraith:5:in `<top (required)>'
        from /usr/local/bin/wraith:22:in `load'
        from /usr/local/bin/wraith:22:in `<main>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants