From fa270d8cdd9b7a715a3a46adb9aaeb89fbd4880e Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Tue, 6 Aug 2024 11:46:06 +0100 Subject: [PATCH] feat: cpms retry --- .../licence/FeeAndPaymentJourney.java | 49 +++++++++++++------ .../Payments/ss-pay-for-application.feature | 2 +- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/dvsa/testing/framework/Journeys/licence/FeeAndPaymentJourney.java b/src/test/java/org/dvsa/testing/framework/Journeys/licence/FeeAndPaymentJourney.java index 32cc64597..f172bd42e 100644 --- a/src/test/java/org/dvsa/testing/framework/Journeys/licence/FeeAndPaymentJourney.java +++ b/src/test/java/org/dvsa/testing/framework/Journeys/licence/FeeAndPaymentJourney.java @@ -6,6 +6,8 @@ import org.dvsa.testing.framework.pageObjects.BasePage; import org.dvsa.testing.framework.pageObjects.enums.SelectorType; import org.jetbrains.annotations.NotNull; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.TimeoutException; import java.util.HashMap; @@ -124,22 +126,39 @@ public void selectFee() { } public void customerPaymentModule() { + final int MAX_RETRIES = 3; + int attempt = 0; + boolean success = false; + while (attempt < MAX_RETRIES && !success) { + try { + attempt++; + waitForTextToBePresent("Card Number*"); + waitAndEnterText("//*[@id='scp_cardPage_cardNumber_input']", SelectorType.XPATH, SecretsManager.getSecret("cardNumber")); + waitAndEnterText("//*[@id='scp_cardPage_expiryDate_input']", SelectorType.XPATH, SecretsManager.getSecret("cardExpiryMonth")); + waitAndEnterText("//*[@id='scp_cardPage_expiryDate_input2']", SelectorType.XPATH, SecretsManager.getSecret("cardExpiryYear")); + waitAndEnterText("//*[@id='scp_cardPage_csc_input']", SelectorType.XPATH, "123"); + + if (isElementPresent("scp_cardPage_storedCard_payment_input", SelectorType.ID)) { + click("scp_cardPage_storedCard_payment_input", SelectorType.ID); + } + click("//*[@id='scp_cardPage_buttonsNoBack_continue_button']", SelectorType.XPATH); + enterCardHolderDetails(); + waitForTextToBePresent("Payment Confirmation Page"); - waitForTextToBePresent("Card Number*"); - waitAndEnterText("//*[@id='scp_cardPage_cardNumber_input']", SelectorType.XPATH, SecretsManager.getSecret("cardNumber")); - waitAndEnterText("//*[@id='scp_cardPage_expiryDate_input']", SelectorType.XPATH, SecretsManager.getSecret("cardExpiryMonth")); - waitAndEnterText("//*[@id='scp_cardPage_expiryDate_input2']", SelectorType.XPATH, SecretsManager.getSecret("cardExpiryYear")); - waitAndEnterText("//*[@id='scp_cardPage_csc_input']", SelectorType.XPATH, "123"); - if (isElementPresent("scp_cardPage_storedCard_payment_input", SelectorType.ID)) { - click("scp_cardPage_storedCard_payment_input", SelectorType.ID); - } - click("//*[@id='scp_cardPage_buttonsNoBack_continue_button']", SelectorType.XPATH); - enterCardHolderDetails(); - waitForTextToBePresent("Payment Confirmation Page"); - click("//*[@id='scp_confirmationPage_buttons_payment_button']", SelectorType.XPATH); - if (isElementPresent("//*[@id='scp_storeCardConfirmationPage_buttons_back_button']", SelectorType.XPATH)) { - waitForTextToBePresent("Online Payments"); - click("//*[@value='Save']", SelectorType.XPATH); + click("//*[@id='scp_confirmationPage_buttons_payment_button']", SelectorType.XPATH); + + if (isElementPresent("//*[@id='scp_storeCardConfirmationPage_buttons_back_button']", SelectorType.XPATH)) { + waitForTextToBePresent("Online Payments"); + click("//*[@value='Save']", SelectorType.XPATH); + } + + success = true; + } catch (TimeoutException | NoSuchElementException e) { + if (attempt >= MAX_RETRIES) { + throw e; + } + System.out.println("Retry attempt " + attempt + " due to " + e.getMessage()); + } } } diff --git a/src/test/resources/org/dvsa/testing/framework/features/SelfServe/CPMS/Payments/ss-pay-for-application.feature b/src/test/resources/org/dvsa/testing/framework/features/SelfServe/CPMS/Payments/ss-pay-for-application.feature index bad2f366e..5be779500 100644 --- a/src/test/resources/org/dvsa/testing/framework/features/SelfServe/CPMS/Payments/ss-pay-for-application.feature +++ b/src/test/resources/org/dvsa/testing/framework/features/SelfServe/CPMS/Payments/ss-pay-for-application.feature @@ -21,7 +21,7 @@ Feature: Self Serve Apply for licence | north_west | | north_east | And i choose to print and sign - When i pay for my application + When i pay for my applicationx Then the application should be submitted And i pay my second application with my saved card details Then the application should be submitted