0

We are new to Protractor and are going through the code to better understand its functionalists and in comparison with writing tests with selenium. As an exercise we have tried to automate the angularjs home page (http://www.angularjs.org) using page objects

Our TestSpec.js file is as follows

'use strict';

  var DevelopPage = require('../test_11th/Develop_pom.js');
  describe('angularjs homepage', function () {
  var Devpage;

beforeEach(function () {
  Devpage = new DevelopPage();
});

it('Develop page should be open', function () {
  Devpage.click_develop().click();
  //Devpage.Api_Reference();
  //Devpage.func_link();
  //Devpage.search('angular');
});
});

and the page object file Develop_pom.js is as follows

'use strict';

var DevelopPage = function () {
  browser.get('http://www.angularjs.org');
};
 DevelopPage.prototype = Object.create({}, {
     click_develop: {  function () 
    {  browser.driver.findElement(By.linkText("Develop")).click(); }},

     Api_Reference: {  function () 
    {  browser.driver.findElement(By.linkText("API Reference")).click(); }},

     func_link: {  function () 
    {  browser.driver.findElement(By.linkText("function")).click(); }},

     search: { : function (txt) 
    {  element(by.model('q')).click().sendKeys(txt); }}


    });

while running it we are encountering the error 1) Exception loading: C:\Users\kirti.vm\AppData\Roaming\npm\node_modules\protractor\test_11th\AngularSpec.js Error Message: SyntaxError: Unexpected token ( Stacktrace: SyntaxError: Unexpected token ( at require (module.js:380:17) at Object. (C:\Users\kirti.vm\AppData\Roaming\npm\node_modules\protractor\test_11th\AngularSpec.js:4:21)

Finished in 0.012 seconds 1 test, 1 assertion, 1 failure

can you please let us know what and where we are going wrong. Can we not use page objects to implement our test and call those page objects in the spec script.

1 Answers1

1

You need to export the page object at the end of the file:

module.exports = DevelopPage;

Take a look at the following example if you want to see a cleaner syntax:

https://github.com/angular/protractor/blob/master/website/test/e2e/api-page.js

Andres D
  • 8,910
  • 2
  • 26
  • 31