title: 'TypeError: undefined is not a function' using Protractor
body: <p>I am aware there are many topics on this error code. However, I am struggling to find any solutions that help (or maybe I'm just stupid).</p>
  <p>I am building a Protractor test for a web page, and my original JavaScript worked perfectly. But I wanted to convert it all into using page objects, to make it easier to edit and understand as well as avoid code repetition.</p>
  <p>The first page object I use for logging in works perfectly fine, however my second page object for adding new users does not.</p>
  <p>The main test document from which I am linking the page objects to and from contains both instances of the code that do and don't work, respectively.
  </p>
  <ul>
  <li><p>The first instance that works is line 12.
  </p>
  </li>
  <li><p>The second instance that doesn't is on line 23.</p>
  <p>This is shown below:</p>
  <pre><code>  var util = require('util')
  
    describe ('This is to test the functionality of the Admin page.', function()
    {
  
        beforeEach(function(){
            browser.ignoreSynchronization = true;
            browser.get('https://website');
        });
  
        it ('Should log in and move to the Users page.', function() {
            var login_page = require('../page/login_page.js');
            var loginPage = new login_page;
            loginPage.login('user', 'pass');
  
            beforeEach(function () {
                expect(browser.getCurrentUrl()).toEqual('https://website');
            });
  
            describe('This should hold all the tests while logged in to Admin site', function () {
  
                it('Should create first new User.', function() {
                    var users_page = require('../page/users_page.js');
                    var usersPage = new login_page;
                    usersPage.addUserButton().click();
                    usersPage.addUser('Test', 'Smith', 'Test100@testing.co.nz', 'Password', 'Password', '0')
                    usersPage.userRole[0];
                    usersPage.confirm().click();
                    usersPage.back().click();
                });
  
                 it('Should logout', function () {
                    element(by.cssContainingText('span', 'Logout')).element(by.linkText('Logout')).click();
                });
            });
        });
    });
  </code></pre>
  </li>
  </ul>
  <p>The error I get when running the Protractor test in cmd is:</p>
  <pre class="lang-none prettyprint-override"><code>1) This should hold all the tests while logged in to Admin site Should create first new User.
  
         Message:
           TypeError: undefined is not a function
         Stacktrace:
           TypeError: undefined is not a function
          at [object Object].&lt;anonymous&gt; (C:\\\\\\test
      04_spec.js:25:27)
  </code></pre>
  <p>The page that the first instance references is:</p>
  <pre><code>require ('../page/users_page.js');
  
  var login_page = function(){
  
      this.username = element(by.id('username'));
      this.password = element(by.id('password'));
  
      this.get = function(urlVal){
          browser.get(urlVal);
      };
  
      this.login = function(un, pass){
          this.username.sendKeys(un);
          this.password.sendKeys(pass);
          element(by.tagName('button')).click();
      };
  };
  
  module.exports = login_page;
  </code></pre>
  <p>And the page that the second instance references is:</p>
  <pre><code>require ('../page/users_page.js');
  
  var users_page = function(){
  
      this.addUserButton = element(by.css('[role=&quot;button&quot;]'));
      this.firstName = element(by.model('firstname'));
      this.lastName = element(by.model('lastname'));
      this.userName = element(by.model('username'));
      this.password = element(by.model('password'));
      this.confirmPassword = element(by.model('confirmpassword'));
      this.confirm = element(by.css('[class=&quot;btn btn-success marginRight10px floatLeft&quot;]'));
      this.back = element(by.css('[class=&quot;btn floatLeft&quot;]'));
  
      this.addUser = function(fn, ln, un, pw, cpw){
          this.firstname.sendKeys(fn);
          this.lastword.sendKeys(ln);
          this.username.sendKeys(un);
          this.password.sendKeys(pw);
          this.confirmpassword.sendKeys(cpw);
      };
  
      this.userRole = function(index){
          element(by.model('tes.userRole')).$('[value=&quot;'+index+'&quot;]').click();
      };
  
      return require('./users_page.js');
  
  };
  module.exports = new users_page();
  </code></pre>