Phantomjs 在摩卡咖啡中使用幻影的问题

Phantomjs 在摩卡咖啡中使用幻影的问题,phantomjs,mocha.js,gulp,Phantomjs,Mocha.js,Gulp,我在尝试从Mocha测试套件向服务器发送PhantomJS调用时遇到问题 问题 我正在尝试使用PhantomJS对端点进行调用。我的第一个电话正在工作 但我有两个问题: 当前脚本第一次运行良好,但在观察某些文件时连续运行会导致测试失败。我能解决这个问题吗 这似乎不是进行这些测试的好方法,有更好的替代方法吗 设置: 作为观察者吞咽 大口喝摩卡以运行测试 幻影同步以执行一些end2end测试 摩卡测试文件(简化): Gulpfile(简化): 错误: ➜ [project_dir]git:

我在尝试从Mocha测试套件向服务器发送PhantomJS调用时遇到问题

问题 我正在尝试使用PhantomJS对端点进行调用。我的第一个电话正在工作

但我有两个问题:

  • 当前脚本第一次运行良好,但在观察某些文件时连续运行会导致测试失败。我能解决这个问题吗
  • 这似乎不是进行这些测试的好方法,有更好的替代方法吗
设置:
  • 作为观察者吞咽
  • 大口喝摩卡以运行测试
  • 幻影同步以执行一些end2end测试
摩卡测试文件(简化): Gulpfile(简化): 错误:
➜  [project_dir]git:(特性/幻影测试)✗ 咽表试验
[gulp]使用gulpfile[project_dir]/gulpfile.js
[gulp]开始“观察测试”。。。
[gulp]在26毫秒后完成“观察测试”
[gulp]正在启动“脚本”。。。
[gulp]530毫秒后完成“脚本”
[gulp]开始“测试开发”。。。
主页
菜单
-应该无误地打开
-应无误关闭
登录
✓ 应能打开CMS(2126毫秒)
-应该捕获错误的用户名
-应该捕获错误的密码
-应捕获错误的用户名和密码
-成功登录后应重定向
ArtobjectPage
#ArtobjectPage
-应该节省$container
-应该调用setupZoom
-应该调用setupInfoButton
-应该调用setupObjectData
1次通过(2秒)
10待定
[吞咽]在2.42秒后完成“测试开发”
[gulp]正在启动“脚本”。。。
[吞咽]94毫秒后完成“脚本”
[gulp]开始“测试开发”。。。
主页
菜单
-应该无误地打开
-应无误关闭
登录
1) 应该能够打开CMS
-应该捕获错误的用户名
-应该捕获错误的密码
-应捕获错误的用户名和密码
-成功登录后应重定向
ArtobjectPage
#ArtobjectPage
-应该节省$container
-应该调用setupZoom
-应该调用setupInfoButton
-应该调用setupObjectData
0通过(2ms)
10待定
1失败
1) 登录时应能够打开CMS:
TypeError:undefined不是函数
同步时([project_dir]/node_modules/phantom sync/node_modules/make sync/lib/make sync.js:132:10)
在上下文中。([project_dir]/test/e2e/login.js:13:5)
在Test.Runnable.run([project_dir]/node_modules/gulp mocha/node_modules/mocha/lib/Runnable.js:196:15)
在Runner.runTest([project_dir]/node_modules/gulp mocha/node_modules/mocha/lib/Runner.js:374:10)
在[project_dir]/node_modules/gulp mocha/node_modules/mocha/lib/runner.js:452:12
下一步([project_dir]/node_modules/gulp mocha/node_modules/mocha/lib/runner.js:299:14)
在[project_dir]/node_modules/gulp mocha/node_modules/mocha/lib/runner.js:309:7
下一步([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)
在processImmediate[as_immediateCallback](timers.js:330:15)
插件“gulp mocha”中出现[gulp]错误:1次测试失败。
[吞咽]85毫秒后完成“测试开发”

当被要求时,它的状态是邪恶的,幻影没有正确地清除它的缓存和cookies

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');

});
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']);
});
➜  [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