Cucumber post API

1. 接口

1
2
3
Request URL: http://10.194.109.125/UserHabit/ICSUI/QuickLogin
Request Method: POST
Status Code: 204 No Content

 

2. feature 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
Feature: API test
 
 
  Scenario: Login with role
    Given  LoginWithRole
      |Environment       |DT5                   |
      |UserId            |allencckan            |
      |BusinessFunctionId|2                     |
      |BusinessFunction  |BOCC                  |
      |RoleId            |16                   |
      |RoleName          |Assistant BOCC Manager|
      |FromEntry         |/QuickAccess/ICSUI    |
    Then LoginWithRoleSuccess

 

3. TestRunner文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package APITestCase.TestRunner;
 
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
 
 
@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/APITestCase/Resources/",
        glue = {"Login/"},
        plugin = {"pretty","json:src/TestResult/cucumber.json","junit:src/TestResult/cucumber.xml"},
        tags = "@Smoke"
//        dryRun = true
)
 
//
public class TestRunner  extends AbstractTestNGCucumberTests{
//    public static void main(String[] args){
//        //System.out.println("args");
//        //System.out.println(args);
////        JUnitCore.main("TestRunner.TestRunner");
//    }
}

 

4. 公共方法封装文件

1
2
3
4
5
6
7
8
9
10
11
12
13
package APITestCase.APICommonMethods;
 
import static io.restassured.RestAssured.*;
 
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
 
public class commonMethods {
    public Response postRequest(String baseURI, String basePath, String methodPath, RequestSpecification requestSpecification){
        Response postResponse = with().spec(requestSpecification).baseUri(baseURI).basePath(basePath).log().all().when().post(methodPath);
        return postResponse;
    }
}

 

5. Given Then 方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package APITestCase.Login;
 
import APITestCase.APICommonMethods.commonMethods;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
 
import java.util.HashMap;
import java.util.Map;
 
import static io.restassured.RestAssured.given;
 
public class LoginWithRole {
    public Response loginWithRoleResponse;
    @Given("LoginWithRole")
    public void loginRole(Map<String, String> dataTable){
        commonMethods cm = new commonMethods();
        String baseURI = "http://10.194.109.125";
        String basePath = "UserHabit";
        String methodPath = "ICSUI/QuickLogin";
        Map<String,String> headerMap =new HashMap();
        headerMap.put("Accept", "application/json,text/javascript");
        headerMap.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        RequestSpecification loginRole = new RequestSpecBuilder().addHeaders(headerMap).addParams(dataTable).build();
        Response loginRoleResponse = cm.postRequest(baseURI,basePath,methodPath,loginRole);
        this.loginWithRoleResponse = loginRoleResponse;
    }
 
    @Then("LoginWithRoleSuccess")
    public void logninWithRole(){
        this.loginWithRoleResponse.then().statusCode(204);
    }
}

 

posted @   筱筱的春天  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2018-03-21 http://xx.xxx.xxx.xx:8080/把路径设置成http服务访问的形式
2018-03-21 Scrapy: 初识Scrapy
点击右上角即可分享
微信分享提示