Dalekjs:打开浏览器窗口

时间:2014-07-17 12:27:29

标签: dalekjs

我是使用Dalekjs的新手,我正在尝试打开浏览器,运行一些测试,并且(至关重要的是)想要打开浏览器窗口。

有没有办法在Dalekjs这样做?默认情况似乎是浏览器自动关闭。

module.exports = {
'Page title is correct': function (test) {
  test
    .open('http://google.com')
    .assert.title().is('Google', 'It has title')
    .done();
}
};

我使用以下命令在控制台中运行:

dalek my-test.js -b chrome

1 个答案:

答案 0 :(得分:1)

运行done函数后,它会运行一个带有测试结果的promise并完成测试运行 - 即关闭所有正在运行的浏览器。

如果要阻止测试并打开窗口,则需要使用wait睡眠一段时间或waitFor等待给定条件是在处理下一步之前遇到了。

我建议您按照以下方式执行操作:

module.exports = {
  'Page title is correct': function (test) {
    test
      .open('http://google.com')
      .assert.title().is('Google', 'It has title')
      .execute(function(){
        // Save any value from current browser context in global variable for later use
        var foo = window.document.getElementById(...).value;
        this.data('foo', foo);
      })
      .waitFor(function (aCheck) {
        // Access your second window from here and fetch dependency value
        var foo = test.data('foo');

        // Do something with foo...

        return window.myThing === aCheck;
      }, ['arg1', 'arg2'], 10000)
      .done();
  }
};
相关问题