Reputation: 79
I've been trying to transfer my restassured tests using testng over to cucumber and I've almost cracked it however the assertion has thrown me a little bit. This issue I have is the body in my assertion is throwing this error.
java: cannot find symbol
symbol: method body(java.lang.String,org.hamcrest.Matcher<java.lang.String>)
location: class stepdefs.articlesCucumberTests
Here is my current working tests.
import static io.restassured.RestAssured.*;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import static org.hamcrest.Matchers.*;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import org.testng.annotations.Test;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("unchecked")
public class articlesTestNg extends enablers {
//Checks articles individual ID's.
@Test(dataProvider = "getId")
public void TestAllArticles(String articlesId) {
given().
given().log().all().and().
pathParam("id", articlesId).
when().
get(singleArticles).
then().
assertThat().
statusCode(200).
body(("id"), equalTo(articlesId));
}
//Checks the whole content of the json file using an expected outcome in the project structure.
@Test
public void GetArticlesJson() {
JsonPath expectedJson = new JsonPath(new File(pathJson));
given().
when().
get(allArticles).
then().
assertThat().
statusCode(200).
and().
body("", hasItem(expectedJson.getMap("")));
}
Here is my so far attempt at the cucmber tests in the I will receive an individual article the body is throwing the error. Is there a better way to do this?
package stepdefs;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.junit.jupiter.api.Assertions;
import org.testng.Assert;
import org.testng.annotations.Test;
import skySportsPages.enablers;
import static io.restassured.RestAssured.baseURI;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
public class articlesCucumberTests extends enablers {
private Response response;
@Test
@Given("I have a set of articles containing individual ID's")
public void i_have_a_set_of_articles_containing_individual_id_s() {
RestAssured.baseURI = singleArticles;
System.out.println(baseURI);
}
@Test(dataProvider = "getId")
@When("I get an the article ID")
public void i_get_an_the_article_id(String articlesId) {
given().
given().log().all().and().
pathParam("id", articlesId).
when().
get(singleArticles);
}
@Test
@Then("I will receive an individual article")
public void i_will_receive_an_individual_article(String articlesId) {
Assert.assertEquals(body(("id"), equalTo(articlesId)));
}
@Test
@Given("I have a set of articles")
public void i_have_a_set_of_articles(String articlesId) {
}
@Test
@When("I get the list of articles")
public void i_get_the_list_of_articles() {
}
@Test
@Then("It will match the json file")
public void it_will_match_the_json_file() {
}
}
Upvotes: 0
Views: 332
Reputation: 526
Error is here because Assert.assertEquals
should have two parameters, in your case you have only one body(("id"), equalTo(articlesId))
that may return boolean, so check first what you have just performing:
@Test
@Then("I will receive an individual article")
public void i_will_receive_an_individual_article(String articlesId) {
body(("id"), equalTo(articlesId));
}
And then try to change to:
Assert.assertTrue(body(("id"), equalTo(articlesId)));
Upvotes: 0