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 all 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
43 changes: 43 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,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<String, LocalDate> 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;
}
}
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);
}
}
32 changes: 32 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,31 @@ 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.

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

@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))));
}
}
16 changes: 16 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,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<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));
}
}
14 changes: 14 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,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));
}
}
12 changes: 12 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,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<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]*"));
}
}
15 changes: 15 additions & 0 deletions src/test/java/ru/alfabank/steps/RoundUpStepsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Loading