Accessing secured APIs
Basic Authentication (i.e., the consumer of this API needs to provide a valid username and password combination every time they call the API)
@Test
public void test_APIWithBasicAuthentication() {
given().
auth().
preemptive().
basic("username", "password").
when().
get("http://path.to/basic/secured/api").
then().
assertThat().
statusCode(200);
}
Accessing an OAuth2-secured API
@Test
public void test_APIWithOAuth2Authentication() {
given().
auth().
oauth2(YOUR_AUTHENTICATION_TOKEN_GOES_HERE).
when().
get("http://path.to/oath2/secured/api").
then().
assertThat().
statusCode(200);
}
Passing parameters between tests
@Test
public void test_ScenarioRetrieveFirstCircuitFor2017SeasonAndGetCountry_ShouldBeAustralia() {
// First, retrieve the circuit ID for the first circuit of the 2017 season
String circuitId = given().
when().
get("http://ergast.com/api/f1/2017/circuits.json").
then().
extract().
path("MRData.CircuitTable.Circuits.circuitId[0]");
// Then, retrieve the information known for that circuit and verify it is located in Australia
given().
pathParam("circuitId",circuitId).
when().
get("http://ergast.com/api/f1/circuits/{circuitId}.json").
then().
assertThat().
body("MRData.CircuitTable.Circuits.Location[0].country",equalTo("Australia"));
}
Basic Authentication (i.e., the consumer of this API needs to provide a valid username and password combination every time they call the API)
@Test
public void test_APIWithBasicAuthentication() {
given().
auth().
preemptive().
basic("username", "password").
when().
get("http://path.to/basic/secured/api").
then().
assertThat().
statusCode(200);
}
Accessing an OAuth2-secured API
@Test
public void test_APIWithOAuth2Authentication() {
given().
auth().
oauth2(YOUR_AUTHENTICATION_TOKEN_GOES_HERE).
when().
get("http://path.to/oath2/secured/api").
then().
assertThat().
statusCode(200);
}
Passing parameters between tests
@Test
public void test_ScenarioRetrieveFirstCircuitFor2017SeasonAndGetCountry_ShouldBeAustralia() {
// First, retrieve the circuit ID for the first circuit of the 2017 season
String circuitId = given().
when().
get("http://ergast.com/api/f1/2017/circuits.json").
then().
extract().
path("MRData.CircuitTable.Circuits.circuitId[0]");
// Then, retrieve the information known for that circuit and verify it is located in Australia
given().
pathParam("circuitId",circuitId).
when().
get("http://ergast.com/api/f1/circuits/{circuitId}.json").
then().
assertThat().
body("MRData.CircuitTable.Circuits.Location[0].country",equalTo("Australia"));
}
Appium Interview Questions and Answers
ReplyDeleteGood content. You write beautiful things.
ReplyDeletemrbahis
vbet
sportsbet
vbet
hacklink
sportsbet
mrbahis
taksi
hacklink
Success Write content success. Thanks.
ReplyDeletebetmatik
kralbet
betpark
kıbrıs bahis siteleri
betturkey
deneme bonusu
canlı poker siteleri
maraÅŸ
ReplyDeletebursa
tokat
uÅŸak
samsun
5D044
ağrı
ReplyDeletemuÅŸ
mersin
afyon
uÅŸak
Z5WVXO
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
Ä°AZ
çeşme transfer
ReplyDeletesoulmate ajans
bor yağı filtre kağıdı
yağ süzme filtre kağıdı
7HB2