0

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('(\\?)');
Brian
  • 2,294
  • 6
  • 30
  • 51
  • How are you adding the new vendor? Could you provide a little more of your code showing how the test goes about adding new elements to the repeater? – ivarni Oct 26 '13 at 08:30
  • Added my full test code. – Brian Oct 26 '13 at 13:19
  • Haven't been online this weekend, but it looks like you solved it? – ivarni Oct 27 '13 at 21:52
  • Yea I have it working using the code below, whether this is best or not I have no idea either way, however I am using this method across various tests and rules (less than,greater than, equal to etc...) Thanks for checking back. – Brian Oct 28 '13 at 01:42

1 Answers1

1

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);
Community
  • 1
  • 1
Brian
  • 2,294
  • 6
  • 30
  • 51