diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f6b961fd..29953ea1 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4b239a95..e0b3fb8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Jan 12 21:22:14 MSK 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/gradlew.bat b/gradlew.bat index f9553162..e95643d6 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,84 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/ru/alfabank/alfatest/cucumber/utils/DateUtils.java b/src/main/java/ru/alfabank/alfatest/cucumber/utils/DateUtils.java new file mode 100644 index 00000000..1b4a2dda --- /dev/null +++ b/src/main/java/ru/alfabank/alfatest/cucumber/utils/DateUtils.java @@ -0,0 +1,43 @@ +package ru.alfabank.alfatest.cucumber.utils; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@Getter +@AllArgsConstructor +public enum DateUtils { + + YESTERDAY("вчера", LocalDate.now().minusDays(1)), + TOMORROW("завтра", LocalDate.now().plusDays(1)), + TODAY("сегодня", LocalDate.now()), + MONTH_AGO("месяц назад", LocalDate.now().minusMonths(1)), + THREE_MONTH_AGO("3 месяца назад", LocalDate.now().minusMonths(3)), + YEAR_AGO("год назад", LocalDate.now().minusYears(1)), + MONTH_AHEAD("месяц вперед", LocalDate.now().plusMonths(1)), + THREE_MONTH_AHEAD("3 месяца вперед", LocalDate.now().plusMonths(3)), + YEAR_AHEAD("год вперед", LocalDate.now().plusMonths(3)); + + private final String textDate; + private final LocalDate date; + + private static final Map DATES = new HashMap<>(); + + static { + for (DateUtils date: values()) { + DATES.put(date.getTextDate(), date.getDate()); + } + } + + public static LocalDate convertStringDateToValues(String expectedTextDate) throws IllegalArgumentException{ + LocalDate date = DATES.get(expectedTextDate); + + if (Objects.isNull(date)) { + throw new IllegalArgumentException(String.format("Некорректнное значение даты: %s", expectedTextDate)); + } + return date; + } + } diff --git a/src/main/java/ru/alfabank/steps/BaseMethods.java b/src/main/java/ru/alfabank/steps/BaseMethods.java index dc957fd0..ed39bb92 100644 --- a/src/main/java/ru/alfabank/steps/BaseMethods.java +++ b/src/main/java/ru/alfabank/steps/BaseMethods.java @@ -328,4 +328,9 @@ public void checkPageTitle(String pageTitleName) { assertThat(String.format("Заголовок страницы не совпадает с ожидаемым значением. Ожидаемый результат: %s, текущий результат: %s", pageTitleName, currentTitle), pageTitleName, IsEqualIgnoringCase.equalToIgnoringCase(currentTitle)); } + + public void clearField(String nameOfField) { + SelenideElement valueInput = akitaScenario.getCurrentPage().getElement(nameOfField); + valueInput.doubleClick().sendKeys(Keys.DELETE); + } } \ No newline at end of file diff --git a/src/main/java/ru/alfabank/steps/ElementsInteractionSteps.java b/src/main/java/ru/alfabank/steps/ElementsInteractionSteps.java index 33ed62ea..65bf1df1 100644 --- a/src/main/java/ru/alfabank/steps/ElementsInteractionSteps.java +++ b/src/main/java/ru/alfabank/steps/ElementsInteractionSteps.java @@ -21,8 +21,13 @@ import org.openqa.selenium.By; import java.io.File; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import static com.codeborne.selenide.Selenide.$; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static ru.alfabank.alfatest.cucumber.utils.DateUtils.convertStringDateToValues; import static ru.alfabank.tests.core.helpers.PropertyLoader.loadValueFromFileOrPropertyOrVariableOrDefault; /** @@ -82,4 +87,31 @@ public void clickOnButtonAndUploadFile(String buttonName, String fileName) { File attachmentFile = new File(file); akitaScenario.getCurrentPage().getElement(buttonName).uploadFile(attachmentFile); } + + /** + * Выполняется ввод даты в поле + * Дата преобразуется из значения "сегодня", "вчера", "завтра", "месяц назад", "3 месяца назад", "год назад", "месяц вперед", "3 месяца вперед", "год вперед" + */ + @И("^в поле \"([^\"]*)\" введено и преобразовано в дату значение \"([^\"]*)\"$") + @And("^in the field \"([^\"]*)\" the value is entered and converted to a date \"([^\"]*)\"$") + public void enterDateInField(String fieldName, String expectedDate) { + SelenideElement valueInput = akitaScenario.getCurrentPage().getElement(fieldName); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); + LocalDate actualdate = convertStringDateToValues(expectedDate); + clearField(fieldName); + valueInput.setValue(actualdate.format(formatter)); + } + /** + * Проверяется, что поле содержит дату + * Дата преобразуется из значения "сегодня", "вчера", "завтра", "месяц назад", "3 месяца назад", "год назад", "месяц вперед", "3 месяца вперед", "год вперед" + */ + @И("^(?:поле|элемент) \"([^\"]*)\" содержит дату \"(.*)\"$") + @And("^(?:field|element) \"([^\"]*)\" contains date \"(.*)\"$") + public void checkDateInField(String elementName, String expectedDate) { + expectedDate = getPropertyOrStringVariableOrValue(expectedDate); + LocalDate actualdate = convertStringDateToValues(expectedDate); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); + String actualValue = akitaScenario.getCurrentPage().getAnyElementText(elementName); + assertThat(String.format("Поле [%s] не содержит значение [%s]", elementName, actualdate.format(formatter)), actualValue, containsString(String.valueOf(actualdate.format(formatter)))); + } } \ No newline at end of file diff --git a/src/main/java/ru/alfabank/steps/ListVerificationSteps.java b/src/main/java/ru/alfabank/steps/ListVerificationSteps.java index 39bb0973..b30d852e 100644 --- a/src/main/java/ru/alfabank/steps/ListVerificationSteps.java +++ b/src/main/java/ru/alfabank/steps/ListVerificationSteps.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.regex.Pattern; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; @@ -188,4 +189,19 @@ public void checkListInnerTextCorrespondsToListFromVariable(String listName, Str assertThat(String.format("Список со страницы %s: %s не совпадает с ожидаемым списком из переменной %s:%s", listName, actualList, listVariable, expectedList) , actualList, containsInAnyOrder(expectedList.toArray())); } + + /** + * Производится проход по списку и проверятся текст на соответствие формату регулярного выражения + */ + @Тогда("^элементы списка \"([^\"]*)\" удовлетворяют регулярному выражению \"(.*)\"") + @When("^list items \"([^\"]*)\" satisfy regular expression \"(.*)\"") + public void checkListMatchesRegex(String listName, String pattern) { + List listOfElementsFromPage = akitaScenario.getCurrentPage().getElementsList(listName); + List elementsListText = listOfElementsFromPage.stream() + .map(element -> element.getText().trim()) + .collect(toList()); + Pattern r = Pattern.compile(pattern); + assertTrue(elementsListText.stream().allMatch(item -> r.matcher(item).matches()), + String.format("Элемены списка %s: [%s] содержат не только символы [%s] ", listName, elementsListText, pattern)); + } } \ No newline at end of file diff --git a/src/main/java/ru/alfabank/steps/RoundUpSteps.java b/src/main/java/ru/alfabank/steps/RoundUpSteps.java index c34b9efc..21d009e5 100644 --- a/src/main/java/ru/alfabank/steps/RoundUpSteps.java +++ b/src/main/java/ru/alfabank/steps/RoundUpSteps.java @@ -222,4 +222,18 @@ public void checkIfValueFromVariableEqualPropertyVariable(String envVarible, Str public void expressionExpression(String expression) { akitaScenario.getVars().evaluate("assert(" + expression + ")"); } + + /** + * Проверка что в переменной содержится ожидаемое количество символов + */ + @Тогда("^в переменной \"([^\"]*)\" содержится (\\d+) символов$") + @Then("the variable \"([^\"]*)\" contains (\\d+) characters") + public void checkInVariableContainsCharacters(String variableName, int numbersCount) { + String reason = String.format( + "Количество символов в поле %s должно быть %d", + akitaScenario.getVar(variableName).toString(), + numbersCount + ); + assertThat(reason, akitaScenario.getVar(variableName).toString().length(), equalTo(numbersCount)); + } } \ No newline at end of file diff --git a/src/main/java/ru/alfabank/steps/WebPageInteractionSteps.java b/src/main/java/ru/alfabank/steps/WebPageInteractionSteps.java index aa3ee1bb..079b6d79 100644 --- a/src/main/java/ru/alfabank/steps/WebPageInteractionSteps.java +++ b/src/main/java/ru/alfabank/steps/WebPageInteractionSteps.java @@ -23,6 +23,8 @@ import org.openqa.selenium.Keys; import org.openqa.selenium.interactions.Actions; +import java.util.ArrayList; + import static com.codeborne.selenide.Selenide.*; import static com.codeborne.selenide.WebDriverRunner.getWebDriver; import static com.codeborne.selenide.WebDriverRunner.url; @@ -190,4 +192,14 @@ public void savePageTitleToVariable(String variableName) { akitaScenario.setVar(variableName, titleName); akitaScenario.write("Значение заголовка страницы [" + titleName + "] сохранено в переменную [" + variableName + "]"); } + + /** + * Производится переключение на вкладку с номером + */ + @Когда("^выполнено переключение на \"([^\"]*)\" вкладку$") + @When("^switched to a tab \"([^\"]*)\"$") + public void switchToTheTab(Integer number) { + ArrayList tabs = new ArrayList<>(getWebDriver().getWindowHandles()); + getWebDriver().switchTo().window(tabs.get(number-1)); + } } \ No newline at end of file diff --git a/src/test/java/ru/alfabank/steps/ListStepsTest.java b/src/test/java/ru/alfabank/steps/ListStepsTest.java index fd1fdfce..d6eb5a48 100644 --- a/src/test/java/ru/alfabank/steps/ListStepsTest.java +++ b/src/test/java/ru/alfabank/steps/ListStepsTest.java @@ -24,6 +24,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; @@ -350,4 +351,16 @@ void selectElementNumberFromListAndSaveToVarOverMaxBorder() { assertThrows(IndexOutOfBoundsException.class, () -> lis.selectElementNumberFromListAndSaveToVar(4, "List", "varName")); } + + @Test + void testCheckListMatchesRegexPositive() { + akitaScenario.setVar("List", Arrays.asList("ab", "bc")); + lvs.checkListMatchesRegex("List", "[A-z]*"); + } + @Test + void testCheckListMatchesRegexNegative() { + akitaScenario.setVar("List", Arrays.asList("ab", "bc")); + assertThrows(AssertionError.class, () -> + lvs.checkListMatchesRegex("List", "[0-9]*")); + } } \ No newline at end of file diff --git a/src/test/java/ru/alfabank/steps/RoundUpStepsTest.java b/src/test/java/ru/alfabank/steps/RoundUpStepsTest.java index 1dbc92f4..3b801953 100644 --- a/src/test/java/ru/alfabank/steps/RoundUpStepsTest.java +++ b/src/test/java/ru/alfabank/steps/RoundUpStepsTest.java @@ -187,4 +187,19 @@ void testTestScript() { void expressionExpressionPositive() { rus.expressionExpression("\"test\".equals(\"test\")"); } + + @Test + void checkInVariableContainsCharactersPositive() { + String varName = "testName"; + String varValue = "testValue"; + akitaScenario.setVar(varName, varValue); + rus.checkInVariableContainsCharacters(varName, varValue.length()); + } + @Test + public void checkInVariableContainsCharactersNegative() { + String varName = "testName"; + String varValue = "testValue"; + akitaScenario.setVar(varName,varValue); + assertThrows(AssertionError.class, () -> rus.checkInVariableContainsCharacters(varName, 5)); + } } \ No newline at end of file diff --git a/src/test/java/ru/alfabank/steps/WebPageStepsTest.java b/src/test/java/ru/alfabank/steps/WebPageStepsTest.java index be95f39b..ebb4ad45 100644 --- a/src/test/java/ru/alfabank/steps/WebPageStepsTest.java +++ b/src/test/java/ru/alfabank/steps/WebPageStepsTest.java @@ -26,10 +26,13 @@ import ru.alfabank.alfatest.cucumber.api.AkitaScenario; import java.io.File; +import java.util.ArrayList; import static com.codeborne.selenide.Selenide.executeJavaScript; +import static com.codeborne.selenide.WebDriverRunner.getWebDriver; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; public class WebPageStepsTest { @@ -70,7 +73,7 @@ static void close() { @Test void navigateToUrl() { - assertThat(WebDriverRunner.getWebDriver().getTitle(), equalTo("Title")); + assertThat(getWebDriver().getTitle(), equalTo("Title")); } @Test @@ -244,4 +247,12 @@ void testCloseCurrentTab() { mbs.closeCurrentTab(); wpis.switchToTheTabWithTitle("Title"); } + + @Test + void testSwitchToTheTab() { + executeJavaScript("window.open(\"RedirectionPage.html\")"); + wpis.switchToTheTab(2); + int tabIndex = new ArrayList<>(getWebDriver().getWindowHandles()).indexOf(getWebDriver().getWindowHandle()); + assertEquals(2, tabIndex + 1); + } } \ No newline at end of file