You are on page 1of 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()
}