使用方式基本都是参考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