Dialog Service
Learn how to use BELLATRIX dialog service.
Example
public class DialogServiceTests extends WebTest {
@Test
public void acceptDialogAlert() {
app().navigate().to("http://demos.bellatrix.solutions/welcome/");
var couponButton = app().create().byId(Button.class, "couponBtn");
couponButton.click();
app().dialogs().handle();
}
@Test
public void happyBirthdayCouponDisplayed_When_ClickOnCouponButton() {
app().navigate().to("http://demos.bellatrix.solutions/welcome/");
var couponButton = app().create().byId(Button.class, "couponBtn");
couponButton.click();
app().dialogs().handle(a -> Assert.assertEquals(a.getText(), "Try the coupon- happybirthday"));
}
@Test
@Ignore
public void dismissDialogAlert() {
app().navigate().to("http://demos.bellatrix.solutions/welcome/");
var couponButton = app().create().byId(Button.class, "couponBtn");
couponButton.click();
app().dialogs().handle(DialogButton.CANCEL);
}
}
Explanations
BELLATRIX gives you some methods for handling dialogs.
app().dialogs().handle();
You can click on the OK button and handle the alert.
app().dialogs().handle(a -> Assert.assertEquals(a.getText(), "Try the coupon- happybirthday"));
You can pass an anonymous lambda function and do something with the alert.
app().dialogs().handle(DialogButton.CANCEL);
You can tell the dialog service to click a different button.