package Ġcom . test app . tests . payments . flows . pay later Ċ Ċ import Ġcom . test app . base . Base App ium Test Ċ import Ġcom . test app . base . Payment Category Ċ import Ġcom . test app . base . Retry Rule Ċ import Ġcom . test app . model . Session Ċ import Ġcom . test app . network . Kl arna Api Ċ import Ġcom . test app . utils .* Ċ import Ġio . app ium . java _ client . android . Android Driver Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . BeforeClass Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . openqa . selenium . By Ċ import Ġorg . openqa . selenium . support . ui . Expected Conditions Ċ Ċ internal Ġclass ĠTest Pay Later Ġ: ĠBase App ium Test () Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Jvm Static ĊĠĠĠĠĠĠĠ Ġ@ BeforeClass ĊĠĠĠĠĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtest Name Ġ= ĠTest Pay Later :: class . java . simple Name ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBase App ium Test . setup () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġvar Ġretry Rule Ġ= ĠRetry Rule ( retry Count , Ġignore On Failure ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġsw eden Ġsuccessful Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest SE ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( true , Ġsession , ĠBilling Address TestHelper . get Billing Info SE ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġsw eden Ġfailure Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest SE ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( false , Ġsession , ĠBilling Address TestHelper . get Billing Info SE ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġnor way Ġsuccessful Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest NO ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( true , Ġsession , ĠBilling Address TestHelper . get Billing Info NO ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġnor way Ġfailure Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest NO ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( false , Ġsession , ĠBilling Address TestHelper . get Billing Info NO ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġfin land Ġsuccessful Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest FI ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( true , Ġsession , ĠBilling Address TestHelper . get Billing Info FI ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġfin land Ġfailure Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest FI ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( false , Ġsession , ĠBilling Address TestHelper . get Billing Info FI ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġger many Ġsuccessful Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest DE ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( true , Ġsession , ĠBilling Address TestHelper . get Billing Info DE ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġlater Ġger many Ġfailure Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest DE ()) ?. session ĊĠĠĠĠĠĠĠ Ġtest Pay Later ( false , Ġsession , ĠBilling Address TestHelper . get Billing Info DE ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġtest Pay Later ( success : ĠBoolean , Ġsession : ĠSession ?, Ġbilling : ĠLinkedHashMap < String , ĠString ?> ){ ĊĠĠĠĠĠĠĠ Ġif ( session ?. client _ token Ġ== Ġnull Ġ|| Ġ! session . payment _ method _ categories . map Ġ{ Ġit . identifier Ġ}. contains ( Payment Category . PAY _ L ATER . value )){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġtoken Ġ= Ġsession . client _ token ĊĊĠĠĠĠĠĠĠ Ġinit Load SDK ( token , ĠPayment Category . PAY _ L ATER . value ) ĊĠĠĠĠĠĠĠ ĠDriver Utils . switch Context To WebView ( driver ) ĊĠĠĠĠĠĠĠ Ġval Ġmain Window Ġ= ĠWebView TestHelper . find Window For ( driver , ĠBy . id (" kl arna - some - hard coded - instance - id - fullscreen ")) ĊĠĠĠĠĠĠĠ Ġmain Window ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdriver . switch To (). window ( it ) ĊĠĠĠĠĠĠĠ Ġ} Ġ?: ĠAssert . fail (" Main Ġwindow Ġwasn 't Ġfound ") ĊĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ). until ( Expected Conditions . frame ToBe Available And Switch To It (" kl arna - some - hard coded - instance - id - fullscreen ")) ĊĠĠĠĠĠĠĠ ĠDriver Utils . switch Context To Native ( driver ) ĊĊĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . dismiss Console () ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdriver . findElement ( By Rn Id ( driver , Ġ" authorize Button _${ Payment Category . PAY _ L ATER . value } ")). click () ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( t : ĠThrowable ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdriver . findElement By Android UI Autom ator (" new ĠUi Scroll able ( new ĠUi Selector (). scroll able ( true ). instance ( 0 )). scroll Into View ( new ĠUi Selector (). description (\" authorize Button _${ Payment Category . PAY _ L ATER . value }\" )) ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ). until ( Expected Conditions . presence Of Element Loc ated ( By Rn Id ( driver , Ġ" authorize Button _${ Payment Category . PAY _ L ATER . value } ")) ). click () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġif (! success ){ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBilling Address TestHelper . set Email Flag ( billing , ĠBilling Address TestHelper . EMAIL _ FLAG _ RE JECT ED ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . fill Billing Address ( driver , Ġbilling ) ĊĊĠĠĠĠĠĠĠ Ġif (! success ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrefused Text By Ġ= ĠBy . xpath (" //* [@ id =\" message - component - root \"] ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrefused Text Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ). until ( Expected Conditions . presence Of Element Loc ated ( ref used Text By )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwith ( ref used Text . text . toLowerCase ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġassert ( this . contains (" sor ry ") Ġ|| Ġthis . contains (" un fortunately ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} Ġelse { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsubmit Button By Ġ= ĠBy . xpath (" //* [@ id =\" confirmation __ footer - button - wrapper \"] / div / button ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ). until ( Expected Conditions . presence Of Element Loc ated ( submit Button By )). click () ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . switch Context To Native ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġresponse Ġ= ĠPayment Flows TestHelper . read Console Message ( driver , Ġ" auth Token ") ?. text ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . check Authorize Response ( response , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }