Friday, November 24, 2017

Struggling to persist a reference to table cells during a suite run

Leave a Comment

I am attempting to read out values from table cells on a row for checking values match as expected.

I am facing a situation where protractor is unable to get the text of particular cells I am interested in as it cannot find the cells I am querying.

Here is my test suite steps:

beforeAll(function() {     common.journeyValidationBtn.click();     helper.waitForUrlToContain('journey-validation');     helper.waitForElementToHide(common.spinner);     common.fabBtn.click();     helper.waitForPresenceOf(common.calculateBtn);     common.runCalculation(secondaryPeriod);     helper.waitForPresenceOf(common.fabBtn, 30000);     helper.waitForElementToHide(common.spinner);     common.selectComparisonPeriod(initialPeriod);     helper.waitForTableRows(page.reimbursementCalculations).then(function() {         console.log('*** Table Rows Found - promise resolved ***');         page.reimbursementCalculations.count().then(function(count){             console.log('*** Number of Table Rows Found - ' + count + ' ***');             row = page.reimbursementCalculations.first();             cells = row.all(by.css('td'));             cells.count().then(function(cellCount){                 console.log('*** Number of Table Cells Found - ' + cellCount + ' ***');                 cells.get(0).getText().then(function(text){                     console.log('*** First Table Cell Text - ' + text + ' ***');                 });             });         });     }, function(reason){         console.log('*** Table Rows Not Found - promise rejected ***');         console.log(reason);     }); }); it('Then I should get more than one cell returned', function() {     expect(cellCount.count()).toBeGreaterThan(0); }); 

When running the test, I am seeing some Jasmine timeout errors followed by a failure for my expectation where it cannot call count() on my cells variable that gets assigned in the beforeAll block. Perhaps this timeout is related to what I am seeing but I am struggling to debug this further.

[12:20:01] I/testLogger - [chrome #01-6] PID: 9609 [chrome #01-6] Specs: /var/jenkins/workspace/project_x/test/e2e/features/featureA/workflow/SW0005.spec.js [chrome #01-6]  [chrome #01-6] [12:18:56] I/direct - Using ChromeDriver directly... [chrome #01-6] Started [chrome #01-6] *** Comparison period selected *** [chrome #01-6] [12:19:07] W/element - more than one element found for locator By(css selector, .spinnerContainer) - the first result will be used [chrome #01-6] [12:19:41] W/element - more than one element found for locator By(css selector, .spinnerContainer) - the first result will be used [chrome #01-6] *** Table Rows Found - promise resolved *** [chrome #01-6] *** Number of Table Rows Found - 1 *** [chrome #01-6] *** Number of Table Cells Found - 11 *** [chrome #01-6] *** First Table Cell Text - blaa *** [chrome #01-6] A Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] [31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow. [chrome #01-6] Failures: [chrome #01-6]   Message: [chrome #01-6] [31m    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.[0m [chrome #01-6]   Stack: [chrome #01-6]     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. [chrome #01-6]         at ontimeout (timers.js:365:14) [chrome #01-6]         at tryOnTimeout (timers.js:237:5) [chrome #01-6]         at Timer.listOnTimeout (timers.js:207:5) [chrome #01-6]   Message: [chrome #01-6] [31m    Failed: Cannot read property 'count' of undefined[0m [chrome #01-6]   Stack: [chrome #01-6]     TypeError: Cannot read property 'count' of undefined 

As can be seen from the console logs I have added, protractor is able to find a row and retrieve cells which I assign to my cells property (console log shows 11 cells), but it seems this is becoming undefined at the point the expectation is run. The cells property is defined outside of my beforeAll also, so I would have thought this would remain assigned and not undefined by the time the expectation check is performed.

This causes me problems for later tests where I want to read and check the values of each cell.

I feel like I am doing something fundamentally wrong, can anyone help?

Thanks

1 Answers

Answers 1

By default Jasmine beforeAll, beforeEach, afterEach, afterAll and it will expect a timeout-variable as second/third parameter. Though your example is not explicitly mentioned, read about the timeout-parameter of jasmine here

Though your callback is from your helper-function, my assumption is, that your reason-function makes it fail, because Jasmine might not support every aspect of JavaScript.

Try without the reason-function:

beforeAll(function() {     //all your test code      }); //don't add ", function(reason){etc}); }); it('Then I should get more than one cell returned', function() {     expect(cells.count()).toBeGreaterThan(0); }); 

Further the remark, that here you forgot to re-set "count", which is why your table rows and table cells are the same number:

cells = row.all(by.css('td')); cells.count().then(function(count2){ //Here the "count" is missing     console.log('*** Number of Table Cells Found - ' + count2 + ' ***'); 

UPDATE

You're right, the callback is of your own function, not the helper.

I now just saw that you have errors "cannot read property 'count' of 'undefined' ". Therefore your object page.reimbursementCalculations might be empty.

Currently these two lines log the same variable:

console.log('*** Number of Table Rows Found - ' + count + ' ***'); console.log('*** Number of Table Cells Found - ' + count + ' ***'); 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment