Using data objects while testing E2E with Protractor

So, my colleague and I discussed creating a data object for our e2e tests. From my understanding of data objects, they are used to decouple test cases. For example, my first test suite is to create an account and check if the fields are valid, and the second test suite is included in the account and runs its own tests. I am told that it is useful to use data objects (rather than a page object) by simply knocking down the first test suite when creating an account. Thus, we can use the data object in the second set of tests to create a new user for input testing only. My problem is that if my first test suite was unable to create an account, why create an account in my second test suite? Whatever error I get in the first test set, should I get in the second test set too? I still have many questions about data objects and their use. I was wondering if anyone could explain data objects and how to use / write them.

/*** 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 a data object that my colleague wrote. We have not finished writing tests because we stopped thinking about it anymore, but here are the tests that we still have.

 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() { }); }); 
+2
source share
1 answer

I use hashes for my data objects. Here is 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 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'); }); }); 
+1
source

Source: https://habr.com/ru/post/1213752/


All Articles