Error loading jQuery object in Rails4 / PhantomJS / Rspec / Capybara


#1

I keep getting an error with PhantomJS finding jQuery. Seems like on circle it can’t load the javascript. Perhaps its looking in the wrong location? I ma using a CDN (allows both HTTP and HTTPS). This is working locally.

I don’t know how to see the locations of assets files PhantomJS is trying to load on circle. Here is the error message:

 Capybara::Poltergeist::JavascriptError:
   One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).

   ReferenceError: Can't find variable: jQuery
   ReferenceError: Can't find variable: jQuery
       at http://127.0.0.1:56449/dashboard/247:46 in global code
 # /home/ubuntu/.rvm/gems/ruby-2.2.2/gems/poltergeist-1.8.1/lib/capybara/poltergeist/browser.rb:347:in `command'
 # /home/ubuntu/.rvm/gems/ruby-2.2.2/gems/poltergeist-1.8.1/lib/capybara/poltergeist/browser.rb:34:in `visit'
 # /home/ubuntu/.rvm/gems/ruby-2.2.2/gems/poltergeist-1.8.1/lib/capybara/poltergeist/driver.rb:95:in `visit'
 # /home/ubuntu/.rvm/gems/ruby-2.2.2/gems/capybara-2.5.0/lib/capybara/session.rb:232:in `visit'
 # /home/ubuntu/.rvm/gems/ruby-2.2.2/gems/capybara-2.5.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
 # ./spec/features/dashboard_controller_feature_spec.rb:21:in `block (3 levels) in <top (required)>'

circle.yml:

database:
  override:
    - foreman run rake db:create db:schema:load
dependencies:
  pre:
    - sudo apt-get update; sudo apt-get install libicu52
    - curl --output /home/ubuntu/bin/phantomjs-2.0.1-linux-x86_64-dynamic https://s3.amazonaws.com/circle-support-bucket/phantomjs/phantomjs-2.0.1-linux-x86_64-dynamic
    - chmod a+x /home/ubuntu/bin/phantomjs-2.0.1-linux-x86_64-dynamic
    - sudo ln -s --force /home/ubuntu/bin/phantomjs-2.0.1-linux-x86_64-dynamic /usr/local/bin/phantomjs 

In spec_helper.rb

require ‘capybara/poltergeist’

Capybara.javascript_driver = :poltergeist


#2

also here is an example of one of the tests:

context "no orders are associated to campaign" do
	  it "views empty state orders page ", js: true  do

	    visit "/dashboard/#{@campaign.id}/orders"
	    wait_for_ajax

	    expect(page).to have_css "div.page-title", text: "ORDERS", wait: 5

	    expect(page).to have_css "td.dataTables_empty", text: "No data available in table", wait: 10

	  end
    end

thanks


#3

Looks like this may be an issue when using CDN and jQuery

See https://github.com/teampoltergeist/poltergeist/issues/58#issuecomment-16254638

More details here as well: http://stackoverflow.com/q/30496090/335583 (where I found the link to the issue)


#4

Thanks for the reply. I had seen the stackoverflow article previously. Is there an example of how I pass those params to phantomJS? I searched on how to do that with circle.yml but couldn’t find anything that was phantomJS specific.

Is there a way to pass ‘–ssl-protocol=any’ to PhantomJS through circle.yml ir antoher way?

Thanks, Tom


#5

Looks like you can pass options to PhantomJS using phantomjs_options

See the customization section.

Ref: https://github.com/teampoltergeist/poltergeist


#6

Thanks for the help. It is using http for the assets


#7