Load a web page into a spec
dpilafian opened this issue · 4 comments
Is it possible to read in a page from localhost
when using the { console: true }
option?
gulpfile.js
var gulp = require('gulp');
var jasmineBrowser = require('gulp-jasmine-browser');
function specRunner() {
gulp.src(['node_modules/jquery/dist/jquery.js', 'src/js/*.js', 'spec/*.js'])
.pipe(jasmineBrowser.specRunner({ console: true }))
.pipe(jasmineBrowser.headless());
}
gulp.task('spec', specRunner);
spec/cart-spec.js
describe('Cart component', function() {
it('displays on the gateway page', function() {
var page = loadWebPage('http://localhost/'); //fictitious function
var cart = page.find('#cart');
expect(cart.length).toBe(1);
});
});
The fictitious loadWebPage()
function is just to illustrate the functionality I believe is needed.
Also asked on SO:
http://stackoverflow.com/q/40646680
Jasmine browser expects to be run in the same browser where jasmine and the test code is loaded together at once. Are you trying to do some integration testing? If so it might be easier to use gulp-jasmine and webdriver.io to load start a phantom browser instead. This is more suited to the kind of thing it looks like you are trying to achieve.
No, I'm just trying to do some very simple lightweight testing. Installing Java and running a Selenium server is not ideal for this project.
Loading a page into an iframe
would be sufficient:
beforeEach(done => {
$('<iframe>', { src: 'http://localhost' }).on('load', done).appendTo($('body'));
});
However, the same-origin policy restriction seems to be blocking the iframe
from loading.
Looks like it would be necessary to add a flag to disable web security to phantom.
Closing since gulp-jasmine-browser is discontinued