如何让脚本在执行下一个量角器块之前等待给定的时间跨度
How to make script to wait for given time span before executing next it block in protractor
自动化测试用例,其中需要填写包含 5 个日期选择器和 30 个字段的表单。填写表格后需要调用一个 jar,它将从数据库中提取填写的数据并独立处理。
注意:jar 不会 return 将任何值返回给脚本,但是预计 jar 会在 1 分钟后在 UI 上更新进程状态。
已尝试在 beforeEach() 块中等待,但它导致整个脚本不必要的延迟,因为它在每个步骤之前引入了等待。
在这个论坛的一个帖子中,有人建议使用 Jasmine 2 的完成功能。但我不明白如何使用它。
示例代码:
describe("Test functionality of xyz", ()=>{
// few it block
it();
it();
//login to the UI
it("Login to application", ()=>{
utility.signIn(inputTestdata.Common.LoginPage.Username, inputTestdata.Common.LoginPage.Password);
});
// filling the form
it("Fill the form", ()=>{
utility.fill_form(dataSet);
}); // wanted to make protractor should wait for specifically 1 min before executing the next it block
it("Process the data", ()=>{
utility.runSimulator();
}); //wanted to wait here to for 2 min
it("Verify the result", ()=>{
//verifying the result
});
//some more it blocks
});
预期:一旦填充表单块被处理,那么只调用 jar 它块应该被执行。然后在执行验证结果步骤之前等待指定的时间。
但实际上,protractor 调用 form filling it block 并立即调用 jar it block。
正如您提到的,您不想在每个 'it' 之后等待,您将不得不在 'it' 块内等待。
另一种方法 是只对要等待的测试用例进行嵌套描述。并在 afterEach
方法
中添加等待
您可以使用"browser.sleep(time in milliseconds)"来暂停程序的执行。
describe("Test functionality of xyz", ()=>{
// few it block
it();
it();
//login to the UI
it("Login to application", ()=>{
utility.signIn(inputTestdata.Common.LoginPage.Username,
inputTestdata.Common.LoginPage.Password);
});
// filling the form
it("Fill the form", ()=>{
utility.fill_form(dataSet);
browser.sleep(2000);// here you can specify how long you want to wait at this
stage.
}); // wanted to make protractor should wait for specifically 1 min before executing
the next it block
it("Process the data", ()=>{
utility.runSimulator();
browser.sleep(2000); // here you can specify how long you want to wait at this
stage.
}); //wanted to wait here to for 2 min
it("Verify the result", ()=>{
//verifying the result
});
//some more it blocks
});
自动化测试用例,其中需要填写包含 5 个日期选择器和 30 个字段的表单。填写表格后需要调用一个 jar,它将从数据库中提取填写的数据并独立处理。
注意:jar 不会 return 将任何值返回给脚本,但是预计 jar 会在 1 分钟后在 UI 上更新进程状态。
已尝试在 beforeEach() 块中等待,但它导致整个脚本不必要的延迟,因为它在每个步骤之前引入了等待。 在这个论坛的一个帖子中,有人建议使用 Jasmine 2 的完成功能。但我不明白如何使用它。
示例代码:
describe("Test functionality of xyz", ()=>{
// few it block
it();
it();
//login to the UI
it("Login to application", ()=>{
utility.signIn(inputTestdata.Common.LoginPage.Username, inputTestdata.Common.LoginPage.Password);
});
// filling the form
it("Fill the form", ()=>{
utility.fill_form(dataSet);
}); // wanted to make protractor should wait for specifically 1 min before executing the next it block
it("Process the data", ()=>{
utility.runSimulator();
}); //wanted to wait here to for 2 min
it("Verify the result", ()=>{
//verifying the result
});
//some more it blocks
});
预期:一旦填充表单块被处理,那么只调用 jar 它块应该被执行。然后在执行验证结果步骤之前等待指定的时间。
但实际上,protractor 调用 form filling it block 并立即调用 jar it block。
正如您提到的,您不想在每个 'it' 之后等待,您将不得不在 'it' 块内等待。
另一种方法 是只对要等待的测试用例进行嵌套描述。并在 afterEach
方法
您可以使用"browser.sleep(time in milliseconds)"来暂停程序的执行。
describe("Test functionality of xyz", ()=>{
// few it block
it();
it();
//login to the UI
it("Login to application", ()=>{
utility.signIn(inputTestdata.Common.LoginPage.Username,
inputTestdata.Common.LoginPage.Password);
});
// filling the form
it("Fill the form", ()=>{
utility.fill_form(dataSet);
browser.sleep(2000);// here you can specify how long you want to wait at this
stage.
}); // wanted to make protractor should wait for specifically 1 min before executing
the next it block
it("Process the data", ()=>{
utility.runSimulator();
browser.sleep(2000); // here you can specify how long you want to wait at this
stage.
}); //wanted to wait here to for 2 min
it("Verify the result", ()=>{
//verifying the result
});
//some more it blocks
});