package Ġcom . co uple blog Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . fragment . app . testing . Fragment Scenario Ċ import Ġandroidx . fragment . app . testing . launch Fragment In Container Ċ import Ġandroidx . navigation . Navigation Ċ import Ġandroidx . navigation . testing . Test Nav Host Controller Ċ import Ġandroidx . test . core . app . Activity Scenario Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . action . View Actions Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . base . MainThread Ċ import Ġandroidx . test . espress o . matcher . View Matchers .* Ċ import Ġandroidx . test . internal . runner . junit 4 . statement . Ui Thread Statement . run On Ui Thread Ċ import Ġcom . co uple blog . fragment . CB _ Login Fragment Ċ import Ġcom . co uple blog . singleton . CB _ App Func Ċ import Ġcom . co uple blog . util . Test Fragment Util Ċ import Ġjunit . framework . Assertion Failed Error Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġjava . util . concurrent . TimeoutException Ċ Ċ @ RunWith ( android x . test . ext . junit . runners . Android JUnit 4 :: class ) Ċ class ĠLogin Fragment Test Ċ { ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnav Controller : ĠTest Nav Host Controller ĊĊĠĠĠ Ġprivate Ġfun Ġlaunch Login Fragment Scenario ( bundle : ĠBundle ?): ĠFragment Scenario < CB _ Login Fragment > ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ= ĠTest Fragment Util . launch Fragment Scenario ( bundle , ĠCB _ Login Fragment (), Ġnav Controller ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ ĠActivity Scenario . launch ( CB _ MainActivity :: class . java ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcreate Ġa Ġtest Nav Controller ĊĠĠĠĠĠĠĠ Ġ// Ġset Ġa Ġgraph Ġon Ġthe ĠTest Nav Controller Ġand Ġavailable Ġfor Ġfind Nav Controller () ĠAPIs ĊĠĠĠĠĠĠĠ Ġrun On Ui Thread Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnav Controller Ġ= ĠTest Nav Host Controller ( Application Provider . getApplicationContext ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnav Controller . set Graph ( R . navigation . nav _ graph ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcheck Login Valid Value () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġcreate Ġa Ġgraphical ĠFragment Scenario ĊĠĠĠĠĠĠ Ġ// Ġval Ġlogin Scenario Ġ= Ġlaunch Login Fragment Scenario ( null ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġnot Ġauto Ġlogin ĊĠĠĠĠĠĠĠ Ġif ( CB _ App Func . get Auth (). currentUser Ġ== Ġnull ) ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġinput Ġemail Ġand Ġpassword ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . email _ edit _ text )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( View Actions . type Text (" test 3 @ gmail . com "), ĠView Actions . close Soft Keyboard ()) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . password _ edit _ text )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( View Actions . type Text (" rl adb als 8 2 ^^ * "), ĠView Actions . close Soft Keyboard ()) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġmove Ġto ĠMain Fragment ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . login _ button )). perform ( View Actions . click ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Ġanimation Ġloading ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġ// Ġê³µ ë¶Ģ íķł Ġê²ĥ Ġ: Ġtesting - samples / ui / espress o / Id ling Resource Sample / ĊĊĠĠĠĠĠĠĠ Ġ// Ġverify Ġit 's Ġmain Fragment ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . main _ fragment _ parent )). check ( matches ( is Displayed ())) ĊĊĠĠĠĠĠĠ Ġ/* ĠassertThat (" Expecting Ġto Ġgo Ġto Ġlogin Fragment ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnav Controller . current Destination ?. id , ĠequalTo ( R . id . CB _ Main Fragment )) */ ĊĠĠĠ Ġ} Ċ }