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ề Window Tab. Khi bạn mở 1 trang web bất kỳ và click vào 1 cái link nào đó (ví dụ như link facebook or quảng cáo). Lúc đó, 1 tab mới sẽ được hiển thị.

Ví dụ như hình trên, khi bạn click vào Click Here link or Elemental Selenium link, 2 tab mới sẽ được hiển thị. Trong auto, mọi thao tác chỉ có thể thực hiện trên page đầu tiên. Để thao tác với 2 tab bạn vừa mở, bạn phải switch sang 2 tab đó mới có thể thao tác được. Bên dưới là những Katalon keyword để xử lý cho trường hợp này.
Nội dung
1. [WebUI] Switch To Window Index
- Switch to the window với index được chỉ định.
- Khi bạn lần đầu tiên open browser lên, thì index của page hiện tại sẽ bắt đầu bằng 0. Nếu bạn mở thêm 1 tab nữa, thì tab này sẽ có index = 1. Tương tự như thế, nếu trên browser có 10 tab, thì tab thứ 10 sẽ có index = 9.

'Switch to new Window by index'
WebUI.switchToWindowIndex(1)
2. [WebUI] Get Window Index
- Get index của page hiện tại bạn đang thao tác

'Get Index của Window hiện tại đang active'
String parentWindowIndex = WebUI.getWindowIndex()
3. [WebUI] Close Window Index
- Close window với 1 index bất kỳ.
- Như mình nói ở trên, thì index của page đầu tiên sẽ bắt đầu = 0. Ví dụ mình có 4 tabindex 0: tab 1
- index 1: tab 2
- index 2: tab 3
- index 3: tab 4
- Nếu bạn close 1 tab nó đó, ví dụ như tab 2 (index 1), thì lúc này tab 3 sẽ có index = 1, tab 4 có index = 2

'Close Window by index'
WebUI.closeWindowIndex(1)
4. [WebUI] Get Window Title
- Get title của page hiện tại bạn đang thao tác

'Get Title của Window hiện tại đang active'
parentWindowTitle = WebUI.getWindowTitle()
5. [WebUI] Switch To Window Title
- Switch to window với title được chỉ định

'Switch to New Window'
WebUI.switchToWindowTitle("New Window")
6. [WebUI] Close Window Title
- Close window với title được chỉ định

'Close window: New Window'
WebUI.closeWindowTitle("New Window")
7. [WebUI] Get Url
- Get URL của page hiện tại bạn đang thao tác

'Get URL của Window - Tab vừa được mở'
parentWindowURL = WebUI.getUrl()
8. [WebUI] Switch To Window Url
- Switch to window với URL được chỉ định

'Switch to Url'
WebUI.switchToWindowUrl(parentWindowURL)
9. [WebUI] Close Window Url
- Close window với URL được chỉ định

'Close Url'
WebUI.closeWindowUrl(parentWindowURL)
10. Kết
Như vậy chúng ta đã tìm hiểu qua 1 số keyworks để xử lý cho Window/Tab. 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