testing - 使用angularjs编写测试时如何处理重定向?

标签 testing redirect angularjs

关于如何使用 angularjs 运行 E2E 测试有一个基本文档:http://docs.angularjs.org/guide/dev_guide.e2e-testing

在我的项目中,我将 angularjs 用于多页面 Web 应用程序。当我单击页面中的链接时,它将打开一个全新的页面。还有一个登录页面,我必须在测试前登录。

我将在测试中执行以下操作:

  1. 访问登录页面
  2. 输入用户名和密码
  3. 提交表格
  4. 访问我要测试的真实页面
  5. 测试页面

但是我没有在该文档中找到有关 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/

相关文章:

ruby-on-rails - 开始在 Rails 中进行测试

python - 相对导入和单元测试

IE 10.0 的 PHP UserAgent 不匹配

javascript - Angular 在 orderBy 之后获取中间索引

ios - 分享 iOS development.provision 文件

amazon-web-services - 基于 Geo 的域重定向 - AWS

.htaccess - htaccess 重定向并保留变量

javascript - 如何在 AngularJS 中的后续请求中正确存储本地数组

angularjs - 如何在 <script type ="text/ng-template"...> 中获取 HTML 以在编辑器中正确显示?

node.js - 是否可以测试 Jest 测试?