I read for a while, and I cannot get it right. I have a file with my scripts in it login_process.js and another file with module functions that I need for routines.js .
I get a string parsing error message var routine = require('../routines'); I assume that this means that the error may be in the routines.js file but the node (used for syntax checking) and jshint only tell me that casper and other libraries are not defined (i.e. phantomjs require ect).
The files are as follows: routines.js:
var require = patchRequire(require); var casper = require('casper').create(); exports.login = function(email, pass, test) { casper.then(function() { this.withFrame(0, function() { this.waitUntilVisible('form#login-form', function() { this.fill('form#login-form', { email: email, password: pass }, false); }); }); }); casper.then(function(){ casper.withFrame(0, function() { this.click("#modalButtonLogin"); }); }); }; exports.signup = function(first_name, last_name, email, pass, other_pass, test) { casper.then(function() { this.withFrame(0, function() { this.waitUntilVisible('form#signup-form', function() { this.fill('form#signup-form', { first_name: first_name, last_name: last_name, login: email, password: pass, re_enter_password: 'pass' }, false); }); }); }); casper.then(function(){ casper.withFrame(0, function() { this.click("#modalButton"); }); }); };
login_process.js:
// var require = patchRequire(require); var routine = require('../routines'); casper.test.begin('Logs in', 1, function(test) { var fs = require('fs') var data = fs.read('../cookies.txt'); phantom.cookies = JSON.parse(data); casper.start("https://web.test.com/#") .wait(1000, function(){ routine.login('****@test.com', '******', test); }) .wait(1000, function(){ this.withFrame(0, function() { test.assertExists('.wkKitTitle'); }); }) .then(function(){ phantom.clearCookies(); casper.echo(JSON.stringify(routine.login)+ "here") }) .run(function() { test.done(); }); }); casper.test.begin('Wrong login warning', 2, function(test) { casper.start("https://web.test.com/#") .then(function(){ phantom.clearCookies(); }) .wait(1000, function(){ routine.login('****@test.com', '******', test); }) .wait(1000, function(){ this.withFrame(0, function() { test.assertExists('.wkErrorMessageText'); test.assertSelectorHasText('.wkErrorMessageText', 'Wrong email or password'); }); }) .then(function(){ phantom.clearCookies(); }) .run(function() { test.done(); }); }); casper.test.begin('Directs to correct url on form submission', 2, function(test) { casper.start("https://web.test.com/#") .then(function(){ test.assertUrlMatch('https://web.test.com/#') }) .wait(1000, function(){ routine.login('*******@test.com', '**', test); }) .wait(1000, function(){ test.assertUrlMatch('https://web.test.com/#kit/176********') }) .then(function(){ phantom.clearCookies(); }) .run(function() { test.done(); }); });
Output:
Test file: login_process.js SyntaxError: Parse error FAIL SyntaxError: Parse error