Automated API Kuedzwa Kwakaitwa Nyore NeKarate

Kana iwe uchida kutora chikamu muAquated API Kuedzwa, asi usina programming kumashure, ipapo ungangoda kupa Karate kuenda!

Karate yakaburitswa seyakavhurika-sosi chishandiso na Intuit . Chishandiso chakagadzirirwa kushandiswa pakuongorora kweAPI uye ine zvese zvinodiwa kuti API iedze mweya uye inakidze.

Kusiyana nemamwe maturusi ekuongorora eAPI anongoda huwandu hwakaringana hwekukodha, kunyangwe kungoita zvinhu zvekutanga, Karate inoshanda kunze kwebhokisi. Iwe unogona kuvaka yakaoma kunzwisisa-yekukumbira-mhinduro mashandiro usina ruzivo rwechero chirongwa chemutauro. Zvese iwe zvunofanirwa kuita kunyora iyo ficha faira uchishandisa yakajeka mavara Gherkin maitiro.

Nekuti Karate ndeye DSL yakazara uye inogara pamusoro pe Cucumber-JVM , iwe unogona kumhanyisa bvunzo uye kugadzira mashumo senge chero akajairwa Java chirongwa, asi pachinzvimbo chekunyora Java kodhi, iwe unonyora bvunzo mumutauro wakagadzirirwa kuita kubata neHTTP, JSON kana XML nyore uye nyore.

Kunyangwe paine zvisati zvafanirwa kushandisa Karate, zvinobatsira kana iwe uine nzwisiso yekutanga yeHTTP, JSON, XML, JsonPath uye XPath neJavaScript.

Mune ino posvo, isu tinotarisa kumwe kwakajairika mashandiro iwe aunowanzoita muAutomated API Kuedzwa, asi kutanga, gwaro rinokurumidza pakuseta nharaunda yako yeKarate.



Maven

Kana iwe uri kushandisa Maven, iwe unoda izvo zviviri zvinotevera kutsamira


com.intuit.karate
karate-apache
0.6.0
test
com.intuit.karate
karate-junit4
0.6.0
test

Gradle

Neimwe nzira, kana iwe uri kushandisa Gradle, iwe unoda

testCompile 'com.intuit.karate:karate-junit4:0.6.0' testCompile 'com.intuit.karate:karate-apache:0.6.0'

Chimiro cheFolder

Kirate yekuyedza script ine iyo yekuwedzera faira .feature unova ndiwo muyero unoteverwa neCucumber. Iwe wakasununguka kuronga mafaera ako uchishandisa akajairwa Java mapakeji epasuru.

Iyo Maven tsika ndeyekuve neisiri-Java sosi mafaera mune akaparadzana src/test/resources dhairekitori - asi vagadziri veKarate chishandiso vanokurudzira kuti uzvichengetedze padivi neako *.java mafaira.

Kunge Cucumber, iwe unofanirwa kuve ne 'Runner' kirasi iyo inomhanya iyo ficha faira (s). Kusiyana neCucumber, zvisinei, hapana tsananguro dzedanho! Uye aya ndiwo mashiripiti eKarate.

Kuti ushandise iyo TestRunner.java kirasi kuitisa iyo ficha faira, iwe unofanirwa kuve nechikamu chekuvaka mune pom.xml faira.


4.0.0
Tutorials
Karate
1.0-SNAPSHOT




com.intuit.karate

karate-apache

0.6.0.4





com.intuit.karate

karate-junit4

0.6.0.4










src/test/java






**/*.java








Uye yako TestRunner.java kirasi yaizoita senge

package com.tutorials.karate; import com.intuit.karate.junit4.Karate; import org.junit.runner.RunWith; @RunWith(Karate.class) public class TestRunner { }

Zvakareruka Zvoga API Kuedzwa neKarate

Ngatiti iwe uri kuyedza API (https://some-api.com/api/users) iyo inodzosera runyorwa rwevashandisi muJSON fomati.

[
{
'id': 1,
'name': 'FirstUser',
'password': 'User1Pass'
},
{
'id': 2,
'name': 'SecondUser',
'password': 'User2Pass'
} ]

Yako Karate ficha faira ichaita senge:

Feature: Test User API
Scenario: Fetch all users
Given url 'https://some-api.com/api/users'
When method GET
Then status 200
And assert response.length == 2
And match response[0].name == 'FirstUser'

Uye ndizvo zvazviri - zvakapfupika uye kune poindi uye zvakanyanya kukosha, hapana kodhi!

Karate inouya neyakafuma kwazvo seti yezvinhu zvinobatsira izvo zvinoita kuti iwe uite maAquated API Kuedzwa zviri nyore uye nekukurumidza. Mune ramangwana zvinyorwa, isu tinotsvaga zvakanyanya mune ichi chinoshamisa chishandiso uye tinopa mienzaniso yekuti ungaita sei nezve chero chinhu chaunoda kana uchiedza APIs!