Skip to content

Support both in PO assertions and out of PO assertions via helper methods #2

@samvloeberghs

Description

@samvloeberghs

Hi,

You should not be doing expectations in a page object. That's defeating the purpose of a page object and somewhat bad practice. I saw the generation of the simple example on the website here:

var UnnamedPageObject = function() {

    this.get = function() {
        browser.get('');
    };

    this.a0 = element(by.css('a.a'));

    this.clickA0 = function() {
        this.a0.click();
    };

    this.a0ShouldBeVisible = function() {
        expect(this.a0.isDisplayed()).toBeTruthy();
    };

    this.a0ShouldNotBeVisible = function() {
        expect(this.a0.isDisplayed()).toBeFalsy();
    };

    this.a0ShouldHaveClass = function(className) {
        this.a0.getAttribute('class').then(function(classes) {
            expect(classes.split(' ').indexOf(className) !== -1).toBeTruthy();
        });
    };

    this.a0ShouldNotHaveClass = function(className) {
        this.a0.getAttribute('class').then(function(classes) {
            expect(classes.split(' ').indexOf(className) === -1).toBeTruthy();
        });
    };

};
module.exports = new UnnamedPageObject();

The expectations are typically something you should do in your test file. Not in a helper class. This beats the purpose of seperation of concern.

All that aside, very nice project! :)
Please keep on updating/improving!

Grtz!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions