puppeteer_tests: Convert now-deprecated waitForXPath, $x methods.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-09-09 20:37:50 -07:00
committed by Anders Kaseorg
parent c8f346b5e5
commit 5ea44bc4ee
8 changed files with 25 additions and 30 deletions

View File

@@ -499,12 +499,12 @@ class CommonUtils {
): Promise<void> { ): Promise<void> {
console.log(`Looking in ${field_selector} to select ${str}, ${item}`); console.log(`Looking in ${field_selector} to select ${str}, ${item}`);
await this.clear_and_type(page, field_selector, str); await this.clear_and_type(page, field_selector, str);
const entry = await page.waitForXPath( const entry = await page.waitForSelector(
`//*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`, `xpath///*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`,
{visible: true}, {visible: true},
); );
assert.ok(entry); assert.ok(entry);
await (entry as ElementHandle<Element>).hover(); await entry.hover();
await page.evaluate((entry) => { await page.evaluate((entry) => {
if (!(entry instanceof HTMLElement)) { if (!(entry instanceof HTMLElement)) {
throw new TypeError("expected HTMLElement"); throw new TypeError("expected HTMLElement");

View File

@@ -42,12 +42,12 @@ async function test_change_new_stream_notifications_setting(page: Page): Promise
).val() === "rome", ).val() === "rome",
); );
const rome_in_dropdown = await page.waitForXPath( const rome_in_dropdown = await page.waitForSelector(
'//*[@id="realm_notifications_stream_id_widget"]//*[@class="dropdown-list-body"]/li[1]', 'xpath///*[@id="realm_notifications_stream_id_widget"]//*[@class="dropdown-list-body"]/li[1]',
{visible: true}, {visible: true},
); );
assert.ok(rome_in_dropdown); assert.ok(rome_in_dropdown);
await (rome_in_dropdown as ElementHandle<Element>).click(); await rome_in_dropdown.click();
await submit_notifications_stream_settings(page); await submit_notifications_stream_settings(page);

View File

@@ -17,12 +17,8 @@ async function close_compose_box(page: Page): Promise<void> {
await page.waitForSelector("#compose-textarea", {hidden: true}); await page.waitForSelector("#compose-textarea", {hidden: true});
} }
function get_message_xpath(text: string): string { function get_message_selector(text: string): string {
return `//p[text()='${text}']`; return `xpath///p[text()='${text}'][last()]`;
}
function get_last_element<T>(array: T[]): T {
return array.slice(-1)[0];
} }
async function test_send_messages(page: Page): Promise<void> { 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> { 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"); const stream_message_selector = get_message_selector("Compose stream reply test");
await page.waitForXPath(stream_message_xpath, {visible: true}); const stream_message = await page.waitForSelector(stream_message_selector, {visible: true});
const stream_message = get_last_element(await page.$x(stream_message_xpath));
// we chose only the last element make sure we don't click on any duplicates. // we chose only the last element make sure we don't click on any duplicates.
await (stream_message as ElementHandle<Element>).click(); await (stream_message as ElementHandle<Element>).click();
await common.check_form_contents(page, "#send_message_form", { 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( async function test_reply_by_click_prepopulates_private_message_recipient(
page: Page, page: Page,
): Promise<void> { ): Promise<void> {
const private_message = get_last_element( const private_message = await page.$(
await page.$x(get_message_xpath("Compose private message reply test")), get_message_selector("Compose private message reply test"),
); );
await (private_message as ElementHandle<Element>).click(); await (private_message as ElementHandle<Element>).click();
await page.waitForSelector("#private_message_recipient", {visible: true}); await page.waitForSelector("#private_message_recipient", {visible: true});

View File

@@ -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 page.click("#dialog_widget_modal .dialog_submit_button");
await common.wait_for_micromodal_to_close(page); await common.wait_for_micromodal_to_close(page);
await page.waitForXPath( await page.waitForSelector(
'//*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="Teams"]', 'xpath///*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="Teams"]',
); );
assert.strictEqual( assert.strictEqual(
await common.get_text_from_selector(page, `${profile_field_row} span.profile_field_type`), 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 page.click("#dialog_widget_modal .dialog_submit_button");
await common.wait_for_micromodal_to_close(page); await common.wait_for_micromodal_to_close(page);
await page.waitForXPath( await page.waitForSelector(
'//*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="team"]', 'xpath///*[@id="admin_profile_fields_table"]//tr[last()]/td[normalize-space()="team"]',
); );
assert.strictEqual( assert.strictEqual(
await common.get_text_from_selector(page, `${profile_field_row} span.profile_field_type`), await common.get_text_from_selector(page, `${profile_field_row} span.profile_field_type`),

View File

@@ -29,8 +29,8 @@ async function test_mention(page: Page): Promise<void> {
assert.ok(stream_size > threshold); assert.ok(stream_size > threshold);
await page.click("#compose-send-button"); await page.click("#compose-send-button");
await page.waitForXPath( await page.waitForSelector(
'//*[@class="compose-all-everyone-msg" and contains(text(), "Are you sure you want to mention all")]', '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.click(".compose-all-everyone-confirm");
await page.waitForSelector(".compose-all-everyone-msg", {hidden: true}); await page.waitForSelector(".compose-all-everyone-msg", {hidden: true});

View File

@@ -108,8 +108,8 @@ async function navigation_tests(page: Page): Promise<void> {
await test_reload_hash(page); await test_reload_hash(page);
// Verify that we're narrowed to the target stream // Verify that we're narrowed to the target stream
await page.waitForXPath( await page.waitForSelector(
'//*[@id="message_view_header"]//*[@class="stream" and normalize-space()="Verona"]', 'xpath///*[@id="message_view_header"]//*[@class="stream" and normalize-space()="Verona"]',
); );
} }

View File

@@ -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. // 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.waitForSelector("#edit_bot_modal", {hidden: true});
await page.waitForXPath( await page.waitForSelector(
`//*[@class="btn open_edit_bot_form" and @data-email="${bot1_email}"]/ancestor::*[@class="details"]/*[@class="name" and text()="Bot one"]`, `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); 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, cancel_button_selector,
); );
await page.click(cancel_button_selector); await page.click(cancel_button_selector);
await page.waitForXPath( await page.waitForSelector(
`//*[@class="btn open_edit_bot_form" and @data-email="${bot1_email}"]/ancestor::*[@class="details"]/*[@class="name" and text()="Bot one"]`, `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); await common.wait_for_micromodal_to_close(page);

View File

@@ -78,7 +78,7 @@ async function test_user_filter_ui(page: Page): Promise<void> {
} }
async function create_stream(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", { await common.fill_form(page, "form#stream_creation_form", {
stream_name: "Puppeteer", stream_name: "Puppeteer",
stream_description: "Everything Puppeteer", stream_description: "Everything Puppeteer",