Question

I am trying to write some e2e tests for my angularjs application and am hitting a stopping block when working on the following issue: I have a ng-repeater outputting a table of vendors. I run the e2e test to create a new vendor which loads the previous (list) page. What I would like to do is compare the length of the original table rows to the new (should be +1) length of the rows after creating a new vendor. I seemed to have tried everything I can think of and haven't found an answer anywhere else. Here is some of the code I have tried to use:

var currentVendors = element('table tr').count();
expect(currentVendors + 1).toBe(element('table tr').count());
expect(currentVendors).toBeLessThan(element('table tr').count());
expect(element('table tr').count()).toBeGreaterThan(currentVendors);

None of which work and come back with errors. Is there a way of accomplishing this?

Edit Here is my entire test code except for what I attemping to do with the table repeater:

element('a.btn-default:eq(0)').click();
expect(browser().location().url()).toBe("/vendors/new");
expect(element('button.btn:disabled').count()).toBe(2);
input('vendor._name').enter('Test Runner Vendor');
input('vendor._address').enter('123 Fake Street');
input('vendor._city').enter('A City');
input('vendor._zip').enter('50000');
input('vendor._contactName').enter('Test Runner');
input('vendor._phoneNumber').enter('5555555555');
input('vendor._email').enter('test@ppcmfg.com');
expect(element('button.btn:disabled').count()).toBe(0);
element('button.btn.btn-primary').click();
expect(browser().location().url()).toBe("/vendors");
expect(element('div.alert.alert-success').count()).toBe(1);
var successMsg = element('div.alert.alert-success').text();
expect(successMsg).not().toMatch('(\\?)');
Was it helpful?

Solution

After searching around some more using different terms somehow I stumbled upon this SO question/answer: Angularjs e2e testing past/future comparisons

I applied this to check for current vs. future value adding 1 within the function call and checking against that at the very end of my test.

Here are the relevent pieces I ended up with:

angular.scenario.matcher('toBeExactlyOneLessThanFuture', function(future) {
    return (+this.actual + 1) == +future.value;
});
var currentVendors = element('table tr').count();
//Create a new vendor (see code above for reference)
var newVendorCount = element('table tr').count();
expect(currentVendors).toBeExactlyOneLessThanFuture(newVendorCount);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top