-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
608 additions
and
195 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package helpers; | ||
|
||
import io.qameta.allure.Allure; | ||
import io.qameta.allure.AllureLifecycle; | ||
import io.qameta.allure.model.Status; | ||
import io.qameta.allure.model.StepResult; | ||
import io.qameta.allure.util.ExceptionUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
|
||
import static io.qameta.allure.Allure.getLifecycle; | ||
import static io.qameta.allure.util.ResultsUtils.getStatus; | ||
import static io.qameta.allure.util.ResultsUtils.getStatusDetails; | ||
|
||
public class CustomAllure { | ||
public static final Logger log = LoggerFactory.getLogger(CustomAllure.class); | ||
private static final AllureLifecycle lifecycle = getLifecycle(); | ||
|
||
public static void logCurrentStep() { | ||
Optional<String> currentTestCaseOrStep = lifecycle.getCurrentTestCaseOrStep(); | ||
log.debug("Step UUID: {}", currentTestCaseOrStep.orElse("empty")); | ||
lifecycle.updateStep(step -> log.debug("Step name: {}", step.getName())); | ||
} | ||
|
||
/** | ||
* Run provided {@link Allure.ThrowableRunnable} as step with given name. Takes no effect | ||
* if no test run at the moment. | ||
* | ||
* @param runnable the step's body. | ||
*/ | ||
public static <T> T stepWithChangeableStatus(String name, final Allure.ThrowableRunnable<T> runnable) { | ||
final String uuid = UUID.randomUUID().toString(); | ||
getLifecycle().startStep(uuid, new StepResult().setName(name)); | ||
|
||
try { | ||
T result = runnable.run(); | ||
getLifecycle().updateStep(uuid, step -> step.setStatus( | ||
step.getStatus() == null | ||
? Status.PASSED | ||
: step.getStatus() | ||
)); | ||
return result; | ||
} catch (Throwable throwable) { | ||
getLifecycle().updateStep(s -> s | ||
.setStatus(getStatus(throwable).orElse(Status.BROKEN)) | ||
.setStatusDetails(getStatusDetails(throwable).orElse(null))); | ||
throw new RuntimeException(throwable); | ||
} finally { | ||
getLifecycle().stopStep(uuid); | ||
} | ||
} | ||
|
||
public static void stepWithChangeableStatus(String name, final Allure.ThrowableRunnableVoid runnable) { | ||
final String uuid = UUID.randomUUID().toString(); | ||
getLifecycle().startStep(uuid, new StepResult().setName(name)); | ||
|
||
try { | ||
runnable.run(); | ||
getLifecycle().updateStep(uuid, step -> step.setStatus( | ||
step.getStatus() == null | ||
? Status.PASSED | ||
: step.getStatus() | ||
)); | ||
} catch (Throwable throwable) { | ||
getLifecycle().updateStep(s -> s | ||
.setStatus(getStatus(throwable).orElse(Status.BROKEN)) | ||
.setStatusDetails(getStatusDetails(throwable).orElse(null))); | ||
ExceptionUtils.sneakyThrow(throwable); | ||
} finally { | ||
getLifecycle().stopStep(uuid); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
src/main/java/helpers/pageable/AssertionCheckThatEachElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package helpers.pageable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Класс для проверки элементов страницы с помощью переданного <i>утверждения</i> ({@code assertion}). | ||
* При каждом вызове perform() сохраняет ошибку, если хотя бы один элемент не прошел поверку. | ||
* Список ошибок можно получить вызвав {@link AssertionCheckThatEachElement#getCollectedErrors()}. | ||
* Рекомендуется использовать только в контексте класса {@link PageableChecker}. | ||
* | ||
* @param <PAGE_OBJ> класс объекта, предоставляющего набор проверяемых элементов | ||
* @param <E> тип проверяемых элементов | ||
* @author Achitheus (Yury Yurchenko) | ||
*/ | ||
public class AssertionCheckThatEachElement<PAGE_OBJ, E> extends ElementsCheck<PAGE_OBJ> { | ||
private final Function<PAGE_OBJ, Collection<E>> elementsProvider; | ||
private final BiConsumer<E, String> assertion; | ||
|
||
/** | ||
* Создает новый объект проверки. | ||
* | ||
* @param continueConstructorName продолжение фразы "Убедиться, что каждый элемент...", т.е. | ||
* словесное описание элемента, соответствующего утверждению {@code assertion}. | ||
* Не начинать с отрицания ("не превышает величину X" - плохо). | ||
* Примеры: "содержит подстроку фыва", "соответствует условию: actualPrice > minPrice" и т.п. | ||
* @param elementsProvider функция, предоставляющая коллекцию проверяемых объектов. | ||
* @param assertion утверждение о проверяемом элементе, где первый параметр сам элемент, | ||
* второй - сформированное сообщение. Пример, если элемент является ценой: <p> | ||
* {@code (price, message) -> assertTrue(price < 10_000, message)}. | ||
* @author Achitheus (Yury Yurchenko) | ||
*/ | ||
public AssertionCheckThatEachElement(String continueConstructorName, Function<PAGE_OBJ, Collection<E>> elementsProvider, BiConsumer<E, String> assertion) { | ||
super(continueConstructorName); | ||
this.assertion = assertion; | ||
this.elementsProvider = elementsProvider; | ||
} | ||
|
||
@Override | ||
protected ElementsCheckResult performWithoutNumberIncrement(PAGE_OBJ target) { | ||
Collection<E> elementCollection = elementsProvider.apply(target); | ||
List<AssertionError> errorList = new ArrayList<>(); | ||
for (E el : elementCollection) { | ||
try { | ||
assertion.accept(el, "Элемент \"" + el + "\" не " + passedElementDescription); | ||
} catch (AssertionError error) { | ||
errorList.add(error); | ||
} | ||
} | ||
|
||
ElementsCheckResult elementsCheckResult = new ElementsCheckResult(passedElementDescription, checkNumber, errorList, elementCollection.size()); | ||
elementsCheckResult.getError().ifPresent(collectedErrors::add); | ||
return elementsCheckResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package helpers.pageable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Базовый абстрактный класс проверки элементов. | ||
* | ||
* @param <T> тип объекта, предоставляющего набор проверяемых элементов (page object). | ||
* @author Achitheus (Yury Yurchenko) | ||
*/ | ||
public abstract class ElementsCheck<T> implements ElementsCheckWithErrorCollector<T> { | ||
protected String passedElementDescription; | ||
protected final List<AssertionError> collectedErrors = new ArrayList<>(); | ||
protected int checkNumber = 0; | ||
|
||
public ElementsCheck(String passedElementDescription) { | ||
this.passedElementDescription = passedElementDescription; | ||
} | ||
|
||
@Override | ||
final public ElementsCheckResult perform(T target) { | ||
checkNumber++; | ||
return performWithoutNumberIncrement(target); | ||
} | ||
|
||
protected abstract ElementsCheckResult performWithoutNumberIncrement(T target); | ||
|
||
@Override | ||
final public Collection<? extends AssertionError> getCollectedErrors() { | ||
return collectedErrors; | ||
} | ||
} |
Oops, something went wrong.