使用量角器进行端到端测试时使用数据对象 [英] Using Data Objects while E2E testing with Protractor

查看:113
本文介绍了使用量角器进行端到端测试时使用数据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我和一位同事正在讨论为e2e测试创建数据对象.根据我对数据对象的了解,它们用于解耦测试套件.例如,我的第一个测试套件是创建一个帐户并测试字段是否有效,第二个测试套件将登录到该帐户并进行自己的测试.有人告诉我最好使用数据对象(而不是页面对象),以防万一第一个测试套件在创建帐户时失败.这样,我们可以使用第二个测试套件中的数据对象来创建一个仅用于测试登录的新用户.我的问题是,如果我的第一个测试套件无法创建帐户,为什么要在我的第二个测试套件中创建帐户通过?无论我在第一个测试套件中遇到什么错误,我都应该也进入第二个测试套件中吗?我还有更多关于数据对象以及如何使用它们的问题.我想知道是否有人可以解释数据对象以及如何使用/编写数据对象.

So a coworker and I were discussing making a data object for our e2e tests. From my understanding about data objects they are used for decoupling your test suites. For example, my first test suite is to create an account and to test if the fields are valid and the second test suite logins into the account and does its own tests. I am told it is good to use data objects (not a page object) just incase the first test suite fails when making an account. That way we can use the data object in the second test suite to create a new user just for testing login. My problem is that if my first test suite fails at making an account, why would creating an account in my second test suite pass? Whatever error I get in the First test suite, I should also get in the second test suite right? I have many more questions about data objects and how to use them. I was wondering if someone could explain data objects and how to use/write one.

    /***
    Test Data Object
***/

var Member = function() {
    var unixTime = String(Math.round(new Date()/1000));
    this.username = "TestAccount" + unixTime;
    this.email = this.username + "@gmail.com";
    this.password = "password";
};

Member.prototype.create = function () {
    var signup = new signupPage.Signup();
    signup.getPage();
    signup.memberAs(this.username, this.email, this.password);
};

Member.prototype.login = function () {
    var login = new loginPage.Login();
    login.getPage();
    login.memberAs(this.username, this.password);
};

Member.prototype.logout = function () {
    // k.logoutMember();
};

exports.Member = Member;

这是我的同事写的数据对象.我们还没有完成测试的编写,因为我们停止了进一步考虑,但是这里是到目前为止的测试.

This is the data object my coworker wrote. We haven't finished writing the tests because we stopped to think about it more, but here are the tests we have so far.

var chai = require('chai');
var chaiAsPromised = require("chai-as-promised");
var expect = chai.expect;
var member = require('./lib/test-data');

chai.use(chaiAsPromised);

describe.only('Member Account Settings and Information', function() {
    before(function () {
        member.create();
    });

    before.each(function() {
        member.login();
    });

    describe('My Account', function () {
        it('Logging in should enable the "My Account" link.', function() {
            member.login();
        });

        it('Clicking on "My Account" should expand the account options', function() {
        });
    });

推荐答案

我将哈希用于数据对象.这是我在GitHub上的protractor_example代码中的示例.

I use hashes for my data objects. Here's an example from my protractor_example code on GitHub.

给出一个数据文件:

var UserData = function() {
    this.testUser = {'username': 'test', 'password': 'test'};
};
module.exports = new UserData();

然后是规格...

describe ('non-angular login test', function() {
    var loginPage = require('../pages/nonAngularLoginPage.js');
    var userData = require('../data/userData.js');

    it('should goto friend pages on successful login', function() {
        loginPage.loginAs(userData.testUser);

        expect(browser.getTitle()).toContain('Angular JS Demo');
    });
});

这篇关于使用量角器进行端到端测试时使用数据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆