package Ġcom . code bor ne . se len ide . impl Ċ Ċ import Ġcom . code bor ne . se len ide . Browser Ċ import Ġcom . code bor ne . se len ide . Driver Stub Ċ import Ġcom . code bor ne . se len ide . Sel en ide Config Ċ import Ġcom . code bor ne . se len ide . files . File Filters . none Ċ import Ġcom . code bor ne . se len ide . impl . Download File To Folder . Companion . isFile Modified Later Than Ċ import Ġcom . code bor ne . se len ide . impl . WebElement Source Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġkotlinx . coroutines . with Context Ċ import Ġok io . Experimental FileSystem Ċ import Ġok io . Path Ċ import Ġok io . Path . Companion . to Ok io Path Ċ import Ġorg . apache . commons . io . FileUtils Ċ import Ġorg . assertj . core . api . Assertions Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . io . TempDir Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . invocation . Invocation On Mock Ċ import Ġorg . mockito . stub bing . Answer Ċ import Ġorg . openqa . selenium . WebDriver Ċ import Ġorg . openqa . selenium . WebElement Ċ import Ġjava . io . File Ċ import Ġjava . io . IOException Ċ import Ġjava . nio . charset . StandardCharsets Ċ import Ġjava . util . function . Supplier Ċ Ċ @ Experimental FileSystem Ċ internal Ġclass ĠDownload File To Folder Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġdown loader Ġ= ĠDown loader () ĊĠĠĠ Ġprivate Ġval Ġwait er : ĠWait er Ġ= ĠDummy Wait er () ĊĠĠĠ Ġprivate Ġval Ġwindows Closer : ĠWindows Closer Ġ= ĠMockito . spy ( Dummy Windows Closer ()) ĊĠĠĠ Ġprivate Ġval Ġcommand Ġ= ĠDownload File To Folder ( downloader , Ġwait er , Ġwindows Closer ) ĊĠĠĠ Ġprivate Ġval Ġconfig Ġ= ĠSelen ide Config () ĊĠĠĠ Ġprivate Ġval Ġwebdriver Ġ= ĠMockito . mock ( WebDriver :: class . java ) ĊĠĠĠ Ġprivate Ġval Ġlink With Href Ġ= ĠMockito . mock ( WebElement Source :: class . java ) ĊĠĠĠ Ġprivate Ġval Ġlink Ġ= ĠMockito . mock ( WebElement :: class . java ) ĊĊĠĠĠ Ġ@ TempDir ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġvar Ġtemp Dir : ĠFile ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġval Ġdriver Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠDriver Stub ({ Ġtemp Dir !! Ġ}, Ġconfig , ĠBrowser (" oper a ", Ġfalse ), Ġwebdriver , Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠsetUp () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( link With Href . driver ()). thenReturn ( driver ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `< Any >( link With Href . find And Assert Element Is Interact able ()). thenReturn ( link ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( link With Href . toString ()). thenReturn ("< a Ġhref =' report . pdf '> report </ a >") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun Ġtracks For New Files In Downloads Folder () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnew FileName Ġ= Ġ" bing o - b ongo . txt " ĊĠĠĠĠĠĠĠ ĠMockito . do Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFileUtils . writeString ToFile ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdriver . browser Downloads Folder (). file ( new FileName ). to File (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Hello ĠB ingo - B ongo ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠStandard Charsets . UTF _ 8 ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠĠĠ Ġ}. ` when `( link ). click () ĊĠĠĠĠĠĠĠ Ġval Ġdownloaded File Ġ= Ġcommand . download ( link With Href , Ġlink , Ġ 3 0 0 0 , Ġnone ()) ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( downloaded File . name ). isEqualTo ( new FileName ) ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( downloaded File . parent ). isNot EqualTo ( driver . browser Downloads Folder ()) ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( FileUtils . readFile ToString ( downloaded File . to File (), ĠStandard Charsets . UTF _ 8 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEqualTo (" Hello ĠB ingo - B ongo ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun Ġfile Modification Check () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( isFile Modified Later Than ( file ( 1 5 9 7 3 3 3 0 0 0 L ), Ġ 1 5 9 7 3 3 3 0 0 0 L )). isTrue ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( isFile Modified Later Than ( file ( 1 5 9 7 3 3 3 0 0 0 L ), Ġ 1 5 9 7 3 3 2 9 9 9 L )). isTrue ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( isFile Modified Later Than ( file ( 1 5 9 7 3 3 3 0 0 0 L ), Ġ 1 5 9 7 3 3 4 0 0 0 L )). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun Ġfile Modification Check _ work With Seconds Precision () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( isFile Modified Later Than ( file ( 1 1 1 1 1 1 1 0 0 0 L ), Ġ 1 1 1 1 1 1 1 0 0 0 L )). isTrue ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( isFile Modified Later Than ( file ( 1 1 1 1 1 1 1 0 0 0 L ), Ġ 1 1 1 1 1 1 1 9 9 9 L )). isTrue ĊĠĠĠĠĠĠĠ ĠAssertions . assertThat ( isFile Modified Later Than ( file ( 1 1 1 1 1 1 1 0 0 0 L ), Ġ 1 1 1 1 1 1 2 0 0 0 L )). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġprivate Ġfun Ġfile ( modified At : ĠLong ): ĠPath Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfile Ġ= ĠFile . create TempFile (" se len ide - tests ", Ġ" new - file ") ĊĠĠĠĠĠĠĠ ĠFileUtils . touch ( file ) ĊĠĠĠĠĠĠĠ Ġfile . set LastModified ( modified At ) ĊĠĠĠĠĠĠĠ Ġreturn Ġfile . to Ok io Path () ĊĠĠĠ Ġ} Ċ } Ċ