0% found this document useful (0 votes)
153 views5 pages

Test Automation Akamai AGH Lab - Solutions

Solutions for 6 tasks showing how to test REST service and its client. Prepared for the short course around Test Engineering at Krakow's AGH University of Computer Science, in collaboration with Akamai Technologies.

Uploaded by

Maciej Gawinecki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views5 pages

Test Automation Akamai AGH Lab - Solutions

Solutions for 6 tasks showing how to test REST service and its client. Prepared for the short course around Test Engineering at Krakow's AGH University of Computer Science, in collaboration with Akamai Technologies.

Uploaded by

Maciej Gawinecki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TestAutomation:AkamaiAGHLab

Solutions
MaciejGawinecki

SolutionforTask1
Creditcardnumber 4012888888881881
Creditcardowner MACIEK
CreditcardCSC 757

SolutionforTask2
publicclassNegativeGuiTest{

privateWebDriverdriver

@Before
publicvoidsetUp(){
driver=newFirefoxDriver()
}

@Test
publicvoidforValidCardInfoTransactionShouldBeAccepted(){

//given
driver.get(Configuration.SHOP_HOST+"/shop/summary")

Selectproducts=new
Select(driver.findElement(By.name("product_id")))
products.selectByVisibleText("CanonEOS5000D")

driver.findElement(By.name("cc_number"))
.sendKeys("4012888888881881")

driver.findElement(By.name("cc_csc"))
.sendKeys("123")

WebElementcc_owner=driver.findElement(By.name("cc_owner"))

cc_owner.sendKeys("MACIEK")

//when
cc_owner.submit()

//then
assertTrue(driver.getPageSource().contains("Transactionrejected"))
}

@After
publicvoidtearDown(){
driver.close()//canbecommentedouttostopclosingbrowser
}

SolutionforTask3
1.

Checkanotheraccountbalancebeforetransaction

curlhttp://YOUR_VM_IP:8090/bank/accounts/4567/balance
2.

TransfermoneytoHackersaccount

curl'http://YOUR_VM_IP:8070/shop/orderH'Origin:
http://YOUR_VM_IP:8070'H'AcceptEncoding:gzip,deflate'H
'AcceptLanguage:enUS,enq=0.8,itq=0.6,plq=0.4'H
'UpgradeInsecureRequests:1'H'UserAgent:Mozilla/5.0(Macintosh
IntelMacOSX10_10_5)AppleWebKit/537.36(KHTML,likeGecko)
Chrome/48.0.2564.116Safari/537.36'H'ContentType:
application/xwwwformurlencoded'H'Accept:
text/html,application/xhtml+xml,application/xmlq=0.9,image/webp,*/*q
=0.8'H'CacheControl:maxage=0'H'Referer:
http://YOUR_VM_IP:8070/shop/summaryH'Connection:keepalive'data
'target_account_iban=4567&product_id=002&cc_number=4012888888881881&cc
_owner=MACIEK&cc_csc=757'compressed

3. Makesuremoneyhasbeenwithdrawnfromshopaccount
curlhttp://YOUR_VM_IP:8090/bank/cards/4917610000000000/balance
4.

MakesuremoneyhasbeenmovedtoHackersaccount

curlhttp://YOUR_VM_IP:8090/bank/accounts/4567/balance

SolutionforTask4
publicclassNegativeShopBackendTest{

@Test
publicvoidforWrongProductIdTransactionShouldBeRejected(){

//@formatter:off
given().
log().all().
baseUri(Configuration.SHOP_HOST).
contentType(ContentType.URLENC).
formParam("target_account_iban","1234").
formParam("product_id","000").
formParam("cc_number","4012888888881881").
formParam("cc_owner","MACIEK").
formParam("cc_csc",757).
when().
post("/shop/order").
then().
log().all().
statusCode(400).
body(hasXPath("/html/body/h2[text()='Transaction
rejected]"))
//@formatter:on

}

}

ItsOKifthetestfailsbecauseitdemonstrateswehavefoundabuginthesystem.

SolutionforTask5
@Test
publicvoidforValidCardInfoTransactionShouldBeAccepted(){

intinitialCardBalance=getCardBalance(CARD_NUMBER)
intinitialshopAccountBalance=getAccountBalance(SHOP_ACCOUNT_NUMBER)

//@formatter:off
given().
log().all().
baseUri(Configuration.BANK_HOST).
formParam("target_account_iban","1234").
formParam("amount","600").
formParam("cc_number",CARD_NUMBER).

formParam("cc_owner","MACIEK").
formParam("cc_csc",000).
when().
post("/bank/pay").
then().
log().all().
statusCode(401)
//@formatter:on

intcardBalance=getCardBalance(CARD_NUMBER)
intshopAccountBalance=getAccountBalance(SHOP_ACCOUNT_NUMBER)

assertThat(cardBalance,equalTo(initialCardBalance))
assertThat(shopAccountBalance,equalTo(initialshopAccountBalance))
}

SolutionforTask6
publicclassNegativeTestWithMockedBank{

privateClientAndServerserverMock

@Before
publicvoidsetupMock(){
serverMock=startClientAndServer(8090)
serverMock.
when(request().
withMethod("POST").
withPath("/bank/pay")).
respond(response().
withStatusCode(500))
}

@Test
publicvoidtest(){
//@formatter:off
given().
log().all().
baseUri(Configuration.SHOP_HOST).
contentType(ContentType.URLENC).
formParam("target_account_iban","9484984948948498").
formParam("product_id","600").
formParam("cc_number","4012888888881881").
formParam("cc_owner","MACIEK").
formParam("cc_csc",757).
when().
post("/shop/order").
then().

log().all().
statusCode(401).
body(hasXPath("/html/body/h2[text()='Transaction
rejected']"))
//@formatter:on
}

@After
publicvoidcloseMock(){
serverMock.stop()
}

You might also like