测试用例执行失败,它在命令行中抛出任何错误堆栈跟踪

test case execution is getting failed and it is throwing any error stack trace in command line

我使用 Protractor-cucumber 框架创建了一个测试用例,并使用 Grunt 来执行该测试用例。但是,在执行时它失败了,并且它没有提供任何错误堆栈跟踪来了解它失败的原因。

我搜索了 Google 并查看了其他 Stack Overflow 解决方案,但我没有找到解决方案。

配置文件

exports.config = {

  //seleniumAddress: 'http://localhost:4444/wd/hub',
  getPageTimeout: 60000,
  allScriptsTimeout: 500000,
  directConnect:true,

  framework: 'custom',
  // path relative to the current config file
  frameworkPath: require.resolve('C:\...\node_modules\protractor-cucumber-framework'),
  capabilities: {
    'browserName': 'chrome'
  },
  ignoreUncaughtExceptions:true,
  // Spec patterns are relative to this directory.
  specs: [
    './learnFramework/utility/test.feature'
  ],

  cucumberOpts: {
    require: './learnFramework/TestCases/spec.js',
    tags: false,
    profile: false,
    'no-source': true
  },
  onPrepare: function () {
    browser.ignoreSynchronization=true;
    browser.manage().window().maximize();
  }
};

规格文件

module.exports=function(){
    this.Given(/^Open the browser and Load the URL$/,async function(){
        browser.get("https://google.com");
    });

    this.When(/^User entered the text in the search box$/,async function(){
        browser.sleep(5000);
        console.log(await browser.getTitle());
        await element(By.name("q")).sendKeys("facebook");
        browser.sleep(3000);
    });

    this.Then(/^click on search$/,async function(){
        browser.action().sendKeys(protractor.Key.ENTER).perform();
        browser.sleep(5000);
    });
}

错误日志

Running "jshint:files" (jshint) task
>> 1 file lint free.
>
Running "protractor:singlerun" (protractor) task
[00:08:29] I/launcher - Running 1 instances of WebDriver
[00:08:29] I/direct - Using ChromeDriver directly...
>
DevTools listening on ws://127.0.0.1:50146/devtools/browser/5c09d68c-f3ff-43b2-b645-0b5c098c41d9
Feature: Title of your feature
>
    I want to use this template for my feature file
>
  Scenario: Title of your scenario
  ✓ Given Open the browser and Load the URL
  ✖ When User entered the text in the search box
  - And click on search
>
Failures:
>
[00:09:03] I/launcher - 0 instance(s) of WebDriver still running
[00:09:03] I/launcher - chrome #01 failed 1 test(s)
[00:09:03] I/launcher - overall: 1 failed spec(s)
[00:09:03] E/launcher - Process exited with error code 1
>>>
>>> Test failed but keep the grunt process alive.
>
Done.

如果您观察错误日志 "When" 步骤失败但命令行中没有错误堆栈跟踪来查找失败原因。

我的期望是它应该显示失败原因的错误堆栈跟踪。

您需要在浏览器操作上使用 await,否则它会同步执行操作。

例如 等待 browser.get("https://google.com");