Skip to content

Commit

Permalink
feat: cpms retry
Browse files Browse the repository at this point in the history
  • Loading branch information
sr4850 committed Aug 6, 2024
1 parent 02f42af commit fa270d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa270d8

Please sign in to comment.