Skip to content

Commit

Permalink
fixed issues with json mapper, renamed timeouts, optimized imports, a…
Browse files Browse the repository at this point in the history
…dded watches for pass/abort/disabled tests
  • Loading branch information
borzykin committed Jul 27, 2020
1 parent 814d77f commit 68b3334
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<webdrivermanager.version>3.8.1</webdrivermanager.version>
<fairy.version>0.5.9</fairy.version>
<guice.version>4.2.3</guice.version>
<gson.version>2.8.5</gson.version>
<rest.assured..version>4.3.0</rest.assured..version>
<gson.version>2.8.6</gson.version>
<rest.assured..version>4.3.1</rest.assured..version>
<javax.mail.version>1.4.7</javax.mail.version>
<!-- Plugins versions -->
<maven.checkstyle.version>3.1.0</maven.checkstyle.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.borzykin.webautomation.pages.DropDownPage;
import com.borzykin.webautomation.pages.FormAuthenticationPage;
import com.borzykin.webautomation.pages.HomePage;
import com.borzykin.webautomation.rest.RestService;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
Expand All @@ -28,6 +29,7 @@ protected void configure() {
bind(HomePage.class).in(Scopes.SINGLETON);
bind(DropDownPage.class).in(Scopes.SINGLETON);
bind(FormAuthenticationPage.class).in(Scopes.SINGLETON);
bind(RestService.class).in(Scopes.SINGLETON);
}

@Provides @Singleton
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/borzykin/webautomation/pages/BasePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ protected void waitForElementToBeVisible(final WebElement element) {
wait.until(ExpectedConditions.visibilityOf(element));
}

protected void waitForElementToBeVisible(final WebElement element, final int timeoutMs) {
final WebDriverWait wait = new WebDriverWait(driver, timeoutMs / 1000);
protected void waitForElementToBeVisible(final WebElement element, final int timeout) {
final WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.visibilityOf(element));
}

Expand All @@ -79,8 +79,8 @@ protected void waitForElementToBeClickable(final WebElement element) {
wait.until(ExpectedConditions.elementToBeClickable(element));
}

protected void waitForElementToBeClickable(final WebElement element, final int timeoutMs) {
final WebDriverWait wait = new WebDriverWait(driver, timeoutMs / 1000);
protected void waitForElementToBeClickable(final WebElement element, final int timeout) {
final WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.elementToBeClickable(element));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void enterLoginData(final String username, final String password) {
}

public String getErrorMessage() {
waitForElementToBeVisible(errorAlert, 5_000);
waitForElementToBeVisible(errorAlert, 5);
return errorAlert.getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.restassured.specification.ResponseSpecification;
import lombok.extern.log4j.Log4j2;

import static io.restassured.RestAssured.given;

/**
* @author Oleksii B
*/
Expand All @@ -33,7 +31,12 @@ public RestService() {
responseSpec = new ResponseSpecBuilder()
.expectStatusCode(200)
.build();
RestAssured.config().objectMapperConfig(new ObjectMapperConfig(ObjectMapperType.GSON));
}

private static RequestSpecification given() {
return RestAssured.given()
.config(RestAssured.config()
.objectMapperConfig(new ObjectMapperConfig(ObjectMapperType.GSON)));
}

public User getUser(final int id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.borzykin.webautomation.tests;

import javax.mail.Message;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
Expand All @@ -14,16 +12,14 @@
import com.borzykin.webautomation.pages.FormAuthenticationPage;
import com.borzykin.webautomation.pages.HomePage;
import com.borzykin.webautomation.rest.RestService;
import com.borzykin.webautomation.tests.base.BaseTest;
import com.google.inject.Inject;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.io.FileUtils;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.data.Percentage;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.borzykin.webautomation.tests;
package com.borzykin.webautomation.tests.base;

import com.borzykin.webautomation.common.provider.DriverFactory;
import com.borzykin.webautomation.modules.CoreModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
package com.borzykin.webautomation.tests;
package com.borzykin.webautomation.tests.base;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

import com.borzykin.webautomation.common.provider.DriverFactory;
import io.qameta.allure.Allure;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

@Log4j2
public class ExecutionWatcher implements TestWatcher {
@Override
public void testFailed(ExtensionContext exCont, Throwable thr) {
public void testAborted(ExtensionContext context, Throwable thr) {
log.info("Test '{}' is aborted", context.getDisplayName());
}

@Override
public void testDisabled(ExtensionContext context, Optional<String> optional) {
log.info("Test '{}' is disabled", context.getDisplayName());
}

@Override
public void testSuccessful(ExtensionContext context) {
log.info("Test '{}' is passed", context.getDisplayName());
}

@Override
public void testFailed(ExtensionContext context, Throwable thr) {
log.info("Test '{}' is failed", context.getDisplayName());
// take screenshot and attach to allure
byte[] screenshot = ((TakesScreenshot) DriverFactory.getDriver()).getScreenshotAs(OutputType.BYTES);
try (InputStream is = new ByteArrayInputStream(screenshot)) {
Expand Down

0 comments on commit 68b3334

Please sign in to comment.