关于如何使用 angularjs 运行 E2E 测试有一个基本文档:http://docs.angularjs.org/guide/dev_guide.e2e-testing
在我的项目中,我将 angularjs 用于多页面 Web 应用程序。当我单击页面中的链接时,它将打开一个全新的页面。还有一个登录页面,我必须在测试前登录。
我将在测试中执行以下操作:
- 访问登录页面
- 输入用户名和密码
- 提交表格
- 访问我要测试的真实页面
- 测试页面
但是我没有在该文档中找到有关 redirect
的任何信息。我该怎么办?
最佳答案
不用担心考试准备。整个事情发生在一个可以独立存在的 iframe 中。
因此,如果您单击发生重定向的链接,它无论如何都会重定向。
请注意,在带有 Angular 的 e2e 测试中没有特殊的设置部分,这意味着一切都是测试,这意味着您的设置阶段也是一个测试。
您可以做的是正确准备设置的第一个测试:
describe('My Whole Test Suite', function () {
it('Should be able to access page', function () {
browser().navigateTo('/whereSetupOccurs');
input('#username').enter('john');
input('#password').enter('psswrd');
// when you click redirection happen anyway
element('#submit').click();
//check that redirection was made properly
expect(browser().location().url()).toContain("/whereIWantedToGoForMyTests");
});
it('Should be able to ...', function () {
// the real tests you wanted here
});
});
关于testing - 使用angularjs编写测试时如何处理重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15245822/