package Ġcom . test app . tests . payments . flows . pay now Ċ Ċ import Ġcom . test app . base . Base App ium Test Ċ import Ġcom . test app . base . Payment Category Ċ import Ġcom . test app . extensions . hide Keyboard Compat Ċ import Ġcom . test app . extensions . tap Element Center Ċ import Ġcom . test app . network . Kl arna Api Ċ import Ġcom . test app . utils .* Ċ import Ġio . app ium . java _ client . android . Android Driver Ċ import Ġio . app ium . java _ client . ios . IO SE lement Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ import Ġorg . openqa . selenium . By Ċ import Ġorg . openqa . selenium . support . ui . Expected Conditions Ċ Ċ internal Ġclass ĠPay Now S of ort Test Ġ: ĠBase App ium Test () Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġnow ĠDE ĠS of ort Ġsuccessful Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Pay Now S of ort ( true ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġpayment Ġpay Ġnow ĠDE ĠS of ort Ġfailure Ġflow `() Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Pay Now S of ort ( false ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġtest Pay Now S of ort ( success : ĠBoolean ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= ĠK l arna Api . getSession Info ( Session Helper . getRequest DE ()) ?. session ĊĠĠĠĠĠĠĠ Ġif Ġ( session ?. client _ token Ġ== Ġnull Ġ|| Ġ! session . payment _ method _ categories . map Ġ{ Ġit . identifier Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains ( Payment Category . PAY _ NOW . value )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġtoken Ġ= Ġsession . client _ token ĊĠĠĠĠĠĠĠ Ġinit Load SDK ( token , ĠPayment Category . PAY _ NOW ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( android ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ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 - main ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmain Window ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdriver . switch To (). window ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġ?: ĠAssert . fail (" Main Ġwindow Ġwasn 't Ġfound ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . switch To I frame ( driver , Ġ" kl arna - some - hard coded - instance - id - main ") ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. until ( Expected Conditions . presence Of Element Loc ated ( By . id (" install ments - card |- 1 ")) ). click () ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . switch To I frame ( driver , ĠBy . xpath (" //* [@ id =\" pay - now - card \"] // iframe ")) ĊĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. until ( Expected Conditions . presence Of Element Loc ated ( By . xpath ("// XC UI ElementType Other [@ name =' Payment ĠView '] "))) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. until ( Expected Conditions . presence Of Element Loc ated ( By . xpath ("// XC UI ElementType Static Text [@ name =' TEST DRIVE '] "))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcard : ĠIO SE lement Ġ= ĠDriver Utils . get Wait er ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. until ( Expected Conditions . presence Of Element Loc ated ( By . xpath ("// XC UI ElementType Static Text [@ name =' Card '] "))) Ġas ĠIO SE lement ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcard . tap Element Center ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . wait ( driver , Ġ 5 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . fill Card Info ( driver ) ĊĊĠĠĠĠĠĠĠ ĠDriver Utils . switch Context To Native ( driver ) ĊĊĠĠĠĠĠĠĠ Ġdriver . hide Keyboard Compat () ĊĊĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . dismiss Console ( driver ) ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdriver . findElement ( By Rn Id ( driver , Ġ" authorize Button _${ Payment Category . PAY _ NOW . value } ")). click () ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( t : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( driver Ġas ? ĠAndroid Driver <* >) ?. let Ġ{ Ġdriver Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ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 _ NOW . value }\" )) ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ). until ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠExpected Conditions . presence Of Element Loc ated ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠBy Rn Id ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdriver , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" authorize Button _${ Payment Category . PAY _ NOW . value }" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ). click () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġbilling Ġ= ĠBilling Address TestHelper . get Billing Info DE () ĊĠĠĠĠĠĠĠ Ġ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 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( android ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ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 Ġchange Payment By Ġ= ĠBy . xpath ("// XC UI ElementType Button [ contains (@ name , Ġ' Change Ġpayment Ġmethod ')] ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġchange Payment Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . get Wait er ( driver ). until ( Expected Conditions . presence Of Element Loc ated ( change Payment By )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġchange Payment . tap Element Center ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠPayment Flows TestHelper . read State Message ( driver , ĠPayment Category . PAY _ NOW ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . check Authorize Response ( response , Ġfalse ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDriver Utils . switch Context To Native ( driver ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠPayment Flows TestHelper . read State Message ( driver , ĠPayment Category . PAY _ NOW ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠPayment Flows TestHelper . check Authorize Response ( response , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ