首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mocha内部使用PhantomJS的几个问题

Mocha内部使用PhantomJS的几个问题
EN

Stack Overflow用户
提问于 2014-04-30 20:50:21
回答 1查看 992关注 0票数 2

在试图从我的Mocha测试套件向服务器发送PhantomJS调用时,我遇到了问题。

问题

我试图使用PhantomJS对端点进行调用。我有第一个电话在工作。

但我有两个问题:

  • 当前脚本第一次运行良好,但是当看到一些文件导致测试失败时,会连续运行。我能解决这个问题吗?
  • 这似乎不是做这些测试的好方法,还有更好的选择吗?

设置:

  • 狼吞虎咽
  • 喝摩卡跑测试
  • 幻影同步做一些end2end测试

Mocha测试文件(简化):

代码语言:javascript
复制
if(typeof process != 'undefined') {
  var should = require('chai').should();
  var _ps = require('phantom-sync');
  var phantom = _ps.phantom;
  var sync = _ps.sync;
}

describe('Login', function() {
  this.timeout(5000);

  it('should be able to open CMS', function(done) {

    sync(function() {
      var ph = phantom.create();
      var page = ph.createPage();
      var status = page.open('http://www.google.com'); // Get a default CMS url...
      status.should.equal('success');
      ph.exit();
      return done();
    });

  });

  it('should redirect after successful login');

});

Gulpfile (简化):

代码语言:javascript
复制
gulp.task('test-develop', ['scripts'], function() {
  return test(null, true);
});

var keepAlive = false;

function test(reporter, _keepAlive) {

  keepAlive = _keepAlive;

  return gulp.src('test/**/*.js')
    .pipe(plugins.plumber())
    .pipe(plugins.mocha({ reporter: reporter || 'spec' })
      .on('error', onError));

}

function onError(err) {

  console.log(err.toString());
  if (keepAlive) {
    this.emit('end');
  } else {
    // if you want to be really specific
    process.exit(1);
  }

}

gulp.task('watch-test', function() {
  gulp.watch('test/**/*.js', ['test-develop']);
});

错误:

代码语言:javascript
复制
➜  [project_dir] git:(feature/phantomjs-tests) ✗ gulp watch-test
[gulp] Using gulpfile [project_dir]/gulpfile.js
[gulp] Starting 'watch-test'...
[gulp] Finished 'watch-test' after 26 ms
[gulp] Starting 'scripts'...
[gulp] Finished 'scripts' after 530 ms
[gulp] Starting 'test-develop'...


  Homepage
    Menu
      - should open without error
      - should close without error

  Login
    ✓ should be able to open CMS (2126ms)
    - should capture wrong username
    - should capture wrong password
    - should capture wrong username & password
    - should redirect after successful login

  ArtobjectPage
    #ArtobjectPage
      - should save $container
      - should call setupZoom
      - should call setupInfoButton
      - should call setupObjectData


  1 passing (2s)
  10 pending

[gulp] Finished 'test-develop' after 2.42 s
[gulp] Starting 'scripts'...
[gulp] Finished 'scripts' after 94 ms
[gulp] Starting 'test-develop'...


  Homepage
    Menu
      - should open without error
      - should close without error

  Login
    1) should be able to open CMS
    - should capture wrong username
    - should capture wrong password
    - should capture wrong username & password
    - should redirect after successful login

  ArtobjectPage
    #ArtobjectPage
      - should save $container
      - should call setupZoom
      - should call setupInfoButton
      - should call setupObjectData


  0 passing (2ms)
  10 pending
  1 failing

  1) Login should be able to open CMS:
     TypeError: undefined is not a function
      at sync ([project_dir]/node_modules/phantom-sync/node_modules/make-sync/lib/make-sync.js:132:10)
      at Context.<anonymous> ([project_dir]/test/e2e/login.js:13:5)
      at Test.Runnable.run ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:196:15)
      at Runner.runTest ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:374:10)
      at [project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:452:12
      at next ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:299:14)
      at [project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:309:7
      at next ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:247:23)
      at Object._onImmediate ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:330:15)



[gulp] Error in plugin 'gulp-mocha': 1 test failed.
[gulp] Finished 'test-develop' after 85 ms
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-30 11:18:58

结果是状态是邪恶的,幻影没有正确地清除它的缓存&当被要求的时候使用cookie。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23397752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档