Chào các bạn đã đến với chủ đề tiếp theo của topic User Action. Hôm nay, chúng ta sẽ tiếp tục discuss về Alert. Các bạn sẽ thường thấy 4 loại Alert như sau:
- Basic Alert

- Confirm Alert

- Prompt Alert

- Basic Authen

Những keywords mà Katalon support để handle cho Alert như sau:
Nội dung
1. [WebUI] Wait For Alert
- Keyword này dùng để chờ vài giây để cho alert hiển thị trên UI

'Wait for an alert to present in 5 seconds'
WebUI.waitForAlert(5)
2. [WebUI] Verify Alert Present
- Kiểm tra xem alert có đang hiển thị trên UI hay không?

'Verify Alert Present'
WebUI.verifyAlertPresent(2)
3. [WebUI] Get Alert Text
- Get text đang hiển thị trong alert
- Được sử dụng cho basic alert, confirmation alert, prompt alert

'Get Alert Text to verify'
String alertText = WebUI.getAlertText()
4. [WebUI] Accept Alert
- Giả lập hành động của user để click vào button “OK” trong Alert
- Được sử dụng cho basic alert, confirmation alert, prompt alert

'Accept Alert'
WebUI.acceptAlert()
5. [WebUI] Verify Alert Not Present
- Kiểm tra xem alert có đang KHÔNG hiển thị trên UI hay không?

'Verify Alert closed'
WebUI.verifyAlertNotPresent(2)
6. [WebUI] Dismiss Alert
- Giả lập hành động của user để click vào button “Cancel” trong Alert
- Được sử dụng cho confirmation alert, prompt alert

'Click Cancel'
WebUI.dismissAlert()
7. [WebUI] Set Alert Text
- Giả lập hành động của user để input text vào textbox trong Alert
- Được sử dụng cho Prompt Alert

'Input text to Alert'
WebUI.setAlertText("This is Alert text.")
8. [WebUI] Authenticate
- Keyword này dùng để input username and password vào Basic Authen
- Lưu ý: chỉ support cho Windows.

'Navigate to site: http://the-internet.herokuapp.com/basic_auth'
WebUI.authenticate("http://the-internet.herokuapp.com/basic_auth", username, password, 5)
Đến đây thì các bạn có thể handle được 4 loại alert trong automation rồi đó. Chúc các bạn thành công nhé.
9. Kết
Đến đây thì các bạn có thể handle được 4 loại alert trong automation rồi đó. Cảm ơn các bạn đã theo dõi bài viết của mình. Chúc các bạn thành công. Hẹn gặp lại các bạn ở những chủ đề tiếp theo. Bái bai.
Bài viết được mình tham khảo từ Katalon doc: https://docs.katalon.com/docs/katalon-studio-enterprise/keywords/web-ui-keywords/webui-accept-alert