This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
API and DB+API tests #70
Open
ava1on
wants to merge
22
commits into
autoschool:master
Choose a base branch
from
ava1on:api_and_db
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4bcf882
Добавлены два новых теста:
74e6e75
исправление в соответствии с полученными комментариями:
eeff145
Refactored all WebElement types to HtmlElements
029201a
Adding additional items to Page Object structure
a18b6a3
Arranging smoke test pack: marking existing tests and adding new tests
8086dd2
Adding Regression tests
5404c22
Updating recording to comments, adding new tests and some refactoring
8d2fdce
Refactoring: moving PageMethods methods to DefaultSteps
fba20d3
Fixing error in regexp for time and date
d9b45bf
First api auto test using Rest-assured
4e52750
Adding second test for Rest assured
6e56c15
Added Title and statusCode verification for second test
c4fa2c6
Refactoring: removed unused imports and unused getters
b6ea52d
Added test cases via Retrofit
76151dd
Removed unused Responses classes fields and getters
018ae9a
Merging dbClient from master
4f510bb
Added test for database and api
723d594
Changed matcher in db test
13b23a8
Refactored Retfofit test class
8189592
Adding getFirstWidget method
a87f50e
Adding DbClientRule
b3b3b5b
Optimizing POM files for all modules
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>school-2016</artifactId> | ||
<groupId>ru.qatools.school</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>api-tests-module</artifactId> | ||
<name>API Tests</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.jayway.restassured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<version>2.9.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.retrofit2</groupId> | ||
<artifactId>retrofit</artifactId> | ||
<version>2.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.6.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.retrofit2</groupId> | ||
<artifactId>converter-gson</artifactId> | ||
<version>2.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ru.yandex.qatools.allure</groupId> | ||
<artifactId>allure-junit-adaptor</artifactId> | ||
<version>1.4.23</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ru.qatools.school</groupId> | ||
<artifactId>dbclient-module</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ru.yandex.qatools.matchers</groupId> | ||
<artifactId>collection-matchers</artifactId> | ||
<version>1.3</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
api-tests-module/src/test/java/ru/qatools/school/Responses/CitiesResponse.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,10 @@ | ||
package ru.qatools.school.Responses; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class CitiesResponse { | ||
|
||
public CitiesResponse() { | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
api-tests-module/src/test/java/ru/qatools/school/Responses/SuggestResponse.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,12 @@ | ||
package ru.qatools.school.Responses; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class SuggestResponse { | ||
private int id; | ||
|
||
public SuggestResponse(int id){ | ||
this.id = id; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api-tests-module/src/test/java/ru/qatools/school/Responses/TemperatureValues.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,16 @@ | ||
package ru.qatools.school.Responses; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class TemperatureValues { | ||
private double value; | ||
|
||
public TemperatureValues(double value) { | ||
this.value = value; | ||
} | ||
|
||
public double getValue() { | ||
return value; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
api-tests-module/src/test/java/ru/qatools/school/Responses/WeatherResponse.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,20 @@ | ||
package ru.qatools.school.Responses; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class WeatherResponse { | ||
private TemperatureValues[] temperatures; | ||
|
||
public WeatherResponse(TemperatureValues[] temperatures) { | ||
this.temperatures = temperatures; | ||
} | ||
|
||
public TemperatureValues[] getTemperatures() { | ||
return temperatures; | ||
} | ||
|
||
public Double recalculateCelsiusToFahrenheit(){ | ||
return (this.getTemperatures()[0].getValue()*9/5+32); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
api-tests-module/src/test/java/ru/qatools/school/apitests/DbAPITest.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,48 @@ | ||
package ru.qatools.school.apitests; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import ru.qatools.school.DbClient; | ||
import ru.yandex.qatools.allure.annotations.Title; | ||
|
||
import java.util.List; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
import static ru.qatools.school.data.Constants.*; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class DbAPITest { | ||
private DbClient dbClient; | ||
|
||
@Before | ||
public void setupDbConnection(){ | ||
dbClient = new DbClient(); | ||
} | ||
|
||
@After | ||
public void closeDbConnection(){ | ||
dbClient.close(); | ||
} | ||
|
||
@Test | ||
@Title("Списки городов, полученные через API и Database, должны совпадать") | ||
public void apiResponseShouldMatchDatabaseData(){ | ||
List<Integer> ids = | ||
given() | ||
.baseUri(BASE_URL) | ||
.param(QUERY_PARAMETER, CITYNAME_PART) | ||
.when() | ||
.get(SUGGEST_REQUEST) | ||
.then() | ||
.assertThat().statusCode(HttpStatus.SC_OK) | ||
.and().extract().body().path("id"); | ||
assertThat("Полученные через API данные не соответствуют Database", ids, | ||
is(dbClient.getCitiesByNamePart(CITYNAME_PART))); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
api-tests-module/src/test/java/ru/qatools/school/apitests/RestAssuredAPITests.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,51 @@ | ||
package ru.qatools.school.apitests; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.Test; | ||
import ru.qatools.school.Responses.CitiesResponse; | ||
import ru.qatools.school.Responses.WeatherResponse; | ||
import ru.yandex.qatools.allure.annotations.Title; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.closeTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static ru.qatools.school.data.Constants.*; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class RestAssuredAPITests { | ||
|
||
@Test | ||
@Title("Должны получить заданное в параметре количество городов в ответе") | ||
public void shouldReturnRequestedNumberOfCities(){ | ||
CitiesResponse[] citiesArray = | ||
given(). | ||
baseUri(BASE_URL). | ||
param(LIMIT_PARAMETER, LIMIT_VALUE). | ||
when(). | ||
get(CITIES_REQUEST). | ||
then().statusCode(HttpStatus.SC_OK). | ||
and().extract(). | ||
body().as(CitiesResponse[].class); | ||
assertThat("Неверное количество городов в ответе", citiesArray.length, is(LIMIT_VALUE)); | ||
} | ||
|
||
@Test | ||
@Title("Значение температуры по шкале Фаренгейта должно соответствовать значению по шкале Цельсия") | ||
public void shouldReturnCompatibleTemperatureValuesForCelsiusAndFahrenheit(){ | ||
WeatherResponse weatherResponse = | ||
given(). | ||
baseUri(BASE_URL). | ||
param(CITY_PARAMETER, CITY_VALUE). | ||
when(). | ||
get(WEATHER_REQUEST). | ||
then().statusCode(HttpStatus.SC_OK). | ||
and().extract(). | ||
body().as(WeatherResponse.class); | ||
assertThat("Значение температуры не правильно переведено из шкалы Цельсия в шкалу Фаренгейта", | ||
weatherResponse.getTemperatures()[2].getValue(), | ||
is(closeTo(weatherResponse.recalculateCelsiusToFahrenheit(), TEMPERATURE_ERROR))); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
api-tests-module/src/test/java/ru/qatools/school/apitests/RetrofitAPITests.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,55 @@ | ||
package ru.qatools.school.apitests; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import retrofit2.Response; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
import ru.qatools.school.Responses.CitiesResponse; | ||
import ru.qatools.school.Responses.WeatherResponse; | ||
import ru.qatools.school.interfaces.Cities; | ||
import ru.qatools.school.interfaces.Weather; | ||
import ru.yandex.qatools.allure.annotations.Title; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.closeTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static ru.qatools.school.data.Constants.*; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class RetrofitAPITests { | ||
|
||
private static Retrofit retrofit; | ||
|
||
@BeforeClass | ||
public static void initRetrofit(){ | ||
retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build(); | ||
} | ||
|
||
@Test | ||
@Title("Должны получить заданное в параметре количество городов в ответе") | ||
public void shouldReturnRequestedNumberOfCities() throws IOException{ | ||
Cities cities = retrofit.create(Cities.class); | ||
Response<List<CitiesResponse>> response = cities.citiesList(LIMIT_VALUE).execute(); | ||
assertThat("Код ответа неверный", response.code(), is(HttpStatus.SC_OK)); | ||
assertThat("Неверное количество городов в ответе", response.body(), hasSize(LIMIT_VALUE)); | ||
} | ||
|
||
@Test | ||
@Title("Значение температуры по шкале Фаренгейта должно соответствовать значению по шкале Цельсия") | ||
public void shouldReturnCompatibleTemperatureValuesForCelsiusAndFahrenheit() throws IOException{ | ||
Weather weather = retrofit.create(Weather.class); | ||
Response<WeatherResponse> response = weather.weather(CITY_PARAMETER, null).execute(); | ||
assertThat("Код ответа неверный", response.code(), is(HttpStatus.SC_OK)); | ||
assertThat("Значение температуры не правильно переведено из шкалы Цельсия в шкалу Фаренгейта", | ||
response.body().getTemperatures()[2].getValue(), | ||
is(closeTo(response.body().recalculateCelsiusToFahrenheit(), TEMPERATURE_ERROR))); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
api-tests-module/src/test/java/ru/qatools/school/data/Constants.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,19 @@ | ||
package ru.qatools.school.data; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public class Constants { | ||
public static final String BASE_URL = "http://weather.lanwen.ru/api/"; | ||
public static final String LIMIT_PARAMETER = "limit"; | ||
public static final String CITIES_REQUEST = "cities"; | ||
public static final int LIMIT_VALUE = 3; | ||
public static final String WEATHER_REQUEST = "weather"; | ||
public static final String CITY_PARAMETER = "city"; | ||
public static final String CITY_VALUE = "Saint Petersburg"; | ||
public static final double TEMPERATURE_ERROR = 0.1; | ||
public static final String REGION_PARAMETER = "region"; | ||
public static final String SUGGEST_REQUEST = "suggest"; | ||
public static final String QUERY_PARAMETER = "query"; | ||
public static final String CITYNAME_PART = "Saint"; | ||
} |
18 changes: 18 additions & 0 deletions
18
api-tests-module/src/test/java/ru/qatools/school/interfaces/Cities.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,18 @@ | ||
package ru.qatools.school.interfaces; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Query; | ||
import ru.qatools.school.Responses.CitiesResponse; | ||
|
||
import java.util.List; | ||
|
||
import static ru.qatools.school.data.Constants.LIMIT_PARAMETER; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public interface Cities { | ||
@GET("cities") | ||
Call<List<CitiesResponse>> citiesList(@Query(LIMIT_PARAMETER) int limitValue); | ||
} |
17 changes: 17 additions & 0 deletions
17
api-tests-module/src/test/java/ru/qatools/school/interfaces/Weather.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,17 @@ | ||
package ru.qatools.school.interfaces; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Query; | ||
import ru.qatools.school.Responses.WeatherResponse; | ||
|
||
import static ru.qatools.school.data.Constants.CITY_PARAMETER; | ||
import static ru.qatools.school.data.Constants.REGION_PARAMETER; | ||
|
||
/** | ||
* @author ava1on | ||
*/ | ||
public interface Weather { | ||
@GET("weather") | ||
Call<WeatherResponse> weather(@Query(CITY_PARAMETER) String city, @Query(REGION_PARAMETER) String region); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://blog.qatools.ru/junit/junit-rules-tutorial/