【问题标题】:Reuse E2E testing scenario in multiple scenarios多场景复用端到端测试场景
【发布时间】:2013-10-22 14:32:18
【问题描述】:

我有一个应用程序,我想在该应用程序上实现多个 E2E 测试场景,每个场景都特定于应用程序的一个部分。问题是我的应用程序需要登录。我创建了一个登录场景,一切正常。为了描述不同的场景,我需要能够重用登录代码。我该怎么做?

describe('login page flow', function () {
    it('should open the login page', function () {
        browser().navigateTo('/#/login');
        sleep(1);
        expect(browser().window().hash()).toBe('/login');
    });

    it('should have login elements', function () {
        expect(element('#username').count()).toBe(1);
        expect(element('#password').count()).toBe(1);
    });           

    it('should be able to login successfully', function () {
        input('ui.username').enter('user');
        input('ui.password').enter('pass');

        element('#signin').click();
        sleep(1);
        expect(browser().window().hash()).toBe('/welcome/');
    });
});

我唯一能想到的就是在 beforeEach 中写这个,但我认为这不是一个非常干净的解决方案。有什么想法吗?

【问题讨论】:

    标签: angularjs karma-runner angularjs-e2e angular-scenario


    【解决方案1】:

    我认为beforeEach() 是一个完美的地方。

    此外,您还可以创建自己的页面片段,例如

    function homePage()
    {
        return {
            loginForm: {
                email: input("credentials.email"),
                password: input("credentials.password"),
                login: element("#login-form button[type=submit]")
            }
        };
    }
    

    并像这样重用它:

          describe("and user logs in", function ()
                {
                    describe("successfully", function ()
                    {
                        beforeEach(function ()
                        {                        
                            homePage().loginForm.email.enter("username");
                            homePage().loginForm.password.enter("password");
                            homePage().loginForm.login().click();
                        });
          ...
    

    Here你可以阅读关于页面片段的想法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多