From 9a51654a7623da6ebade0afb19e5fa991fb73e2b Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Wed, 12 Feb 2025 11:20:18 +0000 Subject: [PATCH 01/32] Add fix from PR #101 --- cms/settings/dev.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cms/settings/dev.py b/cms/settings/dev.py index 45efd866..cd90c383 100644 --- a/cms/settings/dev.py +++ b/cms/settings/dev.py @@ -57,7 +57,12 @@ DATABASES["read_replica"] = copy.deepcopy(DATABASES["default"]) # Redis -REDIS_URL = "redis://localhost:6379" +REDIS_URL = env.get("REDIS_URL", "redis://localhost:6379") # noqa: F405 +CACHES["default"] = { # noqa: F405 + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": REDIS_URL, + "OPTIONS": {**redis_options}, # noqa: F405 +} # Django Defender ENABLE_DJANGO_DEFENDER = False From 98ba8a41a15544cb7ce6d7de04938c97d1eaa854 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Thu, 13 Feb 2025 10:17:16 +0000 Subject: [PATCH 02/32] Added the test --- .../features/methodology_page.feature | 54 ++++++++++ functional_tests/steps/article_page.py | 10 ++ functional_tests/steps/methodology_page.py | 100 ++++++++++++++++++ functional_tests/steps/theme_page.py | 9 ++ functional_tests/steps/topic_page.py | 9 ++ 5 files changed, 182 insertions(+) create mode 100644 functional_tests/features/methodology_page.feature create mode 100644 functional_tests/steps/article_page.py create mode 100644 functional_tests/steps/methodology_page.py create mode 100644 functional_tests/steps/theme_page.py create mode 100644 functional_tests/steps/topic_page.py diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature new file mode 100644 index 00000000..b76d031f --- /dev/null +++ b/functional_tests/features/methodology_page.feature @@ -0,0 +1,54 @@ +Feature: A general use of Methodology Page + + Scenario: A CMS user can create and publish a Methodology Page + Given a theme page exists + And a topic page exists as a child of the existing theme page + And a CMS user logs into the admin site + When the user creates a methodology page as a child of the existing topic page + And the user populates the methodology page + And the user clicks publish page + And the user clicks "View Live" on the publish confirmation banner + Then the published methodology page is displayed with the populated data + + Scenario: A CMS user can add a published statistical articles in the Related publication section of the Methodology page + Given a theme page exists + And a topic page exists as a child of the existing theme page + And a statistical article page has been published under the existing theme page + And a CMS user logs into the admin site + When the user creates a methodology page as a child of the existing topic page + And the user populates the methodology page + And the user selects the article page in the Related publications block + And the user clicks publish page + And the user clicks "View Live" on the publish confirmation banner + Then the article is displayed correctly under the Related publication section + + Scenario: A CMS user can add a Contact Details snippet on the Methodology page + Given a theme page exists + And a topic page exists as a child of the existing theme page + And a contact details snippet exists + And a CMS user logs into the admin site + When the user creates a methodology page as a child of the existing topic page + And the user populates the methodology page + And the user selects the Contact Details + And the user clicks publish page + And the user clicks "View Live" on the publish confirmation banner + Then the Contact Details are visible on the page + + Scenario: The mandatory fields raise validation errors when left empty on the Methodology page. + Given a theme page exists + And a topic page exists as a child of the existing theme page + And a CMS user logs into the admin site + When the user creates a methodology page as a child of the existing topic page + And the user clicks Save draft + Then the mandatory fields raise a validation error + + Scenario: The Last revised date field has appropriate validation on Methodology page. + Given a theme page exists + And a topic page exists as a child of the existing theme page + And a CMS user logs into the admin site + When the user creates a methodology page as a child of the existing topic page + And the user populates the methodology page + And the Last revised date is set to be before the Publication date + And the user clicks Save draft + Then a validation error for the Last revised date is displayed + diff --git a/functional_tests/steps/article_page.py b/functional_tests/steps/article_page.py new file mode 100644 index 00000000..d416dbda --- /dev/null +++ b/functional_tests/steps/article_page.py @@ -0,0 +1,10 @@ +from behave import given +from behave.runner import Context + +from cms.articles.tests.factories import ArticleSeriesFactory, StatisticalArticlePageFactory + + +@given("a statistical article page has been published under the existing theme page") +def create_article_page(context: Context): + context.article_series = ArticleSeriesFactory(parent=context.topic_page) + context.statistical_article = StatisticalArticlePageFactory(parent=context.article_series) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py new file mode 100644 index 00000000..2120d6f9 --- /dev/null +++ b/functional_tests/steps/methodology_page.py @@ -0,0 +1,100 @@ +from behave import then, when +from behave.runner import Context +from playwright.sync_api import expect + + +@when("the user creates a methodology page as a child of the existing topic page") +def user_creates_methodology_page(context: Context): + context.page.get_by_role("button", name="Pages").click() + context.page.get_by_role("link", name="View child pages of 'Home'").click() + context.page.get_by_role("link", name=f"View child pages of '{context.theme_page.title}'").click() + context.page.get_by_role("link", name=f"Edit '{context.topic_page.title}'").click() + context.page.get_by_role("button", name="Actions", exact=True).click() + context.page.get_by_label(f"Add a child page to '{context.topic_page.title}'").click() + context.page.get_by_role("link", name="Methodology page", exact=True).click() + + +@when("the user populates the methodology page") +def user_populates_the_methodology_page(context: Context): + context.page.get_by_placeholder("Page title*").fill("Methodology page") + context.page.get_by_role("region", name="Summary*").get_by_role("textbox").fill("Page summary") + + context.page.get_by_label("Publication date*").fill("1950-01-01") + + context.page.get_by_title("Insert a block").click() + context.page.get_by_label("Section heading*").fill("Heading") + context.page.locator("#panel-child-content-content-content").get_by_role("region").get_by_role( + "button", name="Insert a block" + ).click() + context.page.get_by_text("Rich text").click() + context.page.get_by_role("region", name="Rich text *").get_by_role("textbox").fill("Content") + + +@then("the published methodology page is displayed with the populated data") +def the_methodology_page_is_displayed_correctly(context: Context): + expect(context.page.get_by_role("heading", name="Methodology page")).to_be_visible() + + expect(context.page.get_by_text("Page summary")).to_be_visible() + + expect(context.page.get_by_text("Published: 1 January 1950")).to_be_visible() + + expect(context.page.get_by_role("heading", name="Cite this methodology")).to_be_visible() + + +@when("the user selects the article page in the Related publications block") +def the_user_selects_statistical_articles_as_related_publications(context: Context): + context.page.get_by_role("button", name="Add related publications").click() + context.page.get_by_role("button", name="Choose a page (Statistical").click() + context.page.get_by_role( + "cell", name=f"{context.article_series.title}: {context.statistical_article.title}" + ).click() + + +@then("the article is displayed correctly under the Related publication section") +def related_publications_are_displayed_correctly(context: Context): + expect(context.page.get_by_role("heading", name="Related publications")).to_be_visible() + expect(context.page.locator("li").filter(has_text=f"{context.topic_page.title}")).to_be_visible() + + +@when("the user selects the Contact Details") +def user_selects_the_contact_details(context: Context): + context.page.get_by_role("button", name="Choose contact details").click() + context.page.get_by_role("link", name=context.contact_details_snippet.name).click() + + +@then("the Contact Details are visible on the page") +def contact_details_are_visible_on_the_page(context: Context): + # in the header + expect(context.page.get_by_text(f"Contact: {context.contact_details_snippet.name}")).to_be_visible() + # in the section + expect(context.page.get_by_role("heading", name="Contact details")).to_be_visible() + expect(context.page.get_by_text(f"Name: {context.contact_details_snippet.name}")).to_be_visible() + expect(context.page.get_by_text(f"Email: {context.contact_details_snippet.email}")).to_be_visible() + + +@when("the Last revised date is set to be before the Publication date") +def set_last_revised_date_before_publication_date(context: Context): + context.page.get_by_label("Publication date*").fill("1950-01-02") + context.page.get_by_label("Last revised date").fill("1950-01-01") + + +@then("a validation error for the Last revised date is displayed") +def validation_error_displayed_when_incorrect_date_selected(context: Context): + expect(context.page.get_by_text("The last revised date must be after the published date.")).to_be_visible() + + +@then("the mandatory fields raise a validation error") +def mandatory_fields_raise_validation_error_when_not_set(context: Context): + expect(context.page.get_by_text("The page could not be created due to validation errors")).to_be_visible() + + expect(context.page.locator("#panel-child-content-child-title-errors")).to_be_visible() + expect(context.page.locator("#panel-child-content-child-summary-errors")).to_be_visible() + expect( + context.page.locator("#panel-child-content-child-metadata-child-panel-child-publication_date-errors") + ).to_be_visible() + expect(context.page.locator(".help-block.help-critical").get_by_text("This field is required")) + + +@when("the user clicks Save draft") +def user_saves_draft(context: Context): + context.page.get_by_role("button", name="Save draft").click() diff --git a/functional_tests/steps/theme_page.py b/functional_tests/steps/theme_page.py new file mode 100644 index 00000000..4c9ea298 --- /dev/null +++ b/functional_tests/steps/theme_page.py @@ -0,0 +1,9 @@ +from behave import given +from behave.runner import Context + +from cms.themes.tests.factories import ThemePageFactory + + +@given("a theme page exists") +def a_theme_page_already_exists(context: Context): + context.theme_page = ThemePageFactory() diff --git a/functional_tests/steps/topic_page.py b/functional_tests/steps/topic_page.py new file mode 100644 index 00000000..f061fe88 --- /dev/null +++ b/functional_tests/steps/topic_page.py @@ -0,0 +1,9 @@ +from behave import given +from behave.runner import Context + +from cms.topics.tests.factories import TopicPageFactory + + +@given("a topic page exists as a child of the existing theme page") +def a_topic_page_already_exists_under_theme_page(context: Context): + context.topic_page = TopicPageFactory(parent=context.theme_page) From bfba37ffcb47ce93857f17ae3eeaaced3174be6a Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Thu, 13 Feb 2025 10:23:51 +0000 Subject: [PATCH 03/32] Ignore pylint errors --- functional_tests/steps/article_page.py | 2 +- functional_tests/steps/methodology_page.py | 2 +- functional_tests/steps/theme_page.py | 2 +- functional_tests/steps/topic_page.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/functional_tests/steps/article_page.py b/functional_tests/steps/article_page.py index d416dbda..e33268d8 100644 --- a/functional_tests/steps/article_page.py +++ b/functional_tests/steps/article_page.py @@ -1,4 +1,4 @@ -from behave import given +from behave import given # pylint: disable=no-name-in-module from behave.runner import Context from cms.articles.tests.factories import ArticleSeriesFactory, StatisticalArticlePageFactory diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 2120d6f9..893b969e 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -1,4 +1,4 @@ -from behave import then, when +from behave import then, when # pylint: disable=no-name-in-module from behave.runner import Context from playwright.sync_api import expect diff --git a/functional_tests/steps/theme_page.py b/functional_tests/steps/theme_page.py index 4c9ea298..e55af9f3 100644 --- a/functional_tests/steps/theme_page.py +++ b/functional_tests/steps/theme_page.py @@ -1,4 +1,4 @@ -from behave import given +from behave import given # pylint: disable=no-name-in-module from behave.runner import Context from cms.themes.tests.factories import ThemePageFactory diff --git a/functional_tests/steps/topic_page.py b/functional_tests/steps/topic_page.py index f061fe88..95b9ae57 100644 --- a/functional_tests/steps/topic_page.py +++ b/functional_tests/steps/topic_page.py @@ -1,4 +1,4 @@ -from behave import given +from behave import given # pylint: disable=no-name-in-module from behave.runner import Context from cms.topics.tests.factories import TopicPageFactory From 651fd5c9cb0d298fcf48f0bb426742937a04c6fe Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Thu, 13 Feb 2025 12:02:01 +0000 Subject: [PATCH 04/32] Make them pass --- functional_tests/features/methodology_page.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index b76d031f..c6c441a7 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -36,7 +36,7 @@ Feature: A general use of Methodology Page Scenario: The mandatory fields raise validation errors when left empty on the Methodology page. Given a theme page exists - And a topic page exists as a child of the existing theme page + And a topic page exists as a child of the existing theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user clicks Save draft From d49d9f26cff5d3f5d938ce7ccee9b3b58b5b1c0c Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Thu, 13 Feb 2025 16:56:22 +0000 Subject: [PATCH 05/32] Fix an issue with tests failing in headless and passing in headed mode --- functional_tests/steps/methodology_page.py | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 893b969e..112e62aa 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -87,12 +87,27 @@ def validation_error_displayed_when_incorrect_date_selected(context: Context): def mandatory_fields_raise_validation_error_when_not_set(context: Context): expect(context.page.get_by_text("The page could not be created due to validation errors")).to_be_visible() - expect(context.page.locator("#panel-child-content-child-title-errors")).to_be_visible() - expect(context.page.locator("#panel-child-content-child-summary-errors")).to_be_visible() expect( - context.page.locator("#panel-child-content-child-metadata-child-panel-child-publication_date-errors") + context.page.locator("#panel-child-content-child-title-errors .error-message").get_by_text( + "This field is required" + ) + ).to_be_visible() + + expect( + context.page.locator("#panel-child-content-child-summary-errors .error-message").get_by_text( + "This field is required" + ) + ) + + expect( + context.page.locator( + "#panel-child-content-child-metadata-child-panel-child-publication_date-errors .error-message" + ).get_by_text("This field is required") + ).to_be_visible() + + expect( + context.page.locator(".help-block.help-critical").get_by_text("This field is required") ).to_be_visible() - expect(context.page.locator(".help-block.help-critical").get_by_text("This field is required")) @when("the user clicks Save draft") From eea9a2f35d4a3f6779f9778847ead590eaf5e37e Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 14 Feb 2025 09:57:43 +0000 Subject: [PATCH 06/32] Rewording to match steps pulled from main --- .../features/information_page.feature | 2 +- .../features/methodology_page.feature | 22 +++++++++---------- .../features/release_page.feature | 2 +- functional_tests/steps/article_page.py | 10 --------- functional_tests/steps/articles.py | 8 ++++++- functional_tests/steps/methodology_page.py | 4 ---- functional_tests/steps/page_editor.py | 2 +- 7 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 functional_tests/steps/article_page.py diff --git a/functional_tests/features/information_page.feature b/functional_tests/features/information_page.feature index 2be35620..40576648 100644 --- a/functional_tests/features/information_page.feature +++ b/functional_tests/features/information_page.feature @@ -5,7 +5,7 @@ Feature: A general use information page When the user navigates to the pages menu And the user clicks add child page and chooses information page type And the user adds content to the new information page - And the user clicks publish page + And the user clicks "Publish page" And the user clicks "View Live" on the publish confirmation banner Then the new information page with the added content is displayed And the user can see the breadcrumbs diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index c6c441a7..d7f0ed52 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -2,53 +2,53 @@ Feature: A general use of Methodology Page Scenario: A CMS user can create and publish a Methodology Page Given a theme page exists - And a topic page exists as a child of the existing theme page + And a topic page exists And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page - And the user clicks publish page + And the user clicks "Publish page" And the user clicks "View Live" on the publish confirmation banner Then the published methodology page is displayed with the populated data Scenario: A CMS user can add a published statistical articles in the Related publication section of the Methodology page Given a theme page exists - And a topic page exists as a child of the existing theme page - And a statistical article page has been published under the existing theme page + And a topic page exists + And the user has created a statistical article in a series And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page And the user selects the article page in the Related publications block - And the user clicks publish page + And the user clicks "Publish page" And the user clicks "View Live" on the publish confirmation banner Then the article is displayed correctly under the Related publication section Scenario: A CMS user can add a Contact Details snippet on the Methodology page Given a theme page exists - And a topic page exists as a child of the existing theme page + And a topic page exists And a contact details snippet exists And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page And the user selects the Contact Details - And the user clicks publish page + And the user clicks "Publish page" And the user clicks "View Live" on the publish confirmation banner Then the Contact Details are visible on the page Scenario: The mandatory fields raise validation errors when left empty on the Methodology page. Given a theme page exists - And a topic page exists as a child of the existing theme page + And a topic page exists And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page - And the user clicks Save draft + And clicks the "Save Draft" button Then the mandatory fields raise a validation error Scenario: The Last revised date field has appropriate validation on Methodology page. Given a theme page exists - And a topic page exists as a child of the existing theme page + And a topic page exists And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page And the Last revised date is set to be before the Publication date - And the user clicks Save draft + And clicks the "Save Draft" button Then a validation error for the Last revised date is displayed diff --git a/functional_tests/features/release_page.feature b/functional_tests/features/release_page.feature index 72894819..630b9cb3 100644 --- a/functional_tests/features/release_page.feature +++ b/functional_tests/features/release_page.feature @@ -7,7 +7,7 @@ Feature: CMS users can draft, edit, and publish release pages And clicks "add child page" to create a new draft release page And the user sets the page status to "Published" And enters some example content on the page - And the user clicks publish page + And the user clicks "Publish page" And the user clicks "View Live" on the publish confirmation banner Then the new published release page with the example content is displayed And the user can see the breadcrumbs diff --git a/functional_tests/steps/article_page.py b/functional_tests/steps/article_page.py deleted file mode 100644 index e33268d8..00000000 --- a/functional_tests/steps/article_page.py +++ /dev/null @@ -1,10 +0,0 @@ -from behave import given # pylint: disable=no-name-in-module -from behave.runner import Context - -from cms.articles.tests.factories import ArticleSeriesFactory, StatisticalArticlePageFactory - - -@given("a statistical article page has been published under the existing theme page") -def create_article_page(context: Context): - context.article_series = ArticleSeriesFactory(parent=context.topic_page) - context.statistical_article = StatisticalArticlePageFactory(parent=context.article_series) diff --git a/functional_tests/steps/articles.py b/functional_tests/steps/articles.py index b938b100..dc86ba20 100644 --- a/functional_tests/steps/articles.py +++ b/functional_tests/steps/articles.py @@ -7,9 +7,15 @@ @given("the user creates a new article series") @given("the user has created a statistical article in a series") def create_article_series(context: Context): - context.article_series = ArticleSeriesPageFactory() + context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) @when("the user creates a new statistical article in the series") def create_article_in_series(context: Context): context.article = StatisticalArticlePageFactory(title="January 2025", parent=context.article_series) + + +@given("a statistical article page has been published under the existing theme page") +def create_article_page(context: Context): + context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) + context.statistical_article = StatisticalArticlePageFactory(parent=context.article_series) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 112e62aa..b6846339 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -109,7 +109,3 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): context.page.locator(".help-block.help-critical").get_by_text("This field is required") ).to_be_visible() - -@when("the user clicks Save draft") -def user_saves_draft(context: Context): - context.page.get_by_role("button", name="Save draft").click() diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index b4e72ca4..510d7e67 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -3,7 +3,7 @@ from django.urls import reverse -@when("the user clicks publish page") +@when('the user clicks "Publish page"') @when("publishes the page") def user_clicks_publish_page(context: Context) -> None: context.page.get_by_role("button", name="More actions").click() From 87625be5395f3c5edec1fcdc3d300b7d1819cea9 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 14 Feb 2025 10:48:44 +0000 Subject: [PATCH 07/32] Formatting + rewording --- functional_tests/features/methodology_page.feature | 12 ++++++------ functional_tests/steps/methodology_page.py | 5 +---- functional_tests/steps/topic_page.py | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index d7f0ed52..c73df345 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -2,7 +2,7 @@ Feature: A general use of Methodology Page Scenario: A CMS user can create and publish a Methodology Page Given a theme page exists - And a topic page exists + And a topic page exists under the theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page @@ -12,8 +12,8 @@ Feature: A general use of Methodology Page Scenario: A CMS user can add a published statistical articles in the Related publication section of the Methodology page Given a theme page exists - And a topic page exists - And the user has created a statistical article in a series + And a topic page exists under the theme page + And a statistical article page has been published under the existing theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page @@ -24,7 +24,7 @@ Feature: A general use of Methodology Page Scenario: A CMS user can add a Contact Details snippet on the Methodology page Given a theme page exists - And a topic page exists + And a topic page exists under the theme page And a contact details snippet exists And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page @@ -36,7 +36,7 @@ Feature: A general use of Methodology Page Scenario: The mandatory fields raise validation errors when left empty on the Methodology page. Given a theme page exists - And a topic page exists + And a topic page exists under the theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And clicks the "Save Draft" button @@ -44,7 +44,7 @@ Feature: A general use of Methodology Page Scenario: The Last revised date field has appropriate validation on Methodology page. Given a theme page exists - And a topic page exists + And a topic page exists under the theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index b6846339..aff6776e 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -105,7 +105,4 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): ).get_by_text("This field is required") ).to_be_visible() - expect( - context.page.locator(".help-block.help-critical").get_by_text("This field is required") - ).to_be_visible() - + expect(context.page.locator(".help-block.help-critical").get_by_text("This field is required")).to_be_visible() diff --git a/functional_tests/steps/topic_page.py b/functional_tests/steps/topic_page.py index eb3d890b..d6665ebc 100644 --- a/functional_tests/steps/topic_page.py +++ b/functional_tests/steps/topic_page.py @@ -11,6 +11,11 @@ def a_topic_page_exists(context: Context): context.topic_page = TopicPageFactory(title="Public Sector Finance") +@given("a topic page exists under the theme page") +def a_topic_page_exists_under_theme_page(context: Context): + context.topic_page = TopicPageFactory(parent=context.theme_page) + + @given("the topic page has a statistical article in a series") def the_topic_page_has_a_statistical_article_in_a_series(context: Context): context.article_series = ArticleSeriesPageFactory(title="PSF") From 8f9754ff864823bd90a31171a2353379f2d33b4f Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 14 Feb 2025 10:57:20 +0000 Subject: [PATCH 08/32] Revert a change to make tests pass --- functional_tests/steps/articles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/steps/articles.py b/functional_tests/steps/articles.py index dc86ba20..da52ec0d 100644 --- a/functional_tests/steps/articles.py +++ b/functional_tests/steps/articles.py @@ -7,7 +7,7 @@ @given("the user creates a new article series") @given("the user has created a statistical article in a series") def create_article_series(context: Context): - context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) + context.article_series = ArticleSeriesPageFactory() @when("the user creates a new statistical article in the series") From d2f07a6b4858700bec952503a37eaaf3fd4fd4d9 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 14 Feb 2025 12:37:34 +0000 Subject: [PATCH 09/32] A bunch of improvements --- .../features/methodology_page.feature | 17 ++++++----------- functional_tests/features/topic_page.feature | 5 ++--- functional_tests/steps/articles.py | 14 +++----------- functional_tests/steps/methodology_page.py | 2 +- functional_tests/steps/topic_page.py | 15 ++++++++------- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index c73df345..5a904e9d 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -1,8 +1,7 @@ Feature: A general use of Methodology Page Scenario: A CMS user can create and publish a Methodology Page - Given a theme page exists - And a topic page exists under the theme page + Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page @@ -11,9 +10,8 @@ Feature: A general use of Methodology Page Then the published methodology page is displayed with the populated data Scenario: A CMS user can add a published statistical articles in the Related publication section of the Methodology page - Given a theme page exists - And a topic page exists under the theme page - And a statistical article page has been published under the existing theme page + Given a topic page exists under a theme page + And the user has created a statistical article in a series And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page @@ -23,8 +21,7 @@ Feature: A general use of Methodology Page Then the article is displayed correctly under the Related publication section Scenario: A CMS user can add a Contact Details snippet on the Methodology page - Given a theme page exists - And a topic page exists under the theme page + Given a topic page exists under a theme page And a contact details snippet exists And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page @@ -35,16 +32,14 @@ Feature: A general use of Methodology Page Then the Contact Details are visible on the page Scenario: The mandatory fields raise validation errors when left empty on the Methodology page. - Given a theme page exists - And a topic page exists under the theme page + Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And clicks the "Save Draft" button Then the mandatory fields raise a validation error Scenario: The Last revised date field has appropriate validation on Methodology page. - Given a theme page exists - And a topic page exists under the theme page + Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page diff --git a/functional_tests/features/topic_page.feature b/functional_tests/features/topic_page.feature index 2f596e1e..5dc52888 100644 --- a/functional_tests/features/topic_page.feature +++ b/functional_tests/features/topic_page.feature @@ -8,7 +8,7 @@ Feature: CMS users can draft, edit, and publish topic pages And clicks the "Choose Article Series page" button And the user selects the article series And publishes the page - And visits the topic page + And the user visits the topic page Then the topic page with the example content is displayed And the user can see the topic page featured article @@ -16,6 +16,5 @@ Feature: CMS users can draft, edit, and publish topic pages Given a topic page exists And the user has created a statistical article in a series And the user has featured the series - When the user creates a new statistical article in the series - And visits the topic page + When the user visits the topic page Then the user can see the newly created article in featured spot diff --git a/functional_tests/steps/articles.py b/functional_tests/steps/articles.py index da52ec0d..18f53d4c 100644 --- a/functional_tests/steps/articles.py +++ b/functional_tests/steps/articles.py @@ -4,18 +4,10 @@ from cms.articles.tests.factories import ArticleSeriesPageFactory, StatisticalArticlePageFactory -@given("the user creates a new article series") @given("the user has created a statistical article in a series") -def create_article_series(context: Context): - context.article_series = ArticleSeriesPageFactory() - - -@when("the user creates a new statistical article in the series") -def create_article_in_series(context: Context): +@given("a statistical article page has been published under the topic page") +def create_article_in_a_series(context: Context): + context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) context.article = StatisticalArticlePageFactory(title="January 2025", parent=context.article_series) -@given("a statistical article page has been published under the existing theme page") -def create_article_page(context: Context): - context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) - context.statistical_article = StatisticalArticlePageFactory(parent=context.article_series) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index aff6776e..2ea3b698 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -46,7 +46,7 @@ def the_user_selects_statistical_articles_as_related_publications(context: Conte context.page.get_by_role("button", name="Add related publications").click() context.page.get_by_role("button", name="Choose a page (Statistical").click() context.page.get_by_role( - "cell", name=f"{context.article_series.title}: {context.statistical_article.title}" + "cell", name=f"{context.article_series.title}: {context.article.title}" ).click() diff --git a/functional_tests/steps/topic_page.py b/functional_tests/steps/topic_page.py index d6665ebc..41613daf 100644 --- a/functional_tests/steps/topic_page.py +++ b/functional_tests/steps/topic_page.py @@ -3,6 +3,7 @@ from playwright.sync_api import expect from cms.articles.tests.factories import ArticleSeriesPageFactory, StatisticalArticlePageFactory +from cms.themes.tests.factories import ThemePageFactory from cms.topics.tests.factories import TopicPageFactory @@ -10,9 +11,9 @@ def a_topic_page_exists(context: Context): context.topic_page = TopicPageFactory(title="Public Sector Finance") - -@given("a topic page exists under the theme page") -def a_topic_page_exists_under_theme_page(context: Context): +@given("a topic page exists under a theme page") +def the_user_creates_theme_and_topic_pages(context: Context): + context.theme_page = ThemePageFactory() context.topic_page = TopicPageFactory(parent=context.theme_page) @@ -28,14 +29,14 @@ def the_user_has_featured_the_series(context: Context): context.topic_page.save_revision().publish() -@when("visits the topic page") +@when("the user visits the topic page") def visit_topic_page(context: Context): context.page.goto(f"{context.base_url}{context.topic_page.url}") @when("the user selects the article series") def the_user_select_article_series(context: Context): - context.page.get_by_role("link", name="PSF", exact=True).click() + context.page.get_by_role("link", name=context.article_series.title, exact=True).click() @then("the topic page with the example content is displayed") @@ -53,5 +54,5 @@ def user_sees_featured_article(context: Context): @then("the user can see the newly created article in featured spot") def user_sees_newly_featured_article(context: Context): expect(context.page.get_by_role("heading", name="Featured")).to_be_visible() - expect(context.page.get_by_text(context.article.display_title)).to_be_visible() - expect(context.page.get_by_text(context.article.main_points_summary)).to_be_visible() + expect(context.page.locator("#featured").get_by_text(context.article.display_title)).to_be_visible() + expect(context.page.locator("#featured").get_by_text(context.article.main_points_summary)).to_be_visible() From 9da95a6d9d3ccbcb65b26c5db3bb7a6eee6e7367 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 14 Feb 2025 13:05:42 +0000 Subject: [PATCH 10/32] Remove no longer needed file for theme page set up --- functional_tests/steps/articles.py | 4 +--- functional_tests/steps/methodology_page.py | 18 +++++++++++++++--- functional_tests/steps/theme_page.py | 9 --------- functional_tests/steps/topic_page.py | 1 + 4 files changed, 17 insertions(+), 15 deletions(-) delete mode 100644 functional_tests/steps/theme_page.py diff --git a/functional_tests/steps/articles.py b/functional_tests/steps/articles.py index 18f53d4c..ce23c986 100644 --- a/functional_tests/steps/articles.py +++ b/functional_tests/steps/articles.py @@ -1,4 +1,4 @@ -from behave import given, when # pylint: disable=no-name-in-module +from behave import given # pylint: disable=no-name-in-module from behave.runner import Context from cms.articles.tests.factories import ArticleSeriesPageFactory, StatisticalArticlePageFactory @@ -9,5 +9,3 @@ def create_article_in_a_series(context: Context): context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) context.article = StatisticalArticlePageFactory(title="January 2025", parent=context.article_series) - - diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 2ea3b698..57d86324 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -45,9 +45,7 @@ def the_methodology_page_is_displayed_correctly(context: Context): def the_user_selects_statistical_articles_as_related_publications(context: Context): context.page.get_by_role("button", name="Add related publications").click() context.page.get_by_role("button", name="Choose a page (Statistical").click() - context.page.get_by_role( - "cell", name=f"{context.article_series.title}: {context.article.title}" - ).click() + context.page.get_by_role("cell", name=f"{context.article_series.title}: {context.article.title}").click() @then("the article is displayed correctly under the Related publication section") @@ -106,3 +104,17 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): ).to_be_visible() expect(context.page.locator(".help-block.help-critical").get_by_text("This field is required")).to_be_visible() + + +@then("the preview is visible with the populated data") +def preview_is_visible(context: Context): + context.page.locator(".w-preview__size-button > .icon > use").first.click() + expect( + context.page.locator('iframe[title="Preview"]').content_frame.get_by_role( + "heading", name="Cite this methodology" + ) + ).to_be_visible() + + # expect( + # context.page.locator('iframe[title="Preview"]').content_frame.get_by_role("heading", name=) + # ).to_be_visible() diff --git a/functional_tests/steps/theme_page.py b/functional_tests/steps/theme_page.py deleted file mode 100644 index e55af9f3..00000000 --- a/functional_tests/steps/theme_page.py +++ /dev/null @@ -1,9 +0,0 @@ -from behave import given # pylint: disable=no-name-in-module -from behave.runner import Context - -from cms.themes.tests.factories import ThemePageFactory - - -@given("a theme page exists") -def a_theme_page_already_exists(context: Context): - context.theme_page = ThemePageFactory() diff --git a/functional_tests/steps/topic_page.py b/functional_tests/steps/topic_page.py index 41613daf..731bef2d 100644 --- a/functional_tests/steps/topic_page.py +++ b/functional_tests/steps/topic_page.py @@ -11,6 +11,7 @@ def a_topic_page_exists(context: Context): context.topic_page = TopicPageFactory(title="Public Sector Finance") + @given("a topic page exists under a theme page") def the_user_creates_theme_and_topic_pages(context: Context): context.theme_page = ThemePageFactory() From fa52b9177156198c07753d4ba65e68cd75697e76 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 14 Feb 2025 13:35:39 +0000 Subject: [PATCH 11/32] Remove duplicated step definition --- functional_tests/features/topic_page.feature | 4 ++-- functional_tests/steps/topic_page.py | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/functional_tests/features/topic_page.feature b/functional_tests/features/topic_page.feature index 5dc52888..b66eefdf 100644 --- a/functional_tests/features/topic_page.feature +++ b/functional_tests/features/topic_page.feature @@ -2,7 +2,7 @@ Feature: CMS users can draft, edit, and publish topic pages Scenario: A CMS user can feature an article series Given a CMS user logs into the admin site - And a topic page exists + And a topic page exists under a theme page And the topic page has a statistical article in a series When the user edits the topic page And clicks the "Choose Article Series page" button @@ -13,7 +13,7 @@ Feature: CMS users can draft, edit, and publish topic pages And the user can see the topic page featured article Scenario: The feature series on a topic page displays the latest article - Given a topic page exists + Given a topic page exists under a theme page And the user has created a statistical article in a series And the user has featured the series When the user visits the topic page diff --git a/functional_tests/steps/topic_page.py b/functional_tests/steps/topic_page.py index 731bef2d..45550d83 100644 --- a/functional_tests/steps/topic_page.py +++ b/functional_tests/steps/topic_page.py @@ -7,15 +7,10 @@ from cms.topics.tests.factories import TopicPageFactory -@given("a topic page exists") -def a_topic_page_exists(context: Context): - context.topic_page = TopicPageFactory(title="Public Sector Finance") - - @given("a topic page exists under a theme page") def the_user_creates_theme_and_topic_pages(context: Context): context.theme_page = ThemePageFactory() - context.topic_page = TopicPageFactory(parent=context.theme_page) + context.topic_page = TopicPageFactory(parent=context.theme_page, title="Public Sector Finance") @given("the topic page has a statistical article in a series") From 4b8c769536f5fc3da6b8682fecea2774a629d94e Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 17 Feb 2025 12:46:07 +0000 Subject: [PATCH 12/32] Add missing assertion --- functional_tests/steps/methodology_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 57d86324..8acdf6d7 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -95,7 +95,7 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): context.page.locator("#panel-child-content-child-summary-errors .error-message").get_by_text( "This field is required" ) - ) + ).to_be_visible() expect( context.page.locator( From 45d784bd05183344e6e2a5433cff89b90796ca4a Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 17 Feb 2025 15:17:06 +0000 Subject: [PATCH 13/32] Topic page test fix --- functional_tests/features/topic_page.feature | 5 +++-- functional_tests/steps/articles.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/functional_tests/features/topic_page.feature b/functional_tests/features/topic_page.feature index b66eefdf..d685e9da 100644 --- a/functional_tests/features/topic_page.feature +++ b/functional_tests/features/topic_page.feature @@ -12,9 +12,10 @@ Feature: CMS users can draft, edit, and publish topic pages Then the topic page with the example content is displayed And the user can see the topic page featured article - Scenario: The feature series on a topic page displays the latest article + Scenario: The featured series on a topic page displays the latest article Given a topic page exists under a theme page And the user has created a statistical article in a series And the user has featured the series - When the user visits the topic page + When the user creates a new statistical article in the series + And the user visits the topic page Then the user can see the newly created article in featured spot diff --git a/functional_tests/steps/articles.py b/functional_tests/steps/articles.py index ce23c986..3558877e 100644 --- a/functional_tests/steps/articles.py +++ b/functional_tests/steps/articles.py @@ -1,4 +1,6 @@ -from behave import given # pylint: disable=no-name-in-module +from datetime import timedelta + +from behave import given, when # pylint: disable=no-name-in-module from behave.runner import Context from cms.articles.tests.factories import ArticleSeriesPageFactory, StatisticalArticlePageFactory @@ -8,4 +10,12 @@ @given("a statistical article page has been published under the topic page") def create_article_in_a_series(context: Context): context.article_series = ArticleSeriesPageFactory(parent=context.topic_page) - context.article = StatisticalArticlePageFactory(title="January 2025", parent=context.article_series) + context.article = StatisticalArticlePageFactory(parent=context.article_series) + + +@when("the user creates a new statistical article in the series") +def create_a_new_article_in_the_series(context: Context): + old_article_release_date = context.article.release_date + context.article = StatisticalArticlePageFactory( + title="January 2025", release_date=old_article_release_date + timedelta(days=1), parent=context.article_series + ) From 3a63889d7418b0b6203de855d1deff43bae5a9ae Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 17 Feb 2025 15:40:54 +0000 Subject: [PATCH 14/32] Added missing checks + where I got with testing preview (failing so commented out) --- .../features/methodology_page.feature | 7 ++++++ functional_tests/steps/methodology_page.py | 25 ++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index 5a904e9d..e23441c2 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -47,3 +47,10 @@ Feature: A general use of Methodology Page And clicks the "Save Draft" button Then a validation error for the Last revised date is displayed + Scenario: A CMS user can create and preview the Methodology page + Given a topic page exists under a theme page + And a CMS user logs into the admin site + When the user creates a methodology page as a child of the existing topic page + And the user populates the methodology page + And clicks the "Save Draft" button + Then the preview is visible with the populated data diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 8acdf6d7..feab5e77 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -33,13 +33,13 @@ def user_populates_the_methodology_page(context: Context): @then("the published methodology page is displayed with the populated data") def the_methodology_page_is_displayed_correctly(context: Context): expect(context.page.get_by_role("heading", name="Methodology page")).to_be_visible() - expect(context.page.get_by_text("Page summary")).to_be_visible() - expect(context.page.get_by_text("Published: 1 January 1950")).to_be_visible() - expect(context.page.get_by_role("heading", name="Cite this methodology")).to_be_visible() + expect(context.page.get_by_role("heading", name="Heading")).to_be_visible() + expect(context.page.get_by_role("heading", name="Content")).to_be_visible() + @when("the user selects the article page in the Related publications block") def the_user_selects_statistical_articles_as_related_publications(context: Context): @@ -108,13 +108,14 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): @then("the preview is visible with the populated data") def preview_is_visible(context: Context): - context.page.locator(".w-preview__size-button > .icon > use").first.click() - expect( - context.page.locator('iframe[title="Preview"]').content_frame.get_by_role( - "heading", name="Cite this methodology" - ) - ).to_be_visible() + context.page.get_by_role("button", name="Toggle preview").click() + + # iframe_locator = context.page.frame_locator("#w-preview-iframe") + + # expect(iframe_locator.get_by_role("heading", name="Methodology page")).to_be_visible() + # expect(iframe_locator.get_by_text("Page summary")).to_be_visible() + # expect(iframe_locator.get_by_text("Published: 1 January 1950")).to_be_visible() + # expect(iframe_locator.get_by_role("heading", name="Cite this methodology")).to_be_visible() + # expect(iframe_locator.get_by_role("heading", name="Heading")).to_be_visible() + # expect(iframe_locator.page.get_by_role("heading", name="Content")).to_be_visible() - # expect( - # context.page.locator('iframe[title="Preview"]').content_frame.get_by_role("heading", name=) - # ).to_be_visible() From 4897f9944a383ca9c0c3f93669513ca4dbcf8b3a Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 17 Feb 2025 15:45:00 +0000 Subject: [PATCH 15/32] Formatting - all green locally --- functional_tests/steps/methodology_page.py | 1 - 1 file changed, 1 deletion(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index feab5e77..945fd2bd 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -118,4 +118,3 @@ def preview_is_visible(context: Context): # expect(iframe_locator.get_by_role("heading", name="Cite this methodology")).to_be_visible() # expect(iframe_locator.get_by_role("heading", name="Heading")).to_be_visible() # expect(iframe_locator.page.get_by_role("heading", name="Content")).to_be_visible() - From 2f944a2fc90ffe83fc1a10e74171c9ce2ae4e5a2 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 17 Feb 2025 15:52:52 +0000 Subject: [PATCH 16/32] Test --- functional_tests/steps/methodology_page.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 945fd2bd..4fdbf176 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -92,9 +92,7 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): ).to_be_visible() expect( - context.page.locator("#panel-child-content-child-summary-errors .error-message").get_by_text( - "This field is required" - ) + context.page.locator("#panel-child-content-child-summary-errors").get_by_text("This field is required") ).to_be_visible() expect( From b6cf356b18c9a05de0011dc6ccbc1d4c5dc89130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Braghi=C8=99?= Date: Tue, 18 Feb 2025 14:02:15 +0000 Subject: [PATCH 17/32] Attempt to fix headless failures --- functional_tests/steps/page_editor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 510d7e67..c9298d90 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -17,6 +17,8 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('clicks the "{button_text}" button') def clicks_the_given_button(context: Context, button_text: str): + # add a small delay to allow any client-side JS to initialize. + context.page.wait_for_timeout(100) context.page.get_by_role("button", name=button_text).click() From 6fa3b217019fd744fd47cfc512f958b677adfc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Braghi=C8=99?= Date: Tue, 18 Feb 2025 16:00:08 +0000 Subject: [PATCH 18/32] Bump the wait time a bit --- functional_tests/steps/page_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index c9298d90..7c80ece2 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -18,7 +18,7 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('clicks the "{button_text}" button') def clicks_the_given_button(context: Context, button_text: str): # add a small delay to allow any client-side JS to initialize. - context.page.wait_for_timeout(100) + context.page.wait_for_timeout(500) context.page.get_by_role("button", name=button_text).click() From 0c8bdbc74dcd6abeabc9001ea5c17a3ecbc3c7d8 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 18 Feb 2025 16:30:13 +0000 Subject: [PATCH 19/32] Refactor the fix above into it's own step --- functional_tests/features/methodology_page.feature | 2 +- functional_tests/steps/page_editor.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index e23441c2..3f88d29c 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -35,7 +35,7 @@ Feature: A general use of Methodology Page Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page - And clicks the "Save Draft" button + And the user clicks the "Save Draft" button and waits for the page to reload Then the mandatory fields raise a validation error Scenario: The Last revised date field has appropriate validation on Methodology page. diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 7c80ece2..3f84419c 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -14,14 +14,16 @@ def user_clicks_publish_page(context: Context) -> None: def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> None: context.page.get_by_role("link", name="View live").click() +@when('the user clicks the "Save Draft" button and waits for the page to reload') +def press_save_draft_with_delay(context: Context): + # add a small delay to allow any client-side JS to initialize. + context.page.wait_for_timeout(500) + context.page.get_by_role("button", name="Save Draft").click() @when('clicks the "{button_text}" button') def clicks_the_given_button(context: Context, button_text: str): - # add a small delay to allow any client-side JS to initialize. - context.page.wait_for_timeout(500) context.page.get_by_role("button", name=button_text).click() - @when("the user edits the {page} page") def the_user_edits_the_topic_page(context: Context, page: str) -> None: the_page = page.lower().replace(" ", "_") From 5f6f6a00e12f1377e912397ff73e84e733bbbedc Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 18 Feb 2025 16:32:30 +0000 Subject: [PATCH 20/32] Uncommented the preview test --- .../features/methodology_page.feature | 1 - functional_tests/steps/methodology_page.py | 21 ++++++++++++------- functional_tests/steps/page_editor.py | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index 3f88d29c..a1d79731 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -52,5 +52,4 @@ Feature: A general use of Methodology Page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page - And clicks the "Save Draft" button Then the preview is visible with the populated data diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 4fdbf176..7e951380 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -92,7 +92,9 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): ).to_be_visible() expect( - context.page.locator("#panel-child-content-child-summary-errors").get_by_text("This field is required") + context.page.locator("#panel-child-content-child-summary-errors .error-message").get_by_text( + "This field is required" + ) ).to_be_visible() expect( @@ -108,11 +110,14 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): def preview_is_visible(context: Context): context.page.get_by_role("button", name="Toggle preview").click() - # iframe_locator = context.page.frame_locator("#w-preview-iframe") + # add a small delay to allow the preview to render + context.page.wait_for_timeout(500) + + iframe_locator = context.page.frame_locator("#w-preview-iframe") - # expect(iframe_locator.get_by_role("heading", name="Methodology page")).to_be_visible() - # expect(iframe_locator.get_by_text("Page summary")).to_be_visible() - # expect(iframe_locator.get_by_text("Published: 1 January 1950")).to_be_visible() - # expect(iframe_locator.get_by_role("heading", name="Cite this methodology")).to_be_visible() - # expect(iframe_locator.get_by_role("heading", name="Heading")).to_be_visible() - # expect(iframe_locator.page.get_by_role("heading", name="Content")).to_be_visible() + expect(iframe_locator.get_by_role("heading", name="Methodology page")).to_be_visible() + expect(iframe_locator.get_by_text("Page summary")).to_be_visible() + expect(iframe_locator.get_by_text("Published: 1 January 1950")).to_be_visible() + expect(iframe_locator.get_by_role("heading", name="Cite this methodology")).to_be_visible() + expect(iframe_locator.get_by_role("heading", name="Heading")).to_be_visible() + expect(iframe_locator.get_by_role("heading", name="Content")).to_be_visible() diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 3f84419c..9fcb9e1d 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -14,16 +14,19 @@ def user_clicks_publish_page(context: Context) -> None: def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> None: context.page.get_by_role("link", name="View live").click() + @when('the user clicks the "Save Draft" button and waits for the page to reload') def press_save_draft_with_delay(context: Context): # add a small delay to allow any client-side JS to initialize. context.page.wait_for_timeout(500) context.page.get_by_role("button", name="Save Draft").click() + @when('clicks the "{button_text}" button') def clicks_the_given_button(context: Context, button_text: str): context.page.get_by_role("button", name=button_text).click() + @when("the user edits the {page} page") def the_user_edits_the_topic_page(context: Context, page: str) -> None: the_page = page.lower().replace(" ", "_") From 6e37061411365865a070a3533fb7250c02423f4b Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 18 Feb 2025 17:17:29 +0000 Subject: [PATCH 21/32] Added a test for the draft functionality of the page --- .../features/methodology_page.feature | 10 ++++++++++ functional_tests/steps/methodology_page.py | 19 +++++++++++++++++-- functional_tests/steps/page_editor.py | 5 +++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index a1d79731..19033e36 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -53,3 +53,13 @@ Feature: A general use of Methodology Page When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page Then the preview is visible with the populated data + + Scenario: A CMS user can save and access a draft of the Methodology page + Given a topic page exists under a theme page + And a CMS user logs into the admin site + And the user creates a methodology page as a child of the existing topic page + And the user populates the methodology page + When clicks the "Save Draft" button + And the user navigates to the page history menu + Then the saved draft version is visible + And the preview data matches the populated data diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 7e951380..85280b0e 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -1,8 +1,9 @@ -from behave import then, when # pylint: disable=no-name-in-module +from behave import given, then, when # pylint: disable=no-name-in-module from behave.runner import Context from playwright.sync_api import expect +@given("the user creates a methodology page as a child of the existing topic page") @when("the user creates a methodology page as a child of the existing topic page") def user_creates_methodology_page(context: Context): context.page.get_by_role("button", name="Pages").click() @@ -14,6 +15,7 @@ def user_creates_methodology_page(context: Context): context.page.get_by_role("link", name="Methodology page", exact=True).click() +@given("the user populates the methodology page") @when("the user populates the methodology page") def user_populates_the_methodology_page(context: Context): context.page.get_by_placeholder("Page title*").fill("Methodology page") @@ -31,7 +33,7 @@ def user_populates_the_methodology_page(context: Context): @then("the published methodology page is displayed with the populated data") -def the_methodology_page_is_displayed_correctly(context: Context): +def the_methodology_page_is_with_the_populated_data(context: Context): expect(context.page.get_by_role("heading", name="Methodology page")).to_be_visible() expect(context.page.get_by_text("Page summary")).to_be_visible() expect(context.page.get_by_text("Published: 1 January 1950")).to_be_visible() @@ -121,3 +123,16 @@ def preview_is_visible(context: Context): expect(iframe_locator.get_by_role("heading", name="Cite this methodology")).to_be_visible() expect(iframe_locator.get_by_role("heading", name="Heading")).to_be_visible() expect(iframe_locator.get_by_role("heading", name="Content")).to_be_visible() + + +@then("the saved draft version is visible") +def draft_version_visible(context: Context): + expect(context.page.get_by_role("button", name="Just now").first).to_be_visible() + expect(context.page.get_by_text("Draft saved")).to_be_visible() + + +@then("the preview data matches the populated data") +def draft_data_matches_populated_data(context: Context): + context.page.get_by_role("button", name="Actions").click() + context.page.get_by_role("link", name="Preview").click() + the_methodology_page_is_with_the_populated_data(context) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 9fcb9e1d..5dfee8e3 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -34,3 +34,8 @@ def the_user_edits_the_topic_page(context: Context, page: str) -> None: the_page += "_page" edit_url = reverse("wagtailadmin_pages:edit", args=[getattr(context, the_page).pk]) context.page.goto(f"{context.base_url}{edit_url}") + + +@when("the user navigates to the page history menu") +def test(context: Context): + context.page.get_by_role("link", name="History").click() From add2895233aa699d338464128fc09ee096628f9c Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Wed, 19 Feb 2025 09:49:42 +0000 Subject: [PATCH 22/32] Refactoring --- functional_tests/steps/methodology_page.py | 8 +------- functional_tests/steps/page_editor.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 85280b0e..f660f168 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -125,14 +125,8 @@ def preview_is_visible(context: Context): expect(iframe_locator.get_by_role("heading", name="Content")).to_be_visible() -@then("the saved draft version is visible") -def draft_version_visible(context: Context): - expect(context.page.get_by_role("button", name="Just now").first).to_be_visible() - expect(context.page.get_by_text("Draft saved")).to_be_visible() - - @then("the preview data matches the populated data") -def draft_data_matches_populated_data(context: Context): +def saved_draft_data_matches_populated_data(context: Context): context.page.get_by_role("button", name="Actions").click() context.page.get_by_role("link", name="Preview").click() the_methodology_page_is_with_the_populated_data(context) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 5dfee8e3..fe8a17de 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -1,6 +1,7 @@ -from behave import when # pylint: disable=no-name-in-module +from behave import then, when # pylint: disable=no-name-in-module from behave.runner import Context from django.urls import reverse +from playwright.sync_api import expect @when('the user clicks "Publish page"') @@ -37,5 +38,11 @@ def the_user_edits_the_topic_page(context: Context, page: str) -> None: @when("the user navigates to the page history menu") -def test(context: Context): +def user_navigates_to_the_history_menu(context: Context): context.page.get_by_role("link", name="History").click() + + +@then("the saved draft version is visible") +def saved_draft_version_is_visible(context: Context): + expect(context.page.get_by_role("button", name="Just now").first).to_be_visible() + expect(context.page.get_by_text("Draft saved")).to_be_visible() From 7260ac04389708200d81aff8728029e55f762d7d Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Thu, 20 Feb 2025 13:15:51 +0000 Subject: [PATCH 23/32] Renamed a test function --- functional_tests/steps/page_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index fe8a17de..3146156c 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -29,7 +29,7 @@ def clicks_the_given_button(context: Context, button_text: str): @when("the user edits the {page} page") -def the_user_edits_the_topic_page(context: Context, page: str) -> None: +def the_user_edits_a_page(context: Context, page: str) -> None: the_page = page.lower().replace(" ", "_") if not the_page.endswith("_page"): the_page += "_page" From 6031393bed53f36e812847fc39b07713570d6ee9 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 09:46:41 +0000 Subject: [PATCH 24/32] Experiment - removed the delay in preview test --- functional_tests/steps/methodology_page.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index f660f168..9408b2b2 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -112,9 +112,6 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): def preview_is_visible(context: Context): context.page.get_by_role("button", name="Toggle preview").click() - # add a small delay to allow the preview to render - context.page.wait_for_timeout(500) - iframe_locator = context.page.frame_locator("#w-preview-iframe") expect(iframe_locator.get_by_role("heading", name="Methodology page")).to_be_visible() From 2e69f7ff7688ae87d7f4576eb26d8545f2a53ade Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 09:59:22 +0000 Subject: [PATCH 25/32] =?UTF-8?q?^=20the=20same=20for=20the=20mandatory=20?= =?UTF-8?q?fields=20scenario=20=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functional_tests/features/methodology_page.feature | 2 +- functional_tests/steps/methodology_page.py | 4 ++-- functional_tests/steps/page_editor.py | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index 19033e36..96b8c26c 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -35,7 +35,7 @@ Feature: A general use of Methodology Page Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page - And the user clicks the "Save Draft" button and waits for the page to reload + And the user clicks the "Save Draft" button Then the mandatory fields raise a validation error Scenario: The Last revised date field has appropriate validation on Methodology page. diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 9408b2b2..db51619d 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -33,7 +33,7 @@ def user_populates_the_methodology_page(context: Context): @then("the published methodology page is displayed with the populated data") -def the_methodology_page_is_with_the_populated_data(context: Context): +def the_methodology_page_is_displayed_with_the_populated_data(context: Context): expect(context.page.get_by_role("heading", name="Methodology page")).to_be_visible() expect(context.page.get_by_text("Page summary")).to_be_visible() expect(context.page.get_by_text("Published: 1 January 1950")).to_be_visible() @@ -126,4 +126,4 @@ def preview_is_visible(context: Context): def saved_draft_data_matches_populated_data(context: Context): context.page.get_by_role("button", name="Actions").click() context.page.get_by_role("link", name="Preview").click() - the_methodology_page_is_with_the_populated_data(context) + the_methodology_page_is_displayed_with_the_populated_data(context) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 3146156c..21d25b66 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -16,10 +16,8 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No context.page.get_by_role("link", name="View live").click() -@when('the user clicks the "Save Draft" button and waits for the page to reload') +@when('the user clicks the "Save Draft" button') def press_save_draft_with_delay(context: Context): - # add a small delay to allow any client-side JS to initialize. - context.page.wait_for_timeout(500) context.page.get_by_role("button", name="Save Draft").click() From e9cb0a594d0d3f78ee306940ee230caf746cc565 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 10:13:28 +0000 Subject: [PATCH 26/32] Add back the delay for mandatory fields scenario + make step wording more precise --- functional_tests/features/methodology_page.feature | 6 +++--- functional_tests/steps/methodology_page.py | 4 ++-- functional_tests/steps/page_editor.py | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index 96b8c26c..04042abd 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -35,8 +35,8 @@ Feature: A general use of Methodology Page Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page - And the user clicks the "Save Draft" button - Then the mandatory fields raise a validation error + And the user clicks the "Save Draft" button and waits for the page to reload + Then the methodology page mandatory fields raise validation errors Scenario: The Last revised date field has appropriate validation on Methodology page. Given a topic page exists under a theme page @@ -52,7 +52,7 @@ Feature: A general use of Methodology Page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page And the user populates the methodology page - Then the preview is visible with the populated data + Then the preview of the methodology page is displayed with the populated data Scenario: A CMS user can save and access a draft of the Methodology page Given a topic page exists under a theme page diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index db51619d..73137af4 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -83,7 +83,7 @@ def validation_error_displayed_when_incorrect_date_selected(context: Context): expect(context.page.get_by_text("The last revised date must be after the published date.")).to_be_visible() -@then("the mandatory fields raise a validation error") +@then("the methodology page mandatory fields raise validation errors") def mandatory_fields_raise_validation_error_when_not_set(context: Context): expect(context.page.get_by_text("The page could not be created due to validation errors")).to_be_visible() @@ -108,7 +108,7 @@ def mandatory_fields_raise_validation_error_when_not_set(context: Context): expect(context.page.locator(".help-block.help-critical").get_by_text("This field is required")).to_be_visible() -@then("the preview is visible with the populated data") +@then("the preview of the methodology page is displayed with the populated data") def preview_is_visible(context: Context): context.page.get_by_role("button", name="Toggle preview").click() diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 21d25b66..9ff65a67 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -16,8 +16,10 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No context.page.get_by_role("link", name="View live").click() -@when('the user clicks the "Save Draft" button') -def press_save_draft_with_delay(context: Context): +@when('the user clicks the "Save Draft" button and waits for the page to reload') +def click_save_draft_with_delay(context: Context): + # add a small delay to allow any client-side JS to initialize. + context.page.wait_for_timeout(500) context.page.get_by_role("button", name="Save Draft").click() From c5f28f7258bf9d9b140e5f490aea237396dee5d4 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 10:31:33 +0000 Subject: [PATCH 27/32] Experiment - move the delay to the 'then' step of the mandatory fields scenario --- functional_tests/steps/methodology_page.py | 3 +++ functional_tests/steps/page_editor.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 73137af4..1981107f 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -85,6 +85,9 @@ def validation_error_displayed_when_incorrect_date_selected(context: Context): @then("the methodology page mandatory fields raise validation errors") def mandatory_fields_raise_validation_error_when_not_set(context: Context): + # add a small delay to allow any client-side JS to initialize. + context.page.wait_for_timeout(500) + expect(context.page.get_by_text("The page could not be created due to validation errors")).to_be_visible() expect( diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 9ff65a67..a51c150f 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -18,8 +18,6 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('the user clicks the "Save Draft" button and waits for the page to reload') def click_save_draft_with_delay(context: Context): - # add a small delay to allow any client-side JS to initialize. - context.page.wait_for_timeout(500) context.page.get_by_role("button", name="Save Draft").click() From ffff22deae1e31677c212418ba9156cf879a63f1 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 11:02:27 +0000 Subject: [PATCH 28/32] ^ revert the above --- functional_tests/steps/methodology_page.py | 3 --- functional_tests/steps/page_editor.py | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 1981107f..73137af4 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -85,9 +85,6 @@ def validation_error_displayed_when_incorrect_date_selected(context: Context): @then("the methodology page mandatory fields raise validation errors") def mandatory_fields_raise_validation_error_when_not_set(context: Context): - # add a small delay to allow any client-side JS to initialize. - context.page.wait_for_timeout(500) - expect(context.page.get_by_text("The page could not be created due to validation errors")).to_be_visible() expect( diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index a51c150f..9ff65a67 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -18,6 +18,8 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('the user clicks the "Save Draft" button and waits for the page to reload') def click_save_draft_with_delay(context: Context): + # add a small delay to allow any client-side JS to initialize. + context.page.wait_for_timeout(500) context.page.get_by_role("button", name="Save Draft").click() From f70920f23f8a5989a5d357e6a5545c89b642d6ee Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 12:15:59 +0000 Subject: [PATCH 29/32] Experiment - replace delay with wait_for_load_state --- functional_tests/steps/page_editor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 9ff65a67..8a8803ff 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -18,8 +18,7 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('the user clicks the "Save Draft" button and waits for the page to reload') def click_save_draft_with_delay(context: Context): - # add a small delay to allow any client-side JS to initialize. - context.page.wait_for_timeout(500) + context.page.wait_for_load_state() context.page.get_by_role("button", name="Save Draft").click() From eb87cf1e105c36c1dc6f432b1018e25200cd3b5d Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 13:51:31 +0000 Subject: [PATCH 30/32] ^ the same but after clicking the button --- functional_tests/steps/page_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 8a8803ff..60bbef28 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -18,8 +18,8 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('the user clicks the "Save Draft" button and waits for the page to reload') def click_save_draft_with_delay(context: Context): - context.page.wait_for_load_state() context.page.get_by_role("button", name="Save Draft").click() + context.page.wait_for_load_state() @when('clicks the "{button_text}" button') From ac9c4214fe051f31bcb93fc67a050133cb1c5dc4 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 13:57:49 +0000 Subject: [PATCH 31/32] Revert to using delay --- functional_tests/steps/page_editor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 60bbef28..9ff65a67 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -18,8 +18,9 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No @when('the user clicks the "Save Draft" button and waits for the page to reload') def click_save_draft_with_delay(context: Context): + # add a small delay to allow any client-side JS to initialize. + context.page.wait_for_timeout(500) context.page.get_by_role("button", name="Save Draft").click() - context.page.wait_for_load_state() @when('clicks the "{button_text}" button') From 9755549f29603593566656eadbce80d9a3e04ae9 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Fri, 21 Feb 2025 15:18:00 +0000 Subject: [PATCH 32/32] Test improvements --- functional_tests/features/methodology_page.feature | 4 ++-- functional_tests/steps/methodology_page.py | 10 ++++------ functional_tests/steps/page_editor.py | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/functional_tests/features/methodology_page.feature b/functional_tests/features/methodology_page.feature index 04042abd..d24eaa2a 100644 --- a/functional_tests/features/methodology_page.feature +++ b/functional_tests/features/methodology_page.feature @@ -35,7 +35,7 @@ Feature: A general use of Methodology Page Given a topic page exists under a theme page And a CMS user logs into the admin site When the user creates a methodology page as a child of the existing topic page - And the user clicks the "Save Draft" button and waits for the page to reload + And the user clicks the "Save Draft" button Then the methodology page mandatory fields raise validation errors Scenario: The Last revised date field has appropriate validation on Methodology page. @@ -62,4 +62,4 @@ Feature: A general use of Methodology Page When clicks the "Save Draft" button And the user navigates to the page history menu Then the saved draft version is visible - And the preview data matches the populated data + And the preview of the methodology page matches the populated data diff --git a/functional_tests/steps/methodology_page.py b/functional_tests/steps/methodology_page.py index 73137af4..9860e914 100644 --- a/functional_tests/steps/methodology_page.py +++ b/functional_tests/steps/methodology_page.py @@ -1,10 +1,9 @@ -from behave import given, then, when # pylint: disable=no-name-in-module +from behave import step, then, when # pylint: disable=no-name-in-module from behave.runner import Context from playwright.sync_api import expect -@given("the user creates a methodology page as a child of the existing topic page") -@when("the user creates a methodology page as a child of the existing topic page") +@step("the user creates a methodology page as a child of the existing topic page") def user_creates_methodology_page(context: Context): context.page.get_by_role("button", name="Pages").click() context.page.get_by_role("link", name="View child pages of 'Home'").click() @@ -15,8 +14,7 @@ def user_creates_methodology_page(context: Context): context.page.get_by_role("link", name="Methodology page", exact=True).click() -@given("the user populates the methodology page") -@when("the user populates the methodology page") +@step("the user populates the methodology page") def user_populates_the_methodology_page(context: Context): context.page.get_by_placeholder("Page title*").fill("Methodology page") context.page.get_by_role("region", name="Summary*").get_by_role("textbox").fill("Page summary") @@ -122,7 +120,7 @@ def preview_is_visible(context: Context): expect(iframe_locator.get_by_role("heading", name="Content")).to_be_visible() -@then("the preview data matches the populated data") +@then("the preview of the methodology page matches the populated data") def saved_draft_data_matches_populated_data(context: Context): context.page.get_by_role("button", name="Actions").click() context.page.get_by_role("link", name="Preview").click() diff --git a/functional_tests/steps/page_editor.py b/functional_tests/steps/page_editor.py index 9ff65a67..a049a906 100644 --- a/functional_tests/steps/page_editor.py +++ b/functional_tests/steps/page_editor.py @@ -16,7 +16,7 @@ def user_clicks_view_live_on_publish_confirmation_banner(context: Context) -> No context.page.get_by_role("link", name="View live").click() -@when('the user clicks the "Save Draft" button and waits for the page to reload') +@when('the user clicks the "Save Draft" button') def click_save_draft_with_delay(context: Context): # add a small delay to allow any client-side JS to initialize. context.page.wait_for_timeout(500)