From 992387be5f28566c221699626adee250634f34a2 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 20 Aug 2019 08:52:24 -0600 Subject: [PATCH 1/8] Update and rename blank.yml to build-test.yml --- .github/workflows/build-test.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/build-test.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..f2752f9 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,17 @@ +name: CI + +on: [push] + +jobs: + build: + + runs-on: ${{ matrix.os }} + strategy: + matrix: + node_version: [8, 10, 12] + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - uses: actions/checkout@v1 + - name: Run a one-line script + run: powershell ./Selenium.tests.ps1 From c7014f5312f0894821eeca504cb233386f7c8ca7 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 20 Aug 2019 08:53:38 -0600 Subject: [PATCH 2/8] Remove node versions. --- .github/workflows/build-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index f2752f9..3c8106c 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -8,7 +8,6 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - node_version: [8, 10, 12] os: [ubuntu-latest, windows-latest, macOS-latest] steps: From 28a76e52266fbcb0974d934f1bb92622b8170047 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 20 Aug 2019 08:55:03 -0600 Subject: [PATCH 3/8] Update build-test.yml --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 3c8106c..51f389c 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v1 - name: Run a one-line script - run: powershell ./Selenium.tests.ps1 + run: pwsh ./Selenium.tests.ps1 From 09fe0ec57ac0d9b5c84b03ca1c5aa6cdafacc0f1 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 20 Aug 2019 08:57:03 -0600 Subject: [PATCH 4/8] Update build-test.yml --- .github/workflows/build-test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 51f389c..3dbd9e9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -13,4 +13,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Run a one-line script - run: pwsh ./Selenium.tests.ps1 + run: | + pwsh -Command "Install-Module Pester -Force -Scope CurrentUser" + pwsh ./Selenium.tests.ps1 + From 85d3182f0ac50a48d9fab3b5fe0432351179162e Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 20 Aug 2019 09:06:30 -0600 Subject: [PATCH 5/8] Create release.yml --- .github/workflows/release.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a637496 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: Release + +on: [release] + +jobs: + build: + + runs-on: ubuntu-latest + secrets: ["api_key"] + + steps: + - uses: actions/checkout@v1 + - name: Publish + run: | + pwsh -Command "Publish-Module -Path ./Selenium.psd1 -NuGetApiKey $Env:api_key" + From d0176f4ae41b1acfe480c880759e4e4f737552e8 Mon Sep 17 00:00:00 2001 From: Josh King Date: Tue, 27 Aug 2019 13:45:45 +1200 Subject: [PATCH 6/8] Allow downloads when headless, via Chrome Command --- Selenium.psm1 | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/Selenium.psm1 b/Selenium.psm1 index 1ef1a35..1ef78a0 100644 --- a/Selenium.psm1 +++ b/Selenium.psm1 @@ -8,7 +8,7 @@ elseif($IsMacOS){ $AssembliesPath = "$PSScriptRoot/assemblies/macos" } -# Grant Execution permission to assemblies on Linux and MacOS +# Grant Execution permission to assemblies on Linux and MacOS if($IsLinux -or $IsMacOS){ # Check if powershell is NOT running as root $AssemblieFiles = Get-ChildItem -Path $AssembliesPath |Where-Object{$_.Name -eq 'chromedriver' -or $_.Name -eq 'geckodriver'} @@ -62,7 +62,7 @@ function Start-SeChrome { } PROCESS{ $Chrome_Options = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeOptions" - + if($DefaultDownloadPath){ Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" $Chrome_Options.AddUserProfilePreference('download', @{'default_directory' = $($DefaultDownloadPath.FullName); 'prompt_for_download' = $false; }) @@ -71,11 +71,11 @@ function Start-SeChrome { Write-Verbose "Setting Profile directory: $ProfileDirectoryPath" $Chrome_Options.AddArgument("user-data-dir=$ProfileDirectoryPath") } - + if($DisableBuiltInPDFViewer){ $Chrome_Options.AddUserProfilePreference('plugins', @{'always_open_pdf_externally' = $true;}) } - + if ($Headless) { $Chrome_Options.AddArguments('headless') } @@ -97,7 +97,7 @@ function Start-SeChrome { $Chrome_Options.AddArguments($Argument) } } - + if (!$HideVersionHint) { Write-Verbose "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" } @@ -106,7 +106,7 @@ function Start-SeChrome { $Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $AssembliesPath,$Chrome_Options } else{ - $Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options + $Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options } if($Minimized){ @@ -114,6 +114,14 @@ function Start-SeChrome { } + if($Headless -and $DefaultDownloadPath) { + $CmdParams = New-Object 'system.collections.generic.dictionary[[System.String],[System.Object]]]' + $CmdParams.Add('behavior', 'allow') + $CmdParams.Add('downloadPath', $DefaultDownloadPath.FullName) + + $Driver.ExecuteChromeCommand('Page.setDownloadBehavior', $CmdParams) + } + if($StartURL){ Enter-SeUrl -Driver $Driver -Url $StartURL } @@ -126,7 +134,7 @@ function Start-SeChrome { function Start-SeInternetExplorer { $InternetExplorer_Options = New-Object -TypeName "OpenQA.Selenium.IE.InternetExplorerOptions" $InternetExplorer_Options.IgnoreZoomLevel = $true - New-Object -TypeName "OpenQA.Selenium.IE.InternetExplorerDriver" -ArgumentList $InternetExplorer_Options + New-Object -TypeName "OpenQA.Selenium.IE.InternetExplorerDriver" -ArgumentList $InternetExplorer_Options } function Start-SeEdge { @@ -161,7 +169,7 @@ function Start-SeFirefox { } function Stop-SeDriver { - param($Driver) + param($Driver) $Driver.Dispose() } @@ -222,7 +230,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ById") { $TargetElement = [OpenQA.Selenium.By]::Id($Id) } - + if ($PSCmdlet.ParameterSetName -eq "ByLinkText") { $TargetElement = [OpenQA.Selenium.By]::LinkText($LinkText) } @@ -238,7 +246,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ByTagName") { $TargetElement = [OpenQA.Selenium.By]::TagName($TagName) } - + if ($PSCmdlet.ParameterSetName -eq "ByXPath") { $TargetElement = [OpenQA.Selenium.By]::XPath($XPath) } @@ -246,7 +254,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ByCss") { $TargetElement = [OpenQA.Selenium.By]::CssSelector($Css) } - + $WebDriverWait = New-Object -TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver, (New-TimeSpan -Seconds $Timeout)) $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists($TargetElement) $WebDriverWait.Until($Condition) @@ -279,7 +287,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ByXPath") { $Target.FindElements([OpenQA.Selenium.By]::XPath($XPath)) } - + if ($PSCmdlet.ParameterSetName -eq "ByCss") { $Target.FindElements([OpenQA.Selenium.By]::CssSelector($Css)) } @@ -307,17 +315,17 @@ function Invoke-SeClick { } function Get-SeKeys { - + [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } } function Send-SeKeys { param([OpenQA.Selenium.IWebElement]$Element, [string]$Keys) - + foreach ($Key in @(Get-SeKeys).Name) { $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key } - + $Element.SendKeys($Keys) } @@ -344,7 +352,7 @@ function Remove-SeCookie { function Set-SeCookie { param( - [ValidateNotNull()]$Driver, + [ValidateNotNull()]$Driver, [string]$Name, [string]$Value, [string]$Path, @@ -360,7 +368,7 @@ function Set-SeCookie { Cookie(String, String, String, Nullable) Initializes a new instance of the Cookie class with a specific name, value, path and expiration date. Cookie(String, String, String, String, Nullable) - Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date. + Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date. #> Begin{ if($ExpiryDate -ne $null -and $ExpiryDate.GetType().Name -ne 'DateTime'){ @@ -412,7 +420,7 @@ function Get-SeElementAttribute { Process { $Element.GetAttribute($Attribute) - } + } } function Invoke-SeScreenshot { @@ -448,7 +456,7 @@ function Get-SeWindow { Process { $Driver.WindowHandles - } + } } function Switch-SeWindow { @@ -459,5 +467,5 @@ function Switch-SeWindow { Process { $Driver.SwitchTo().Window($Window)|Out-Null - } + } } From dd25664e43ee3df4c746b1fc3aeb4aed65e3541b Mon Sep 17 00:00:00 2001 From: Josh King Date: Wed, 28 Aug 2019 09:11:26 +1200 Subject: [PATCH 7/8] Revert "Allow downloads when headless, via Chrome Command" This reverts commit d0176f4ae41b1acfe480c880759e4e4f737552e8. --- Selenium.psm1 | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/Selenium.psm1 b/Selenium.psm1 index 1ef78a0..1ef1a35 100644 --- a/Selenium.psm1 +++ b/Selenium.psm1 @@ -8,7 +8,7 @@ elseif($IsMacOS){ $AssembliesPath = "$PSScriptRoot/assemblies/macos" } -# Grant Execution permission to assemblies on Linux and MacOS +# Grant Execution permission to assemblies on Linux and MacOS if($IsLinux -or $IsMacOS){ # Check if powershell is NOT running as root $AssemblieFiles = Get-ChildItem -Path $AssembliesPath |Where-Object{$_.Name -eq 'chromedriver' -or $_.Name -eq 'geckodriver'} @@ -62,7 +62,7 @@ function Start-SeChrome { } PROCESS{ $Chrome_Options = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeOptions" - + if($DefaultDownloadPath){ Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" $Chrome_Options.AddUserProfilePreference('download', @{'default_directory' = $($DefaultDownloadPath.FullName); 'prompt_for_download' = $false; }) @@ -71,11 +71,11 @@ function Start-SeChrome { Write-Verbose "Setting Profile directory: $ProfileDirectoryPath" $Chrome_Options.AddArgument("user-data-dir=$ProfileDirectoryPath") } - + if($DisableBuiltInPDFViewer){ $Chrome_Options.AddUserProfilePreference('plugins', @{'always_open_pdf_externally' = $true;}) } - + if ($Headless) { $Chrome_Options.AddArguments('headless') } @@ -97,7 +97,7 @@ function Start-SeChrome { $Chrome_Options.AddArguments($Argument) } } - + if (!$HideVersionHint) { Write-Verbose "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" } @@ -106,7 +106,7 @@ function Start-SeChrome { $Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $AssembliesPath,$Chrome_Options } else{ - $Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options + $Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options } if($Minimized){ @@ -114,14 +114,6 @@ function Start-SeChrome { } - if($Headless -and $DefaultDownloadPath) { - $CmdParams = New-Object 'system.collections.generic.dictionary[[System.String],[System.Object]]]' - $CmdParams.Add('behavior', 'allow') - $CmdParams.Add('downloadPath', $DefaultDownloadPath.FullName) - - $Driver.ExecuteChromeCommand('Page.setDownloadBehavior', $CmdParams) - } - if($StartURL){ Enter-SeUrl -Driver $Driver -Url $StartURL } @@ -134,7 +126,7 @@ function Start-SeChrome { function Start-SeInternetExplorer { $InternetExplorer_Options = New-Object -TypeName "OpenQA.Selenium.IE.InternetExplorerOptions" $InternetExplorer_Options.IgnoreZoomLevel = $true - New-Object -TypeName "OpenQA.Selenium.IE.InternetExplorerDriver" -ArgumentList $InternetExplorer_Options + New-Object -TypeName "OpenQA.Selenium.IE.InternetExplorerDriver" -ArgumentList $InternetExplorer_Options } function Start-SeEdge { @@ -169,7 +161,7 @@ function Start-SeFirefox { } function Stop-SeDriver { - param($Driver) + param($Driver) $Driver.Dispose() } @@ -230,7 +222,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ById") { $TargetElement = [OpenQA.Selenium.By]::Id($Id) } - + if ($PSCmdlet.ParameterSetName -eq "ByLinkText") { $TargetElement = [OpenQA.Selenium.By]::LinkText($LinkText) } @@ -246,7 +238,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ByTagName") { $TargetElement = [OpenQA.Selenium.By]::TagName($TagName) } - + if ($PSCmdlet.ParameterSetName -eq "ByXPath") { $TargetElement = [OpenQA.Selenium.By]::XPath($XPath) } @@ -254,7 +246,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ByCss") { $TargetElement = [OpenQA.Selenium.By]::CssSelector($Css) } - + $WebDriverWait = New-Object -TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver, (New-TimeSpan -Seconds $Timeout)) $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists($TargetElement) $WebDriverWait.Until($Condition) @@ -287,7 +279,7 @@ function Find-SeElement { if ($PSCmdlet.ParameterSetName -eq "ByXPath") { $Target.FindElements([OpenQA.Selenium.By]::XPath($XPath)) } - + if ($PSCmdlet.ParameterSetName -eq "ByCss") { $Target.FindElements([OpenQA.Selenium.By]::CssSelector($Css)) } @@ -315,17 +307,17 @@ function Invoke-SeClick { } function Get-SeKeys { - + [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } } function Send-SeKeys { param([OpenQA.Selenium.IWebElement]$Element, [string]$Keys) - + foreach ($Key in @(Get-SeKeys).Name) { $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key } - + $Element.SendKeys($Keys) } @@ -352,7 +344,7 @@ function Remove-SeCookie { function Set-SeCookie { param( - [ValidateNotNull()]$Driver, + [ValidateNotNull()]$Driver, [string]$Name, [string]$Value, [string]$Path, @@ -368,7 +360,7 @@ function Set-SeCookie { Cookie(String, String, String, Nullable) Initializes a new instance of the Cookie class with a specific name, value, path and expiration date. Cookie(String, String, String, String, Nullable) - Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date. + Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date. #> Begin{ if($ExpiryDate -ne $null -and $ExpiryDate.GetType().Name -ne 'DateTime'){ @@ -420,7 +412,7 @@ function Get-SeElementAttribute { Process { $Element.GetAttribute($Attribute) - } + } } function Invoke-SeScreenshot { @@ -456,7 +448,7 @@ function Get-SeWindow { Process { $Driver.WindowHandles - } + } } function Switch-SeWindow { @@ -467,5 +459,5 @@ function Switch-SeWindow { Process { $Driver.SwitchTo().Window($Window)|Out-Null - } + } } From 0e0f1a49e75eadde9ed65bf2b1756094a42a2311 Mon Sep 17 00:00:00 2001 From: Josh King Date: Wed, 28 Aug 2019 09:16:12 +1200 Subject: [PATCH 8/8] Allow headless download to default path, with better variable name --- Selenium.psm1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Selenium.psm1 b/Selenium.psm1 index 1ef1a35..b0411ff 100644 --- a/Selenium.psm1 +++ b/Selenium.psm1 @@ -114,6 +114,14 @@ function Start-SeChrome { } + if($Headless -and $DefaultDownloadPath) { + $HeadlessDownloadParams = New-Object 'system.collections.generic.dictionary[[System.String],[System.Object]]]' + $HeadlessDownloadParams.Add('behavior', 'allow') + $HeadlessDownloadParams.Add('downloadPath', $DefaultDownloadPath.FullName) + + $Driver.ExecuteChromeCommand('Page.setDownloadBehavior', $HeadlessDownloadParams) + } + if($StartURL){ Enter-SeUrl -Driver $Driver -Url $StartURL }