diff --git a/src/test/java/giis/eshopcontainers/e2e/functional/tests/OrderTests.java b/src/test/java/giis/eshopcontainers/e2e/functional/tests/OrderTests.java index a26723e..05ef900 100644 --- a/src/test/java/giis/eshopcontainers/e2e/functional/tests/OrderTests.java +++ b/src/test/java/giis/eshopcontainers/e2e/functional/tests/OrderTests.java @@ -86,14 +86,25 @@ void testCancelOrder() throws ElementNotFoundException { expectedStatesPriorCancelling.add("stockconfirmed"); LinkedList expectedStatesPostCancelling = new LinkedList<>(); expectedStatesPostCancelling.add("cancelled"); + LinkedList expectedStatesBeforeLongDelay = new LinkedList<>(); + expectedStatesBeforeLongDelay.add("paid"); login(); toOrdersPage(driver, waiter); createOrder(); + long startTime = System.currentTimeMillis(); checkLastOrderState( expectedStatesPriorCancelling); - cancelLastOrder(); + long endTime = System.currentTimeMillis(); + long duration =endTime-startTime; + log.debug("The time invested in place the order was: {}s", duration); + if(duration<=3000) { + cancelLastOrder(); + checkLastOrderState(expectedStatesPostCancelling); + } + else { + checkLastOrderState(expectedStatesBeforeLongDelay); + } - checkLastOrderState( expectedStatesPostCancelling); logout(); } @@ -109,6 +120,7 @@ void testCancelOrder() throws ElementNotFoundException { private void checkLastOrderState( List expectedStates) throws ElementNotFoundException { int maxIterations = 10; String actualState = ""; + for (int iter = 0; iter < maxIterations; iter++) { log.debug("Performing iteration {} over the orders", iter); toOrdersPage(driver, waiter); @@ -125,6 +137,7 @@ private void checkLastOrderState( List expectedStates) throws ElementNot waiter.waitUntil(ExpectedConditions.not(ExpectedConditions.textToBePresentInElement(statusElement , actualState)), "The actual state remains untouched"); + log.debug("Refreshing the webpage to update order status..."); } catch (Exception ex) { log.debug("Timeout the element remains with the previous state, previous was{}current is:{}", actualState, statusElement.getText()); }