javascript - Is it possible to use a for loop for DRY protractor test? *var coming up undefined* -
goal: want make make loop on it
block tests if element text matches.
error: error: no element found using locator: by.csscontainingtext(".submenu li a", "undefined")
question: how write loop test multiple list items'? moreover, how make var title
visible inner it block
for example: have 2 test want dry via loop this next test example psuedocode doesn't work working test below.
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 sample var title = ['find store', 'clinic']; for(var = 0; < 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]); }); }; }); });
html:
<div class="submenu"> <ul> <li><a >find store</a> </li> <li><a>clinic</a> </li> </ul> </div>
working tests example:
it("should open find store page", function(){ browser.driver.sleep(2000); browser.ignoresynchronization = true; var title = 'find store'; var link = element(by.csscontainingtext('.submenu li a', title)); expect(link.gettext()).toequal(title); }); it("should open find 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); });
update:
it("should open find store page", function(){ browser.driver.sleep(2000); browser.ignoresynchronization = true; var string = 'find store'; var main = '.main'; var link = element(by.csscontainingtext('.submenu li a', string)); expect(link.gettext()).toequal(string); //i want ot click on too! link.click().then(function() { browser.driver.sleep(3000); var title = element(by.csscontainingtext(main, string)); expect(title.gettext()).tobe(string); }); });
this element.all()
+ map()
help:
var titles = element.all(by.css('.submenu li a')).map(function (elm) { return elm.gettext(); }); expect(titles).tobearrayofstrings(); expect(titles).toequal(['find store', 'clinic']);
fyi, here relevant feature request:
also see:
Comments
Post a Comment