【发布时间】:2019-05-27 20:45:02
【问题描述】:
我们需要在登录网页后使用 for 循环,并在页面的 for 块内执行多个测试。我理想的测试场景应该像下面的sn-p。我们有一个表格,每一行都有按钮,我们将导航到该特定按钮的下一页并验证数据。目前我们将所有期望和断言都插入到一个 IT 块中,但这不是一个好的解决方案。我们需要在不同的 IT 块中拆分测试部分。
require('..\\waitAbsent.js');
require("../node_modules/jasmine-expect/index.js");
var EC = protractor.ExpectedConditions;
describe('Student Enrollment Page Content Validation', function() {
beforeAll(function () {
browser.driver.manage().window().maximize();
browser.get(globalVariables.loginMain);
globalVariables.Email_Input_box.sendKeys(globalVariables.Demo_User);
globalVariables.Password_Input_Box.sendKeys(globalVariables.Demo_PWD);
globalVariables.Submit_Button.click();
browser.wait(EC.invisibilityOf(globalVariables.Submit_Button), 25000, 'submit button is not disappearing yet');
});
async function Row_Numbers() {
const RowCount = (globalVariables.tableData_Dashboard.all(by.tagName("tr")).count()).then(function(RC){
return RC;
});
}
for (var i = 1; i<Row_Numbers(); i++){
function tableData(n){
var row_1 = globalVariables.tableData_Dashboard.all(by.tagName("tr")).get(n);
// get cell values
var cells = row_1.all(by.tagName("td"));
it ('should return the data fo the first cell', function(){
var Student_ID = cells.get(0).getText().then(function (SID) {
console.log(SID);
return SID;
});
expect(Student_ID.toEqual('Something'));
});
it ("should show the button in this row", async function(){
const Button = globalVariables['Edit_Button_' + n];
// console.log(Button)
expect(await Button.isDisplayed());
Button.click();
// do some thing
});
}tableData(i)
}
});
当我们使用这个脚本运行测试时,我们得到以下错误:
E/launcher - 等待 Protractor 与页面同步时出错:“angularJS 可测试性和 angular 可测试性都未定义。这可能是因为这是一个非 Angular 页面,也可能是因为您的测试涉及 s 客户端导航,这可能会干扰 Protractor 的引导。详情见https://github.com/angular/protractor/issues/2643”
如何使用 for 循环来实现我们的目标?
【问题讨论】:
标签: javascript jasmine protractor