2

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() {
        });
    });
Frank
  • 215
  • 3
  • 9
  • Please provide an example of a data object and it's usage. Thanks. – alecxe Feb 25 '15 at 19:29
  • So thats the data object we have so far. The way we are trying to use it is to create a new user before all the tests, but I have been creating one user and using that account for all of my tests. This kind of has to do with the echo question i asked earlier that you commented on. – Frank Feb 25 '15 at 19:46
  • This is my favorite answer on the topic: http://www.thoughtworks.com/insights/blog/using-page-objects-overcome-protractors-shortcomings – Isaac Lyman Feb 25 '15 at 21:06
  • Yes page objects helps and we have a couple of them, but I am trying to find out about data objects. I have been googling and can't really find anything about them. From my understanding data objects are similar to page objects but not exactly the same – Frank Feb 25 '15 at 21:38

1 Answers1

1

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

Given a data file:

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

Then the spec...

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');
    });
});
Brine
  • 3,733
  • 1
  • 21
  • 38
  • So in this case you are using the same user for all of your test suites? – Frank Mar 03 '15 at 18:25
  • I this example, yes, but you could add any number of additional users in UserData. Eg. you might also have a `this.admin`, or a `this.userNoWigets`, or `this.guestUser`, etc... If it helps the test, I might also use a var to specify role. Eg. `var admin = userData.tom;` and then use it: `loginPage.loginAs(admin);`. This helps readability and helps document the test (i.e. you know this test expects an admin). – Brine Mar 03 '15 at 20:12