node.js - Selenium Node + Sauce 实验室测试 : Cannot Finish a Task

标签 node.js selenium mocha.js saucelabs

我正在使用 Sauce Labs 来运行我的 Selenium 测试脚本,并以 Mocha 作为测试框架。脚本运行完美,但问题是,作业没有完成 - 似乎 driver.quit() 被忽略,并且在 90 秒后提示我超时错误。

代码如下:

const { driver } = require('./config');
const { By, until } = require('selenium-webdriver');

describe('Integration test', function () {
  this.timeout(20000);

  it('can login as test user', function () {
    driver.get('https://www.example.com');
    driver.wait(until.elementIsNotVisible(driver.findElement(By.id('vale'))), 8000, 'Vale cannot fade');
    driver.findElement(By.name('email')).sendKeys('test_user@test.com');
    driver.findElement(By.name('password')).sendKeys('password');
    return driver.findElement(By.id('authFormSubmitButton')).click();
  });

  after(() => {
    console.log('Quiting driver');
    // This does not work!
    driver.quit();
  });
});

在配置中,构建了一个驱动程序并将其连接到远程服务器。

运行此程序时,在控制台中我可以看到测试通过和退出驱动程序消息,但在 Sauce labs 仪表板中,任务只是一直等待,直到超时。

顺便说一句,我使用本地 chromdriver 测试了上述代码,一切正常 - driver 在任务完成后立即退出。

任何帮助或想法表示赞赏。

最佳答案

driver.quit()之前需要返回

Instead of calling done(), Mocha accepts a promise as return value. If a test returns a promise, Mocha understands that it’s asynchronous, and waits for the Promise to be resolved before passing to the next test.

这个article很有值(value)。

关于node.js - Selenium Node + Sauce 实验室测试 : Cannot Finish a Task,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45318498/

相关文章:

javascript - 将字符串转换为有效的 json

javascript - 如何与公司 LDAP 服务器成功绑定(bind)

react-native - 获取 ReferenceError : fetch is not defined when running react native tests in mocha

javascript - Mocha如何将 Node Controller 功能公开给测试脚本

unit-testing - 没有关于 singlerun 的 Karma 报告 = false

angularjs - 从nodejs将内容添加到mongodb对象数组

node.js - Webhook : Request body is missing data 提供的 Google Cloud HTTP 功能

python - Selenium 网络驱动程序 python : Element is not clickable at point

selenium - RemoteWebDriver SetFileDetector 给出异常 org.openqa.selenium.UnsupportedCommandException :

java流比较列表与局部变量