我定义了以下两种情况:
@high @basic
Scenario Outline: dropdown boxes exist
When I am on the Enernoc application
Then application is running
And <dropdown box> is present
Examples:
|dropdown box|
|templateSelection|
|templateDeliveryPathSelection|
|templateLocaleSelection|
@high
Scenario Outline: dropdown boxes appear and work as expected.
Given I am on the Enernoc application
Then application is running
When click <box>
Then <option> present in <box>
Examples:
|box| option|
|templateSelection| Apparent Energy |
|templateDeliveryPathSelection| EMAIL |
代码是:
Given(/^I am on the Enernoc application$/, function (callback) {
browser.ignoreSynchronization = true; // To be added if the application is non-angular
browser.driver.manage().window().maximize(); // To maximize the window
browser.get("http://d3qdeak1vbuqh4.cloudfront.net/template_definition").then(function () {
callback(); // To tell the cucumber that we are done with this step
});
});
Then(/^application is running$/, function (callback) {
browser.manage().timeouts().pageLoadTimeout(3000);
callback();
});
Then(/^(.*) is present$/, function (dropdown,callback) {
expect(element(by.id(dropdown)).isPresent());
callback();
});
When(/^click (.*)$/, function (dropdown,callback) {
EnernocHomePage.clickDropdown(dropdown,callback);
});
Then(/^(.*) present in (.*)$/, function (value,dropdown,callback) {
EnernocHomePage.checkDropdown(value,dropdown);
callback();
});
在另一个文件中,我有以下代码:
clickDropdown: function(dropdown,callback) {
element(by.id(dropdown)).click().then(function () {
callback();
});
},
checkDropdown: function (value,dropdown) {
expect(element(by.id(dropdown)).$('option:checked').getText()).eventually.equal(value);
},
我在通知此的输出中收到错误:
stale element reference: element is not attached to the page document
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.13.6 x86_64)
[12:15:17] E/launcher - StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.13.6 x86_64)
我该如何解决?似乎由于某种原因,在尝试访问该元素时未找到该元素。有想法吗?
根据详细输出,错误似乎在checkDropdown部分。