I am working on an end-to-end test using Jasmine's Webdriver I / O. One specific scenario gave me serious problems.
I have a page with 5 links to it. In fact, the number of links is related to the dynamics of the page. I want to check the links to see if each link corresponds to the title title page to which it refers. Due to the fact that links are dynamically generated, I canβt just hard-code the code for each link. So, I am trying to do the following:
it('should match link titles to page titles', function(done) { client = webdriverio.remote(settings.capabilities).init() .url('http://www.example.com') .elements('a').then(function(links) { var mappings = []; // For every link store the link title and corresponding page title var results = []; for (var i=0; i<links.value.length; i++) { mappings.push({ linkTitle: links.value[0].title, pageTitle: '' }); results.push(client.click(links.value[i]) .getTitle().then(function(title, i) { mappings[i].pageTitle = title; }); ); } // Once all promises have resolved, compared each link title to each corresponding page title Promise.all(results).then(function() { for (var i=0; i<mappings.length; i++) { var mapping = mappings[i]; expect(mapping.linkTitle).toBe(mapping.pageTitle); } done(); }); }); ; });
I canβt even confirm if I got the link name correctly. I believe that I completely do not understand. I don't even get every title property of the links. I definitely do not get the corresponding page title. I think I am lost in the closing world here. However, I am not sure.
UPDATE - NOV 24 I still do not understand this. However, I believe this is due to the fact that Webdriver I / O uses the Q promise library. I came to this conclusion because the following test works:
it('should match link titles to page titles', function(done) { var promise = new Promise(function(resolve, reject) { setTimeout(function() { resolve(); }, 1000); }); promise.then(function() { var promises = []; for (var i=0; i<3; i++) { promises.push( new Promise(function(resolve, reject) { setTimeout(function() { resolve(); }, 500); }) ); } Promise.all(promises).then(function() { expect(true).toBe(true) done(); }); });
However, it does NOT :
it('should match link titles to page titles', function(done) { client = webdriverio.remote(settings.capabilities).init() .url('http://www.example.com') .elements('a').then(function(links) { var mappings = []; // For every link store the link title and corresponding page title var results = []; for (var i=0; i<links.value.length; i++) { mappings.push({ linkTitle: links.value[0].title, pageTitle: '' }); results.push(client.click(links.value[i]) .getTitle().then(function(title, i) { mappings[i].pageTitle = title; }); ); } // Once all promises have resolved, compared each link title to each corresponding page title Q.all(results).then(function() { for (var i=0; i<mappings.length; i++) { var mapping = mappings[i]; expect(mapping.linkTitle).toBe(mapping.pageTitle); } done(); }); }) ; });
I have no exceptions. However, the code inside Q.all does not seem to be executing. I'm not sure what to do here.