Skip to content

Commit

Permalink
Adding two threads of execution, one that measures
Browse files Browse the repository at this point in the history
  • Loading branch information
augustocristian committed Aug 20, 2024
1 parent 9881f9c commit 68638b8
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ void testCancelOrder() throws ElementNotFoundException {
expectedStatesPriorCancelling.add("stockconfirmed");
LinkedList<String> expectedStatesPostCancelling = new LinkedList<>();
expectedStatesPostCancelling.add("cancelled");
LinkedList <String> 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();
}

Expand All @@ -109,6 +120,7 @@ void testCancelOrder() throws ElementNotFoundException {
private void checkLastOrderState( List<String> 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);
Expand All @@ -125,6 +137,7 @@ private void checkLastOrderState( List<String> 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());
}
Expand Down

0 comments on commit 68638b8

Please sign in to comment.