How to handle multiple, consecutive popup alerts with Serenity's PageObject?

437 views
Skip to first unread message

Jacek Maciąg

unread,
Jun 17, 2016, 3:39:15 AM6/17/16
to Serenity BDD Users Group
Hi All,

I've asked this on Stack Overflow, so please don't mind the repaste:


Here's the issue. I am using Serenity to run tests and PageObject is handling all my actions, either through Serenity's steps or by direct reference in Junit's tests.

The scenario I am currently working on is simple:

1. Enter date into a field (input "99999999").
2. Click Submit button.
3. Get popup alert messages.
   a. Get "The year is invalid." msg first.
   b. Get "Invalid Receipt Date format." msg second.

However, PageObject seems to immediately jump to the second message and completely ignores the first one. My implementation is somewhere along these lines:

@Test
public void receiptDateFieldIncorrectDateFormat() {

    page
.open();

    steps
.inputIntoReceiptDateField("99999999");

    steps.clickSubmitButton();

   
String firstMsg = page.getAlert().getText();

    page
.getAlert().accept();

   
String secondMsg = page.getAlert().getText();

    page
.getAlert().accept();

   
Assert.assertEquals("The year is invalid.", firstMsg);

   
Assert.assertEquals("Invalid Receipt Date format.", secondMsg);

}


I have tried implementing waits with no result. Can someone explain to me how this works and why is the first alert omitted? PageObject does not seem to have functionality to cycle through multiple alerts, or has it?

Thank you!

Jacek Maciąg

unread,
Jun 17, 2016, 3:42:32 AM6/17/16
to Serenity BDD Users Group
It's also worth to add that once the Submit button is hit, a call to JavaScript is made and while it validates the input it spits out those alerts. It is possible to have more than 2 of these.
Reply all
Reply to author
Forward
0 new messages