Skip to content

Akita steps #146

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
168 changes: 84 additions & 84 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions src/main/java/ru/alfabank/alfatest/cucumber/utils/DateUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ru.alfabank.alfatest.cucumber.utils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DateUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выглядит как enum с методом, так почему бы и не сделать enum? А если ещё и вместо свичкейса сделать EnumMap, то и шанс отстрелить себе ногу существенно снизится.


public static LocalDate yesterday() {
return LocalDate.now().minusDays(1);
}
public static LocalDate tomorrow() {
return LocalDate.now().plusDays(1);
}
public static LocalDate today() {
return LocalDate.now();
}
public static LocalDate monthAgo() {
return LocalDate.now().minusMonths(1);
}
public static LocalDate threeMonthAgo() {
return LocalDate.now().minusMonths(3);
}
public static LocalDate yearAgo() {
return LocalDate.now().minusYears(1);
}
public static LocalDate monthAhead() {
return LocalDate.now().plusMonths(1);
}
public static LocalDate threeMonthAhead() {
return LocalDate.now().plusMonths(3);
}
public static LocalDate yearAhead() {
return LocalDate.now().plusYears(1);
}
public static LocalDate convertStringDateToValues(String expectedDate) {
switch (expectedDate) {
case "сегодня":
return today();
case "вчера":
return yesterday();
case "завтра":
return tomorrow();
case "месяц назад":
return monthAgo();
case "3 месяца назад":
return threeMonthAgo();
case "год назад":
return yearAgo();
case "месяц вперед":
return monthAhead();
case "3 месяца вперед":
return threeMonthAhead();
case "год вперед":
return yearAhead();
default:
return LocalDate.parse(expectedDate, DateTimeFormatter.ofPattern("dd.MM.yyyy"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Форматтер выглядит как штука, которую имеет смысл как минимум вынести из конвертера.

}
}
}
5 changes: 5 additions & 0 deletions src/main/java/ru/alfabank/steps/BaseMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
31 changes: 31 additions & 0 deletions src/main/java/ru/alfabank/steps/ElementsInteractionSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -82,4 +87,30 @@ public void clickOnButtonAndUploadFile(String buttonName, String fileName) {
File attachmentFile = new File(file);
akitaScenario.getCurrentPage().getElement(buttonName).uploadFile(attachmentFile);
}

/**
* Выполняется ввод даты в поле
* Дата преобразуется из значения "сегодня", "вчера", "завтра", "месяц назад", "3 месяца назад", "год назад", "месяц вперед", "3 месяца вперед", "год вперед"
*/
@И("^в поле \"([^\"]*)\" введено и преобразовано в дату значение \"([^\"]*)\"$")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что случится, если сунуть сюда, скажем, стрингу «три месяца назад»?

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 месяца вперед", "год вперед"
*/
@И("^(?:поле|элемент) \"([^\"]*)\" содержит дату \"(.*)\"$")
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))));
}
}
15 changes: 15 additions & 0 deletions src/main/java/ru/alfabank/steps/ListVerificationSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -188,4 +189,18 @@ public void checkListInnerTextCorrespondsToListFromVariable(String listName, Str
assertThat(String.format("Список со страницы %s: %s не совпадает с ожидаемым списком из переменной %s:%s", listName, actualList, listVariable, expectedList)
, actualList, containsInAnyOrder(expectedList.toArray()));
}

/**
* Производится проход по списку и проверятся текст на соответствие формату регулярного выражения
*/
@Тогда("^элементы списка \"([^\"]*)\" удовлетворяют регулярному выражению \"(.*)\"")
public void checkListMatchesRegex(String listName, String pattern) {
List<SelenideElement> listOfElementsFromPage = akitaScenario.getCurrentPage().getElementsList(listName);
List<String> 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));
}
}
9 changes: 9 additions & 0 deletions src/main/java/ru/alfabank/steps/RoundUpSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,13 @@ public void checkIfValueFromVariableEqualPropertyVariable(String envVarible, Str
public void expressionExpression(String expression) {
akitaScenario.getVars().evaluate("assert(" + expression + ")");
}

/**
* Проверка что в переменной содержится ожидаемое количество символов
*/
@Тогда("^в переменной \"([^\"]*)\" содержится (\\d+) символов$")
public void checkInVariableContainsCharacters(String variableName, int numbersCount) {
assertThat("Количество символов в поле " + akitaScenario.getVar(variableName).toString().length() + "должно быть " + numbersCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String.format?

akitaScenario.getVar(variableName).toString().length(), equalTo(numbersCount));
}
}
11 changes: 11 additions & 0 deletions src/main/java/ru/alfabank/steps/WebPageInteractionSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -190,4 +192,13 @@ public void savePageTitleToVariable(String variableName) {
akitaScenario.setVar(variableName, titleName);
akitaScenario.write("Значение заголовка страницы [" + titleName + "] сохранено в переменную [" + variableName + "]");
}

/**
* Производится переключение на вкладку с номером
*/
@Когда("^выполнено переключение на \"([^\"]*)\" вкладку$")
public void switchToTheTab(Integer number) {
ArrayList<String> tabs = new ArrayList<>(getWebDriver().getWindowHandles());
getWebDriver().switchTo().window(tabs.get(number-1));
}
}
13 changes: 13 additions & 0 deletions src/test/java/ru/alfabank/steps/ListStepsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]*"));
}
}
Loading