gpt4 book ai didi

javascript - Grunt、Cucumber、Protractor 测试意外失败

转载 作者:行者123 更新时间:2023-11-30 09:54:01 24 4
gpt4 key购买 nike

我有一个像这样的特征文件:

Feature: Test feature

Scenario: Step 1
Given I go to "test-process/#/step-1"
When I have checked the checkbox
Then the button is enabled

我的steps.js文件如下:

'use strict';

var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);

module.exports = function () {

this.Given(/^I go to "([^"]*)"$/, function (path, callback) {
browser.get(path);

callback();
});

this.When(/^When I have checked the checkbox$/, function (callback) {
var checkbox = element(by.id('check'));
checkbox.click();

callback();
});

this.Then(/^the button is enabled$/, function (callback) {
var button = element(by.id('next'));

chai.expect(button.isEnabled()).to.eventually.equal(true).and.notify(callback);
});

};

我也有这样的配置:

exports.config = {
framework: 'custom',
frameworkPath: '../../../../node_modules/protractor-cucumber-framework',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['features/*.feature'],
baseUrl: 'http://localhost:60625/',
cucumberOpts: {
require: 'steps/*.steps.js',
format: 'pretty'
}
};

在实际页面中,checkbox和button都有指定的ID属性。

当我运行测试时,前两步通过,但最后一步失败,原因:

ElementNotVisibleError: element not visible

但是,我看到 Chrome 启动了,而且页面上的复选框和按钮都可见!最糟糕的是,当我第一次编写并运行测试时,所有步骤都通过了。现在,它每次都失败,实际上什么都没有改变。

有什么想法吗?

编辑

我尝试按照建议将回调调用包装在 then() 中。这稍微改变了输出,但没有解决问题。现在,第二步失败,最后一步被跳过。之前是第二步通过,最后一步失败。

我还尝试按照 browser.driver.manage().window().maximize(); 的建议使窗口全屏显示

我还尝试使用 this.setDefaultTimeout(10000); 添加更长的超时时间,但这似乎没有任何区别。

根据要求,这是控制台输出中的堆栈跟踪:

Running "protractor:all" (protractor) task Using the selenium server at http://localhost:4444/wd/hub [launcher] Running 1 instances of WebDriver

Scenario: Step 1
Given I go to "test-process/#/step-1"
When I have checked the checkbox

 ElementNotVisibleError: element not visible
(Session info: chrome=47.0.2526.111)
(Driver info: chromedriver=2.20.353145
(343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) > (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'BDTUK79DW', ip: '172.23.83.166', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_71'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\DanW\AppData\Local\Temp\scoped_dir14556_23663}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=47.0.2526.111, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 8591f8db6eea372305d94c1aea52eca0
at new bot.Error (fakepath\node_modules\grunt-protractor-runner\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
at Object.bot.response.checkResponse (fakepath\node_modules\grunt-protractor-runner\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
at fakepath\node_modules\grunt-protractor-runner\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (fakepath/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (fakepath/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (fakepath/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
at goog.async.run.processWorkQueue (fakepath\node_modules\grunt-protractor-runner\node_modules\selenium-webdriver\lib\goog\async\run.js:124:15)
at process._tickCallback (node.js:405:9)
Error
at [object Object].ElementArrayFinder.applyAction_ (fakepath\node_modules\grunt-protractor-runner\node_modules\protractor\lib\element.js:382:21)
at [object Object].ElementArrayFinder.(anonymous function) [as click] (fakepath\node_modules\grunt-protractor-runner\node_modules\protractor\lib\element.js:78:17)
at [object Object].ElementFinder.(anonymous function) [as click] (fakepath\node_modules\grunt-protractor-runner\node_modules\protractor\lib\element.js:711:7)
at World.<anonymous> (fakepath\Static\test\e2e\steps\test.steps.js:21:18)

Then I am allowed to proceed to the next step

Failing scenarios: fakepath\test\e2e\features\test.feature:3 # Scenario: Acknowledge warnings

1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m02.814s [launcher] 0 instance(s) of WebDriver still running [launcher] chrome #1 failed 1 test(s) [launcher] overall: 1 failed spec(s) [launcher] Process exited with error code 1

Test failed but keep the grunt process alive.

Done, without errors.

这太疯狂了,因为如果我手动访问该页面,该元素就会以预期的 ID 出现。当测试运行并且浏览器启动时,我可以在浏览器再次关闭之前在页面上看到该元素!

如果它能准确指定它认为哪个元素不可见,那将会有所帮助

最佳答案

我发现,如果您不在步骤中包装回调,事情似乎就不会按顺序进行。我会尝试如下重写您的步骤:

this.Given(/^I go to "([^"]*)"$/, function (path, callback) {
browser.get(path).then(function(){callback();});
});

this.When(/^When I have checked the checkbox$/, function (callback) {
var checkbox = element(by.id('check'));
checkbox.click().then(function(){callback();});
});

this.Then(/^the button is enabled$/, function (callback) {
var button = element(by.id('next'));
chai.expect(button.isEnabled()).to.eventually.equal(true)
.and.notify(callback);
});

这样,在 Protractor 完成它需要做的事情之前,回调不会被执行。

关于javascript - Grunt、Cucumber、Protractor 测试意外失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34944946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com