Kubata - Maitiro Ekuchengetedza Saiti Yekupindura

Nzira yekuchengetedza sei mhinduro muviri kuGatling?

Patinoita API yekuyedza kuyedzwa, isu tingangoda kuvaka ketani yezvikumbiro. Semuenzaniso, isu tinoshevedza kuAPI, chengetedza mhinduro uye kupfuudza mhinduro kune imwe API kufona.

Izvi zvinodaidzwa kukumbira-kupindura kusunga cheni uye chiitiko chakajairika pakuyedza APIs.

Kufungidzira kunopa nzira yekuchengetedza mhinduro yese kana chikamu chemhinduro.

Iyi mienzaniso iripazasi inoratidza maitiro ekuchengetedza dhata yekupindura muGatling.

Sevha Muviri Wese Wemhinduro

val authRequest = exec(http('Auth Request')
.post(base_url + '/login/auth')
.body(ElFileBody('payload.json'))
.check(bodyString.saveAs('Auth_Response'))
.check(status is 200))

Isu tinochengetedza iyo yakazara mhinduro yeayo pamusoro API kufona mune yakasarudzika inonzi Auth_Response.



Ipapo isu tinogona kushandisa izvo zvinoshanduka, zvine mhinduro, kupasa semuviri kana kubhadhara mubhadharo kune chimwe chikumbiro, senge:

val validateRequest = exec(http('Validate Request')
.post(base_url + '/login/validate')
.body(StringBody('${Auth_Response}'))
.check(bodyString.saveAs('Validate_Response'))
.check(status is 200) )

Bvisa Element Kubva Kupindura Muviri uye Sevha

MuGatling, isu tinogona zvakare kuenzanisa mhinduro, semuenzaniso naJsonPath, kubvisa kukosha uye kuichengeta seyakasiyana. Senge pamusoro, isu tinokwanisa kubva tapfuudza iyo kusiana mune inotevera API kufona.

val loginRequest: HttpRequestBuilder = http('Login Request')
.post(base_url + '/login')
.header(ContentType, ApplicationJson)
.header(Accept, ApplicationJson)
.body(StringBody(''))
.check(status is 200)
.check(jsonPath('$.tokenId').saveAs('tokenId'))

Muchikumbiro chiri pamusoro, tinopenengura iyo JSON Mhinduro uye tinobvisa kukosha kweparamende tokenId uye chengetedza kukosha kwayo se tokenId.

Tinogona ipapo kureva zvinoshanduka tichishandisa ${tokenId}