javascript - Protractor:Browser.wait() Timeout 在 Jasmine defaultTimeoutInterval 上超时

标签 javascript jasmine protractor

我目前正在尝试使用 browser.wait() 确保负面测试。下面的测试打开页面,执行搜索,清除搜索结果并等待搜索结果可见。下面的测试应该在 5 秒后超时,因为元素在被清除后将永远不可见,但使用 conf.js 文件中设置的 defaultTimeoutInterval(30 秒)会超时。我是否需要更改 conf.js 设置以使用 browser.wait() 语句中指定的超时间隔?

我正在运行 Protractor 版本 5.3.2

conf.js 文件中设置的默认超时间隔

// Options to be passed to Jasmine.
jasmineNodeOpts: {
    showColors: true, // Use colors in the command line report. 
    defaultTimeoutInterval: 30000 // Default time to wait in ms before a test 
fails.
},

我在spec.js文件中的测试

//require page object, actions
var advisorUI = require('../pages/advisor_ui_po.js');
var advisorUIActions = require('../actions/advisor_ui_pa.js');
var advisorUISearchResults = require('../pages/search_results1_po.js');
var advisorUISearchResults2 = require('../pages/search_results2_po.js');
var testExecActions = require('../actions/test_exec_a.js');

//Create instance of the Advisor UI page object
beforeEach(async function () {
 await advisorUI.get();
});

describe('Search By Email', function() {
    it('should display search results', async function() {
        //Execute the Search by email
        var email = browser.params.smoketestdata.email;
        advisorUIActions.searchByEmail(email);
        advisorUIActions.clearSearch();
        var EC = protractor.ExpectedConditions;browser.wait(EC.visibilityOf(advisorUISearchResults.getShowingResultsForLabel(), 5000, 'Wait Timeout is working!')); 
    });
});

这是输出:

λ protractor conf.js --suite regression
Report destination:   screenshots\my-report.html
(node:19008) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use 
os.tmpdir() instead.
[12:04:55] I/launcher - Running 1 instances of WebDriver
[12:04:55] I/hosted - Using the selenium server at 
http://localhost:4444/wd/hub
Started
FA Jasmine spec timed out. Resetting the WebDriver Control Flow.
A Jasmine spec timed out. Resetting the WebDriver Control Flow.

Failures:
1) Search By Email should display search results
  Message:
    Error: Timeout - Async callback was not invoked within timeout specified 
by jasmine.DEFAULT_TIMEOUT_INTERVAL.
  Stack:
    Error: Timeout - Async callback was not invoked within timeout specified 
by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at ontimeout (timers.js:498:11)
        at tryOnTimeout (timers.js:323:5)
        at Timer.listOnTimeout (timers.js:290:5)
  Message:
    Error: Timeout - Async callback was not invoked within timeout specified 
by jasmine.DEFAULT_TIMEOUT_INTERVAL.
  Stack:
    Error: Timeout - Async callback was not invoked within timeout specified 
by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at ontimeout (timers.js:498:11)
        at tryOnTimeout (timers.js:323:5)
        at Timer.listOnTimeout (timers.js:290:5)

1 spec, 1 failure
Finished in 61.941 seconds

[12:06:01] I/launcher - 0 instance(s) of WebDriver still running
[12:06:01] I/launcher - chrome #01 failed 1 test(s)
[12:06:01] I/launcher - overall: 1 failed spec(s)
Closing report
[12:06:01] E/launcher - Process exited with error code 1

最佳答案

尝试在每个测试中返回回调。请做一些断言并返回回调,以便您的测试继续进行。因为您从未返回回调,所以 Jasmine 认为您在等待某些东西。

一旦完成测试中的所有步骤(即 it() block 内的步骤),请确保返回回调。

关于javascript - Protractor:Browser.wait() Timeout 在 Jasmine defaultTimeoutInterval 上超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51773004/

相关文章:

angularjs - 如何在 Jasmine 和 Angular 中模拟 $http 超时

json - 使用 cucumberopts 格式作为 Json 时,浏览器在 Protractor cucumber 测试中立即关闭

javascript - 检索页面加载 Strope js 上的消息

javascript - 使用 Protractor 获取同一元素的不同值的数组

javascript - 关于启动 JS 或 JQuery 进行文件处理的建议

javascript - Jasmine - 如何在没有实现的情况下监视函数

javascript - 失败: Cannot read property 'getWebElements' of undefined

protractor - 执行 Protractor 测试时从命令行传递参数

javascript - 在javascript变量中获取php mysql结果

javascript - Firefox 中的共享 worker