栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

RestAssured实现POST请求

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

RestAssured实现POST请求

.RestAssured简介

REST Assured 是由 Johan Haleby开发和维护,当然这些年有很多人往这个github贡献过代码,使得这么这个工具越来越流行。

这个框架使java语言写接口测试用例变成和ruby和groovy语言一样容易和简单。

官方网站是:http://rest-assured.io/

官方文档:http://rest-assured.io/#docs

github项目地址:https://github.com/rest-assured/rest-assured

这个是这个框架的Logo, 下一篇我们创建一个maven项目,然后引用Rest-Assured框架。
 

相关链接:接口测试 rest-assured 使用指南_hualusiyu的专栏-CSDN博客_rest-assured

import io.restassured.RestAssured;
import io.restassured.path.xml.XmlPath;
import io.restassured.response.Response;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;

public class TestSOAPAPI {
  public String postMethod(String url, String requestPath,String filePath) throws Exception {
    // put the request body in test.xml file.
    FileInputStream fileInputStream = new FileInputStream(filePath);
    RestAssured.baseURI = url;
    Response response =
        RestAssured.given()
            .header("content-Type", "text/xml")
            .and()
            .body(IOUtils.toString(fileInputStream, "UTF-8"))
            .when()
            .post(requestPath)
            .then()
            .statusCode(200)
            .and()
            .log()
            .all()
            .extract()
            .response();

    XmlPath jsXpath = new XmlPath(response.asString()); // Converting string into xml path to assert
    System.out.println(response.asString());
    return  response.asString();
  }
}
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/763656.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号