public void ApplyCoupon(string coupon) { CouponCode.SetText(coupon); ApplyCouponButton.Click(); MessageAlert.ToHasContent().ToBeVisible().WaitToBe(); MessageAlert.ValidateInnerTextIs(CouponSuccessfullyAdded); }
// 3. These elements are always used together when coupon is applied. There are many test cases where you need to apply different coupons and so on. // This way you reuse the code instead of copy-paste it. If there is a change in the way how the coupon is applied, change the workflow only here. // Even single line of code is changed in your tests. public void ApplyCoupon(string coupon) { CouponCode.SetText(coupon); ApplyCouponButton.Click(); MessageAlert.ToHasContent().ToBeVisible().WaitToBe(); // Usually, it is not entirely correct to make assertions inside action methods. However, Validate methods are just waiting for something to happen. MessageAlert.ValidateInnerTextIs(CouponSuccessfullyAdded); }