Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用RESTAPI响应验证ui数据_Java_Rest_Selenium Webdriver_Assert_Rest Assured - Fatal编程技术网

Java 如何使用RESTAPI响应验证ui数据

Java 如何使用RESTAPI响应验证ui数据,java,rest,selenium-webdriver,assert,rest-assured,Java,Rest,Selenium Webdriver,Assert,Rest Assured,我需要验证我的ui数据和api响应是否相同 这是我试过的代码 private ValidateContentPage cp = new ValidateContentPage(); public void getTitle() { String UITitle = driver.findElement(titlepage).getText(); System.out.println(UITitle); Assert.assertEquals(UI

我需要验证我的ui数据和api响应是否相同

这是我试过的代码

private ValidateContentPage cp = new ValidateContentPage();

public void getTitle() {
        String UITitle = driver.findElement(titlepage).getText();
        System.out.println(UITitle);
        Assert.assertEquals(UITitle, cp.getAPICall(),"Passed");
    }
这是我的api回复

public class ValidateContentPage {
    
    public common cm = new common();
    public Properties prop;
    
    public void baseURI() {
        prop = cm.getProperties("./src/test/API/IndiaOne/propertyfile/EndpointURL.properties");
        RestAssured.baseURI = prop.getProperty("baseURI");
    }
    
    public String getAPICall() {
        
        objectpojo ps = given().expect().defaultParser(Parser.JSON).when().get(prop.getProperty("resources")).as(objectpojo.class, cm.getMapper());
        int number = ps.getPosts().size();
        System.out.println(number);
        System.out.println(ps.getPosts().get(0).getTitle());
        return ps.getPosts().get(0).getTitle();
    }

如果我使用testng断言和抛出空指针异常来验证两者,有人会帮助我验证ui数据和api响应。

您需要从
@Test
本身或从
@BeforeTest
调用ValidateContentPage

@Test
public void getTitle() {
        String UITitle = driver.findElement(titlepage).getText();
        System.out.println(UITitle);
        ValidateContentPage cp = new ValidateContentPage();
        Assert.assertEquals(UITitle, cp.getAPICall(),"Passed");
    }