最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't split CasperJS tests across multiple files - Stack Overflow

programmeradmin2浏览0评论

The docs weren't really useful - too brief and vague. As I understood from the docs, We just need to to run casperjs mand on the the directory of tests and ensure each test ends with Tester.done(). Here are my two tests,

//test1.js
var casper = require('casper').create();

var urlPrefix = "http://localhost/NavHawk2/";

casper.start(urlPrefix , function() {
    this.test.assertSelectorHasText('title', 'Login', 'Title Ok! Login Page Expected');
    this.test.assertExists('form[action$="/login"]', 'Login Form is found');
    this.fill('form[action$="/login"]', {
        .....
    }, true);
});

casper.run(function() {
    this.test.done(2);
});


//test2.js
var blinkingCircleImg = "7.gif"

casper.on('page.error', function(){
    console.log("SOme Javascript error persists!");
});

casper.then(function(){
    this.test.assertSelectorHasText('title', 'Map', 'Login Ok! Map Page Expected');
    this.test.assertExists('img[src$="' + blinkingCircleImg + '"]', 'Blinking Circle being shown!');
    this.test.assetNotVisible('#sidebar_content_geofences', 'Geofencing sidebar not being shown!');
});

casper.run(function() {
    this.test.renderResults(true);
    this.test.done(3);
});

The thing is that test2.js file is never run. Maybe I am wrong somewhere.

The docs weren't really useful - too brief and vague. As I understood from the docs, We just need to to run casperjs mand on the the directory of tests and ensure each test ends with Tester.done(). Here are my two tests,

//test1.js
var casper = require('casper').create();

var urlPrefix = "http://localhost/NavHawk2/";

casper.start(urlPrefix , function() {
    this.test.assertSelectorHasText('title', 'Login', 'Title Ok! Login Page Expected');
    this.test.assertExists('form[action$="/login"]', 'Login Form is found');
    this.fill('form[action$="/login"]', {
        .....
    }, true);
});

casper.run(function() {
    this.test.done(2);
});


//test2.js
var blinkingCircleImg = "7.gif"

casper.on('page.error', function(){
    console.log("SOme Javascript error persists!");
});

casper.then(function(){
    this.test.assertSelectorHasText('title', 'Map', 'Login Ok! Map Page Expected');
    this.test.assertExists('img[src$="' + blinkingCircleImg + '"]', 'Blinking Circle being shown!');
    this.test.assetNotVisible('#sidebar_content_geofences', 'Geofencing sidebar not being shown!');
});

casper.run(function() {
    this.test.renderResults(true);
    this.test.done(3);
});

The thing is that test2.js file is never run. Maybe I am wrong somewhere.

Share Improve this question asked May 4, 2013 at 6:01 ShubhamShubham 22.3k18 gold badges69 silver badges91 bronze badges 4
  • How is test2.js loaded in the first place? – Paul Grime Commented May 4, 2013 at 8:56
  • @PaulGrime: How is it supposed to be loaded? Docs weren't clear. – Shubham Commented May 4, 2013 at 13:26
  • Can you show your folder structure? I'm not sure where test2.js is loaded. – Paul Grime Commented May 4, 2013 at 20:12
  • @PaulGrime: They are in the same folder. – Shubham Commented May 5, 2013 at 4:45
Add a ment  | 

1 Answer 1

Reset to default 16

Several things here:

  • you must use the casperjs test submand
  • you may not create a new casper instance within a test script
  • you may not call .renderResults when using the casperjs test submand
  • tests scripts within a given directory will be executed in the alphabetical order of their filename

There's a useful gist which demonstrates how the mand may/should be used.

发布评论

评论列表(0)

  1. 暂无评论