title: Is it possible to use a for loop for DRY protractor test? *var coming up undefined*
body: <p><strong>Goal:</strong>  I want to make make a loop over an <code>it</code> block that tests if an element text matches.</p>
  
  <p><strong>Error:</strong> <code>Error: No element found using locator: by.cssContainingText(".submenu li a", "undefined")</code></p>
  
  <p><strong>Question:</strong>  How do I write a for loop to test multiple list items'?  Moreover, How do i make <code>var title</code> visible to the inner <code>it block</code></p>
  
  <p>For this example: I have 2 test that I want to DRY up via a loop 
  <em>this next test example is just psuedocode doesn't work working test below</em>.</p>
  
  <pre><code>var config = require('../../protractor.conf.js').config;
  
  describe('this Homepage Body Tests', function(){
  
    browser.driver.get(config.homepageUrl);
  
    describe('sub navigation functionality', function () {
      //creates teh array of strings for this sample
      var title = ['find a store', 'clinic'];
  
  
      for(var i = 0; i &lt; title.length; i++){
  
        it("should open find a" + title[i] + "page", function(){
  
          browser.driver.sleep(2000);
          browser.ignoreSynchronization = true;
          var link = element(by.cssContainingText('.submenu li a', title[i]));
          expect(link.getText()).toEqual(title[i]);
  
  
        });
      };
   });
  
  });
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>  &lt;div class="submenu"&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a &gt;find a store&lt;/a&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;a&gt;clinic&lt;/a&gt;
          &lt;/li&gt;
  
      &lt;/ul&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p><strong>Working Tests example:</strong></p>
  
  <pre><code>it("should open find a store page", function(){
  
    browser.driver.sleep(2000);
    browser.ignoreSynchronization = true;
  
    var title = 'find a store';
    var link = element(by.cssContainingText('.submenu li a', title));
  
  
    expect(link.getText()).toEqual(title);
  
  
  });
  
  it("should open find a clinic page", function(){
  
    browser.driver.sleep(2000);
    browser.ignoreSynchronization = true;
  
    var title = 'clinic';
  
    var link = element(by.cssContainingText('.submenu li a', title));
  
  
    expect(link.getText()).toEqual(title);
  
  
  });
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>it("should open find a store page", function(){
  
        browser.driver.sleep(2000);
        browser.ignoreSynchronization = true;
  
        var string = 'find a store';
        var main = '.main';
        var link = element(by.cssContainingText('.submenu li a', string));
  
  
        expect(link.getText()).toEqual(string);
        //I WANT OT CLICK ON THAT TOO!
        link.click().then(function() {
  
          browser.driver.sleep(3000);
          var title = element(by.cssContainingText(main, string));
          expect(title.getText()).toBe(string);
        });
  
      });
  </code></pre>