title: Use a factory in protractor test
body: <p>After a lot of searching and trying how to use a factory in an e2e test, I decided to finally ask here.</p>
  
  <p>I have a factory defined, with some functions, as follows:</p>
  
  <pre><code>regFormApp.factory('myFactory', ['$moment', function($moment) {
          return {
              title: 'Super Title 2014!',
              dates: [
                  {
                      date: '2014-10-21',
                      time: '08:30',
                      timezone: 'America/Mexico_City'
                  },
                  {
                      date: '2014-10-22',
                      time: '08:30',
                      timezone: 'America/Mexico_City'
                  }
              ],
              prices: {
                  earlyBird: 1250,
                  twoMonths: 1375,
                  last: 1700
              },
              salesEndDates: function(ticketType) {
                  var endDate = this.dates[0].date;
                  switch (ticketType) {
                      case 'earlyBird':
                          endDate = '2014-07-19';
                          break;
                      case 'twoMonths':
                          endDate = $moment(endDate)
                                  .subtract('months', 2)
                                  .format('YYYY-MM-DD');
                          break;
                      default:
                          break;
                  }
                  return endDate;
              },
              getSalesPeriod: function(_format) {
                  var format = _format || 'YYYY-MM-DD';
                  var now = $moment().format(format);
                  if (now &lt;= this.salesEndDates('earlyBird')) {
                      return 'earlyBird';
                  } else if (now &gt; this.salesEndDates('earlyBird')
                          &amp;&amp; now &lt;= this.salesEndDates('twoMonths')) {
                      return 'twoMonths'
                  }
                  return 'last';
              }
          };
      }]);
  </code></pre>
  
  <p>And I want to use <code>getSalesPeriod()</code> in my e2e test with protractor, in order to test if a select is enabled or not.</p>
  
  <p>So, my form looks like this:</p>
  
  <pre><code>...
  &lt;select id="earlyBirdSelect" class="form-control" ng-model="qty.earlyBird" ng-change="updateTotal()" ng-disabled="disableEarlyBird()"&gt;
      &lt;option&gt;1&lt;/option&gt;
      ...
  &lt;/select&gt;
  
  &lt;select id="twoMonthsSelect" class="form-control" ng-model="qty.twoMonths" ng-change="updateTotal()" ng-disabled="disableTwoMonths()"&gt;
      &lt;option&gt;1&lt;/option&gt;
      ...
  &lt;/select&gt;
  
  &lt;select id="lastSelect" class="form-control" ng-model="qty.last" ng-change="updateTotal()" ng-disabled="disableLast()"&gt;
      &lt;option&gt;1&lt;/option&gt;
      ...
  &lt;/select&gt;
  ...
  </code></pre>
  
  <p>What is used to enable or disable selects is:</p>
  
  <pre><code>regFormControllers.controller('MainCtrl', ['$scope', '$http', '$filter', 'myFactory',
      function($scope, $http, $filter, myFactory) {
          ...
  
          $scope.disableEarlyBird = function() {
              if (myFactory.getSalesPeriod() === 'earlyBird') {
                  return false;
              }
              return true;
          };
          // and analogously for twoMonths and last
  
          ...
       };
  }]);
  </code></pre>
  
  <p>So, I want to do something like this:</p>
  
  <pre><code>describe('form', function() {
  
  
      beforeEach(function() { 
          browser.get('app/#/'); // here is the form
      });
  
  
      it('should be enabled only earlyBird select', function() {
          var earlyBirdSelect = element(by.css('#earlybirdSelect'));
          var twoMonthsSelect = element(by.css('#earlybirdSelect'));
          var lastSelect = element(by.css('#earlybirdSelect'));
  
          // here I want to get 'earlyBird' from getSalesPeriod()
          var period = myFactory.getSalesPeriod(); // it depends to current date
          if (period === 'earlyBird') {
              expect(earlyBirdSelect.getAttribute('disabled')).toBeFalsy();
              expect(twoMonthsSelect.getAttribute('disabled')).toBeTruthy();
              expect(lastSelect.getAttribute('disabled')).toBeTruthy();
          }
      });
  
  });
  </code></pre>
  
  <p>I have no idea how to test it. Any help is very appreciated!</p>
  
  <p>Thank you very much in advance!</p>