javascript - codeceptJS/webdriverIO 使用抓取命令退出脚本

标签 javascript selenium testing webdriver-io codeceptjs

我是 codeceptJS 的新手,但我只能说它不能与 yield 一起使用。

'use strict';
Feature('Testing Begins');
Before((I) => {
  I.resizeWindow(1500, 1000);
  I.amOnPage('http://absolutenet.com');
});

Scenario('ANI testing', function*(I){
  I.waitForText('bring your site to life');
  I.amOnPage('http://www.absolutenet.com/');
  let title = yield I.grabTitle();
  console.info(title);
  I.see('bogus text that is not there');
});

我已经尝试了几个抓取命令以及 executeScript。我知道这些命令正在运行,因为出于某种原因,一两行在 yield 之后执行,所以我可以输出我正在分配的变量。但是,我永远无法使用它,因为浏览器关闭并且脚本终止。更糟糕的是,我可以放入一个明显无效的测试(I.see('some bogus non existent text');)并且场景成功退出!

上面是实时的,所以你可以执行它来查看问题。如果重要,请使用 Linux 和 FireFox 进行测试。

任何人都可以给我一个如何使用 yield 并继续测试的例子吗?

更新:开发人员说这是一个错误,很快就会修复。

最佳答案

我在 CodeceptJS 自述文件中看到以下内容:

With CodeceptJS your scenario-driven functional and acceptance tests will be as simple and clean as they can be. You don't need to worry about asynchronous nature of NodeJS or about various APIs of Selenium, PhantomJS, Protractor, etc, as CodeceptJS unifies them and makes them work as they were synchronous.

因此您不需要 yield 来运行测试。 CodeceptJS 是 WebdriverIO 的包装器,它为您处理这些异步任务。您应该能够执行以下操作:

Scenario('ANI testing', function*(I){
  I.waitForText('bring your site to life');
  I.amOnPage('http://www.absolutenet.com/');
  I.seeInTitle('my page title');
});

http://codecept.io/basics/

尽管如此,为了更彻底地回答您的问题,codeceptJS 有一个使用生成器的好例子:

Scenario('use page title', function*(I) {
  // ...
  var password = yield I.grabTextFrom('#password');
  I.fillField('password', password);
});

http://codecept.io/acceptance/

关于javascript - codeceptJS/webdriverIO 使用抓取命令退出脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34708828/

相关文章:

php - 在网站上调整图像大小以提高效率。

javascript 扩展预构建原型(prototype)性能

javascript - Grunt 读取模板中的替换文件

python - Selenium/Python - 如何按随机选择的像素滚动?

java - JUnit交换两个变量的测试方法

Javascript - 如何访问事件函数中的对象属性?

java - Selenium 测试未按预期运行

c# - 如果我已经拥有 FindsBy 的元素,如何将 Wait.Until 与 Selenium 一起使用

jquery - Django django.test.client jquery 就绪

java - 模拟具有通用(?扩展集合)返回类型的方法时遇到问题