使用Mocha运行测试时,异步无法按预期工作

时间:2019-09-18 02:11:18

标签: javascript nightwatch.js

当我使用Mocha运行测试时,它没有按预期工作。但是它可以使用守夜人默认运行器。

样品测试 用mocha编写的测试用例

describe('hello world', () => {
  it('001', async (browser) => {
    browser.url('https://github.com');
    const result = await browser.windowHandles();
    console.log(result);
  });
});

使用守夜人默认跑步者编写的测试用例

module.exports = {
  'demo test async': async function(browser) {
    // get the available window handles
    const result = await browser.windowHandles();
    console.log('value', result);
  }
};

用于摩卡测试的测试输出:

NightwatchAPI {   功能:    {acceptInsecureCerts:否,      acceptSslCerts:否,      applicationCacheEnabled:否,      browserConnectionEnabled:false,      browserName:“ chrome”,      铬:       {chromedriverVersion:'2.38.552518(183d19265345f54ce39cbb94cf81ba5f15905011)',         userDataDir:          '/var/folders/cz/qj89bw6s4vx13n5np1d9xqkr0000gp/T/.org.chromium.Chromium.7Ekigy'},      cssSelectorsEnabled:true,      databaseEnabled:否,      handlesAlerts:正确,      hasTouchScreen:否,      javascriptEnabled:是的,      locationContextEnabled:是,      mobileEmulationEnabled:否,      nativeEvents:true,      networkConnectionEnabled:否,      pageLoadStrategy:'正常',      平台:“ Mac OS X”,      可旋转:假,      setWindowRect:是的,      takeHeapSnapshot:是的,      takeScreenshot:是的,      SurpriseAlertBehaviour:'',      版本:“ 77.0.3865.75”,      webStorageEnabled:是, .....

测试默认跑步者的输出:

value { sessionId: 'f8f61ccf22a0a6e2209a249d6d93160c',  
  status: 0,  
  value: [ 'CDwindow-C530FDF4F296268C545B23C7A1402D84' ] }  

nightwatch-版本1.2.2
节点--version

0 个答案:

没有答案