robotframework做http接口测试

使用方式基本都是参考bulkan的GitHub中的例子,地址如下:

https://github.com/bulkan/robotframework-requests/blob/master/tests/testcase.txt

get请求:

 

post请求:

请求对应的后端的一个sping的demo,demo的代码如下

package cn.sunline;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Application {
	private static Connection conn;
	private static Statement statement;
	private static ResultSet rs;

	public static void main(String[] args) {
		prepareDBEnv();
		SpringApplication.run(Application.class, args);
	}

	@RequestMapping("/queryStatus")
//	public String hello(@RequestParam("id") Integer id){
		public String hello(@RequestParam("id") Integer id,@RequestParam("table") String table){

		String result = "no data";
//		String sql = "select * from test where id = " + id; // 要执行的SQL
//		String sql = "select * from txc_system_seq where id = " + id; // 要执行的SQL
		String sql = "select * from txc_"+table+"_seq where id = " + id; // 要执行的SQL


		try {
			rs = statement.executeQuery(sql);// 创建数据对象
			if(rs.next()){
				if (table.equals("system")) {
						result = rs.getString(5);
				}else if(table.equals("branch")){
					result = rs.getString(7);
				}
				else{
					System.out.println("表明输入错误");
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	private static void prepareDBEnv(){
		try {
			conn = DriverManager.getConnection("jdbc:mysql://10.22.4.30:3306/txc", "root", "root");
			statement = conn.createStatement();
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
}

 

suite文件内容如下:

*** Settings ***
Library           RequestsLibrary
Library           Collections

*** Test Cases ***
Case3
    Create Session    test    http://www.kuaidi100.com
    ${headers}=    Create Dictionary    Content-Type=application/json
    ${param}=    Create Dictionary    type=yunda    postid=3832997567488
    ${response}    Post Request    test    /query    params=${param}    headers=${headers}
    log    ${response}
    ${var}    To Json    ${response.content}
    log    ${var}

postAPI
    Create Session    test    http://localhost:5555
    ${headers}=    Create Dictionary    Content-Type=application/json
    &{params}=    Create Dictionary    id=1    table=1
    ${resp}=    Post Request    test    /queryStatus    params=${params}    headers=${headers}
    log    ${resp}
    Should Be Equal As Integers    ${resp.status_code}    200

getAPI
    Create Session    baidu    http://www.baidu.com
    ${resp}=    Get Request    baidu    /
    Should Be Equal As Strings    ${resp.status_code}    200

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值