检查量角器黄瓜框架中是否存在元素
Checking if an element is present in protractor-cucumber-framework
我有一个 e2e 测试包,带有 protractor-cucumber-framework 和 Chai 用于断言。
我有一个包含数据 table 的特征文件,如下所示。
Scenario: Menu Validation
Given I am on the home page
When I do Hover over the menu item I should have the menu dropdown
|menu1 |
|menu2 |
|menu3 |
我的步骤定义如下。
When(/^I do Hover over the menu item I should have the menu dropdown/, (dataTable) => {
let rootMenu : Array<string> = Array.from( dataTable.rawTable )
rootMenu.forEach((ele) => {
console.log(ele[0]);
element(by.id(ele[0])).isPresent().then(function(present) {
expect(present).to.equal(true);
});
});
});
即使菜单元素 ID 不存在,此测试步骤也永远不会失败,我进一步检查了 expect(present).to.equal(true);
永远不会执行。我不确定我错过了什么。
你能试试这个吗
When(/^I do Hover over the menu item I should have the menu dropdown/, async (dataTable) => {
let rootMenu : Array<string> = Array.from( dataTable.rawTable )
for (let i; i < rootMenu.length; i++) {
let ele = = rootMenu[i];
console.log(ele[0]);
expect(await element(by.id(ele[0])).isPresent()).to.equal(true);
}
})
我有一个 e2e 测试包,带有 protractor-cucumber-framework 和 Chai 用于断言。
我有一个包含数据 table 的特征文件,如下所示。
Scenario: Menu Validation
Given I am on the home page
When I do Hover over the menu item I should have the menu dropdown
|menu1 |
|menu2 |
|menu3 |
我的步骤定义如下。
When(/^I do Hover over the menu item I should have the menu dropdown/, (dataTable) => {
let rootMenu : Array<string> = Array.from( dataTable.rawTable )
rootMenu.forEach((ele) => {
console.log(ele[0]);
element(by.id(ele[0])).isPresent().then(function(present) {
expect(present).to.equal(true);
});
});
});
即使菜单元素 ID 不存在,此测试步骤也永远不会失败,我进一步检查了 expect(present).to.equal(true);
永远不会执行。我不确定我错过了什么。
你能试试这个吗
When(/^I do Hover over the menu item I should have the menu dropdown/, async (dataTable) => {
let rootMenu : Array<string> = Array.from( dataTable.rawTable )
for (let i; i < rootMenu.length; i++) {
let ele = = rootMenu[i];
console.log(ele[0]);
expect(await element(by.id(ele[0])).isPresent()).to.equal(true);
}
})