From d1df66d9664950f672104ba4620afdb26c563cac Mon Sep 17 00:00:00 2001 From: Luis E <35935591+luisecm@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:43:17 -0600 Subject: [PATCH] update(test): fix mobile download test (#210) --- playwright/PageObjects/MainPage.ts | 48 +++++++++++++++++---------- playwright/specs/01-pin-input.spec.ts | 2 +- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/playwright/PageObjects/MainPage.ts b/playwright/PageObjects/MainPage.ts index eaabcfb..c735ad6 100644 --- a/playwright/PageObjects/MainPage.ts +++ b/playwright/PageObjects/MainPage.ts @@ -417,28 +417,40 @@ export default class MainPage { ); } - async validateInstallerIsDownloaded() { - const downloadPath = path.join(__dirname, "downloads"); - if (!fs.existsSync(downloadPath)) { - fs.mkdirSync(downloadPath); - } + async validateInstallerIsDownloaded(viewport: string) { + if (viewport === "mobile-chrome") { + const pagePromise = this.page.waitForEvent("popup"); + await this.buttonDownloadInstallAlert.click(); + const newTab = await pagePromise; + await expect(newTab).toHaveURL( + "https://play.google.com/store/apps/details?id=com.uplink.app", + ); + } else { + const downloadPath = path.join(__dirname, "downloads"); + if (!fs.existsSync(downloadPath)) { + fs.mkdirSync(downloadPath); + } - const downloadPromise = this.page.waitForEvent("download"); - await this.buttonDownloadInstallAlert.click(); - const download = await downloadPromise; + const downloadPromise = this.page.waitForEvent("download"); + await this.buttonDownloadInstallAlert.click(); - const fileName = download.suggestedFilename(); // Get the suggested filename - const filePath = path.join(downloadPath, fileName); - await download.saveAs(filePath); // Save the file to the designated path + const download = await downloadPromise; - // Validate the downloaded file - console.log(`Downloaded file saved at: ${filePath}`); - expect(fs.existsSync(filePath)).toBeTruthy(); // Check file exists - expect([".msi", ".dmg", ".deb", ".apk"]).toContain(path.extname(fileName)); // Validate file extension + const fileName = download.suggestedFilename(); // Get the suggested filename + const filePath = path.join(downloadPath, fileName); + await download.saveAs(filePath); // Save the file to the designated path - // Clean up after test - if (fs.existsSync(filePath)) { - fs.unlinkSync(filePath); // Delete the file + // Validate the downloaded file + console.log(`Downloaded file saved at: ${filePath}`); + expect(fs.existsSync(filePath)).toBeTruthy(); // Check file exists + expect([".msi", ".dmg", ".deb", ".apk"]).toContain( + path.extname(fileName), + ); // Validate file extension + + // Clean up after test + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); // Delete the file + } } // Validate install banner is gone diff --git a/playwright/specs/01-pin-input.spec.ts b/playwright/specs/01-pin-input.spec.ts index 58d4a67..3195eda 100644 --- a/playwright/specs/01-pin-input.spec.ts +++ b/playwright/specs/01-pin-input.spec.ts @@ -602,7 +602,7 @@ test.describe("Create Account and Login Tests", () => { }); await test.step("User can download installer from button and banner is hidden", async () => { - await createOrImport.validateInstallerIsDownloaded(); + await createOrImport.validateInstallerIsDownloaded(viewport); }); });