AngularJS – Testing With Protractor Page Objects

index.spec.js

var IndexPage = require('./IndexPage');

describe("hello-protractor", function () {

  var page = new IndexPage();

  beforeEach(function() {
      page.get();
  });

  describe("index", function () {
    it("should display the correct title", function () {
      expect(page.getTitle()).toBe('hello protractor');
    });

    it("should display the message when button clicked", function () {
      page.clickButton();

      expect(page.getMessageText()).toBe('button 1 clicked');
    });
  });
});

IndexPage.js

function IndexPage() {
  this.button = element(by.id('button1'));
  this.message = element(by.binding('messageText'));

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

  this.clickButton = function () {
    this.button.click();
  };

  this.getTitle = function () {
    return browser.getTitle();
  };

  this.getMessageText = function () {
    return this.message.getText();
  }
}

module.exports = IndexPage;

Share and Enjoy !

0Shares
0 0 0