Skip to content

Commit

Permalink
Fix/remove debug (#116)
Browse files Browse the repository at this point in the history
* updated body log with prettyPrint
* updated logging of resolved variable value
  • Loading branch information
GannaChernyshova authored Nov 26, 2018
1 parent 9e28230 commit 73848bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.String.format;
import static ru.alfabank.tests.core.helpers.PropertyLoader.loadProperty;

/**
Expand Down Expand Up @@ -95,6 +96,8 @@ public static String resolveVars(String inputString) {
}
if (newString.isEmpty()) {
newString = inputString;
} else {
AkitaScenario.getInstance().write(format("Значение переменной %s = %s", inputString, newString));
}
return newString;
}
Expand All @@ -117,8 +120,8 @@ public static String resolveJsonVars(String inputJsonAsString) {
String value = loadProperty(varName, (String) AkitaScenario.getInstance().tryGetVar(varName));
if (value == null) {
AkitaScenario.getInstance().write(
"Значение " + varName +
" не было найдено ни в application.properties, ни в environment переменной");
"Значение " + varName +
" не было найдено ни в application.properties, ни в environment переменной");
}
newString = m.replaceFirst(value);
if (isJSONValid(newString)) return newString;
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/ru/alfabank/steps/DefaultApiSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@
import cucumber.api.java.ru.И;
import cucumber.api.java.ru.Тогда;
import io.restassured.http.Method;
import io.restassured.internal.support.Prettifier;
import io.restassured.response.Response;
import io.restassured.specification.RequestSender;
import io.restassured.specification.RequestSpecification;
import lombok.extern.slf4j.Slf4j;
import ru.alfabank.alfatest.cucumber.api.AkitaScenario;
import ru.alfabank.tests.core.rest.RequestParam;

import static io.restassured.RestAssured.given;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static ru.alfabank.alfatest.cucumber.ScopedVariables.resolveJsonVars;
import static ru.alfabank.alfatest.cucumber.ScopedVariables.resolveVars;
import static ru.alfabank.tests.core.helpers.PropertyLoader.*;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -100,7 +103,7 @@ public void checkValuesInJsonAsString(String jsonVar, DataTable dataTable) {
JsonParser parser = new JsonParser();
ReadContext ctx = JsonPath.parse(strJson, createJsonPathConfiguration());
boolean error = false;
for (List<String> row : dataTable.raw()){
for (List<String> row : dataTable.raw()) {
String jsonPath = row.get(0);
JsonElement actualJsonElement;
try {
Expand Down Expand Up @@ -130,7 +133,7 @@ public void getValuesFromJsonAsString(String jsonVar, DataTable dataTable) {
Gson gsonObject = new Gson();
ReadContext ctx = JsonPath.parse(strJson, createJsonPathConfiguration());
boolean error = false;
for (List<String> row : dataTable.raw()){
for (List<String> row : dataTable.raw()) {
String jsonPath = row.get(0);
String varName = row.get(1);
JsonElement jsonElement;
Expand All @@ -149,9 +152,9 @@ public void getValuesFromJsonAsString(String jsonVar, DataTable dataTable) {

private Configuration createJsonPathConfiguration() {
return new Configuration.ConfigurationBuilder()
.jsonProvider(new GsonJsonProvider())
.mappingProvider(new GsonMappingProvider())
.build();
.jsonProvider(new GsonJsonProvider())
.mappingProvider(new GsonMappingProvider())
.build();
}

/**
Expand Down Expand Up @@ -197,9 +200,9 @@ private RequestSender createRequest(List<RequestParam> paramsTable) {
private void getBodyAndSaveToVariable(String variableName, Response response) {
if (response.statusCode() >= 200 && response.statusCode() < 300) {
akitaScenario.setVar(variableName, response.getBody().asString());
if (log.isDebugEnabled()) akitaScenario.write("Тело ответа : \n" + response.getBody().asString());
akitaScenario.write("Тело ответа : \n" + new Prettifier().getPrettifiedBodyIfPossible(response, response));
} else {
fail("Некорректный ответ на запрос: " + response.getBody().asString());
fail("Некорректный ответ на запрос: " + new Prettifier().getPrettifiedBodyIfPossible(response, response));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package ru.alfabank.loadPropertyTests;

import com.codeborne.selenide.WebDriverRunner;
import cucumber.api.Scenario;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ru.alfabank.StubScenario;
import ru.alfabank.alfatest.cucumber.api.AkitaEnvironment;
import ru.alfabank.alfatest.cucumber.api.AkitaScenario;

Expand All @@ -38,7 +40,8 @@ public static void init() {

@Before
public void prepare() {
akitaScenario.setEnvironment(new AkitaEnvironment());
Scenario scenario = new StubScenario();
akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
}

@AfterClass
Expand Down

0 comments on commit 73848bf

Please sign in to comment.