diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java index 6dc7dcf..2bcf989 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java @@ -26,9 +26,12 @@ import java.io.FileReader; import java.io.IOException; import java.net.URISyntaxException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.Locale; import java.util.stream.Stream; import static com.fullteaching.e2e.no_elastest.common.Constants.*; @@ -114,7 +117,7 @@ private void initializeStudents(String pathData) throws IOException, URISyntaxEx * @throws ElementNotFoundException if an element is not found during navigation */ private void createNewSession(String sessionName) throws ElementNotFoundException { - String sessionDate = getCurrentDate(); + String sessionHour = getCurrentTime(); String sessionDescription = "Wow today session will be amazing"; @@ -123,7 +126,7 @@ private void createNewSession(String sessionName) throws ElementNotFoundExceptio WebElement modal = Wait.notTooMuch(user.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(SESSION_LIST_NEW_SESSION_MODAL)); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_TITLE).sendKeys(sessionName); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_CONTENT).sendKeys(sessionDescription); - introduceSessionDate(user,modal,sessionDate); + introduceSessionDate(user,modal); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_TIME).sendKeys(sessionHour); Click.element(user.getDriver(), modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_POST_BUTTON)); Wait.notTooMuch(user.getDriver()); @@ -134,22 +137,27 @@ private void createNewSession(String sessionName) throws ElementNotFoundExceptio assertTrue(session_titles.contains(sessionName), "Session has not been created"); } - private void introduceSessionDate(BrowserUser user, WebElement element, String date) { + private void introduceSessionDate(BrowserUser user, WebElement element) { + String sessionDate = getCurrentDate(); + LocalDate formatteDate = LocalDate.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String expectedDate = formatteDate.format(formatter); + boolean success = false; int attempts = 3; - log.info("The date is going to be:{}",date); + log.info("The date is going to be:{}",sessionDate); for (int i = 0; i < attempts; i++) { try { user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).clear(); - user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).sendKeys(date); - String actualValue= user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).getAttribute("value"); - if(!actualValue.equals(date)) { // Use JavaScript to set the value of the date input + user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).sendKeys(sessionDate); + String actualValue= user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).getDomProperty("value"); + if(!actualValue.equals(expectedDate)) { // Use JavaScript to set the value of the date input log.info("Selenium sendKeys dont working properly, using JS.."); user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).clear(); JavascriptExecutor js = (JavascriptExecutor) user.getDriver(); - js.executeScript("arguments[0].value = arguments[1];", user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE), date); + js.executeScript("arguments[0].value = arguments[1];", user.getDriver().findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE), sessionDate); } - user.getWaiter().until(ExpectedConditions.textToBePresentInElementValue(element.findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE), date)); + user.getWaiter().until(ExpectedConditions.textToBePresentInElementValue(element.findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE), expectedDate)); success = true; break; // } catch (TimeoutException e) { @@ -169,7 +177,15 @@ private String getCurrentDate() { int mYear = calendar.get(Calendar.YEAR); int mMonth = calendar.get(Calendar.MONTH)+1; int mDay = calendar.get(Calendar.DAY_OF_MONTH); - return ""+(mMonth < 10 ? "0" + mMonth : mMonth) +"-" +(mDay < 10 ? "0" + mDay : mDay) +"-"+ mYear; + String dateformat=""; + if(Locale.getDefault().toString().equals("es_ES")){ + dateformat=dateformat+(mDay < 10 ? "0" + mDay : mDay)+"-"+(mMonth < 10 ? "0" + mMonth : mMonth) +"-"+mYear; + } + else{ + dateformat=dateformat+(mMonth < 10 ? "0" + mMonth : mMonth) +"-"+(mDay < 10 ? "0" + mDay : mDay)+"-"+mYear; + } + return dateformat; + } /** * This method gets the current time in the format HHmmA/P, where A/P indicates AM or PM for the video session name