我有几个Protractor测试。当我单独运行每个测试(用xit替换它)时,每个测试工作正常。然而,当我全部运行时,它开始在第3位失败。
顺便说一句,我搜索并发现了几个同样的问题,但解决方案似乎不适用于我的情况。在我发现的其他人中,人们建议隐藏按钮(因此无法点击),或者显示“屏幕外”(因此用户必须先滚动以使按钮可见),等等。我绝对是确保该按钮在视口中是可见的,启用的和可见的。显示的错误如下:
1) e2e tests para admin/afps debería efectuar una búsqueda por código de afp = 2
- Failed: unknown error: Element is not clickable at point (882, 169).
Other element would receive the click: <img class="pg-loading-logo"
src="content/images/salfacorp3.jpg"> (Session info: chrome=53.0.2785.143)
(Driver info: chromedriver=2.24.417431
(9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 10.0.10586
x86_64)
其他错误类似。错误的相关部分是element is not clickable
,但是当我逐个运行测试时,错误不会出现。测试之间是否应该有某种pause
?还有其他想法吗?
我的conf.js文件如下:
exports.config = {
directConnect: true,
onPrepare: function () {
browser.manage().window().maximize();
var SpecReporter = require('jasmine-spec-reporter');
// add jasmine spec reporter
jasmine.getEnv().addReporter(new SpecReporter({ displayStacktrace: 'all' }));
},
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['../specs/salfa_spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
allowColors: true,
defaultTimeoutInterval: 300000,
print: function () { }
}
};
我的规格文件如下: '使用严格'; var AngularPage = require('../ pageObjects / afps.page.js');
describe("e2e tests para admin/afps", function () {
var page;// = require('../pageObjects/afps.page.js');
beforeEach(function () {
//browser.get("http://corporativo%5c79364193:Ariel2906@172.20.1.243/#/admin/afps");
page = new AngularPage();
});
afterEach(function () {
});
it("debería estar en el mantenedor de afps", function () {
expect(browser.getCurrentUrl()).toContain("/admin/afps");
});
it("debería efectuar una búsqueda por código de afp = 2", function () {
page.searchById("2");
expect(page.table.count()).toBeGreaterThan(0);
page.table.then(function (rows) {
var rowElements = rows[0].all(by.css("td"));
rowElements.then(function (cols) {
expect(cols[2].getText()).toEqual("HABITAT");
});
});
});
it("debería efectuar una búsqueda por nombre de afp = cuprum", function () {
page.searchByName("cuprum");
expect(page.table.count()).toBeGreaterThan(0);
page.table.then(function (rows) {
var rowElements = rows[0].all(by.css("td"));
rowElements.then(function (cols) {
expect(cols[2].getText()).toEqual("CUPRUM");
});
});
});
it("debería traer todas las AFPs", function () {
page.txtSearchCodigo.click();
//browser.driver.sleep(500);
page.btnSearch.click();
expect(page.table.count()).toBeGreaterThan(0);
});
it("debería seleccionar la primera AFP, abrir la ventana de edición y modificar el valor de 'cotización SIS'", function () {
page.txtSearchCodigo.click();
browser.driver.sleep(500);
page.btnSearchClick.then(function () {
page.table.get(0).click();
//expect(page.cotizacionSis.getAttribute('value')).toBe('3');
page.cotizacionSis.clear();
page.cotizacionSis.sendKeys(Math.random());
page.btnUpdate.click();
});
});
});
页面文件如下: 'use strict';
var AngularPage = function () {
browser.get('http://corporativo%5c79364193:Ariel2906@172.20.1.243/#/admin/afps');
};
AngularPage.prototype = Object.create({}, {
txtSearchCodigo: { get: function () { return element(by.id("txtSearchCodigo")); } },
txtSearchNombre: { get: function () { return element(by.id("txtSearchNombre")); } },
btnSearch: { get: function () { return element.all(by.css(".btn-primary")).first(); } },
btnUpdate: { get: function () { return element.all(by.css(".btn-primary")).last(); } },
table: { get: function () { return element.all(by.repeater("item in vm.afps")); } },
cotizacionSis: { get: function () { return element(by.id("txtEditCotizacionIsis")); } },
searchById: {
value: function (codigo) {
this.txtSearchCodigo.sendKeys(codigo);
this.btnSearch.click();
}
},
searchByName: {
value: function (name) {
this.txtSearchNombre.sendKeys(name);
this.btnSearch.click();
}
}
});
module.exports = AngularPage;
提前致谢
答案 0 :(得分:1)
我终于根据@alecxe recomendation解决了这个问题。我正在分享以防它对任何面临同样问题的人都有用。我将以下代码添加到beforeEach
块:
var EC = protractor.ExpectedConditions;
var elm = element.all(by.css('[ng-click="vm.searchMainEntities();"]')).first();
browser.wait(EC.elementToBeClickable(elm), 10000);
这允许应用程序在执行按钮单击之前完成加载。