प्रलेखन के रूप में बताते हैं:
इतना तय है कि स्वचालित रूप से निर्धारित करने की कोशिश करेंगे जो पैरामीटर प्रकार (यानी क्वेरी या प्रपत्र पैरामीटर) HTTP पद्धति पर आधारित । के मामले में क्वेरी पैरामीटर स्वचालित रूप से उपयोग किए जाएंगे और POST फ़ॉर्म पैरामीटर का उपयोग किया जाएगा।
लेकिन आपके मामले में ऐसा लगता है कि आपको क्वेरी पैरामीटर के बजाय पथ पैरामीटर की आवश्यकता है। ध्यान दें कि देश प्राप्त करने के लिए सामान्य यूआरएल http://restcountries.eu/rest/v1/name/{country}
है जहां {country}
देश का नाम है।
फिर, पथ पैरामीटर स्थानांतरित करने के कई तरीके हैं।
यहाँ कुछ उदाहरण हैं
उदाहरण का उपयोग करते हुए pathParam(): का उपयोग कर चर
// Here the key name 'country' must match the url parameter {country}
RestAssured.given()
.pathParam("country", "Finland")
.when()
.get("http://restcountries.eu/rest/v1/name/{country}")
.then()
.body("capital", containsString("Helsinki"));
उदाहरण:
String cty = "Finland";
// Here the name of the variable have no relation with the URL parameter {country}
RestAssured.given()
.when()
.get("http://restcountries.eu/rest/v1/name/{country}", cty)
.then()
.body("capital", containsString("Helsinki"));
अब अगर आप विभिन्न सेवाओं कॉल करने की आवश्यकता है, तो आप भी कर सकते हैं parametrize "सेवा" इस तरह:
// Search by name
String val = "Finland";
String svc = "name";
RestAssured.given()
.when()
.get("http://restcountries.eu/rest/v1/{service}/{value}", svc, val)
.then()
.body("capital", containsString("Helsinki"));
// Search by ISO code (alpha)
val = "CH"
svc = "alpha"
RestAssured.given()
.when()
.get("http://restcountries.eu/rest/v1/{service}/{value}", svc, val)
.then()
.body("capital", containsString("Bern"));
// Search by phone intl code (callingcode)
val = "359"
svc = "callingcode"
RestAssured.given()
.when()
.get("http://restcountries.eu/rest/v1/{service}/{value}", svc, val)
.then()
.body("capital", containsString("Sofia"));
एक इकाई परीक्षण के लिए पैरामीटर 'svc' और 'value' को फ़ीड करने के लिए आप आसानी से JUnit @RunWith(Parameterized.class)
का उपयोग भी कर सकते हैं।
ऐसा लगता है, जब मैं आमंत्रित करता हूं, तो आपकी वेब सेवा कॉल सही नहीं है, http://restcountries.eu/rest/v1?name=Finland, मुझे सभी देशों की जानकारी मिल रही है, बल्कि यदि आप "http://restcountries.eu/rest/v1/name/Finland "आपको विशिष्ट देश की जानकारी मिल रही है। – Uday
मेरा उत्तर पहले ही ठीक किया गया है। कृपया –
जांचें यदि हम मूल्य से पैरामीटर पास करते हैं, तो यहां पैरामीटर रखने का क्या फायदा है? \t स्ट्रिंग strCountryName = "फिनलैंड"; \t \t RestAssured.given()। // \t \t \t \t \t \t पैरामीटर ("नाम", "फिनलैंड")। \t \t \t \t \t जब()। \t \t \t \t \t \t \t प्राप्त ("http://restcountries.eu/rest/v1/name/" + strCountryName)। \t \t \t \t \t तब()। \t \t \t \t \t \t शरीर ("पूंजी", हैइटम ("हेलसिंकी")); मुझे ऊपर पैरामीटर की आवश्यकता क्यों है जिस पर मैंने टिप्पणी की? – Uday