0

I have an angular 6 material dialog for deleting entities (employees). I want to set up protractor step to click the dialog's yes button to invoke the delete. Right now I have a page object function that does this:

deleteYesButton = () => element(by.id('deleteYes'));

and in my e2e file, I'm doing this as a step of an async test:

await page.deleteYesButton.click();

The dialog appears, but the click just closes the dialog without doing the delete. If I manually use the app press the yes button everything works ok.

The markup for the dialog is this:

Template:

<h2 mat-dialog-title>{{modalTitle}}</h2>
<mat-dialog-content id="mat-dialog-content">Do you wish to delete this {{entityname}}?</mat-dialog-content>
<mat-dialog-actions>
    <button mat-button mat-dialog-close id="deleteNo">No</button>
    <!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
    <button mat-button [mat-dialog-close]="true" id="deleteYes">Yes</button>
</mat-dialog-actions>

It feels like a timing issue or maybe something else needs to be invoked? Any help would be appreciated

sam-w
  • 7,478
  • 1
  • 47
  • 77
user3253156
  • 381
  • 1
  • 2
  • 10
  • Try making the `deleteYesButton` also as an `async-await`. I faced this kind of scenario when working with Cucumber and Protractor. Let me know if this solves the issue. – demouser123 Oct 21 '18 at 06:15
  • are you sure that your page has only one element with such id? – Oleksii Oct 21 '18 at 14:52

1 Answers1

0

so I changed the code so the page function was async as demouser123 suggested. Had to rework the e2e code a bit to this:

const delBtn = await page.deleteYesButton();
await delBtn.click();

but experienced the same outcome as the original. I also checked to make sure there weren't duplicates as Oleski asked. What got it working was adding a browser.pause after the original code. So this now works:

await page.deleteYesButton().click();
browser.pause(5000);  // adding this allowed the delete to go through???
user3253156
  • 381
  • 1
  • 2
  • 10