量角器:Browser.wait()超时在Jasmine defaultTimeoutInterval上超时

时间:2018-08-09 17:40:46

标签: 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

1 个答案:

答案 0 :(得分:1)

尝试在每个测试中返回回调。请执行一些断言并返回回调,以便测试继续进行。由于您从未返回过回调,因此Jasmine认为您正在等待。

请确保在it()块中完成测试(即)中的所有步骤后,返回回调。