Anton Karpenko
2018-07-26T05:40:27Z

jsonpath

| @BeforeMethod
| public void start(){
| RestAssured.baseURI = "https://dictionary.yandex.net/api/v1/dicservice.json";
| }
|
| @DataProvider
| public Object[][] dictionary(){
| return new Object[][] {
| {"Привет","hallo"}
| };
| }
|
| @Test(dataProvider = "dictionary")
| public void lookupTest(String text, String answer){
| String path = getPathFormated(API_KEY, text, LANGUAGE_FORMAT);
|
| RestAssured.useRelaxedHTTPSValidation();
| String json = given()
| .header("User-Agent", "Mozilla...")
| .header("JWT", "jwt_token")
| .when()
| .get(EndpointURI.LOOKUP.addPath(path)).andReturn().body().print();
| // .then()
| // .statusCode(200)
| // .body("def[0].tr[0].syn[1].text", equalTo(answer));
|
| System.out.println(from(json).get("$.def.length()"));
| }
|
| protected String getPathFormated(String key, String text, String languageFormat) {
| return String.format("?key=%s&text=%s&lang=%s", key, text, languageFormat);
| }