4

I've got a single page that takes a user through a flow of different panels and a number of tests that are almost all identical aside from a couple different inputs I want to give. I tried an approach similar to this question but I have more than 1 it block and only the first one is ever ran, while the following tests after are all ignored.

describe('Page flow test', function() {

    var page    = require('../PageObjects/SomePage.js');
    var configs = require('../Configs.js');

    for(var i = 0; i < configs.length; i++) {
        (function(config) {

            it('should do something', function() {
                expect( config.name ).toEqual( config.nameToExpect );
            });

            it('should find an email', function() {
                page.emailInput.sendKeys( config.email );
                page.emailSearchSubmitButton.click();
                expect( page.emailSearchResult ).toEqual( config.emailToExpect );
            });

            // More tests...

        })( configs[i] );
    }

});

Found somewhat of a workaround although it's less than ideal.

Community
  • 1
  • 1
Corey Rowell
  • 282
  • 2
  • 11
  • 1
    Which test framework is protractor using? (Jasmine1, Jasmine2, Cucumber, etc). This is probably more a question for that module? – P.T. Mar 13 '15 at 04:57

1 Answers1

1

I have this working for me and the only difference i can see between our code is the way we create the self executing function

for(var i=0; i<filterTypes.length; i++){
  function setFilterUsingCheckBox(n){
    var filterType = filterTypes[n]          

    it('- Should check '+filterType+' filter text is correct', function(){
      var checkedCount = 'All'
        , filterText = filtersBar.filterText(filterType).getText();
         expect(filterText).toBe(checkedCount);
    });

    it ('- Should check the '+filterType+' title is correct', function(){
      filtersBar.openFilter(filterType);
      filtersBar.filterTitleText(filterType).getText().then(function(titleText){
        expect(titleText).toEqual(filterTitle);
      })
    });


  }setFilterUsingCheckBox(i)
}

filter-types is an array of strings which is why i'm able to use the current filter type I'm on in my it block description.

no idea why yours doesn't work, maybe someone with better JavaScript knowledge than me can advise, try my implementation and let us know, id be interested in knowing. If the above does work for you, that's great but i wouldn't mark this as an answer because i don't have an explanation as to why.

Sirk
  • 1,547
  • 2
  • 12
  • 18