You are on page 1of 8

TestAutomation:AkamaiAGHLab

MaciejGawinecki

Guidelinesforlabinstructor.

Requirements

Serverandclientsinthesamesubnetwork,withaccesstoexternalnetwork

Server:

Ruby2.3.0,

gems:sinatra,restclient,sqlite3,json

Applicationdownloadedfrom:
https://github.com/dzieciou/aghakamailabapps

Client:

JDK1.7+

IDE(Eclipse,Intellij)

Maven3.0+

Firefox45.0.1

Testsdownloadedfrom:https://github.com/dzieciou/aghakamailabtests

Tasksforstudents
Task1:Blackboxtestingoftheapplication
Thegoalofthetaskistounderstandhowtheapplicationworksfromenduserpointofview.

1. Clonetheprojectsifyoudonthavedoneityet

gitclonehttps://github.com/dzieciou/aghakamailabtests.git
gitclonehttps://github.com/dzieciou/aghakamailabapps.git

1. Startonlineshopapplicationandbankserver:

cdaghakamailabapps
rubyshop.rb

rubybank.rb

1. OpentheURLhttp://localhost:8070/shop/summaryoftheonlineshopapplicationin
yourfavouritebrowser.
2. Experimentwiththeapplication.Trytofindinthebank.rbvalidcreditcardinformation

Hint:
Creditcardnumber 4012888888881881
Creditcardowner MACIEK
CreditcardCSC 757

Task2:AutomatingGUItests
ThegoalofthetaskistounderstandhowtoautomatesimpleGUItestsfortheapplication.
Thiswillbeasystemtestwhichmeansitwilltestthewholesystem.

Launchthehappypathtestthatsendsvalidcreditcardinfoandexpectasuccessful
transaction:

cdaghakamailabtests
mvncleantestDtest=com.akamai.testing.aghlab.gui.PositiveGUITest

Thescriptisimplementationofthefollowingtestscenario:
Testscenario
Givencorrectcreditcardinfo
WhenIclickOrder!button
Thenshopacceptstheorder

Thisimplementationisarawversionmeanttogostraighttothepoint,wenormallycreate
pageclassesthatmodeltheelementsandinteractionsofthewebsitesandwecallthem
"pageobjects".

Implementthefollowingnegativetest:
Testscenariotoautomate
Givenincorrectcreditcardinfo
WhenIclickOrder!button
Thenshoprejectstheorder

Task3:Testingshopbackendwithcurl
curlisacommandlinetoolforperformingHTTPrequests.ItsavailableonallUnixand
MacOssystems.Thegoalofthistaskistounderstandhowcurlprogramcanhelpin
repeatingHTTPrequestssentorreceivedbytheapplicationquickly.

GUIistalkingtotheshopbackendthroughHTTPrequests.Wewillsniffthistrafficwith
Chromewebbrowser:

1. OpentheOnlineShopapp:http://localhost:8070/shop/summary.Open:Tools>
MoreTools>DeveloperTools>Networkpanel.
2. EntervalidcreditcardinformationandclickOrder!button.
3. IntheNetworkpanelyouwillseePOST/shop/orderrequest.


1. Rightclickontherequest>CopyascURL.Youshouldexpect

curl'http://localhost:8070/shop/orderH'Origin:
http://localhost: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
(MacintoshIntelMacOSX10_10_5)AppleWebKit/537.36(KHTML,like
Gecko)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://localhost:8070/shop/summaryH'Connection:keepalive'data
'target_account_iban=9484984948948498&product_id=002&cc_number=401288
8888881881&cc_owner=MACIEK&cc_csc=757'compressed

2. AddvoptiontoseeHTTPrequestsentandHTTPresponsereceivedbyacurl
command.
3. Checkcreditcardbalancebeforeandaftertransaction:

curlhttp://localhost:8090/bank/cards/4012888888881881/balance

4. Checkshopaccountbalancebeforeandaftertransaction:

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

Trytobreaktheshopsbackendbychangingdifferentparametersofthecurlcommand.

Testscenario
GivenIprovidemyaccountinsteadofcompanyaccount
WhenIclickPay!button
ThenThemoneyfrommycardaretransferredtothegivenaccountandnotthecompany
account.

Task4:TestingshopbackendwithRESTAssured
Thegoalofthistaskisautomatenotonlysendingarequestandverifyingtheoutputofshop
API.


Launchthehappypathtestthatsendsvalidcreditcardinfoandexpectsuccessful
transaction:

cdaghlabtests
mvncleantest
Dtest=com.akamai.testing.aghlab.rest.PositiveShopBackendTest

Thetestimplementsthefollowingscenario.
Testscenario
Givencorrectcreditcardinfoandexistingproductid
WhenIsendrequestto/shop/orderRESTAPI
Thenshopacceptstheorder(HTTPresponsestatus200)

Inputdatashouldbevalidatedbothonthefrontendandbackend.Tomakesurethisruleif
fullyrespected,Implementthefollowingscenario:
Testscenario
Givenidofproductthatdoesnotexists
WhenIsendrequestto/shop/orderRESTAPI
Thenshoprejectstheorder(HTTPresponsestatus400)
Doesitpass?

Task5:TestingbankRESTAPIwithRESTAssured
TheonlineshopapplicationtalkstothebankRESTAPItoauthorizecreditcardtransaction.

ThegoalofthistaskistotestbankRESTAPIwithoutusingshopapplication.Thiswillbean
integrationtest,notsystemasystemtest.

WewillneedtolearnthecontractforbankRESTAPI:

howrequestsforbankRESTAPIlookslikeand

whatweshouldexpectintheresponses.

Therearetwowaysforthat:byobservingactualHTTPtrafficandanotherbycheckingbank
RESTAPIdefinition.

ToenableHTTPtrafficlogginginthelogofshop.rbtothefollowing.Stopshop.rbserver
instance(Ctrl+C).Enablelogging:

exportRESTCLIENT_LOG=stdout

Startshop.rbagain

rubyshop.rb

Whenyouopenshopapplicationinyourbrowserandorderaproductthenyouwillseethe
followingentryinconsolelogs:

RestClient.post"http://localhost:8090/bank/pay",
"cc_number=4012888888881881&cc_csc=757&cc_owner=MACIEK&amount=600&target_ac

count_iban=9484984948948498","Accept"=>"application/json",
"AcceptEncoding"=>"gzip,deflate","ContentLength"=>"101",
"ContentType"=>"application/xwwwformurlencoded"
#=>200OK|text/html0bytes

ToseebankRESTAPIcontractopenbank.rbfile.

post'/bank/pay'do
cc_number=params[:cc_number]
cc_csc=params[:cc_csc]

cc_owner=params[:cc_owner]
amount=params[:amount]

target_account_iban=params[:target_account_iban]

ifis_card_valid(cc_number,cc_csc,cc_owner)

transfer_money(amount,cc_number,target_account_iban)
status200
else

status401
end
end

Launchthehappypathtestthatsendsvalidcreditcardinfoandexpectsuccessful
transaction:

mvncleantest
Dtest=com.akamai.testing.aghlab.rest.PositiveBankBackendTest

Thetestimplementsthefollowingscenario
Testscenario
Given
correctcreditcardinfoand
initialbalanceoncreditcardisupdatedproperlyand
shopaccountbalanceisupdatedproperly
WhenIsendrequestto/bank/payRESTAPI
Thenthebankacceptsthetransaction(HTTPresponsestatus200)andaccoun

Implementnegativescenario.
Testscenario
Givenincorrectcreditcardinfo

WhenIsendrequestto/bank/payRESTAPI
Thenthebankrejectsthetransaction(HTTPresponsestatus401)
Trydifferenttypesofincorrectdata:invalidnumber,lettersinsteadofnumbers,etc.

Task6:MockingbankRESTAPIwithServerMock
ThegoalofthistaskistolearnhowtotestshopapplicationwhenthebankRESTAPIisnot
availableorsimulatingsomebehavioursofthebankRESTAPIaretoohard.

LaunchthenegativetestthatexpectsshoptorespondwithTransactionRejectedscreenif
bankrespondsnegatively:

mvncleantest
Dtest=com.akamai.testing.aghlab.rest.NegativeTestWithMockedBank

Testscenario
GivenbankrejectsalltransactionswithHTTPresponsestatus401
WhenIsubmitvalidcreditcarddataandexistingproductid
Thenshoprejectstheorder(HTTPresponsestatus401)

Checkhowtheshopreactswhenbankhasinternalsystemerror:
Testscenario
GivenbankfailstoperformanyrequestandreturnsHTTPresponsestatus500
WhenIsubmitvalidcreditcarddataandexistingproductid
Thenshoprejectstheorder(HTTPresponsestatus401)

You might also like