[英]How to generate cucumber.json per test in respective test folders (I am using Cucumber 5 which uses TestNG for parallel execution)
[英]How can I change my restassured test using testng into cucumber?
我一直在尝试使用 testng 将我放心的测试转移到 cucumber 并且我几乎破解了它,但是断言让我有点失望。 我遇到的这个问题是我断言中的主体抛出了这个错误。
java: cannot find symbol
symbol: method body(java.lang.String,org.hamcrest.Matcher<java.lang.String>)
location: class stepdefs.articlesCucumberTests
这是我目前的工作测试。
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("")));
}
这是我迄今为止在黄瓜测试中的尝试,我将收到一篇正文抛出错误的个人文章。 有一个更好的方法吗?
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() {
}
}
不,我认为我们不在 cucumber 步骤中使用 @Test 注释。 您应该在toolqa上查看更多教程。
错误在这里是因为Assert.assertEquals
应该有两个参数,在您的情况下,您只有一个body(("id"), equalTo(articlesId))
可能返回 boolean,所以首先检查您刚刚执行的操作:
@Test
@Then("I will receive an individual article")
public void i_will_receive_an_individual_article(String articlesId) {
body(("id"), equalTo(articlesId));
}
然后尝试更改为:
Assert.assertTrue(body(("id"), equalTo(articlesId)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.