user249656
user249656

Reputation: 164

E2E test using Entities

I'm trying to optimize my E2E tests to incorporate the usage of entities.

Our tests are basically filling data into a form on a webpage. Our tests are using the PageObject method where our PageObject stores our elements in variables and we also have variables containing the interactions with the elements stored in the PO file.

Our spec file is what calls the PO file and inputs the data into each element similar to(this is just examples of what we are doing):

PO File:

this.firstNameField = by.model('firstName');
this.lastNameField = by.model('lastName');

this.setFirstNameField = function(firstname) {
    element(this.firstNameField).sendKeys(firstname);
};

this.setLastNameField = function(lastname) {
    element(this.lastNameField).sendKeys(lastname);
};

Spec file:

pageObject.setFirstNameField('TestName');
pageObject.setLastNameField('TestLastName');

In our spec file, we have roughly 100 lines of this code which is not very effecient from what I can tell. I want to remove this style and use Entity's instead, however I'm not sure exactly how i would go about this, hence why I'm coming here.

A friend of mine gave me a hint of how i'd go about this and here is what he has provided me:

spec file:

var nameEntity = {
      firstName: 'TestName',
      lastName: 'TestLastName'
    };
pageObject.PopulateUIWithNameEntity(nameEntity);

Now i know i can switch the nameEntity to be stored in the pageObejct file, however i'm not exactly sure how the PopulateUIWIthNameEntity should be created.

I've tried the following but I can't seem to get it to input the values from the nameEntity into the element itself.

pageObject File:

this.PopulateUIWithNameEntity = function(nameEntity) {
    element(this.setFirstNameField).sendKeys(nameEntity);
  };

Upvotes: 2

Views: 161

Answers (1)

Brine
Brine

Reputation: 3731

You were close... just needed a little refactor.

Adding your test data to an object (hash) is definitely a good idea. Then you just need to extract the elements from it in your method. You also already have individual methods for each individual action... so you just needed to use them.

spec...

var nameEntity = {
  firstName: 'TestName',
  lastName: 'TestLastName'
};
pageObject.populateUIWithNameEntity(nameEntity);

page object...

this.populateUIWithNameEntity = function(nameEntity) {
  this.setFirstNameField(nameEntity.firstName);
  this.setLastNameField(nameEntity.lastName);
};

Upvotes: 1

Related Questions