From d2f57c832acce1322fb9cb493a87b3c687bd45de Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 15 Jul 2023 20:38:44 +0200 Subject: [PATCH] Allow invokation of custom downloads --- scripts/Windows/Scripts/BrowserAutomation.ps1 | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/Windows/Scripts/BrowserAutomation.ps1 b/scripts/Windows/Scripts/BrowserAutomation.ps1 index dcd12d84..dd5a564b 100644 --- a/scripts/Windows/Scripts/BrowserAutomation.ps1 +++ b/scripts/Windows/Scripts/BrowserAutomation.ps1 @@ -12,11 +12,11 @@ if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) { [System.Reflection.Assembly]::Load($bytes); } -function Start-AutomatedDownload() { +function Start-CustomDownload() { param( [Context] $context, [string] $url, - [string] $buttonSelector, + [Action[OpenQA.Selenium.Firefox.FirefoxDriver]] $action, [string] $outDir = $null ) @@ -54,7 +54,7 @@ function Start-AutomatedDownload() { $browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options); $browser.Navigate().GoToUrl($url); - $browser.FindElement([OpenQA.Selenium.By]::CssSelector("$buttonSelector")).Click(); + $action.Invoke($browser); while ($downloadChecker.Invoke()) { Write-Information "Waiting for download to finish..."; @@ -72,3 +72,19 @@ function Start-AutomatedDownload() { Remove-Item -Recurse $tempDir; return $result; } + +function Start-AutomatedDownload() { + param( + [Context] $context, + [string] $url, + [string] $buttonSelector, + [string] $outDir = $null + ) + + $action = { + param([OpenQA.Selenium.Firefox.FirefoxDriver] $browser) + $browser.FindElement([OpenQA.Selenium.By]::CssSelector("$buttonSelector")).Click(); + } + + return Start-CustomDownload $context $url $action $outDir; +}