Search code examples
typescriptprotractore2e-testing

Automating E2E in protractor, How do I get a count of events after I have removed one


I need to test the removal of an event and to show the event has been removed. As these events are not unique and can be random in number at the point of testing I thought a count will be the best way to go.

This is all new to me so apologies on the vagueness.
The code below hopefully shows what i want to do but the expect should be a number, whereas im comparing a start and endcount. Can any point me in the right direction or offer alternative solutions?

enter code here

it('should remove the events', async function () {
await browser.get('/');
var removeBtns = element.all(by.id('removeButton')).first();
var startcount = element.all(by.id('removeButton')).count();
console.log(startcount);
removeBtns.click();
element(by.className('...confirm removal of button')).click();
var endcount = element.all(by.id('removeButton')).count();
console.log(endcount);
expect(endcount).toBeLessThan(startcount);

enter code here

The error returned No overload matches this call. Overload 1 of 2, '(expected: number | Promise, expectationFailOutput?: any): Promise', gave the following error.
Argument of type 'Promise' is not assignable to parameter of type 'number | Promise'.
Type 'Promise' is missing the following properties from type 'Promise': [Symbol.toStringTag], finally Overload 2 of 2, '(expected: number, expectationFailOutput?: any): boolean', gave the following error.
Argument of type 'Promise' is not assignable to parameter of type 'number'.


Solution

  • element.all().count() returns a promise.

    for some reason expect() takes a promise but the things you compare to like .toBe() and .toEquals() these dont take promises. You would have to do something like this:

    var endcount = await element.all(by.id('removeButton')).count();
    expect(startcount).not.toBe(endcount);
    

    Notice i changed endcount to the end, It doesnt matter which goes in the expect as long as you make sure that what you compare to is awaited.