Visit pages using PhantomJS directly when writing specs with TeaSpoon - Jasmine

↘锁芯ラ 提交于 2019-12-21 05:43:12

问题


I'm trying to write a Javascript spec for my Rails 3.2 application using Teaspoon (the Jasmine version). I'm trying to write a spec that does something like this

describe("Fun", function() {
    var page = require('webpage').create() //ERROR

    it("should be so much fun", function() {
        page.open('/pageToTest/')
        expect($('#HereIsTheParty')).not.toBe( undefined );
    });
});

However, require('webpage') doesn't run (Error: Module name "system" has not been loaded yet for context) even though the Requirejs gem has been installed and can be accessed from the Chrome console.

My question is, can I easily get require('webpage') to run using Rails or should I be using something else? Is it maybe easier to just use Capybara since so far I've been using

describe "Fun", :type => :feature do
    it "should be so much fun" do
        visit '/pageToTest/'
        expect(page).to have_content 'Success'
    end
end

without any problems. I would however prefer using pure Javascript since in this case it's more convenient. What do you guys think? Thanks!


回答1:


With Teaspoon the specs are not run within the context of phantomjs, they are loaded within the context of the browser, and so don't have access to phantomjs. Only the internal phantomjs driver (runner.js in the repo) has any concept of phantomjs, which loads an html page with your javascripts in it.

It sounds like you may be convoluting Teaspoon with phantomjs, which is not an accurate picture of what's actually happening. Teaspoon only uses phantomjs as a runner layer and treats it no differently than Selenium or Capybara Webdriver (both also supported). So the question is similar to asking how you would access Selenium from within your javascript specs.



来源:https://stackoverflow.com/questions/28968231/visit-pages-using-phantomjs-directly-when-writing-specs-with-teaspoon-jasmine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!