Protractor test trying to find element in table (async)

1,337 views
Skip to first unread message

Jens Hoffmann

unread,
Aug 28, 2015, 9:23:05 AM8/28/15
to AngularJS
Hello, 

I am trying to write a protractor test which check for the existence of an table element. 
If the element doesn't exist in the table, the test should be successful.
But the promise never resolves. I hope you can help me out. 

HTML:
<table>
    ...
    <tr ng-hide="vm.noShippingCosts">
        <td>shippingcosts</td>
    </tr>
    ...
</table>


Page Object: 
FreeShippingPO.prototype = Object.create({}, {
myelement: {
get: function () {
function getShippingCosts() {
var deferred = protractor.promise.defer();

element.all(by.css('table tr')).each(function (element, index) {
if(element.getText() === 'shippingcost') {
deferred.resolve(true);
}
});
return deferred.promise;
}
return getShippingCosts();
}
}
});

describe('free shipping costs', function () {
it('should not have table cell with "shipping costs"', function () {
browser.get('http://localhost:7777/#/shoppingCart#12314313121231');
expect(po.myelement).to.be.false;
});
});

Jens Hoffmann

unread,
Aug 28, 2015, 9:24:18 AM8/28/15
to AngularJS
sorry forgot an 's' in shippingcosts


Am Freitag, 28. August 2015 15:23:05 UTC+2 schrieb Jens Hoffmann:
Hello, 

I am trying to write a protractor test which check for the existence of an table element. 
If the element doesn't exist in the table, the test should be successful.
But the promise never resolves. I hope you can help me out. 

HTML:
<table>
    ...
    <tr ng-hide="vm.noShippingCosts">
        <td>shippingcosts</td>
    </tr>
    ...
</table>


Page Object: 
FreeShippingPO.prototype = Object.create({}, {
myelement: {
get: function () {
function getShippingCosts() {
var deferred = protractor.promise.defer();

element.all(by.css('table tr')).each(function (element, index) {
                    if(element.getText() === 'shippingcosts') {

deferred.resolve(true);
}
});
return deferred.promise;
}
return getShippingCosts();
}
}
});

Mohammed Chand Kousar Sayed

unread,
Feb 7, 2020, 12:25:12 PM2/7/20
to Angular and AngularJS discussion
I am also in same situation, My function returns undefined instead cell value, any help is appreciated

async verifyCreateAuditReport(FieldValue?: string): Promise<any> {
        
        var deferred = protractor.promise.defer();
        browser.logger.info("Verify Data on Create Audit Report");
        await browser.wait(element(by.xpath("//td/span['Name:']")).isDisplayed(), 30000);

        await this.auditCriteriaReport.all(by.tagName('tr')).then(function (rows) {
            browser.logger.info("Row Count::" + rows.length);
            rows.forEach(function (rowElementFinder) {
                row.all(by.tagName('td > span')).then(function (cols) {
                    browser.logger.info("Column Count::" + cols.length);

                    if (cols.length > 0) {
                        cols.forEach(function (colElementFinder) {
                            col.getText().then(function (columnText) {
                                if (columnText == FieldValue) {
                                    //browser.logger.info("Column Text is::" + columnText);
                                    //return Promise.resolve(columnText);
                                    return columnText;
                                    
                                    
                                }
                            });

                        });
                    }

                });
            });
        });
        
    }
Reply all
Reply to author
Forward
0 new messages