【发布时间】:2017-10-14 01:07:12
【问题描述】:
我正在使用量角器,当我在 browserstack 上运行测试时,我收到以下错误
StaleElementReferenceError: stale element reference: element is not attached to the page document
或者取决于我在beforeAll中所做的事情
Error: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.cssSelector ...
这里是导致错误的代码sn-p:
describe('...', () => {
it('...', () => {
expect(element.all(by.css(...)).count()).toBe(9);
expect(element.all(by.css('.items').get(0).isDisplayed()).toBeTruthy();
});
}
describe('', () => {
beforeAll((/* done */) => {
element(by.css('.go-home').click(); // .then(done);
//browser.driver.get('/');//.then(done);
});
...
});
由于某种原因,beforeAll 继续并更改了 url,而之前的 it 仍在运行(我猜是基于错误)。
现在,我设法破解了这个方法。我已将done 添加到it,如下所示
describe('...', () => {
it('...', (done) => {
expect(element.all(by.css(...).count()).toBe(9);
element.all(by.css(...)).get(0).isDisplayed().then((state) => {
expect(state).toBeTruthy();
done();
});
});
}
describe('', () => {
beforeAll(() => {
element(by.css('.go-home').click(); // works
//browser.driver.get('/'); // still fails
});
...
});
现在可以了。但是,如果我使用browser.driver.get('/'),它会再次失败。
通常我不必将done 添加到我的its 所以我的问题是:这里出了什么问题?任何帮助将不胜感激
更新:protractor.config.js:
exports.config = {
chromeDriver: '../node_modules/protra...medriver_2.25',
seleniumServerJar: '../node_...-server-standalone-2.53.1.jar',
exclude: [],
specs: [
'../test/e2e/**/*.js'
],
multiCapabilities: [
{
build: 'test',
project: 'ABC',
browserName: 'firefox',
//browserName: 'chrome',
os: 'Windows',
os_version: '10',
directConnect: true
}],
debug: true,
maxSessions: 1,
framework: 'jasmine2',
onPrepare: function () {
browser.driver.manage().window().setSize(1024, 768);
// Register helpers
require('../test/framework/jasmine2');
var disableNgAnimate = function () {
angular
.module('disableNgAnimate', [])
.run(['$animate', function ($animate) {
$animate.enabled(false);
}]);
};
var disableCssAnimate = function () {
angular
.module('disableCssAnimate', [])
.run(function () {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '* {' +
'-webkit-transition: none !important;' +
'-moz-transition: none !important' +
'-o-transition: none !important' +
'-ms-transition: none !important' +
'transition: none !important' +
'}';
document.getElementsByTagName('head')[0].appendChild(style);
});
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
browser.addMockModule('disableCssAnimate', disableCssAnimate);
}
};
【问题讨论】:
标签: selenium-webdriver protractor browserstack