ngrinder腳本get請求調試

1、啓動agent端口

ngrinder腳本get請求調試

2、點擊腳本跳轉到腳本

ngrinder腳本get請求調試
文件加跳轉到腳本如下:


    public static GTest test
    public static HTTPRequest request
    public static NVPair[] headers = []
    public static NVPair[] params = []
    public static Cookie[] cookies = []

    @BeforeProcess
    public static void beforeProcess() {
        HTTPPluginControl.getConnectionDefaults().timeout = 6000
        test = new GTest(1, "blog.51cto.com")
        request = new HTTPRequest()
        grinder.logger.info("before process.");
    }

    @BeforeThread 
    public void beforeThread() {
        test.record(this, "test")
        grinder.statistics.delayReports=true;
        grinder.logger.info("before thread.");
    }

    @Before
    public void before() {
        request.setHeaders(headers)
        cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
        grinder.logger.info("before thread. init headers and cookies");
    }

    @Test
    public void test(){
        HTTPResponse result = request.GET("https://blog.51cto.com/357712148/2440849", params)

        if (result.statusCode == 301 || result.statusCode == 302) {
            grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode); 
        } else {
            assertThat(result.statusCode, is(200));
        }
    }

3、點擊保存驗證腳本是否可運行

ngrinder腳本get請求調試

提示:

ngrinder腳本get請求調試

查看日誌:

ngrinder腳本get請求調試

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章