Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
puppeteer_tests: Convert now-deprecated waitForXPath, $x methods.
Anders Kaseorg5ea44bc4eefd
diff --git a/frontend_tests/puppeteer_lib/common.ts b/frontend_tests/puppeteer_lib/common.tsindex b30c830b9de..db4287bcb09 100644--- a/frontend_tests/puppeteer_lib/common.ts+++ b/frontend_tests/puppeteer_lib/common.ts@@ -499,12 +499,12 @@ class CommonUtils {): Promise<void> {console.log(`Looking in ${field_selector} to select ${str}, ${item}`);await this.clear_and_type(page, field_selector, str);- const entry = await page.waitForXPath(- `//*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`,+ const entry = await page.waitForSelector(+ `xpath///*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`,{visible: true},);assert.ok(entry);- await (entry as ElementHandle<Element>).hover();+ await entry.hover();await page.evaluate((entry) => {if (!(entry instanceof HTMLElement)) {throw new TypeError("expected HTMLElement");diff --git a/frontend_tests/puppeteer_tests/admin.ts b/frontend_tests/puppeteer_tests/admin.tsindex db72b350aad..c6728465980 100644--- a/frontend_tests/puppeteer_tests/admin.ts+++ b/frontend_tests/puppeteer_tests/admin.ts@@ -42,12 +42,12 @@ async function test_change_new_stream_notifications_setting(page: Page): Promise).val() === "rome",);- const rome_in_dropdown = await page.waitForXPath(- '//*[@id="realm_notifications_stream_id_widget"]//*[@class="dropdown-list-body"]/li[1]',+ const rome_in_dropdown = await page.waitForSelector(+ 'xpath///*[@id="realm_notifications_stream_id_widget"]//*[@class="dropdown-list-body"]/li[1]',{visible: true},);assert.ok(rome_in_dropdown);- await (rome_in_dropdown as ElementHandle<Element>).click();+ await rome_in_dropdown.click();await submit_notifications_stream_settings(page);diff --git a/frontend_tests/puppeteer_tests/compose.ts b/frontend_tests/puppeteer_tests/compose.tsindex ea3b194c9aa..5b3710cf73a 100644--- a/frontend_tests/puppeteer_tests/compose.ts+++ b/frontend_tests/puppeteer_tests/compose.ts@@ -17,12 +17,8 @@ async function close_compose_box(page: Page): Promise<void> {await page.waitForSelector("#compose-textarea", {hidden: true});}-function get_message_xpath(text: string): string {- return `//p[text()='${text}']`;-}--function get_last_element<T>(array: T[]): T {- return array.slice(-1)[0];+function get_message_selector(text: string): string {+ return `xpath///p[text()='${text}'][last()]`;}async function test_send_messages(page: Page): Promise<void> {@@ -59,9 +55,8 @@ async function test_keyboard_shortcuts(page: Page): Promise<void> {}async function test_reply_by_click_prepopulates_stream_topic_names(page: Page): Promise<void> {- const stream_message_xpath = get_message_xpath("Compose stream reply test");- await page.waitForXPath(stream_message_xpath, {visible: true});- const stream_message = get_last_element(await page.$x(stream_message_xpath));+ const stream_message_selector = get_message_selector("Compose stream reply test");+ const stream_message = await page.waitForSelector(stream_message_selector, {visible: true});// we chose only the last element make sure we don't click on any duplicates.await (stream_message as ElementHandle<Element>).click();await common.check_form_contents(page, "#send_message_form", {@@ -75,8 +70,8 @@ async function test_reply_by_click_prepopulates_stream_topic_names(page: Page):async function test_reply_by_click_prepopulates_private_message_recipient(page: Page,): Promise<void> {- const private_message = get_last_element(- await page.$x(get_message_xpath("Compose private message reply test")),+ const private_message = await page.$(+ get_message_selector("Compose private message reply test"),);await (private_message as ElementHandle<Element>).click();await page.waitForSelector("#private_message_recipient", {visible: true});diff --git a/frontend_tests/puppeteer_tests/custom-profile.ts b/frontend_tests/puppeteer_tests/custom-profile.tsindex 337f86d64b0..e7bee6df6bb 100644--- a/frontend_tests/puppeteer_tests/custom-profile.ts+++ b/frontend_tests/puppeteer_tests/custom-profile.ts@@ -26,8 +26,8 @@ async function test_add_new_profile_field(page: Page): Promise<void> {await page.click("#dialog_widget_modal .dialog_submit_button");await common.wait_for_micromodal_to_close(page);- await page.waitForXPath(- '//*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="Teams"]',+ await page.waitForSelector(+ 'xpath///*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="Teams"]',);assert.strictEqual(await common.get_text_from_selector(page, `${profile_field_row} span.profile_field_type`),@@ -52,8 +52,8 @@ async function test_edit_profile_field(page: Page): Promise<void> {await page.click("#dialog_widget_modal .dialog_submit_button");await common.wait_for_micromodal_to_close(page);- await page.waitForXPath(- '//*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="team"]',+ await page.waitForSelector(+ 'xpath///*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="team"]',);assert.strictEqual(await common.get_text_from_selector(page, `${profile_field_row} span.profile_field_type`),diff --git a/frontend_tests/puppeteer_tests/mention.ts b/frontend_tests/puppeteer_tests/mention.tsindex e3c6798dfd7..161c5d06b3a 100644--- a/frontend_tests/puppeteer_tests/mention.ts+++ b/frontend_tests/puppeteer_tests/mention.ts@@ -29,8 +29,8 @@ async function test_mention(page: Page): Promise<void> {assert.ok(stream_size > threshold);await page.click("#compose-send-button");- await page.waitForXPath(- '//*[@class="compose-all-everyone-msg" and contains(text(), "Are you sure you want to mention all")]',+ await page.waitForSelector(+ 'xpath///*[@class="compose-all-everyone-msg" and contains(text(), "Are you sure you want to mention all")]',);await page.click(".compose-all-everyone-confirm");await page.waitForSelector(".compose-all-everyone-msg", {hidden: true});diff --git a/frontend_tests/puppeteer_tests/navigation.ts b/frontend_tests/puppeteer_tests/navigation.tsindex 9d68af85df7..057667f35f3 100644--- a/frontend_tests/puppeteer_tests/navigation.ts+++ b/frontend_tests/puppeteer_tests/navigation.ts@@ -108,8 +108,8 @@ async function navigation_tests(page: Page): Promise<void> {await test_reload_hash(page);// Verify that we're narrowed to the target stream- await page.waitForXPath(- '//*[@id="message_view_header"]//*[@class="stream" and normalize-space()="Verona"]',+ await page.waitForSelector(+ 'xpath///*[@id="message_view_header"]//*[@class="stream" and normalize-space()="Verona"]',);}diff --git a/frontend_tests/puppeteer_tests/settings.ts b/frontend_tests/puppeteer_tests/settings.tsindex 204ff3eba11..2d0105b7d34 100644--- a/frontend_tests/puppeteer_tests/settings.ts+++ b/frontend_tests/puppeteer_tests/settings.ts@@ -177,8 +177,8 @@ async function test_edit_bot_form(page: Page): Promise<void> {// The form gets closed on saving. So, assert it's closed by waiting for it to be hidden.await page.waitForSelector("#edit_bot_modal", {hidden: true});- await page.waitForXPath(- `//*[@class="btn open_edit_bot_form" and @data-email="${bot1_email}"]/ancestor::*[@class="details"]/*[@class="name" and text()="Bot one"]`,+ await page.waitForSelector(+ `xpath///*[@class="btn open_edit_bot_form" and @data-email="${bot1_email}"]/ancestor::*[@class="details"]/*[@class="name" and text()="Bot one"]`,);await common.wait_for_micromodal_to_close(page);@@ -221,8 +221,8 @@ async function test_invalid_edit_bot_form(page: Page): Promise<void> {cancel_button_selector,);await page.click(cancel_button_selector);- await page.waitForXPath(- `//*[@class="btn open_edit_bot_form" and @data-email="${bot1_email}"]/ancestor::*[@class="details"]/*[@class="name" and text()="Bot one"]`,+ await page.waitForSelector(+ `xpath///*[@class="btn open_edit_bot_form" and @data-email="${bot1_email}"]/ancestor::*[@class="details"]/*[@class="name" and text()="Bot one"]`,);await common.wait_for_micromodal_to_close(page);diff --git a/frontend_tests/puppeteer_tests/stream_create.ts b/frontend_tests/puppeteer_tests/stream_create.tsindex ab431dbc1c9..a101f45739f 100644--- a/frontend_tests/puppeteer_tests/stream_create.ts+++ b/frontend_tests/puppeteer_tests/stream_create.ts@@ -78,7 +78,7 @@ async function test_user_filter_ui(page: Page): Promise<void> {}async function create_stream(page: Page): Promise<void> {- await page.waitForXPath('//*[text()="Create stream"]', {visible: true});+ await page.waitForSelector('xpath///*[text()="Create stream"]', {visible: true});await common.fill_form(page, "form#stream_creation_form", {stream_name: "Puppeteer",stream_description: "Everything Puppeteer",