From 8dfb48e48f3c39f4760fe3c143bd76fdf7237f01 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Tue, 7 Jan 2025 00:01:27 +0000 Subject: [PATCH] #1431 correct flakey tests, increase fetch upcoming invoices wait time (to give time for invoices to be created at stripes end --- .../e2e/133_shop_owner_plan_creation.spec.js | 82 +++++++++++-------- .../212_shop_owner_slogan_creation.spec.js | 3 +- ...h_choice_options_and_required_note.spec.js | 1 + .../e2e/features/admin_login.js | 1 + .../e2e/features/fetch_upcomming_invoices.js | 5 +- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/tests/browser-automated-tests-playwright/e2e/133_shop_owner_plan_creation.spec.js b/tests/browser-automated-tests-playwright/e2e/133_shop_owner_plan_creation.spec.js index 57ace24e..4371f92d 100644 --- a/tests/browser-automated-tests-playwright/e2e/133_shop_owner_plan_creation.spec.js +++ b/tests/browser-automated-tests-playwright/e2e/133_shop_owner_plan_creation.spec.js @@ -169,7 +169,6 @@ test.describe("Plan Creation tests:", () => { } }); - test("@264@shop-owner @264_shop_owner_create_plan_with_choice_options", async ({ page }) => { await admin_login(page); await set_test_name_cookie(page, "@264_shop_owner_create_plan_with_choice_options") @@ -224,44 +223,54 @@ test.describe("Plan Creation tests:", () => { //Add options and choices console.log('adding plan options and choices'); - await page.goto('/admin/add-choice-group'); - - //add choice group + await page.goto('/admin/list-choice-groups'); const add_choice_group = await page.textContent('text="Add Choice Group"'); expect(add_choice_group === "Add Choice Group"); - await page.fill('.form-control', 'Choices'); - await page.click("text='Save'"); - await page.textContent('.alert-heading') === "Notification"; - console.log("Choice Created"); - //add first option - console.log("adding options...") - await page.goto('/admin/list-choice-groups'); - await page.getByRole('button', { name: 'Options' }).click(); - - await page.click("text=Add Option"); - await page.fill('.form-control', 'Red'); - await page.click("text='Save'"); - await page.textContent('.alert-heading') === "Notification"; - console.log("First Option added"); - - //add second option - await page.click("text=Add Option"); - await page.fill('.form-control', 'Blue'); - await page.click("text='Save'"); - await page.textContent('.alert-heading') === "Notification"; - console.log("Second Option added"); - - //assign choice to plan - console.log("Assigning Choice to plan...") - await page.goto('/admin/list-choice-groups'); - await page.click("text=Assign Plan"); - const assign_choice_to_plan = await page.textContent('text="Choice Group - Assign Plan"'); - expect(assign_choice_to_plan === "Choice Group - Assign Plan"); - await page.click("text=Plan with choice and options"); - await page.click("text='Save'"); - await page.textContent('.alert-heading') === "Notification"; - console.log("Choice assigned to plan"); + // Check if choice group named 'Choices' already exists + try { + const check_choice_group = await page.textContent('text="Choices"', { timeout: 2000 }); + if (check_choice_group === "Choices") { + console.log("Choice Group already created."); + } + } catch (e) { + console.log("Choice Group 'Choices' does not exist, continuing with creation"); + //add choice group + await page.goto('/admin/add-choice-group'); + await page.fill('.form-control', 'Choices'); + await page.click("text='Save'"); + await page.textContent('.alert-heading') === "Notification"; + console.log("Choice Created"); + + //add first option + console.log("adding options...") + await page.goto('/admin/list-choice-groups'); + await page.getByRole('button', { name: 'Options' }).first().click(); + + await page.click("text=Add Option"); + await page.fill('.form-control', 'Red'); + await page.click("text='Save'"); + await page.textContent('.alert-heading') === "Notification"; + console.log("First Option added"); + + //add second option + await page.click("text=Add Option"); + await page.fill('.form-control', 'Blue'); + await page.click("text='Save'"); + await page.textContent('.alert-heading') === "Notification"; + console.log("Second Option added"); + + //assign choice to plan + console.log("Assigning Choice to plan...") + await page.goto('/admin/list-choice-groups'); + await page.click("text=Assign Plan"); + const assign_choice_to_plan = await page.textContent('text="Choice Group - Assign Plan"'); + expect(assign_choice_to_plan === "Choice Group - Assign Plan"); + await page.click("text=Plan with choice and options"); + await page.click("text='Save'"); + await page.textContent('.alert-heading') === "Notification"; + console.log("Choice assigned to plan"); + } //confirm choice and option plan was added await page.goto('/'); @@ -280,6 +289,7 @@ test.describe("Plan Creation tests:", () => { const expand_choice = await page.textContent('text="Choices (2 options)"'); expect(expand_choice === "Choices (2 options)"); console.log("Plan with option and choices shown in homepage"); + }); }); diff --git a/tests/browser-automated-tests-playwright/e2e/212_shop_owner_slogan_creation.spec.js b/tests/browser-automated-tests-playwright/e2e/212_shop_owner_slogan_creation.spec.js index d982c968..7f49c8ce 100644 --- a/tests/browser-automated-tests-playwright/e2e/212_shop_owner_slogan_creation.spec.js +++ b/tests/browser-automated-tests-playwright/e2e/212_shop_owner_slogan_creation.spec.js @@ -23,8 +23,7 @@ test("@212@shop-owner@slogan creation @212_shop_owner_slogan_creation", async ({ //verify home page plan creation await page.goto("/"); - await new Promise(x => setTimeout(x, 1000)); // 1 secconds + await page.reload(); const slogan_created = await page.textContent('text=this is a slogan'); expect(slogan_created === 'this is a slogan'); - // TODO screenshot cooling off plan }); \ No newline at end of file diff --git a/tests/browser-automated-tests-playwright/e2e/264_subscriber_order_plan_with_choice_options_and_required_note.spec.js b/tests/browser-automated-tests-playwright/e2e/264_subscriber_order_plan_with_choice_options_and_required_note.spec.js index 4eff77c6..a1a70595 100644 --- a/tests/browser-automated-tests-playwright/e2e/264_subscriber_order_plan_with_choice_options_and_required_note.spec.js +++ b/tests/browser-automated-tests-playwright/e2e/264_subscriber_order_plan_with_choice_options_and_required_note.spec.js @@ -91,6 +91,7 @@ test("@264@subscriber @264_subscriber_order_plan_with_choice_options_and_require await page.goto('/admin/upcoming-invoices'); // Fetch Upcoming Invoices await fetch_upcomming_invoices(page); + await page.reload(); await page.locator('css=span.plan-price-interval', {hasText: "£15.00"}).first().textContent() === '£15.00'; const content_upcoming_invoice_plan_sell_price = await page.textContent('.upcoming-invoices-plan-no-sell_price'); diff --git a/tests/browser-automated-tests-playwright/e2e/features/admin_login.js b/tests/browser-automated-tests-playwright/e2e/features/admin_login.js index a7cbf5e7..dff37cb0 100644 --- a/tests/browser-automated-tests-playwright/e2e/features/admin_login.js +++ b/tests/browser-automated-tests-playwright/e2e/features/admin_login.js @@ -3,6 +3,7 @@ var admin_login = async function (page) { await page.fill('#email', 'admin@example.com'); await page.fill('#password', 'password'); await page.click('#login'); + await page.goto(process.env['PLAYWRIGHT_HOST'] + '/admin/dashboard'); } diff --git a/tests/browser-automated-tests-playwright/e2e/features/fetch_upcomming_invoices.js b/tests/browser-automated-tests-playwright/e2e/features/fetch_upcomming_invoices.js index 7ee24aa0..9a4c8849 100644 --- a/tests/browser-automated-tests-playwright/e2e/features/fetch_upcomming_invoices.js +++ b/tests/browser-automated-tests-playwright/e2e/features/fetch_upcomming_invoices.js @@ -1,9 +1,10 @@ var fetch_upcomming_invoices = async function (page) { // Go to upcoming payments and ensure plan is attached to upcoming invoice await page.goto('/admin/upcoming-invoices'); - await new Promise(x => setTimeout(x, 25000)); + await new Promise(x => setTimeout(x, 35000)); await page.click('#fetch_upcoming_invoices'); - await new Promise(x => setTimeout(x, 20000)); + await new Promise(x => setTimeout(x, 30000)); + await page.reload(); } module.exports.fetch_upcomming_invoices = fetch_upcomming_invoices; \ No newline at end of file