diff --git a/.gitignore b/.gitignore index fb6ad1f..fa789a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -.vscode/launch.json -CI/LocalPostProcessing.ps1 - +.vscode +CI/LocalPostProcessing.ps1 +Scratchpad.ps1 +Output/testResults*.xml +Output/stats.json diff --git a/CI/CI.ps1 b/CI/CI.ps1 index dd11804..00d8145 100644 --- a/CI/CI.ps1 +++ b/CI/CI.ps1 @@ -1,69 +1,69 @@ param ( - [string[]]$BrowserList=@('Chrome','Firefox') + [string[]]$BrowserList = @('Chrome', 'Firefox') ) #Get the OS/PS version info for later. On Linux run headless On windows and PS 6 (but not 7) add WindowsPowershell to the module path. -$Platform = ([environment]::OSVersion.Platform).ToString() + ' PS' + $PSVersionTable.PSVersion.Major -if ($Platform -notlike 'win*') {$env:AlwaysHeadless = $true} -if ($Platform -like 'win*6') { - $env:PSModulePath -split ';' | Where-Object {$_ -match "\w:\\Prog.*PowerShell\\modules"} | ForEach-Object { - $env:PSModulePath = ($_ -replace "PowerShell","WindowsPowerShell") + ";" + $env:PSModulePath - } +$Platform = ([environment]::OSVersion.Platform).ToString() + ' PS' + $PSVersionTable.PSVersion.Major +if ($Platform -notlike 'win*') { $env:AlwaysHeadless = $true } +if ($Platform -like 'win*6') { + $env:PSModulePath -split ';' | Where-Object { $_ -match "\w:\\Prog.*PowerShell\\modules" } | ForEach-Object { + $env:PSModulePath = ($_ -replace "PowerShell", "WindowsPowerShell") + ";" + $env:PSModulePath + } } #Make sure we have the modules we need -Import-Module .\Selenium.psd1 -Force -ErrorAction Stop +Import-Module .\Output\Selenium\Selenium.psd1 -Force -ErrorAction Stop $checkImportExcel = Get-Module -ListAvailable ImportExcel if (-not ($checkImportExcel)) { Write-Verbose -Verbose 'Installing ImportExcel' Install-Module ImportExcel -Force -SkipPublisherCheck } -else {$checkImportExcel | Out-Host} -$checkPester = Get-Module -ListAvailable Pester| Where-Object {$_.version.major -ge 4 -and $_.version.minor -ge 4} +else { $checkImportExcel | Out-Host } +$checkPester = Get-Module -ListAvailable Pester | Where-Object { $_.version.major -ge 4 -and $_.version.minor -ge 4 } if (-not $checkPester) { Write-Verbose -Verbose 'Installing Pester' Install-Module Pester -Force -SkipPublisherCheck } -else {$checkPester | Out-Host} +else { $checkPester | Out-Host } #Run the test and results export to an Excel file for current OS - Test picks up the selected browser from an environment variable. -$RunParameters = @{ - XLFile = '{0}/results/Results-{1}.xlsx' -f $env:BUILD_ARTIFACTSTAGINGDIRECTORY, [environment]::OSVersion.Platform.ToString() - Script = Join-Path -Path (Join-Path $pwd 'Examples') -ChildPath 'Combined.tests.ps1' +$RunParameters = @{ + XLFile = '{0}/results/Results-{1}.xlsx' -f $env:BUILD_ARTIFACTSTAGINGDIRECTORY, [environment]::OSVersion.Platform.ToString() + Script = Join-Path -Path (Join-Path $pwd 'Examples') -ChildPath 'Combined.tests.ps1' } foreach ( $b in $BrowserList) { $env:DefaultBrowser = $b - $RunParameters['OutputFile'] = Join-Path $pwd "TestResults-$platform$b.xml" - $RunParameters['WorkSheetName'] = "$B $Platform" + $RunParameters['OutputFile'] = Join-Path $pwd "TestResults-$platform$b.xml" + $RunParameters['WorkSheetName'] = "$B $Platform" $RunParameters | Out-Host & "$PSScriptRoot\Pester-To-XLSx.ps1" @RunParameters } #Merge the results sheets into a sheet named 'combined'. -$excel = Open-ExcelPackage $RunParameters.XLFile -$wslist = $excel.Workbook.Worksheets.name +$excel = Open-ExcelPackage $RunParameters.XLFile +$wslist = $excel.Workbook.Worksheets.name Close-ExcelPackage -NoSave $excel -Merge-MultipleSheets -path $RunParameters.XLFile -WorksheetName $wslist -OutputSheetName combined -OutputFile $RunParameters.XLFile -HideRowNumbers -Property name,result +Merge-MultipleSheets -path $RunParameters.XLFile -WorksheetName $wslist -OutputSheetName combined -OutputFile $RunParameters.XLFile -HideRowNumbers -Property name, result #Hide everything on 'combined' except test name, results for each browser, and test group, Set column widths, tweak titles, apply conditional formatting. -$excel = Open-ExcelPackage $RunParameters.XLFile -$ws = $excel.combined +$excel = Open-ExcelPackage $RunParameters.XLFile +$ws = $excel.combined 2..$ws.Dimension.end.Column | ForEach-Object { - if ($ws.Cells[1,$_].value -notmatch '^Name|Result$|PS\dGroup$') { + if ($ws.Cells[1, $_].value -notmatch '^Name|Result$|PS\dGroup$') { Set-ExcelColumn -Worksheet $ws -Column $_ -Hid } - elseif ($ws.Cells[1,$_].value -match 'Result$' ) { + elseif ($ws.Cells[1, $_].value -match 'Result$' ) { Set-ExcelColumn -Worksheet $ws -Column $_ -Width 17 - Set-ExcelRange $ws.Cells[1,$_] -WrapText + Set-ExcelRange $ws.Cells[1, $_] -WrapText } - if ($ws.cells[1,$_].value -match 'PS\dGroup$') { - Set-ExcelRange $ws.Cells[1,$_] -WrapText -Value 'Group' + if ($ws.cells[1, $_].value -match 'PS\dGroup$') { + Set-ExcelRange $ws.Cells[1, $_] -WrapText -Value 'Group' } - if ($ws.cells[1,$_].value -match '^Name|PS\dGroup$' -and ($ws.Column($_).Width -gt 80)) { + if ($ws.cells[1, $_].value -match '^Name|PS\dGroup$' -and ($ws.Column($_).Width -gt 80)) { $ws.Column($_).Width = 80 } } Set-ExcelRow -Worksheet $ws -Height 28.5 -$cfRange = [OfficeOpenXml.ExcelAddress]::new(2,3,$ws.Dimension.end.Row, (3*$wslist.count -2)).Address +$cfRange = [OfficeOpenXml.ExcelAddress]::new(2, 3, $ws.Dimension.end.Row, (3 * $wslist.count - 2)).Address Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Failure" -BackgroundPattern None -ForegroundColor Red -Bold Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Success" -BackgroundPattern None -ForeGroundColor Green Close-ExcelPackage $excel diff --git a/CI/pipeline.yml b/CI/pipeline.yml index af8ce22..2118f43 100644 --- a/CI/pipeline.yml +++ b/CI/pipeline.yml @@ -1,48 +1,48 @@ # https://aka.ms/yaml trigger: - branches: - include: - - '*' - # - master - # - releases/* - paths: - exclude: + branches: + include: + - "*" + # - master + # - releases/* + paths: + exclude: - additions.md - ChangeLog.Txt - README.md jobs: - - job: 'Windows' + - job: "Windows" pool: - vmImage: 'windows-latest' + vmImage: "windows-latest" steps: - - powershell: './CI/CI.ps1 -browserlist Chrome,Firefox,IE' - displayName: 'Run Test on Windows PowerShell' - - pwsh: './CI/CI.ps1 -browserlist Chrome' - displayName: 'Run Test on PowerShell core on Windows' - - task: PublishPipelineArtifact@1 - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/results' - artifact: 'Windows Results' - - task: PublishTestResults@2 - inputs: - testResultsFormat: 'NUnit' - testResultsFiles: '**/TestResults*.xml' - failTaskOnFailedTests: true + - powershell: "./CI/CI.ps1 -browserlist Chrome,Firefox,IE" + displayName: "Run Test on Windows PowerShell" + - pwsh: "./CI/CI.ps1 -browserlist Chrome" + displayName: "Run Test on PowerShell core on Windows" + - task: PublishPipelineArtifact@1 + inputs: + targetPath: "$(Build.ArtifactStagingDirectory)/results" + artifact: "Windows Results" + - task: PublishTestResults@2 + inputs: + testResultsFormat: "NUnit" + testResultsFiles: "**/TestResults*.xml" + failTaskOnFailedTests: true - - job: 'Ubuntu' + - job: "Ubuntu" pool: - vmImage: 'ubuntu-latest' + vmImage: "ubuntu-latest" steps: - - powershell: './CI/CI.ps1 -browserlist Chrome,Firefox' - displayName: 'Run Test on Linux' - - task: PublishPipelineArtifact@1 - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/results' - artifact: 'Linux Results' - - task: PublishTestResults@2 - inputs: - testResultsFormat: 'NUnit' - testResultsFiles: '**/TestResults*.xml' - failTaskOnFailedTests: true + - powershell: "./CI/CI.ps1 -browserlist Chrome,Firefox" + displayName: "Run Test on Linux" + - task: PublishPipelineArtifact@1 + inputs: + targetPath: "$(Build.ArtifactStagingDirectory)/results" + artifact: "Linux Results" + - task: PublishTestResults@2 + inputs: + testResultsFormat: "NUnit" + testResultsFiles: "**/TestResults*.xml" + failTaskOnFailedTests: true diff --git a/ChangeLog.md b/ChangeLog.md index f5bb751..de47a81 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,12 +4,16 @@ - Added -IgnoreProtectedModeSettings to Start-SeInternetExplorer - https://github.com/adamdriscoll/selenium-powershell/issues/79 - Thanks, @MysticRyuujin! +- Added Markdown documentation (See Help subfolder) for all the cmdlets (PlatyPS is used behind the scene to maintain it) +- Added MAML embedded help that can be accessed through `Get-Help`(eg: `Get-Help Start-SeChrome -Examples`) + # 3.0.0 - 3/31/2020 ## Changed - Fixed issue with importing module in PSv5.1 - https://github.com/adamdriscoll/selenium-powershell/issues/69 - Updated Chrome drivers +- Converted monolythic module into a scaffolded module through a Plaster template. Module will now have a debug version and a compiled version that need to be built with Invoke-Build. See the Debug folder for additional informations on how to debug. # 3.0.0-beta2 - 1/29/2020 diff --git a/Debug/Debug.ps1 b/Debug/Debug.ps1 new file mode 100644 index 0000000..4818d38 --- /dev/null +++ b/Debug/Debug.ps1 @@ -0,0 +1,21 @@ +import-module Platyps +import-module InvokeBuild + +# Just a line to replace $PsScriptRoot since the former does not work when debugging with F8 +$ScriptFullPath, $ScriptRoot, $ScriptName, $ScriptNameShort = @('', '', '', ''); $ScriptFullPath = if (-not [String]::IsNullOrEmpty($PSCommandPath)) { $PSCommandPath } elseif ($psEditor -ne $null) { $psEditor.GetEditorContext().CurrentFile.Path } elseif ($psise -ne $null) { $psise.CurrentFile.FullPath }; $ScriptRoot = Split-Path -Path $ScriptFullPath -Parent; $ScriptName = Split-Path -Path $ScriptFullPath -Leaf; $ScriptNameShort = ([System.IO.Path]::GetFileNameWithoutExtension($ScriptFullPath)) +$ProjectPath = Split-Path $ScriptRoot + +# Load Debug version +#import-module "$ProjectPath\Selenium.psd1" -Force + +#Load Compiled version +import-module "$ProjectPath\output\selenium\Selenium.psd1" -Force +Invoke-Pester -Script 'C:\Github\selenium-powershell\Examples\Combined.tests.ps1' + +# Build module +#invoke-build -File "$ProjectPath\Selenium.build.ps1" + + + + + diff --git a/Debug/README.md b/Debug/README.md new file mode 100644 index 0000000..efacd8a --- /dev/null +++ b/Debug/README.md @@ -0,0 +1,31 @@ +# Instructions + +## Prerequisites +- InvokeBuild module +- PlatyPS module + +## How to + +### Debug + +To load the debugging version, simply load the Selenium.psd1 located at the root of this directory. + +`import-module "$ProjectPath\Selenium.psd1" -Force` + +To load the compiled version, load the psd1 located in the output directory instead. + +`import-module "$ProjectPath\output\selenium\Selenium.psd1" -Force` + +When developping, you should always load the development version of the module. Never work in the files from the **output** directory directly as these will be wiped out whenever you compile the module again. + +### Compile the module +The module is scaffolded into multiple files for convenience and compiled into a psm1 file when ready to be published. + +Alongside this, additional tasks are performed suche as basic Powershell validation, self-updating Markdown documentation, embedded help file generation, psd1 function replace based on Public folder content, etc. + +To perform these tasks and produce a compiled (but not packaged) version of the module, run the following + +`invoke-build -File "$ProjectPath\Selenium.build.ps1"` + + +See the debug.ps1 file in this directory to get started. \ No newline at end of file diff --git a/Examples/Combined.tests.ps1 b/Examples/Combined.tests.ps1 index d60a804..ef68781 100644 --- a/Examples/Combined.tests.ps1 +++ b/Examples/Combined.tests.ps1 @@ -1,174 +1,178 @@ -if ($Global:SeDriver) {Write-Warning -Message 'Close any previous session first'; return} +if ($Global:SeDriver) { Write-Warning -Message 'Close any previous session first'; return } #SeOpen will use an environment variable DefaultBrowser if no browser is specified on the command line, so # we can run the script with different browsers by changing that and running invoke-pester again. If it wasn't set, set it now -if (-not $env:DefaultBrowser) {$env:DefaultBrowser = 'Chrome'} +if (-not $env:DefaultBrowser) { $env:DefaultBrowser = 'Chrome' } #For each browser we will test in, specify the options for headless, inprivate & window title label for in-private -$AlwaysHeadless = $env:AlwaysHeadless -eq $true -$TestCaseSettings = @{ - 'NewEdge' = @{ DefaultOptions = @{Headless=$AlwaysHeadless} - # HeadlessOptions = @{Headless=$true} - PrivateOptions = @{PrivateBrowsing=$true - Headless=$AlwaysHeadless } - # InPrivateLabel = 'InPrivate' +$AlwaysHeadless = $env:AlwaysHeadless -eq $true +$TestCaseSettings = @{ + 'NewEdge' = @{ DefaultOptions = @{Headless = $AlwaysHeadless } + # HeadlessOptions = @{Headless=$true} + PrivateOptions = @{PrivateBrowsing = $true + Headless = $AlwaysHeadless + } + # InPrivateLabel = 'InPrivate' } # broken after build 79 of web driver#> - 'Chrome' = @{ PrivateOptions = @{PrivateBrowsing=$true - Headless=$AlwaysHeadless} - DefaultOptions = @{Headless=$AlwaysHeadless} - HeadlessOptions = @{Headless=$true} + 'Chrome' = @{ PrivateOptions = @{PrivateBrowsing = $true + Headless = $AlwaysHeadless + } + DefaultOptions = @{Headless = $AlwaysHeadless } + HeadlessOptions = @{Headless = $true } } - 'Firefox' = @{ PrivateOptions = @{PrivateBrowsing=$true - Headless=$AlwaysHeadless} - DefaultOptions = @{Headless=$AlwaysHeadless} - HeadlessOptions = @{Headless=$true} + 'Firefox' = @{ PrivateOptions = @{PrivateBrowsing = $true + Headless = $AlwaysHeadless + } + DefaultOptions = @{Headless = $AlwaysHeadless } + HeadlessOptions = @{Headless = $true } } - 'MSEdge' = @{ DefaultOptions = @{Headless=$AlwaysHeadless} - PrivateOptions = @{PrivateBrowsing=$true} + 'MSEdge' = @{ DefaultOptions = @{Headless = $AlwaysHeadless } + PrivateOptions = @{PrivateBrowsing = $true } } - 'IE' = @{ DefaultOptions = @{ImplicitWait=30} - PrivateOptions = @{ImplicitWait=30} + 'IE' = @{ DefaultOptions = @{ImplicitWait = 30 } + PrivateOptions = @{ImplicitWait = 30 } } } function Build-StringFromHash { param ($Hash) - $(foreach ($k in $Hash.Keys) {"$K`:$($hash[$K])"}) -join '; ' + $(foreach ($k in $Hash.Keys) { "$K`:$($hash[$K])" }) -join '; ' } #region tailspin demo from the Azure Devops training materials if (-not $env:SITE_URL) { $env:SITE_URL = 'http://tailspin-spacegame-web.azurewebsites.net' } -$ModaltestCases = @( - @{Name = 'Download Page' - linkXPath = '/html/body/div/div/section[2]/div[2]/a' - modalXPath = '//*[@id="pretend-modal"]/div/div' +$ModaltestCases = @( + @{Name = 'Download Page' + linkXPath = '/html/body/div/div/section[2]/div[2]/a' + modalXPath = '//*[@id="pretend-modal"]/div/div' }, - @{Name = 'Screen Image' - linkXPath = '/html/body/div/div/section[3]/div/ul/li[1]/a' - modalXPath = '/html/body/div[1]/div/div[2]' + @{Name = 'Screen Image' + linkXPath = '/html/body/div/div/section[3]/div/ul/li[1]/a' + modalXPath = '/html/body/div[1]/div/div[2]' }, - @{Name = 'Top Player' - linkXPath = '/html/body/div/div/section[4]/div/div/div[1]/div[2]/div[2]/div/a/div' - modalXPath = '//*[@id="profile-modal-1"]/div/div'} + @{Name = 'Top Player' + linkXPath = '/html/body/div/div/section[4]/div/div/div[1]/div[2]/div[2]/div/a/div' + modalXPath = '//*[@id="profile-modal-1"]/div/div' + } ) -$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].DefaultOptions -$BrowserOptText = Build-StringFromHash $BrowserOptHash +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].DefaultOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash Describe "Testing the tailspin toys demo site at $env:SITE_URL" { BeforeAll { #Relying on environment variable to pick the browser. Capture ID for use in logs by requesting verbose and redirecting it. $BrowserID = SeOpen -URL $env:SITE_URL -Options $BrowserOptHash -Verbose 4>&1 - $BrowserID = ($BrowserID.Message -replace '^Opened ','') + ' on ' + [System.Environment]::OSVersion.Platform + $BrowserID = ($BrowserID.Message -replace '^Opened ', '') + ' on ' + [System.Environment]::OSVersion.Platform } - Context "in $BrowserID with settings ($BrowserOptText)"{ + Context "in $BrowserID with settings ($BrowserOptText)" { It "produced the right modal dialog for the " -TestCases $ModaltestCases { Param ($linkXPath, $modalXPath) - SeShouldHave $modalXPath -With displayed eq $false - SeElement $linkXPath | SeClick -JavaScriptClick -SleepSeconds 1 - SeShouldHave $modalXPath -With displayed eq $true -PassThru| SeElement -By Class 'close' | SeClick -J -S 1 - SeShouldHave 'body' -By TagName - SeShouldHave $modalXPath -With displayed eq $false + SeShouldHave $modalXPath -With displayed eq $false + SeElement $linkXPath | SeClick -JavaScriptClick -SleepSeconds 1 + SeShouldHave $modalXPath -With displayed eq $true -PassThru | SeElement -By Class 'close' | SeClick -J -S 1 + SeShouldHave 'body' -By TagName + SeShouldHave $modalXPath -With displayed eq $false } } -# Additional tests would be here - AfterAll {SeClose} + # Additional tests would be here + AfterAll { SeClose } } #endregion #URLs we will visit in the remaining tests -$PSGalleryPage = 'https://www.powershellgallery.com/' -$AlertTestPage = 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' -$SelectTestPage = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' +$PSGalleryPage = 'https://www.powershellgallery.com/' +$AlertTestPage = 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' +$SelectTestPage = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' #As before rely on environment variable to pick browser. Capture ID by requesting & redirecting verbose -$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].DefaultOptions -$BrowserOptText = Build-StringFromHash $BrowserOptHash -$BrowserID = SeOpen -URL $PSGalleryPage -Options $BrowserOptHash -Verbose 4>&1 -$BrowserID = ($BrowserID.Message -replace '^Opened ','') + ' on ' + [System.Environment]::OSVersion.Platform -Describe "PsGallery Test" { - Context "in $BrowserID with settings ($BrowserOptText)"{ - It 'opened the browser, saving the webdriver in a global variable ' { - $Global:SeDriver | Should -Not -BeNullOrEmpty - $Global:SeDriver | Should -BeOfType [OpenQA.Selenium.Remote.RemoteWebDriver] - } - It 'reached the right starting page ' { - #Should have can check alerts, page title, URL or an element on the page - SeShouldHave -URL eq $PSGalleryPage - } - It 'found the "Sign in" link on the home page by partial text ' { - SeShouldHave -By PartialLinkText 'Sign in' -With href match logon - } - It 'found the search box on the home page by ID ' { - SeShouldHave -By Id search - } - It 'found the search box on the home page by Name ' { - SeShouldHave -By Name 'q' - } - It 'found the search box on the home page by css selector ' { - #can write -By <> [-selection] <> - # or [-selection] <> -By <> - SeShouldHave 'input[name=q]' -By CssSelector - } - It 'found the search box on the home page by class name ' { - SeShouldHave -By ClassName "search-box" - } - It 'found the search box on the home page by Tagname and typed in it ' { - #get element, pipe as input element for Typing, pass the element through - #so pester catches 'null or empty' if it was not found - SeElement -By TagName input | - SeType -ClearFirst "selenium{{Enter}}" -PassThru -SleepSeconds 2 | Should -Not -BeNullorEmpty - } - $linkpath = '//*[@id="skippedToContent"]/section/div[1]/div[2]/div[2]/section[1]/div/table/tbody/tr/td[1]/div/div[2]/header/div[1]/h1/a' - It 'searched successfully ' { - SeShouldHave -URL match 'packages\?q=selenium' -Timeout 15 - #Two tests on the same element, second passes it through to click - SeShouldHave $linkpath -With href match selenium - SeShouldHave $linkpath -With Text like *selenium* -PassThru | SeClick -SleepSeconds 5 - } - It 'opened the search result page and found the expected content ' { - #Just to show we can test for the presence of multiple links. Each one is re-tested ... - SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' , - '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' -Timeout 15 +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].DefaultOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash +$BrowserID = SeOpen -URL $PSGalleryPage -Options $BrowserOptHash -Verbose 4>&1 +$BrowserID = ($BrowserID.Message -replace '^Opened ', '') + ' on ' + [System.Environment]::OSVersion.Platform +Describe "PsGallery Test" { + Context "in $BrowserID with settings ($BrowserOptText)" { + It 'opened the browser, saving the webdriver in a global variable ' { + $Global:SeDriver | Should -Not -BeNullOrEmpty + $Global:SeDriver | Should -BeOfType [OpenQA.Selenium.Remote.RemoteWebDriver] + } + It 'reached the right starting page ' { + #Should have can check alerts, page title, URL or an element on the page + SeShouldHave -URL eq $PSGalleryPage + } + It 'found the "Sign in" link on the home page by partial text ' { + SeShouldHave -By PartialLinkText 'Sign in' -With href match logon + } + It 'found the search box on the home page by ID ' { + SeShouldHave -By Id search + } + It 'found the search box on the home page by Name ' { + SeShouldHave -By Name 'q' + } + It 'found the search box on the home page by css selector ' { + #can write -By <> [-selection] <> + # or [-selection] <> -By <> + SeShouldHave 'input[name=q]' -By CssSelector + } + It 'found the search box on the home page by class name ' { + SeShouldHave -By ClassName "search-box" + } + It 'found the search box on the home page by Tagname and typed in it ' { + #get element, pipe as input element for Typing, pass the element through + #so pester catches 'null or empty' if it was not found + SeElement -By TagName input | + SeType -ClearFirst "selenium{{Enter}}" -PassThru -SleepSeconds 2 | Should -Not -BeNullorEmpty + } + $linkpath = '//*[@id="skippedToContent"]/section/div[1]/div[2]/div[2]/section[1]/div/table/tbody/tr/td[1]/div/div[2]/header/div[1]/h1/a' + It 'searched successfully ' { + SeShouldHave -URL match 'packages\?q=selenium' -Timeout 15 + #Two tests on the same element, second passes it through to click + SeShouldHave $linkpath -With href match selenium + SeShouldHave $linkpath -With Text like *selenium* -PassThru | SeClick -SleepSeconds 5 + } + It 'opened the search result page and found the expected content ' { + #Just to show we can test for the presence of multiple links. Each one is re-tested ... + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' , + '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' -Timeout 15 - SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' -With text match "current" + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' -With text match "current" - #Can test with "Get-SeElement | where-object <>" rather than "with <> <> <>" - SeElement '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' | - Where-Object {($_.text -like "*Project Site*") -and ($_.GetAttribute('href') -match "selenium") } | - SeClick -PassThru | Should -Not -Benullorempty - } - It 'went to Github from the project link on the search result ' { - SeShouldHave -URL match 'github' -Timeout 30 - } - It 'navigated back to the start page and closed the browser ' { - SeNavigate -Back - SeNavigate -Back - SeNavigate -Back - SeShouldHave -URL eq $PSGalleryPage -Timeout 30 - SeClose - $Global:SeDriver | Should -BeNullOrEmpty - } + #Can test with "Get-SeElement | where-object <>" rather than "with <> <> <>" + SeElement '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' | + Where-Object { ($_.text -like "*Project Site*") -and ($_.GetAttribute('href') -match "selenium") } | + SeClick -PassThru | Should -Not -Benullorempty + } + It 'went to Github from the project link on the search result ' { + SeShouldHave -URL match 'github' -Timeout 30 } + It 'navigated back to the start page and closed the browser ' { + SeNavigate -Back + SeNavigate -Back + SeNavigate -Back + SeShouldHave -URL eq $PSGalleryPage -Timeout 30 + SeClose + $Global:SeDriver | Should -BeNullOrEmpty + } + } } -$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].PrivateOptions -$BrowserOptText = Build-StringFromHash $BrowserOptHash +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].PrivateOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash if ($BrowserOptText) { $NoLabel = [string]::IsNullOrEmpty($TestCaseSettings[$env:DefaultBrowser].InPrivateLabel) $wv = $null SeOpen -Options $BrowserOptHash -URL $alertTestPage -WarningVariable wv - if ($wv) {Write-Output "##vso[task.logissue type=warning]$wv"} + if ($wv) { Write-Output "##vso[task.logissue type=warning]$wv" } } else { $NoLabel = $true SeOpen -URL $alertTestPage } -Describe "Alerts and Selection boxes tests"{ +Describe "Alerts and Selection boxes tests" { Context "in $BrowserID with settings ($BrowserOptText)" { It 're-opended the browser and validated "InPrivate" mode by window title ' { - $DriverProcess = Get-Process *driver | Where-Object {$_.Parent.id -eq $pid} - $BrowserProcess = Get-Process | Where-Object {$_.Parent.id -eq $DriverProcess.id -and $_.Name -ne "conhost"} + $DriverProcess = Get-Process *driver | Where-Object { $_.Parent.id -eq $pid } + $BrowserProcess = Get-Process | Where-Object { $_.Parent.id -eq $DriverProcess.id -and $_.Name -ne "conhost" } $BrowserProcess.MainWindowTitle | Should match $TestCaseSettings[$env:DefaultBrowser].InPrivateLabel } -Skip:$NoLabel It 'opened the right page ' { @@ -182,7 +186,7 @@ Describe "Alerts and Selection boxes tests"{ It 'saw and dismissed an alert ' { #Checking the text of the alert is optional. Dissmiss can pass the alert result through SeShouldHave -Alert match "box" -PassThru | - SeDismiss -PassThru | Should -Not -BeNullOrEmpty + SeDismiss -PassThru | Should -Not -BeNullOrEmpty } It 'reselected the parent frame ' { SeFrame -Parent @@ -197,10 +201,10 @@ Describe "Alerts and Selection boxes tests"{ It 'made selections from the "cars" selection box ' { $e = SeElement -by Name "cars" #Values are lower case Text has inital caps comparisons are case sensitve. Index is 0-based - {$e | SeSelection -ByValue "Audi"} | Should -Throw - {$e | SeSelection -ByValue "audi"} | Should -not -throw - $e | SeSelection -ByIndex "2" -GetSelected | Should -Be 'Fiat' - $e | SeSelection -ByPartialText "Sa" + { $e | SeSelection -ByValue "Audi" } | Should -Throw + { $e | SeSelection -ByValue "audi" } | Should -not -throw + $e | SeSelection -ByIndex "2" -GetSelected | Should -Be 'Fiat' + $e | SeSelection -ByPartialText "Sa" } It 'submitted the form and got the expected response ' { SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 @@ -220,15 +224,15 @@ Describe "Alerts and Selection boxes tests"{ } } -$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].HeadlessOptions -$BrowserOptText = Build-StringFromHash $BrowserOptHash -if ($BrowserOptText){ +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].HeadlessOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash +if ($BrowserOptText) { SeOpen -Options $BrowserOptHash Describe "'Headless' mode browser test" { Context "in $BrowserID with settings ($BrowserOptText)" { It 're-opened the Browser in "Headless" mode ' { - $DriverProcess = Get-Process *driver | Where-Object {$_.Parent.id -eq $pid} - $BrowserProcess = Get-Process | Where-Object {$_.Parent.id -eq $DriverProcess.id -and $_.Name -ne 'conhost'} + $DriverProcess = Get-Process *driver | Where-Object { $_.Parent.id -eq $pid } + $BrowserProcess = Get-Process | Where-Object { $_.Parent.id -eq $DriverProcess.id -and $_.Name -ne 'conhost' } $BrowserProcess.MainWindowHandle | Select-Object -First 1 | Should -Be 0 } it 'did a google Search ' { @@ -240,7 +244,7 @@ if ($BrowserOptText){ SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru | should -Not -BeNullOrEmpty SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | - SeClick -PassThru | should -Not -BeNullOrEmpty + SeClick -PassThru | should -Not -BeNullOrEmpty } It 'closed the browser a third time ' { SeClose diff --git a/Help/Clear-SeAlert.md b/Help/Clear-SeAlert.md new file mode 100644 index 0000000..fd936ee --- /dev/null +++ b/Help/Clear-SeAlert.md @@ -0,0 +1,112 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Clear-SeAlert + +## SYNOPSIS +Accept and clear alert popup + +## SYNTAX + +### Alert +``` +Clear-SeAlert [[-Alert] ] [-Action ] [-PassThru] [] +``` + +### Driver +``` +Clear-SeAlert [-Target ] [-Action ] [-PassThru] [] +``` + +## DESCRIPTION +Accept and clear alert popup + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Action +Action to be performed on the alert popup + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: +Accepted values: Accept, Dismiss + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Alert +Specify alert window. Seems to be ignored in favor of Target / Default Target. + +```yaml +Type: Object +Parameter Sets: Alert +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -PassThru +{{ Fill PassThru Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: PT + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: Driver +Aliases: Driver + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeCookie.md b/Help/Get-SeCookie.md new file mode 100644 index 0000000..e54cf61 --- /dev/null +++ b/Help/Get-SeCookie.md @@ -0,0 +1,60 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeCookie + +## SYNOPSIS +List all cookies + +## SYNTAX + +``` +Get-SeCookie [[-Target] ] [] +``` + +## DESCRIPTION +List all cookies + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeCookie +``` + +List all cookies of the default webdriver + +## PARAMETERS + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeElement.md b/Help/Get-SeElement.md new file mode 100644 index 0000000..9f4bdda --- /dev/null +++ b/Help/Get-SeElement.md @@ -0,0 +1,123 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeElement + +## SYNOPSIS + +Finds all IWebElements within the current context using the given mechanism + +## SYNTAX + +``` +Get-SeElement [-By ] [-Selection] [[-Timeout] ] [[-Target] ] [-Wait] + [] +``` + +## DESCRIPTION +Finds all IWebElements within the current context using the given mechanism + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeElement -By Name -Selection 'username' +``` + +Get the username field by name + +## PARAMETERS + +### -By +The locating mechanism to use + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: CssSelector, Name, Id, ClassName, LinkText, PartialLinkText, TagName, XPath + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Selection +String Identifier of the object to find + +```yaml +Type: String +Parameter Sets: (All) +Aliases: CssSelector, Name, Id, ClassName, LinkText, PartialLinkText, TagName, XPath + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Element, Driver + +Required: False +Position: 3 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Timeout +Timeout (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Wait +Set Timeout to 30 seconds (Will not override Timeout value if already defined) + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeElementAttribute.md b/Help/Get-SeElementAttribute.md new file mode 100644 index 0000000..8e1bdf5 --- /dev/null +++ b/Help/Get-SeElementAttribute.md @@ -0,0 +1,76 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeElementAttribute + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-SeElementAttribute [-Element] [-Attribute] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Element = Get-SeElement -By Name -Selection 'username' +PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' +``` + +Get the placeholder attribue of the username element. + +## PARAMETERS + +### -Attribute +{{ Fill Attribute Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +Target IWebElement + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebElement + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeElementCssValue.md b/Help/Get-SeElementCssValue.md new file mode 100644 index 0000000..b0544cd --- /dev/null +++ b/Help/Get-SeElementCssValue.md @@ -0,0 +1,73 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeElementCssValue + +## SYNOPSIS +Get CSS value for the specified name of targeted element. + +## SYNTAX + +``` +Get-SeElementCssValue [-Element] [-Name] [] +``` + +## DESCRIPTION +Get CSS value for the specified name of targeted element. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeElementCssValue -Element $Element -Name 'padding' +``` + +## PARAMETERS + +### -Element +Target IWebElement + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Name +Name of the CSS attribute to query + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebElement + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeKeys.md b/Help/Get-SeKeys.md new file mode 100644 index 0000000..54470b6 --- /dev/null +++ b/Help/Get-SeKeys.md @@ -0,0 +1,44 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeKeys + +## SYNOPSIS +Return a list of the available special keys + +## SYNTAX + +``` +Get-SeKeys [] +``` + +## DESCRIPTION +Return a list of the available special keys. +These keys can be used with `Send-SeKeys` by using their name in the following format `{{SpecialKeyName}}` + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeKeys +``` + +## PARAMETERS + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeSelectionOption.md b/Help/Get-SeSelectionOption.md new file mode 100644 index 0000000..72b84ed --- /dev/null +++ b/Help/Get-SeSelectionOption.md @@ -0,0 +1,271 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeSelectionOption + +## SYNOPSIS +Get Selected option from a Select control + +## SYNTAX + +### default (Default) +``` +Get-SeSelectionOption [-Element] [-Clear] [-ListOptionText] [] +``` + +### byValue +``` +Get-SeSelectionOption [-ByValue] [-Element] [-Clear] [-GetSelected] [-GetAllSelected] + [-PassThru] [] +``` + +### byText +``` +Get-SeSelectionOption [-Element] -ByFullText [-Clear] [-GetSelected] [-GetAllSelected] + [-PassThru] [] +``` + +### bypart +``` +Get-SeSelectionOption [-Element] -ByPartialText [-GetSelected] [-GetAllSelected] + [-PassThru] [] +``` + +### byIndex +``` +Get-SeSelectionOption [-Element] -ByIndex [-Clear] [-GetSelected] [-GetAllSelected] + [-PassThru] [] +``` + +### multi +``` +Get-SeSelectionOption [-Element] [-IsMultiSelect] [] +``` + +### selected +``` +Get-SeSelectionOption [-Element] [-GetSelected] [] +``` + +### allSelected +``` +Get-SeSelectionOption [-Element] [-GetAllSelected] [] +``` + +## DESCRIPTION +Get Selected option from a Select control + +## EXAMPLES + +## PARAMETERS + +### -ByFullText +{{ Fill ByFullText Description }} + +```yaml +Type: String +Parameter Sets: byText +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ByIndex +{{ Fill ByIndex Description }} + +```yaml +Type: Int32 +Parameter Sets: byIndex +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ByPartialText +{{ Fill ByPartialText Description }} + +```yaml +Type: String +Parameter Sets: bypart +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ByValue +{{ Fill ByValue Description }} + +```yaml +Type: String +Parameter Sets: byValue +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Clear +Deselect the option first + +```yaml +Type: SwitchParameter +Parameter Sets: default, byValue, byText, byIndex +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +Targeted IwebElement + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -GetAllSelected +All selected options belonging to this select tag + +```yaml +Type: SwitchParameter +Parameter Sets: byValue, byText, bypart, byIndex +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +```yaml +Type: SwitchParameter +Parameter Sets: allSelected +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -GetSelected +Get selected option + +```yaml +Type: SwitchParameter +Parameter Sets: byValue, byText, bypart, byIndex +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +```yaml +Type: SwitchParameter +Parameter Sets: selected +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IsMultiSelect +To use with multiselect element + +```yaml +Type: SwitchParameter +Parameter Sets: multi +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ListOptionText +This parameter is not used + +```yaml +Type: SwitchParameter +Parameter Sets: default +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Return IWebElement + +```yaml +Type: SwitchParameter +Parameter Sets: byValue, byText, bypart, byIndex +Aliases: PT + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +### OpenQA.Selenium.IWebElement + +### System.Int32 + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeWindow.md b/Help/Get-SeWindow.md new file mode 100644 index 0000000..0fa20d3 --- /dev/null +++ b/Help/Get-SeWindow.md @@ -0,0 +1,60 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeWindow + +## SYNOPSIS +Gets the window handles of open browser windows + +## SYNTAX + +``` +Get-SeWindow [[-Target] ] [] +``` + +## DESCRIPTION +Gets the window handles of open browser windows + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeWindow +``` + +Gets the window handles of open browser windows. + +## PARAMETERS + +### -Target +Target webdriver + +```yaml +Type: IWebDriver +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Invoke-SeClick.md b/Help/Invoke-SeClick.md new file mode 100644 index 0000000..fb430dd --- /dev/null +++ b/Help/Invoke-SeClick.md @@ -0,0 +1,89 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Invoke-SeClick + +## SYNOPSIS +Select an element then send a click action on it. + +## SYNTAX + +### Default (Default) +``` +Invoke-SeClick -Element [] +``` + +### JavaScript +``` +Invoke-SeClick -Element [-JavaScriptClick] [-Driver ] [] +``` + +## DESCRIPTION +Select an element then send a click action on it. + +## EXAMPLES + +## PARAMETERS + +### -Driver +Target webdriver + +```yaml +Type: Object +Parameter Sets: JavaScript +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +Element for which the click will be performed upon + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -JavaScriptClick +Use Javascript to perform the click + +```yaml +Type: SwitchParameter +Parameter Sets: JavaScript +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebElement + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Invoke-SeScreenshot.md b/Help/Invoke-SeScreenshot.md new file mode 100644 index 0000000..d52982d --- /dev/null +++ b/Help/Invoke-SeScreenshot.md @@ -0,0 +1,68 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Invoke-SeScreenshot + +## SYNOPSIS +Take a screenshot of the current page + +## SYNTAX + +``` +Invoke-SeScreenshot [[-Target] ] [-AsBase64EncodedString] [] +``` + +## DESCRIPTION +Take a screenshot of the current page + +## EXAMPLES + +## PARAMETERS + +### -AsBase64EncodedString +Return image as base64 string + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/New-SeScreenshot.md b/Help/New-SeScreenshot.md new file mode 100644 index 0000000..d9589fb --- /dev/null +++ b/Help/New-SeScreenshot.md @@ -0,0 +1,146 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# New-SeScreenshot + +## SYNOPSIS +Take a screenshot of the current page + +## SYNTAX + +### Path (Default) +``` +New-SeScreenshot [-Path] [[-ImageFormat] ] [-Target ] + [] +``` + +### PassThru +``` +New-SeScreenshot [[-Path] ] [[-ImageFormat] ] [-Target ] [-PassThru] + [] +``` + +### Base64 +``` +New-SeScreenshot [-Target ] [-AsBase64EncodedString] [] +``` + +## DESCRIPTION +Take a screenshot of the current page + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> New-SeScreenshot -Path 'c:\temp\Screenshot.png' -ImageFormat Png +``` + +Save a screenshot in PNG format at the specified location + +## PARAMETERS + +### -AsBase64EncodedString +Return image as base64 string + +```yaml +Type: SwitchParameter +Parameter Sets: Base64 +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImageFormat +Set the image format + +```yaml +Type: ScreenshotImageFormat +Parameter Sets: Path, PassThru +Aliases: +Accepted values: Png, Jpeg, Gif, Tiff, Bmp + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Return the screenshot element + +```yaml +Type: SwitchParameter +Parameter Sets: PassThru +Aliases: PT + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +Filepath where the image iwll be saved to. + +```yaml +Type: Object +Parameter Sets: Path +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +```yaml +Type: Object +Parameter Sets: PassThru +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Open-SeUrl.md b/Help/Open-SeUrl.md new file mode 100644 index 0000000..b0d8806 --- /dev/null +++ b/Help/Open-SeUrl.md @@ -0,0 +1,141 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Open-SeUrl + +## SYNOPSIS +Navigate to URL + +## SYNTAX + +### default (Default) +``` +Open-SeUrl [-Target ] [] +``` + +### url +``` +Open-SeUrl [-Url] [-Target ] [] +``` + +### back +``` +Open-SeUrl [-Back] [-Target ] [] +``` + +### forward +``` +Open-SeUrl [-Forward] [-Target ] [] +``` + +### refresh +``` +Open-SeUrl [-Refresh] [-Target ] [] +``` + +## DESCRIPTION +Navigate to URL + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Open-SeUrl -Url 'https://www.google.com' +``` + +Open URL into currently selected Driver + +## PARAMETERS + +### -Back +Enables the web browser to click on the back button in the existing browser window. + +```yaml +Type: SwitchParameter +Parameter Sets: back +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Forward +enables the web browser to click on the forward button in the existing browser window. + +```yaml +Type: SwitchParameter +Parameter Sets: forward +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Refresh +enables the web browser to click on the refresh button in the existing browser window. + +```yaml +Type: SwitchParameter +Parameter Sets: refresh +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Url +Url to navigate to + +```yaml +Type: String +Parameter Sets: url +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/README.MD b/Help/README.MD new file mode 100644 index 0000000..25a7949 --- /dev/null +++ b/Help/README.MD @@ -0,0 +1,92 @@ +--- +Module Name: Selenium +Module Guid: {{ Update Module Guid }} +Download Help Link: {{ Update Download Link }} +Help Version: {{ Update Help Version }} +Locale: {{ Update Locale }} +--- + +# Selenium Module +## Description +{{ Fill in the Description }} + +## Selenium Cmdlets +### [Clear-SeAlert](Clear-SeAlert.md) +Accept and clear alert popup + +### [Get-SeCookie](Get-SeCookie.md) +List all cookies + +### [Get-SeElement](Get-SeElement.md) + +Finds all IWebElements within the current context using the given mechanism + +### [Get-SeElementAttribute](Get-SeElementAttribute.md) +{{ Fill in the Synopsis }} + +### [Get-SeElementCssValue](Get-SeElementCssValue.md) +Get CSS value for the specified name of targeted element. + +### [Get-SeKeys](Get-SeKeys.md) +Return a list of the available special keys + +### [Get-SeSelectionOption](Get-SeSelectionOption.md) +Get Selected option from a Select control + +### [Get-SeWindow](Get-SeWindow.md) +Gets the window handles of open browser windows + +### [Invoke-SeClick](Invoke-SeClick.md) +Select an element then send a click action on it. + +### [Invoke-SeScreenshot](Invoke-SeScreenshot.md) +Take a screenshot of the current page + +### [New-SeScreenshot](New-SeScreenshot.md) +Take a screenshot of the current page + +### [Open-SeUrl](Open-SeUrl.md) +Navigate to URL + +### [Remove-SeCookie](Remove-SeCookie.md) +Delete the named cookie from the current domain + +### [Save-SeScreenshot](Save-SeScreenshot.md) +Take a screenshot of the current page + +### [Send-SeClick](Send-SeClick.md) +Send a click to the targeted element + +### [Send-SeKeys](Send-SeKeys.md) +Simulates typing text into the element + +### [Set-SeCookie](Set-SeCookie.md) +Add a cookie to the current browsing context + +### [Start-SeChrome](Start-SeChrome.md) +Initializes a new instance of the **ChromeDriver** class. + +### [Start-SeEdge](Start-SeEdge.md) +Initializes a new instance of the EdgeDriver class + +### [Start-SeFirefox](Start-SeFirefox.md) +Initializes a new instance of the **FirefoxDriver** class. + +### [Start-SeInternetExplorer](Start-SeInternetExplorer.md) +{{ Fill in the Synopsis }} + +### [Start-SeNewEdge](Start-SeNewEdge.md) +Initializes a new instance of the EdgeDriver class + +### [Start-SeNewEdge](Start-SeNewEdge.md) +{{ Fill in the Synopsis }} + +### [Stop-SeDriver](Stop-SeDriver.md) +Quits this driver, closing every associated window. + +### [Switch-SeFrame](Switch-SeFrame.md) +Instructs the driver to send future commands to a different frame + +### [Switch-SeWindow](Switch-SeWindow.md) +Instructs the driver to send future commands to a different window + diff --git a/Help/Remove-SeCookie.md b/Help/Remove-SeCookie.md new file mode 100644 index 0000000..e1635fd --- /dev/null +++ b/Help/Remove-SeCookie.md @@ -0,0 +1,103 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Remove-SeCookie + +## SYNOPSIS +Delete the named cookie from the current domain + +## SYNTAX + +### DeleteAllCookies +``` +Remove-SeCookie [-Target ] [-DeleteAllCookies] [] +``` + +### NamedCookie +``` +Remove-SeCookie [-Target ] -Name [] +``` + +## DESCRIPTION +Delete the named cookie from the current domain + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Remove-SeCookie -Name 'CookieName' +``` + +Remove cookie from targeted Driver + +### Example 2 +```powershell +PS C:\> Remove-SeCookie -DeleteAllCookies +``` + +Remove all cookies from targeted Driver + +## PARAMETERS + +### -DeleteAllCookies +Remove all cookies from webdriver + +```yaml +Type: SwitchParameter +Parameter Sets: DeleteAllCookies +Aliases: Purge + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Cookie name to remove + +```yaml +Type: String +Parameter Sets: NamedCookie +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: IWebDriver +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Save-SeScreenshot.md b/Help/Save-SeScreenshot.md new file mode 100644 index 0000000..10c2277 --- /dev/null +++ b/Help/Save-SeScreenshot.md @@ -0,0 +1,85 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Save-SeScreenshot + +## SYNOPSIS +Take a screenshot of the current page + +## SYNTAX + +``` +Save-SeScreenshot [-Screenshot] [-Path] [[-ImageFormat] ] + [] +``` + +## DESCRIPTION +Take a screenshot of the current page + +## EXAMPLES + +## PARAMETERS + +### -ImageFormat +Set the image format + +```yaml +Type: ScreenshotImageFormat +Parameter Sets: (All) +Aliases: +Accepted values: Png, Jpeg, Gif, Tiff, Bmp + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +Filepath where the image iwll be saved to. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Screenshot +Screenshot element + +```yaml +Type: Screenshot +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.Screenshot + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/SeOpen.md b/Help/SeOpen.md new file mode 100644 index 0000000..7147780 --- /dev/null +++ b/Help/SeOpen.md @@ -0,0 +1,106 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# SeOpen + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +SeOpen [-In ] [[-URL] ] [-Options ] [-SleepSeconds ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -In +{{ Fill In Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: +Accepted values: Chrome, CrEdge, FireFox, InternetExplorer, IE, MSEdge, NewEdge + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Options +{{ Fill Options Description }} + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SleepSeconds +{{ Fill SleepSeconds Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -URL +{{ Fill URL Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/SeShouldHave.md b/Help/SeShouldHave.md new file mode 100644 index 0000000..3d24749 --- /dev/null +++ b/Help/SeShouldHave.md @@ -0,0 +1,252 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# SeShouldHave + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +### DefaultPS (Default) +``` +SeShouldHave [-Selection] [-By ] [-PassThru] [-Timeout ] [] +``` + +### Element +``` +SeShouldHave [-Selection] [-By ] [-With] [[-Operator] ] [[-Value] ] + [-PassThru] [-Timeout ] [] +``` + +### Alert +``` +SeShouldHave [-Alert] [[-Operator] ] [[-Value] ] [-PassThru] [-Timeout ] + [] +``` + +### NoAlert +``` +SeShouldHave [-NoAlert] [-Timeout ] [] +``` + +### Title +``` +SeShouldHave [-Title] [[-Operator] ] [-Value] [-Timeout ] [] +``` + +### URL +``` +SeShouldHave [-URL] [[-Operator] ] [-Value] [-Timeout ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Alert +{{ Fill Alert Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: Alert +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -By +{{ Fill By Description }} + +```yaml +Type: String +Parameter Sets: DefaultPS, Element +Aliases: +Accepted values: CssSelector, Name, Id, ClassName, LinkText, PartialLinkText, TagName, XPath + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoAlert +{{ Fill NoAlert Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: NoAlert +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Operator +{{ Fill Operator Description }} + +```yaml +Type: String +Parameter Sets: Element, Alert, Title, URL +Aliases: +Accepted values: like, notlike, match, notmatch, contains, eq, ne, gt, lt + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +{{ Fill PassThru Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: DefaultPS, Element, Alert +Aliases: PT + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Selection +{{ Fill Selection Description }} + +```yaml +Type: String[] +Parameter Sets: DefaultPS, Element +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Timeout +{{ Fill Timeout Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Title +{{ Fill Title Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: Title +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -URL +{{ Fill URL Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: URL +Aliases: URI + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +{{ Fill Value Description }} + +```yaml +Type: Object +Parameter Sets: Element, Alert +Aliases: contains, like, notlike, match, notmatch, eq, ne, gt, lt + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +```yaml +Type: Object +Parameter Sets: Title, URL +Aliases: contains, like, notlike, match, notmatch, eq, ne, gt, lt + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -With +{{ Fill With Description }} + +```yaml +Type: String +Parameter Sets: Element +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String[] + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/SeType.md b/Help/SeType.md new file mode 100644 index 0000000..f1816e9 --- /dev/null +++ b/Help/SeType.md @@ -0,0 +1,136 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# SeType + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +SeType [-Keys] -Element [-ClearFirst] [-SleepSeconds ] [-Submit] [-PassThru] + [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -ClearFirst +{{ Fill ClearFirst Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +{{ Fill Element Description }} + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Keys +{{ Fill Keys Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +{{ Fill PassThru Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: PT + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SleepSeconds +{{ Fill SleepSeconds Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Submit +{{ Fill Submit Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebElement + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Send-SeClick.md b/Help/Send-SeClick.md new file mode 100644 index 0000000..d05705a --- /dev/null +++ b/Help/Send-SeClick.md @@ -0,0 +1,121 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Send-SeClick + +## SYNOPSIS +Send a click to the targeted element + +## SYNTAX + +``` +Send-SeClick [-Element] [-JavaScriptClick] [-SleepSeconds ] [-Driver ] + [-PassThru] [] +``` + +## DESCRIPTION +Send a click to the targeted element + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> (Get-SeElement -By Name -Selection 'ButtonX') | Send-SeClick +``` + +Select an element then send a click action on it. + +## PARAMETERS + +### -Driver +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +Element for which the click will be performed upon + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -JavaScriptClick +Use Javascript to perform the click + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: JS + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Return the **IWebElement** + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: PT + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SleepSeconds +Sleep time in seconds after the click + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebElement + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Send-SeKeys.md b/Help/Send-SeKeys.md new file mode 100644 index 0000000..e2199bd --- /dev/null +++ b/Help/Send-SeKeys.md @@ -0,0 +1,92 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Send-SeKeys + +## SYNOPSIS +Simulates typing text into the element + +## SYNTAX + +``` +Send-SeKeys [-Element] [-Keys] [-PassThru] [] +``` + +## DESCRIPTION +Simulates typing text into the element. + +The text to be typed may include special characters like arrow keys, backspaces, function keys, and so on. Valid special keys are defined in Keys. [OpenQA_Selelnium_Keys](https://www.selenium.dev/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Keys.htm) + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru +``` + +ype the defined text and a special key - Enter - defined in the special keys. + +## PARAMETERS + +### -Element +Specify the element where the keys will be typed to + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Keys +Text to be typed. Special keys (Enter, arrow down, etc...) can be typed using double brackets (eg: `{{Enter}}`). See cmdlet description for complete list of keys + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Return `$Element` + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: PT + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebElement + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Set-SeCookie.md b/Help/Set-SeCookie.md new file mode 100644 index 0000000..812ef7d --- /dev/null +++ b/Help/Set-SeCookie.md @@ -0,0 +1,129 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Set-SeCookie + +## SYNOPSIS +Add a cookie to the current browsing context + +## SYNTAX + +``` +Set-SeCookie [[-Name] ] [[-Value] ] [[-Path] ] [[-Domain] ] + [[-ExpiryDate] ] [[-Target] ] [] +``` + +## DESCRIPTION +Add a cookie to the current browsing context + +## EXAMPLES + +## PARAMETERS + +### -Domain +The domain of the cookie + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExpiryDate +The expiration date of the cookie + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +The name of the cookie + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +The path of the cookie + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +Target webdriver + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: 5 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Value +The value of the cookie + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeChrome.md b/Help/Start-SeChrome.md new file mode 100644 index 0000000..7128b7b --- /dev/null +++ b/Help/Start-SeChrome.md @@ -0,0 +1,384 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeChrome + +## SYNOPSIS +Initializes a new instance of the **ChromeDriver** class. + +## SYNTAX + +### default (Default) +``` +Start-SeChrome [[-StartURL] ] [-Arguments ] [-HideVersionHint] [-DefaultDownloadPath ] + [-ProfileDirectoryPath ] [-DisableBuiltInPDFViewer ] [-EnablePDFViewer] [-Incognito] + [-DisableAutomationExtension] [-BinaryPath ] [-WebDriverDirectory ] [-Quiet] + [-AsDefaultDriver] [-ImplicitWait ] [] +``` + +### Headless +``` +Start-SeChrome [[-StartURL] ] [-Arguments ] [-HideVersionHint] [-DefaultDownloadPath ] + [-ProfileDirectoryPath ] [-DisableBuiltInPDFViewer ] [-EnablePDFViewer] [-Incognito] + [-Headless] [-DisableAutomationExtension] [-BinaryPath ] [-WebDriverDirectory ] [-Quiet] + [-AsDefaultDriver] [-ImplicitWait ] [] +``` + +### Minimized +``` +Start-SeChrome [[-StartURL] ] [-Arguments ] [-HideVersionHint] [-DefaultDownloadPath ] + [-ProfileDirectoryPath ] [-DisableBuiltInPDFViewer ] [-EnablePDFViewer] [-Incognito] + [-Maximized] [-DisableAutomationExtension] [-BinaryPath ] [-WebDriverDirectory ] [-Quiet] + [-AsDefaultDriver] [-ImplicitWait ] [] +``` + +### Maximized +``` +Start-SeChrome [[-StartURL] ] [-Arguments ] [-HideVersionHint] [-DefaultDownloadPath ] + [-ProfileDirectoryPath ] [-DisableBuiltInPDFViewer ] [-EnablePDFViewer] [-Incognito] + [-Minimized] [-DisableAutomationExtension] [-BinaryPath ] [-WebDriverDirectory ] [-Quiet] + [-AsDefaultDriver] [-ImplicitWait ] [] +``` + +### Fullscreen +``` +Start-SeChrome [[-StartURL] ] [-Arguments ] [-HideVersionHint] [-DefaultDownloadPath ] + [-ProfileDirectoryPath ] [-DisableBuiltInPDFViewer ] [-EnablePDFViewer] [-Incognito] + [-Fullscreen] [-DisableAutomationExtension] [-BinaryPath ] [-WebDriverDirectory ] [-Quiet] + [-AsDefaultDriver] [-ImplicitWait ] [] +``` + +## DESCRIPTION +Initializes a new instance of the **ChromeDriver** class. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Driver = Start-SeChrome +``` + +### Example 2 +```powershell +PS C:\> $Driver = Start-SeChrome -Incognito +``` + + Run Chrome in incognito mode + +### Example 3 +```powershell +PS C:\> $Driver = Start-SeChrome -DefaultDownloadPath C:\Temp -StartURL 'https://www.google.com/ncr' +``` + + Run Chrome with alternative download folder and set a specific starting URL + +### Example 4 +```powershell +PS C:\> $Driver = Start-SeChrome -Arguments @('Incognito','start-maximized') +``` + + Run Chrome with multiple Arguments + +### Example 5 +```powershell +PS C:\> $Driver = Start-SeChrome -ProfileDirectoryPath '/home//.config/google-chrome' +``` + + Run Chrome with an existing profile. + The default profile paths are as follows: + + Windows: C:\Users\\AppData\Local\Google\Chrome\User Data + + Linux: /home//.config/google-chrome + + MacOS: /Users//Library/Application Support/Google/Chrome + +## PARAMETERS + +### -Arguments +Adds arguments to be appended to the Chrome.exe command line. + +```yaml +Type: Array +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsDefaultDriver +Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BinaryPath +Set the location of the Chrome browser's binary executable file + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: ChromeBinaryPath + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultDownloadPath +Set default download path + +```yaml +Type: FileInfo +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DisableAutomationExtension +Disable AutomationExtension notification + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DisableBuiltInPDFViewer +Obsolete. Use `-EnablePDFViewer` instead. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -EnablePDFViewer +Enable built in PDF Viewer (By default PDF will always open xternally) + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Fullscreen +Driver will open browser in a fullscreen state + +```yaml +Type: SwitchParameter +Parameter Sets: Fullscreen +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headless +Start driver without any visual interface + +```yaml +Type: SwitchParameter +Parameter Sets: Headless +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideVersionHint +Hide download proper driver version message + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Control timeout duration (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Incognito +Drive will open an incognito session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: PrivateBrowsing + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Maximized +Driver will open browser in a maximized state + +```yaml +Type: SwitchParameter +Parameter Sets: Minimized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Minimized +Driver will open browser in a minimized state + +```yaml +Type: SwitchParameter +Parameter Sets: Maximized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProfileDirectoryPath +Driver will use the specified user profile path + +```yaml +Type: FileInfo +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Quiet +Hide command prompt window + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Define Driver starting URL + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverDirectory +Specify web driver custom service location + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeEdge.md b/Help/Start-SeEdge.md new file mode 100644 index 0000000..dd40e33 --- /dev/null +++ b/Help/Start-SeEdge.md @@ -0,0 +1,198 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeEdge + +## SYNOPSIS +Initializes a new instance of the EdgeDriver class + +## SYNTAX + +### default (Default) +``` +Start-SeEdge [[-StartURL] ] [-PrivateBrowsing] [-Quiet] [-AsDefaultDriver] [-Headless] + [-ImplicitWait ] [] +``` + +### Minimized +``` +Start-SeEdge [[-StartURL] ] [-Maximized] [-PrivateBrowsing] [-Quiet] [-AsDefaultDriver] [-Headless] + [-ImplicitWait ] [] +``` + +### Maximized +``` +Start-SeEdge [[-StartURL] ] [-Minimized] [-PrivateBrowsing] [-Quiet] [-AsDefaultDriver] [-Headless] + [-ImplicitWait ] [] +``` + +### Fullscreen +``` +Start-SeEdge [[-StartURL] ] [-FullScreen] [-PrivateBrowsing] [-Quiet] [-AsDefaultDriver] [-Headless] + [-ImplicitWait ] [] +``` + +## DESCRIPTION +Initializes a new instance of the EdgeDriver class + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Driver = Start-SeEdge +``` + +## PARAMETERS + +### -AsDefaultDriver +Set $Global:SeDriver ot the current Driver and dispose previously set driver. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FullScreen +Driver will open browser in a fullscreen state + +```yaml +Type: SwitchParameter +Parameter Sets: Fullscreen +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headless +Start driver without any visual interface + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Control timeout duration (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Maximized +Driver will open browser in a maximized state + +```yaml +Type: SwitchParameter +Parameter Sets: Minimized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Minimized +Driver will open browser in a minimized state + +```yaml +Type: SwitchParameter +Parameter Sets: Maximized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Driver will open a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: Incognito + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Quiet +Hide command prompt window + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Define Driver starting URL + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeFirefox.md b/Help/Start-SeFirefox.md new file mode 100644 index 0000000..65aa575 --- /dev/null +++ b/Help/Start-SeFirefox.md @@ -0,0 +1,276 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeFirefox + +## SYNOPSIS +Initializes a new instance of the **FirefoxDriver** class. + +## SYNTAX + +### default (Default) +``` +Start-SeFirefox [[-StartURL] ] [-Arguments ] [-DefaultDownloadPath ] + [-PrivateBrowsing] [-SuppressLogging] [-Quiet] [-AsDefaultDriver] [-ImplicitWait ] + [-WebDriverDirectory ] [] +``` + +### Headless +``` +Start-SeFirefox [[-StartURL] ] [-Arguments ] [-DefaultDownloadPath ] + [-PrivateBrowsing] [-Headless] [-SuppressLogging] [-Quiet] [-AsDefaultDriver] [-ImplicitWait ] + [-WebDriverDirectory ] [] +``` + +### Minimized +``` +Start-SeFirefox [[-StartURL] ] [-Arguments ] [-DefaultDownloadPath ] + [-PrivateBrowsing] [-Maximized] [-SuppressLogging] [-Quiet] [-AsDefaultDriver] [-ImplicitWait ] + [-WebDriverDirectory ] [] +``` + +### Maximized +``` +Start-SeFirefox [[-StartURL] ] [-Arguments ] [-DefaultDownloadPath ] + [-PrivateBrowsing] [-Minimized] [-SuppressLogging] [-Quiet] [-AsDefaultDriver] [-ImplicitWait ] + [-WebDriverDirectory ] [] +``` + +### Fullscreen +``` +Start-SeFirefox [[-StartURL] ] [-Arguments ] [-DefaultDownloadPath ] + [-PrivateBrowsing] [-Fullscreen] [-SuppressLogging] [-Quiet] [-AsDefaultDriver] [-ImplicitWait ] + [-WebDriverDirectory ] [] +``` + +## DESCRIPTION +Initializes a new instance of the **FirefoxDriver** class. + +## EXAMPLES + +### Example 1 +```powershell +$Driver = Start-SeFirefox +``` + +### Example 2 +```powershell +$Driver = Start-SeFirefox -PrivateBrowsing -DefaultDownloadPath 'c:\temp' -StartURL 'https://www.google.ca/ncr' +``` + +Run Firefox in a private widnow using an alternate download path and set the starting URL + +## PARAMETERS + +### -Arguments +Adds arguments to be appended to the Firefox.exe command line. + +```yaml +Type: Array +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsDefaultDriver +Set $Global:SeDriver ot the current Driver and dispose previously set driver. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultDownloadPath +Set default download path + +```yaml +Type: FileInfo +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Fullscreen +Driver will open browser in a fullscreen state + +```yaml +Type: SwitchParameter +Parameter Sets: Fullscreen +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headless +Start driver without any visual interface + +```yaml +Type: SwitchParameter +Parameter Sets: Headless +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Control timeout duration (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Maximized +Driver will open browser in a maximized state + +```yaml +Type: SwitchParameter +Parameter Sets: Minimized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Minimized +Driver will open browser in a minimized state + +```yaml +Type: SwitchParameter +Parameter Sets: Maximized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Driver will open a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: Incognito + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Quiet +Hide command prompt window + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Define Driver starting URL + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SuppressLogging +Set GeckoDriver log level to Fatal. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverDirectory +Specify web driver custom service location + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeInternetExplorer.md b/Help/Start-SeInternetExplorer.md new file mode 100644 index 0000000..0a90d22 --- /dev/null +++ b/Help/Start-SeInternetExplorer.md @@ -0,0 +1,251 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeInternetExplorer + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +### Default (Default) +``` +Start-SeInternetExplorer [[-StartURL] ] [-Quiet] [-AsDefaultDriver] [-Headless] [-PrivateBrowsing] + [-IgnoreProtectedModeSettings] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Maximized +``` +Start-SeInternetExplorer [[-StartURL] ] [-Quiet] [-AsDefaultDriver] [-Maximized] [-Headless] + [-PrivateBrowsing] [-IgnoreProtectedModeSettings] [-ImplicitWait ] [-WebDriverDirectory ] + [] +``` + +### Minimized +``` +Start-SeInternetExplorer [[-StartURL] ] [-Quiet] [-AsDefaultDriver] [-Minimized] [-Headless] + [-PrivateBrowsing] [-IgnoreProtectedModeSettings] [-ImplicitWait ] [-WebDriverDirectory ] + [] +``` + +### Fullscreen +``` +Start-SeInternetExplorer [[-StartURL] ] [-Quiet] [-AsDefaultDriver] [-FullScreen] [-Headless] + [-PrivateBrowsing] [-IgnoreProtectedModeSettings] [-ImplicitWait ] [-WebDriverDirectory ] + [] +``` + +### Headless +``` +Start-SeInternetExplorer [[-StartURL] ] [-Quiet] [-AsDefaultDriver] [-Headless] [-PrivateBrowsing] + [-IgnoreProtectedModeSettings] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -AsDefaultDriver +{{ Fill AsDefaultDriver Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FullScreen +Driver will open browser in a fullscreen state + +```yaml +Type: SwitchParameter +Parameter Sets: Fullscreen +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headless +Start driver without any visual interface + +```yaml +Type: SwitchParameter +Parameter Sets: Default, Maximized, Minimized, Fullscreen +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +```yaml +Type: SwitchParameter +Parameter Sets: Headless +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IgnoreProtectedModeSettings +{{ Fill IgnoreProtectedModeSettings Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Control timeout duration (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Maximized +Driver will open browser in a maximized state + +```yaml +Type: SwitchParameter +Parameter Sets: Maximized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Minimized +Driver will open browser in a minimized state + +```yaml +Type: SwitchParameter +Parameter Sets: Minimized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Driver will open a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: Incognito + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Quiet +Hide command prompt window + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Define Driver starting URL + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverDirectory +{{ Fill WebDriverDirectory Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeNewEdge.md b/Help/Start-SeNewEdge.md new file mode 100644 index 0000000..7f9c62b --- /dev/null +++ b/Help/Start-SeNewEdge.md @@ -0,0 +1,284 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeNewEdge + +## SYNOPSIS +Initializes a new instance of the EdgeDriver class + +## SYNTAX + +### default (Default) +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Minimized +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-Minimized] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Maximized +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-Maximized] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Fullscreen +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-FullScreen] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Headless +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-Headless] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +## DESCRIPTION +Initializes a new instance of the EdgeDriver class + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Driver = Start-SeNewEdge +``` + +## PARAMETERS + +### -AsDefaultDriver +Set $Global:SeDriver ot the current Driver and dispose previously set driver. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BinaryPath +Set the location of the Chrome browser's binary executable file + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultDownloadPath +Set default download path + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FullScreen +Driver will open browser in a fullscreen state + +```yaml +Type: SwitchParameter +Parameter Sets: Fullscreen +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headless +Start driver without any visual interface + +```yaml +Type: SwitchParameter +Parameter Sets: Headless +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideVersionHint +Hide download proper driver version message + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Control timeout duration (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Maximized +Driver will open browser in a maximized state + +```yaml +Type: SwitchParameter +Parameter Sets: Maximized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Minimized +Driver will open browser in a minimized state + +```yaml +Type: SwitchParameter +Parameter Sets: Minimized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Driver will open a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: Incognito + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProfileDirectoryPath +Driver will use the specified user profile path + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Quiet +Hide command prompt window + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Define Driver starting URL + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverDirectory +{{ Fill WebDriverDirectory Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeRemote.md b/Help/Start-SeRemote.md new file mode 100644 index 0000000..34f680b --- /dev/null +++ b/Help/Start-SeRemote.md @@ -0,0 +1,286 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeNewEdge + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +### default (Default) +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Minimized +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-Minimized] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Maximized +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-Maximized] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Fullscreen +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-FullScreen] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +### Headless +``` +Start-SeNewEdge [[-StartURL] ] [-HideVersionHint] [-Headless] [-BinaryPath ] + [-ProfileDirectoryPath ] [-DefaultDownloadPath ] [-AsDefaultDriver] [-Quiet] + [-PrivateBrowsing] [-ImplicitWait ] [-WebDriverDirectory ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -AsDefaultDriver +{{ Fill AsDefaultDriver Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -BinaryPath +{{ Fill BinaryPath Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultDownloadPath +{{ Fill DefaultDownloadPath Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -FullScreen +Driver will open browser in a fullscreen state + +```yaml +Type: SwitchParameter +Parameter Sets: Fullscreen +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Headless +Start driver without any visual interface + +```yaml +Type: SwitchParameter +Parameter Sets: Headless +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -HideVersionHint +{{ Fill HideVersionHint Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Control timeout duration (in seconds) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Maximized +Driver will open browser in a maximized state + +```yaml +Type: SwitchParameter +Parameter Sets: Maximized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Minimized +Driver will open browser in a minimized state + +```yaml +Type: SwitchParameter +Parameter Sets: Minimized +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Driver will open a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: Incognito + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProfileDirectoryPath +Driver will use the specified user profile path + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Quiet +Hide command prompt window + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Define Driver starting URL + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverDirectory +{{ Fill WebDriverDirectory Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Stop-SeDriver.md b/Help/Stop-SeDriver.md new file mode 100644 index 0000000..bb877eb --- /dev/null +++ b/Help/Stop-SeDriver.md @@ -0,0 +1,68 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Stop-SeDriver + +## SYNOPSIS +Quits this driver, closing every associated window. + +## SYNTAX + +``` +Stop-SeDriver [[-Target] ] [] +``` + +## DESCRIPTION +Quits this driver, closing every associated window. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Stop-SeDriver -Target $Driver +``` + +Stop the specified driver + +### Example 1 +```powershell +PS C:\> Start-SeChrome -AsDefaultDriver +PS C:\> Stop-SeDriver +``` + +Stop the default driver, which was defined using the `-AsDefaultDriver` switch. + +## PARAMETERS + +### -Target +Driver to dispose. When `-AsDefaultDriver` is used with the Start-XXDriver cmdlet, this parameter can be omitted. + +```yaml +Type: IWebDriver +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Switch-SeFrame.md b/Help/Switch-SeFrame.md new file mode 100644 index 0000000..cb8e374 --- /dev/null +++ b/Help/Switch-SeFrame.md @@ -0,0 +1,116 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Switch-SeFrame + +## SYNOPSIS +Instructs the driver to send future commands to a different frame + +## SYNTAX + +### Frame +``` +Switch-SeFrame [-Frame] [-Target ] [] +``` + +### Parent +``` +Switch-SeFrame [-Parent] [-Target ] [] +``` + +### Root +``` +Switch-SeFrame [-Root] [-Target ] [] +``` + +## DESCRIPTION +Instructs the driver to send future commands to a different frame + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Frame +{{ Fill Frame Description }} + +```yaml +Type: Object +Parameter Sets: Frame +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Parent +{{ Fill Parent Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: Parent +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Root +{{ Fill Root Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: Root +Aliases: defaultContent + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Target +{{ Fill Target Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Switch-SeWindow.md b/Help/Switch-SeWindow.md new file mode 100644 index 0000000..8c7f6a8 --- /dev/null +++ b/Help/Switch-SeWindow.md @@ -0,0 +1,75 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Switch-SeWindow + +## SYNOPSIS +Instructs the driver to send future commands to a different window + +## SYNTAX + +``` +Switch-SeWindow [[-Target] ] [-Window] [] +``` + +## DESCRIPTION +Instructs the driver to send future commands to a different window + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Target +{{ Fill Target Description }} + +```yaml +Type: IWebDriver +Parameter Sets: (All) +Aliases: Driver + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Window +{{ Fill Window Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Internal/ValidateURL.ps1 b/Internal/ValidateURL.ps1 new file mode 100644 index 0000000..cd334ed --- /dev/null +++ b/Internal/ValidateURL.ps1 @@ -0,0 +1,9 @@ +function ValidateURL { + [Alias("Validate-Url")] + param( + [Parameter(Mandatory = $true)] + $URL + ) + $Out = $null + [uri]::TryCreate($URL, [System.UriKind]::Absolute, [ref]$Out) +} \ No newline at end of file diff --git a/Internal/init.ps1 b/Internal/init.ps1 new file mode 100644 index 0000000..d37c384 --- /dev/null +++ b/Internal/init.ps1 @@ -0,0 +1,207 @@ +$Script:SeKeys = [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | + Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } + +#region Set path to assemblies on Linux and MacOS and Grant Execution permissions on them +if ($IsLinux) { + $AssembliesPath = "$PSScriptRoot/assemblies/linux" +} +elseif ($IsMacOS) { + $AssembliesPath = "$PSScriptRoot/assemblies/macos" +} + +# Grant Execution permission to assemblies on Linux and MacOS +if ($AssembliesPath) { + # Check if powershell is NOT running as root + Get-Item -Path "$AssembliesPath/chromedriver", "$AssembliesPath/geckodriver" | ForEach-Object { + if ($IsLinux) { $FileMod = stat -c "%a" $_.FullName } + elseif ($IsMacOS) { $FileMod = /usr/bin/stat -f "%A" $_.FullName } + Write-Verbose "$($_.FullName) $Filemod" + if ($FileMod[2] -ne '5' -and $FileMod[2] -ne '7') { + Write-Host "Granting $($AssemblieFile.fullname) Execution Permissions ..." + chmod +x $_.fullname + } + } +} + +#endregion + + + + + + + + + + + + + + +<# +@jhoneill Shouldn't -default be assumed if not feed a webdriver? see alternate below +function Stop-SeDriver { + [alias('SeClose')] + param( + [Parameter(ValueFromPipeline = $true, position = 0, ParameterSetName = 'Driver')] + [ValidateIsWebDriverAttribute()] + $Driver, + [Parameter(Mandatory = $true, ParameterSetName = 'Default')] + [switch]$Default + ) + if (-not $PSBoundParameters.ContainsKey('Driver') -and $Global:SeDriver -and ($Default -or $MyInvocation.InvocationName -eq 'SeClose')) { + Write-Verbose -Message "Closing $($Global:SeDriver.Capabilities.browsername)..." + $Global:SeDriver.Close() + $Global:SeDriver.Dispose() + Remove-Variable -Name SeDriver -Scope global + } + elseif ($Driver) { + $Driver.Close() + $Driver.Dispose() + } + else { Write-Warning -Message 'No Driver Specified' } +} +#> + + + +<# +function Enter-SeUrl { + param($Driver, $Url) + $Driver.Navigate().GoToUrl($Url) +} +#> + + + +<# +function Find-SeElement { + param( + [Parameter()] + $Driver, + [Parameter()] + $Element, + [Parameter()][Switch]$Wait, + [Parameter()]$Timeout = 30, + [Parameter(ParameterSetName = "ByCss")] + $Css, + [Parameter(ParameterSetName = "ByName")] + $Name, + [Parameter(ParameterSetName = "ById")] + $Id, + [Parameter(ParameterSetName = "ByClassName")] + $ClassName, + [Parameter(ParameterSetName = "ByLinkText")] + $LinkText, + [Parameter(ParameterSetName = "ByPartialLinkText")] + $PartialLinkText, + [Parameter(ParameterSetName = "ByTagName")] + $TagName, + [Parameter(ParameterSetName = "ByXPath")] + $XPath + ) + + + process { + + if ($null -ne $Driver -and $null -ne $Element) { + throw "Driver and Element may not be specified together." + } + elseif ($null -ne $Driver) { + $Target = $Driver + } + elseif (-ne $Null $Element) { + $Target = $Element + } + else { + "Driver or element must be specified" + } + + if ($Wait) { + if ($PSCmdlet.ParameterSetName -eq "ByName") { + $TargetElement = [OpenQA.Selenium.By]::Name($Name) + } + + if ($PSCmdlet.ParameterSetName -eq "ById") { + $TargetElement = [OpenQA.Selenium.By]::Id($Id) + } + + if ($PSCmdlet.ParameterSetName -eq "ByLinkText") { + $TargetElement = [OpenQA.Selenium.By]::LinkText($LinkText) + } + + if ($PSCmdlet.ParameterSetName -eq "ByPartialLinkText") { + $TargetElement = [OpenQA.Selenium.By]::PartialLinkText($PartialLinkText) + } + + if ($PSCmdlet.ParameterSetName -eq "ByClassName") { + $TargetElement = [OpenQA.Selenium.By]::ClassName($ClassName) + } + + if ($PSCmdlet.ParameterSetName -eq "ByTagName") { + $TargetElement = [OpenQA.Selenium.By]::TagName($TagName) + } + + if ($PSCmdlet.ParameterSetName -eq "ByXPath") { + $TargetElement = [OpenQA.Selenium.By]::XPath($XPath) + } + + 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) + } + else { + if ($PSCmdlet.ParameterSetName -eq "ByName") { + $Target.FindElements([OpenQA.Selenium.By]::Name($Name)) + } + + if ($PSCmdlet.ParameterSetName -eq "ById") { + $Target.FindElements([OpenQA.Selenium.By]::Id($Id)) + } + + if ($PSCmdlet.ParameterSetName -eq "ByLinkText") { + $Target.FindElements([OpenQA.Selenium.By]::LinkText($LinkText)) + } + + if ($PSCmdlet.ParameterSetName -eq "ByPartialLinkText") { + $Target.FindElements([OpenQA.Selenium.By]::PartialLinkText($PartialLinkText)) + } + + if ($PSCmdlet.ParameterSetName -eq "ByClassName") { + $Target.FindElements([OpenQA.Selenium.By]::ClassName($ClassName)) + } + + if ($PSCmdlet.ParameterSetName -eq "ByTagName") { + $Target.FindElements([OpenQA.Selenium.By]::TagName($TagName)) + } + + if ($PSCmdlet.ParameterSetName -eq "ByXPath") { + $Target.FindElements([OpenQA.Selenium.By]::XPath($XPath)) + } + + if ($PSCmdlet.ParameterSetName -eq "ByCss") { + $Target.FindElements([OpenQA.Selenium.By]::CssSelector($Css)) + } + } + } +} +#> + + + + + + + + + + + + + + + diff --git a/Output/Selenium/ChangeLog.md b/Output/Selenium/ChangeLog.md new file mode 100644 index 0000000..de47a81 --- /dev/null +++ b/Output/Selenium/ChangeLog.md @@ -0,0 +1,345 @@ +# 3.1.0 - Unreleased + +## Added + +- Added -IgnoreProtectedModeSettings to Start-SeInternetExplorer - https://github.com/adamdriscoll/selenium-powershell/issues/79 - Thanks, @MysticRyuujin! + +- Added Markdown documentation (See Help subfolder) for all the cmdlets (PlatyPS is used behind the scene to maintain it) +- Added MAML embedded help that can be accessed through `Get-Help`(eg: `Get-Help Start-SeChrome -Examples`) + +# 3.0.0 - 3/31/2020 + +## Changed + +- Fixed issue with importing module in PSv5.1 - https://github.com/adamdriscoll/selenium-powershell/issues/69 +- Updated Chrome drivers +- Converted monolythic module into a scaffolded module through a Plaster template. Module will now have a debug version and a compiled version that need to be built with Invoke-Build. See the Debug folder for additional informations on how to debug. + +# 3.0.0-beta2 - 1/29/2020 + +## Added + +- Added Get-SeElementCssValue + +# 3.0.0-beta1 - 1/29/2020 + +## Added + +# General +## Start a Browser Driver for the browser of your choice (Chrome/Firefox/Edge/InternetExplorer) +```powershell +#Either: store the driver in your own variable +$Driver = Start-SeChrome + +#OR save it to $global:SeDriver +Start-SeChrome -AsDefaultDriver # alias Chrome +Start-SeFirefox -AsDefaultDriver # alias Firefox +Start-SeEdge -AsDefaultDriver # alias MsEdge +Start-SeNewEdge -AsDefaultDriver # alias CrEdge / NewEdge +Start-SeInternetExplorer -AsDefaultDriver # alias IE / InternetExplorer + +#OR use a shortcut which takes a browser name and sets it as the default. +SeOpen -In Chrome +``` +in the last case, -in can come an environment variable, to run the same script _n_ times with _n_ different browsers + +## Navigate to a page +```powershell +#Use a saved driver and the original function name +Enter-SeUrl https://www.poshud.com -Driver $Driver + +#Use the default driver and the new funtion name +Open-SeUrl https://www.poshud.com #alias SeNavigate + +#or Start the driver and navigate in one +Start-SeChrome -AsDefaultDriver -StartURL https://www.poshud.com + +#or using SeOpen +SeOpen -URL https://www.poshud.com -In Chrome +``` + +## Find an Element on the page +```powershell +#Using the saved driver and the old syntax +$Element = Find-SeElement -Driver $Driver -ClassName 'center-align' + +#Using the default driver and the new syntax +$Element = Get-SeElement -By ClassName 'center-align' #alias SeElement + +#xpath is selected by default - you can specify a timeout to wait for the element to appear. +$xpath = '/html/body/div[1]/div/main/div/div[2]/div[3]/div[1]/div/div/div[2]/a' +$Element = Get-SeElement $xpath -Timeout 10 + +#In a Pester Test you can check the element is present with +SeElement $xpath | should not beNullOrEmpty +#or +SeShouldHave $xpath +``` +_SeElement_ and _Find-SeElement_ are aliases for Get-SeElement. + +## Click on an Element/Button +```powershell +#send to a saved element with old syntax +Invoke-SeClick -Element $Element + +#Pipe an element into the command using new syntax +Get-SeElement $Xpath | Send-SeClick -SleepSeconds 2 #alias SeClick + +#in a Pester Test you can get the element, click and confirm a element was found +SeElement $xPath | SeClick -sleep 2 -passthru | should not beNullOrEmpty +``` +_Invove-SeClick_ and _Send-SeClick_ are almost interchangable, _SeClick_ is an alias for the latter + +## Send Keystrokes + +```powershell +#using a saved element +$Element = Find-SeElement -Driver $Driver -Id "txtEmail" +Send-SeKeys -Element $Element -Keys "adam@poshtools.com" + +#or using the pipeline +seElement -by ID "txtEmail" | Send-SeKeys -Keys "adam@poshtools.com" + +#in a Pester Test you can get the element, sendkeys and confirm a element was found +seElement -by ID "txtEmail" | SeType "adam@poshtools.com" -passthru | should not beNullOrEmpty +``` +_setype_ is a wrapper for _Send-SeKeys_ to be more Pester-friendly + +# using pester +### Navigating to a page (SeNavigate) + +```powershell + Enter-SeUrl -Url "https://www.powershellgallery.com/" -driver $Global:SeDriver + #Enter-SeUrl has an alias of SeNavigate, and will assume the driver is $Global:SeDriver, and take URL by position giving + SeNavigate https://www.powershellgallery.com/ +``` +### Checking the page url and title (SeShouldHave) + +```powershell + #knowing about the driver we could use it with a standard pester command + $Global:SeDriver.Url | should be "https://www.powershellgallery.com/" + + #Or we could use SeShouldHave. The full, explicit form looks like this + SeShouldHave -URL -Operator eq -Value "https://www.powershellgallery.com/" + #which can be shorted by passing Operator and Value parameters by position; + #Operator will tab-complete contains, match, notlike etc and will transform other names; match and notmatch are regular expressions + SeShouldHave -URL equalTo "https://www.powershellgallery.com/" + SeShouldHave -Title match "PowerShell\s+Gallery" +``` +The primary job of _SeShouldHave_ is to work like pesters _should_ and succeed silently or fail the test by throwing an error. + +### Finding and using an element: (SeElement) +```powershell + #we can shorten the command :Get-SeElement -By XPath -Selection '//*[@id="search"]' + #first with an alias and then -by Xpath is assumed and Selection can be passed in the first position to become + # SeElement '//*[@id="search"]' | SeType -ClearFirst "selenium{{Enter}}" + #This will not report a failure if the element was not found so + SeElement '//*[@id="search"]' | SeType -ClearFirst "selenium{{Enter}}" -PassThru | should not beNullorEmpty +``` +This is also possible with SeShouldHave.. see below + +### Checking elements: (SeShouldHave) +```powershell + $linkpath = '//*[@id="skippedToContent"]/section/div[1]/div[2]/div[2]/section[1]/div/table/tbody/tr/td[1]/div/div[2]/header/div[1]/h1/a' + #SeShouldHave can be written explictly like this + SeShouldHave -Selection $linkpath -By XPath -With Text -Operator match 'selenium' + #-by Xpath is assumed and the other parameters can be passed by position. Operators will tab complete, and convert "matching" or "matches" to match etc + SeShouldHave $linkpath Text matching 'selenium' +``` +The `-with` parameter can be 'Text', 'Displayed', 'Enabled', 'TagName', 'X', 'Y', 'Width', 'Height', 'Choice' or _the name of an attribute_, like 'href'. + If `-with` is not specified only _the presence_ of the page element is checked. + If `-PassThru` is specified, matching elements will be sent to the pipeline. (`-Passthru` can't be used when checking the page URL or tile, only with elements on the page). +```powershell + SeShouldHave $linkpath -PassThru | SeClick +``` +### Checking Multiple elements +The selection parameter can take multiple values; in the following command it is specified by position (and assumed to be one or more Xpaths) +```powershell + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' , + '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' +``` +When multiple elements are found from the selection criteria, and '-With' is specified the test will pass _any_ element passess - in other words, all elements do not need to pass. +```powershell + #The following counts 8 elements + SeNavigate 'https://www.google.com/ncr' + SeShouldHave -by TagName input -PassThru | measure + #The following command rejects 7 of these 8, without error, and passes the one with a title attribute of 'search' to another command + SeShouldHave -by TagName input -With Title eq Search -PassThru | SeType 'PowerShell-Selenium' +``` + +### Selecting frames (SeFrame) +on a page which uses frames it is necessary to specify which one containst the data +```powershell + seNavigate 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' + sleep -Seconds 5 #can go too fast for frames + SeFrame 1 +``` + +### Checking alerts (SeShouldHave, SeAccept, SeDismiss) +As well as checking the page URL, and page title. _SeShouldHave_ Supports -Alert and -NoAlert +```powershell + #in Frame 1 on 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' this will produce an alert + SeElement "/html/body/button" -Timeout 10 | SeClick -SleepSeconds 2 + #and this will check for it. + SeShouldHave -Alert match "box" + #Usually you will want to accept or dismiss the alert + SeShouldHave -Alert -PassThru | SeDismiss +``` +### Working with select/option "dropdown" controls (SeShouldHave, SeSelection) +```powershell + #This will go to a page with a dropdown box + SeNavigate 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' + sleep -Seconds 5 #can go too fast for frames + SeFrame 1 + $dropDown = SeShouldHave -By Name "cars" -With choice contains "volvo" -PassThru +``` +In the code above, SeShouldHave finds the dropdown box which is named "Cars", and does a check to confirm one of the choices is Volvo, and assigns the result to a variable. This can be used with SeSelection (alias for Get-SeSelectionOption) to test or set options in the dropdown box. An option can be selected (and in the case of mult-select boxes, deselected) by its index, value or [partof] its display text. And the -GetSelected / -GetAllSelected options can be included in a set operation to (or used alone) to return the selected text. +```powershell + $dropdown | SeSelection -IsMultiSelect | should be $false + $dropdown | SeSelection -GetSelected | should be 'Volvo' + $dropdown | SeSelection -ListOptionText | should not contain "Ferrari" + #not the selections are case sensitive. The value in this case is all lower case, the display text has initial caps. + $dropdown | SeSelection -ByValue 'audi' -GetSelected | should be 'Audi' +``` + +DLL loading is now from the PSD1 file instead of the PSM1 file. +Now use presence of $AssembliesPath to judge "IsMacOS" -or "IsLinux" + +Send-SeKeys + -Element and -Keys parameters are both mandatory + Selenium-keys are now cached in a script-scoped variable for performance. (Get-SEKeys can be dropped) + Added -PassThru + + +Valdate-URL + Function Renamed to validateUrl (private helper function does not need to use verb-noun naming and "validate" verb upsets script analyzer) + Added the old name back as an alias (which _is_ allowed. ) + Moved functionality into a validation class which so URLs are validated before enering functions + +Checks for valid webdriver also moved to a validation class. + +Get-SeCookie & Invoke-SeScreenshot + In line with other functions, -Driver parameter is renamed -Target, with alias "Driver", and will come from $Global:SeDriver + and throws an error if no driver is passed or found from Global var + +Start-SeFirefox & Start-SeChrome + Added aliases "SeChrome" and "SeFirefox" - user can now write in a sort of DSL "SeCHROME $URL -asDefault" etc. + Made -StartUrl the first parameter and use a parameter-validation class to check it. + Now call the .Navigate method directly instead of via Enter-SeURL if -StartURL is specified + Now use parameter-sets to avoid the conflict between Minimized/Maximized/FullScreen/Headless, + Added parameter aliases so "Incognito" works with Firefox and "PrivateBrowsing" works with Chrome + Now trap a failure to return driver, and simplified the subsequent if statements + Set ImplicitWait to 10 seconds + Added Parameter -AsDefaultDriver which sets $Global:SeDriver, instead of returning the driver + Added Parameter -Quiet to run tests without web driver prattle. + Allow AzureDevops environment vars (GeckoWebDriver / ChromeWebDriver) or commandline + parameter -WebDriverDirectory to specify source of Webdriver. + Removed a possible bug with piped input, by returning the driver in the process block instead of the end block + +Start-SeInternetExplorer + Added Aliases "SeInternetExplorer" & "SeIE" and parameter -StartUrl + Plus -AsDefaultDriver which sets $Global:SeDriver, instead of returning the driver, and -Quiet to run tests + without web driver prattle. + Allow AzureDevops environment vars or commandline parameter -WebDriverDirectory to specify source of Webdriver + Set ImplicitWait to 10 seconds + +Start-SeEdge + Added Aliases "MSEdge" & "LegacyEdge", and parameters -StartUrl, -Maximized, -Minimized, FullScreen + and -PrivateBrowsing (alias Incognito) + Plus -AsDefaultDriver which sets $Global:SeDriver, instead of returning the driver, and -Quiet to run tests + without web driver prattle. + Added message if driver load errors - Webdriver is now added as a windows Feature and will be found from windows\system32, + which is on the path. Removed old driver and SHA file. + Set ImplicitWait to 10 seconds + +Stop-SeDriver + Updated to handle the default drive being in $global:SeDriver. + +Start-SeNewEdge **New Function** with alias, credge to support Chromium based edge. + Also added V79 webdriver. Specifying V80. V81 from an ENV variable (EdgeWebDriver), or via command line requires + it to be in the same directory as MSEdge.exe and -inPrivate, -headless, and -binaryLocation options don't work. + +Start-SeRemote **New Function** + Connects to remote driver by URL and requested capablites tested with testingbot.com + + Start-SeChrome Start-SeEdge Start-SeFirefox Start-SeInternetExplorer Start-SeNewEdge Start-SeRemote + AsDefaultDriver X X X X X X + Fullscreen X X X X X + Headless X X X X X + ImplicitWait X X X X X X + Maximized X X X X X + Minimized X X X X X + Incognito X As alias As alias As alias As alias + PrivateBrowsing As alias X X X X + Quiet X X X X X + StartURL X X X X X X + WebDriverDirectory X X X X + or Env var ChromeWebDriver - GeckoWebDriver IEWebDriver EdgeWebDriver + BinaryPath X X + ProfileDirectoryPath X X + DefaultDownloadPath X X X + Arguments X X + +SeOpen **New Function** + Takes -In (name of browser) and opens that browser and optional naviagates to destination in -URL + The browser is opened as with -AsDefault and other options passed in -Options. + If the browser name is omitted the function will look for $env:DefaultBrowser. + Mainly for Pester/DSL freindliness - by changing the environment variable a different browser can be used in different test runs + +Send-SeClick **New Function** (with alias SeClick) {replacement for Invoke-SeClick} + Element can be passed by position (first) + -JavaScriptClick can be abreviated -JS + Driver is ignored (element.wrapedDriver used instead) + Added -SleepSeconds and -PassThru parameters + +New-SeScreenShot: **New Function** with alias SeScreenshot. Merges functionality of Invoke-ScreenShot and SaveSeScreenShot + Can pass -Path, + -Passthru (Alias PT) + -Path & -Passthru + or -AsBase64 + "Target" with alias "Driver", can come from $Global:SeDriver + and throws an error if no driver passed or found from Global var + +Open-SeURL *New Function** with alias SeNavigate + Url is first on the commandline and mandatory + Driver is renamed target, with alias "Driver", and will come from $Global:SeDriver + Throws an error if no driver passed or found from Global var + Made interoperable with Enter-SEURL via aliases + Back, forward and refresh are available via switches + Commented out Enter-SeURL and changed PSD1, + +Get-SeElement **New Function** with alias seElement + New -By parameter with possible values "CssSelector", "Name", "Id", "ClassName", "LinkText", "PartialLinkText", "TagName", "XPath" + combined with a "Selection" parameter which holds the value, replaces the 8 parameters with those names and parametersets. + Wait made optional; -Wait without -Timeout sets timeout to 30 , and -Timeout 5 works without -Wait + -Element and -Driver are merged as -Target which has aliases of 'Element' and 'Driver' + Made interoperable with Find-seElement by aliases + Commented out Find-seElement and updated PSD1. + +Switch-SeFrame **New Function** with alias SeFrame + Selects a frame. + +Clear-SeAlert **New Function** with aliases SeAccept, SeDissmiss + Accepts or dismisses an alert box so execution can continue + If called using the aliases selects Accept or dismiss. + +SeType **New Function** + More DSL friendly form of Send-SeKeys - takes piped element; keys is first parameter and supports + clearing the text box, submit and passthru, to allow element to be fetched and keys typed, and then + Pester to throw if element was not found. + +Get-SeSelectionOption **New Function** alias SeSelection + For setting and checking options in a dropdown lists. + +SeShouldHave **New Function** +Drives pester tests as a single command See examples for details, but allows things like + SeShouldHave -url -match 'packages\?q=selenium' + SeShouldHave -Selection $linkpath -By XPath -With Text -Operator Like -Value "*selenium*" + which can be shortened to + seShouldHave $linkpath text -Like "*selenium*" + +Added some new examples - showing DSL style in Pester. + +Reorder PSD file for easy reading & add file list. + +Create CI directory with files for doing a build / test pass is Azure devops. diff --git a/Output/Selenium/Examples/A-Simple-Google-Search.ps1 b/Output/Selenium/Examples/A-Simple-Google-Search.ps1 new file mode 100644 index 0000000..4f89044 --- /dev/null +++ b/Output/Selenium/Examples/A-Simple-Google-Search.ps1 @@ -0,0 +1,70 @@ +<# +.VERSION - 0.2 + +.DESCRIPTION +This is an example script that will show you how to use the Selenium driver to preform a simple google search. +Using this example script you will learn the basic usage of the Selenium powershell module. +Each comment line will explain the line that will come after it so you can follow it in a step by step fashion. +#> + +# The line below will Import-Module Selenium if it fails it will display the installation command and stop the script. +try{Import-Module -Name Selenium -ErrorAction Stop}catch{Write-Host 'Importing the Selenium module failed. Please install it using the following command: Install-Module Selenium';break} + +# Start the Selenium Chrome Driver +$Driver = Start-SeChrome + +# Next we will check if the driver is running and if it's not running we will show a message. If the driver is running we will run the commands inside the if statment. +if($Driver){ + # Now that we verified that the driver is running we can start doing cool things with it. + + # Using the Enter-SeUrl command we can tell the driver to go to any URL we want in this case we'll go to https://google.com/ncr + # I used the /ncr in the end of the URL because I want google to always stay in english and not redirect to a specific language for consistency. + Enter-SeUrl -Driver $Driver -Url 'https://www.google.com/ncr' + + # After nevigating to the desired URL we can start interacting with elements on the page in this example we are going to find the search box and type something in it. + # We can find elements using different ways like the element id or the Name/ClassName/TagName and a few other ways. + # In the below code we're going to show you a few ways to solve this problem. + + <# This is the HTML code of the search box + + #> + + # By examining the HTML code of the google seach box we can see that the search box name is q so in the below example we'll use the name q to find its element + $SearchBoxElement = Find-SeElement -Driver $Driver -Name q + + # We can also use the class name gLFyf to find the google search box. + $SearchBoxElement = Find-SeElement -Driver $Driver -ClassName 'gLFyf' + + # This line will get us all elements with the input TagName also known as + $AllInputElements = Find-SeElement -Driver $Driver -TagName input + + # The $AllInputElements contains all the input elements on the page if we want to find the specific element for the google search box we will need to loop through each input element in the $AllInputElements array and get the attibute we want in this case we're looking for the title attribute. + # And we only want to return the element that has a title equal to Search we can find this out based on the html code on the page. + $SearchBoxElement = $AllInputElements|ForEach-Object{if($_.GetAttribute('title') -eq 'Search'){return $_}} + + # Now for the fun part after finding the element we want to send keyboard input to it. this will allow us to automate the search process + # We can get the list of all special keyboard keys like enter/backspace etc using the Get-SeKeys command + + # Now that we can see all the keys we can send send some keys to the SearchBoxElement + Send-SeKeys -Element $SearchBoxElement -Keys 'Powershell-Selenium' + + # You can send special key strokes to the SearchBoxElement, you should use the Selenium Keys enum. For example, if we wanted to send an enter key stroke, you could do it like this + Send-SeKeys -Element $SearchBoxElement -Keys ([OpenQA.Selenium.Keys]::Enter) + + # When working with dynamic websites, it's often necessary to wait awhile for elements to appear on the page. By default, Selenium won't wait and you'll receive $null from Find-SeElement because the element isn�t there yet. There are a couple ways to work around this. + # The first is to use the Find-SeElement cmdlet with the -Wait switch to wait for the existence of an element in the document. + # When using the Find-SeElement with the -Wait please take into account that only 1 element can be returned unlike the without the -Wait switch where multiple elements can be returned. + + # This command will wait for the img elements for 10 seconds and then return it to you or time out if the element wasn't found on. + $LogoImageElement = Find-SeElement -Driver $Driver -Wait -Timeout 10 -Id 'logo' + + # Once we have the image element we can simulate a mouse click on it using the Invoke-SeClick command. + Invoke-SeClick -Driver $Driver -Element $LogoImageElement + + # Once we are done with the web driver and we finished with all our testing/automation we can release the driver by running the Stop-SeDriver command. + Stop-SeDriver -Driver $Driver +} +# if the driver is not running we will enter the script block in the else section and display a message +else{ + Write-Host "The selenium driver was not running." -ForegroundColor Yellow +} \ No newline at end of file diff --git a/Output/Selenium/Examples/Combined.tests.ps1 b/Output/Selenium/Examples/Combined.tests.ps1 new file mode 100644 index 0000000..9f2bbab --- /dev/null +++ b/Output/Selenium/Examples/Combined.tests.ps1 @@ -0,0 +1,257 @@ +if ($Global:SeDriver) {Write-Warning -Message 'Close any previous session first'; return} + +#SeOpen will use an environment variable DefaultBrowser if no browser is specified on the command line, so +# we can run the script with different browsers by changing that and running invoke-pester again. If it wasn't set, set it now +if (-not $env:DefaultBrowser) {$env:DefaultBrowser = 'Chrome'} + +#For each browser we will test in, specify the options for headless, inprivate & window title label for in-private +$AlwaysHeadless = $env:AlwaysHeadless -eq $true +$TestCaseSettings = @{ + 'NewEdge' = @{ DefaultOptions = @{Headless=$AlwaysHeadless} + # HeadlessOptions = @{Headless=$true} + PrivateOptions = @{PrivateBrowsing=$true + Headless=$AlwaysHeadless } + # InPrivateLabel = 'InPrivate' + } # broken after build 79 of web driver#> + 'Chrome' = @{ PrivateOptions = @{PrivateBrowsing=$true + Headless=$AlwaysHeadless} + DefaultOptions = @{Headless=$AlwaysHeadless} + HeadlessOptions = @{Headless=$true} + } + 'Firefox' = @{ PrivateOptions = @{PrivateBrowsing=$true + Headless=$AlwaysHeadless} + DefaultOptions = @{Headless=$AlwaysHeadless} + HeadlessOptions = @{Headless=$true} + } + 'MSEdge' = @{ DefaultOptions = @{Headless=$AlwaysHeadless} + PrivateOptions = @{PrivateBrowsing=$true} + } + 'IE' = @{ DefaultOptions = @{ImplicitWait=30} + PrivateOptions = @{ImplicitWait=30} + } +} + +function Build-StringFromHash { + param ($Hash) + $(foreach ($k in $Hash.Keys) {"$K`:$($hash[$K])"}) -join '; ' +} + +#region tailspin demo from the Azure Devops training materials +if (-not $env:SITE_URL) { + $env:SITE_URL = 'http://tailspin-spacegame-web.azurewebsites.net' +} +$ModaltestCases = @( + @{Name = 'Download Page' + linkXPath = '/html/body/div/div/section[2]/div[2]/a' + modalXPath = '//*[@id="pretend-modal"]/div/div' + }, + @{Name = 'Screen Image' + linkXPath = '/html/body/div/div/section[3]/div/ul/li[1]/a' + modalXPath = '/html/body/div[1]/div/div[2]' + }, + @{Name = 'Top Player' + linkXPath = '/html/body/div/div/section[4]/div/div/div[1]/div[2]/div[2]/div/a/div' + modalXPath = '//*[@id="profile-modal-1"]/div/div'} +) +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].DefaultOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash +Describe "Testing the tailspin toys demo site at $env:SITE_URL" { + BeforeAll { + #Relying on environment variable to pick the browser. Capture ID for use in logs by requesting verbose and redirecting it. + $BrowserID = SeOpen -URL $env:SITE_URL -Options $BrowserOptHash -Verbose 4>&1 + $BrowserID = ($BrowserID.Message -replace '^Opened ','') + ' on ' + [System.Environment]::OSVersion.Platform + } + Context "in $BrowserID with settings ($BrowserOptText)"{ + It "produced the right modal dialog for the " -TestCases $ModaltestCases { + Param ($linkXPath, $modalXPath) + SeShouldHave $modalXPath -With displayed eq $false + SeElement $linkXPath | SeClick -JavaScriptClick -SleepSeconds 1 + SeShouldHave $modalXPath -With displayed eq $true -PassThru| SeElement -By Class 'close' | SeClick -J -S 1 + SeShouldHave 'body' -By TagName + SeShouldHave $modalXPath -With displayed eq $false + } + } +# Additional tests would be here + AfterAll {SeClose} +} +#endregion + +#URLs we will visit in the remaining tests +$PSGalleryPage = 'https://www.powershellgallery.com/' +$AlertTestPage = 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' +$SelectTestPage = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' + +#As before rely on environment variable to pick browser. Capture ID by requesting & redirecting verbose +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].DefaultOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash +$BrowserID = SeOpen -URL $PSGalleryPage -Options $BrowserOptHash -Verbose 4>&1 +$BrowserID = ($BrowserID.Message -replace '^Opened ','') + ' on ' + [System.Environment]::OSVersion.Platform +Describe "PsGallery Test" { + Context "in $BrowserID with settings ($BrowserOptText)"{ + It 'opened the browser, saving the webdriver in a global variable ' { + $Global:SeDriver | Should -Not -BeNullOrEmpty + $Global:SeDriver | Should -BeOfType [OpenQA.Selenium.Remote.RemoteWebDriver] + } + It 'reached the right starting page ' { + #Should have can check alerts, page title, URL or an element on the page + SeShouldHave -URL eq $PSGalleryPage + } + It 'found the "Sign in" link on the home page by partial text ' { + SeShouldHave -By PartialLinkText 'Sign in' -With href match logon + } + It 'found the search box on the home page by ID ' { + SeShouldHave -By Id search + } + It 'found the search box on the home page by Name ' { + SeShouldHave -By Name 'q' + } + It 'found the search box on the home page by css selector ' { + #can write -By <> [-selection] <> + # or [-selection] <> -By <> + SeShouldHave 'input[name=q]' -By CssSelector + } + It 'found the search box on the home page by class name ' { + SeShouldHave -By ClassName "search-box" + } + It 'found the search box on the home page by Tagname and typed in it ' { + #get element, pipe as input element for Typing, pass the element through + #so pester catches 'null or empty' if it was not found + SeElement -By TagName input | + SeType -ClearFirst "selenium{{Enter}}" -PassThru -SleepSeconds 2 | Should -Not -BeNullorEmpty + } + $linkpath = '//*[@id="skippedToContent"]/section/div[1]/div[2]/div[2]/section[1]/div/table/tbody/tr/td[1]/div/div[2]/header/div[1]/h1/a' + It 'searched successfully ' { + SeShouldHave -URL match 'packages\?q=selenium' -Timeout 15 + #Two tests on the same element, second passes it through to click + SeShouldHave $linkpath -With href match selenium + SeShouldHave $linkpath -With Text like *selenium* -PassThru | SeClick -SleepSeconds 5 + } + It 'opened the search result page and found the expected content ' { + #Just to show we can test for the presence of multiple links. Each one is re-tested ... + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' , + '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' -Timeout 15 + + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' -With text match "current" + + #Can test with "Get-SeElement | where-object <>" rather than "with <> <> <>" + SeElement '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' | + Where-Object {($_.text -like "*Project Site*") -and ($_.GetAttribute('href') -match "selenium") } | + SeClick -PassThru | Should -Not -Benullorempty + } + It 'went to Github from the project link on the search result ' { + SeShouldHave -URL match 'github' -Timeout 30 + } + It 'navigated back to the start page and closed the browser ' { + SeNavigate -Back + SeNavigate -Back + SeNavigate -Back + SeShouldHave -URL eq $PSGalleryPage -Timeout 30 + SeClose + $Global:SeDriver | Should -BeNullOrEmpty + } + } +} + +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].PrivateOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash +if ($BrowserOptText) { + $NoLabel = [string]::IsNullOrEmpty($TestCaseSettings[$env:DefaultBrowser].InPrivateLabel) + $wv = $null + SeOpen -Options $BrowserOptHash -URL $alertTestPage -WarningVariable wv + if ($wv) {Write-Output "##vso[task.logissue type=warning]$wv"} +} +else { + $NoLabel = $true + SeOpen -URL $alertTestPage +} +Describe "Alerts and Selection boxes tests"{ + Context "in $BrowserID with settings ($BrowserOptText)" { + It 're-opended the browser and validated "InPrivate" mode by window title ' { + $DriverProcess = Get-Process *driver | Where-Object {$_.Parent.id -eq $pid} + $BrowserProcess = Get-Process | Where-Object {$_.Parent.id -eq $DriverProcess.id -and $_.Name -ne "conhost"} + $BrowserProcess.MainWindowTitle | Should match $TestCaseSettings[$env:DefaultBrowser].InPrivateLabel + } -Skip:$NoLabel + It 'opened the right page ' { + SeShouldHave -URL -eq $alertTestPage + } + It 'found and clicked a button in frame 1 ' { + SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult + SeFrame 'iframeResult' + SeElement "/html/body/button" | SeClick -PassThru | Should -Not -BeNullOrEmpty + } + It 'saw and dismissed an alert ' { + #Checking the text of the alert is optional. Dissmiss can pass the alert result through + SeShouldHave -Alert match "box" -PassThru | + SeDismiss -PassThru | Should -Not -BeNullOrEmpty + } + It 'reselected the parent frame ' { + SeFrame -Parent + SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult + } + It 'navigated to a new page, and found the "cars" selection box in frame 1 ' { + SeNavigate $SelectTestPage + SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult + SeFrame 'iframeResult' + SeShouldHave -By Name "cars" -With choice contains "volvo" + } + It 'made selections from the "cars" selection box ' { + $e = SeElement -by Name "cars" + #Values are lower case Text has inital caps comparisons are case sensitve. Index is 0-based + {$e | SeSelection -ByValue "Audi"} | Should -Throw + {$e | SeSelection -ByValue "audi"} | Should -not -throw + $e | SeSelection -ByIndex "2" -GetSelected | Should -Be 'Fiat' + $e | SeSelection -ByPartialText "Sa" + } + It 'submitted the form and got the expected response ' { + SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 + SeFrame -Parent + SeFrame 'iframeResult' + SeShouldHave "/html/body/div[1]" -with text match "cars=saab" + } + It 'closed the in-private browser instance ' { + SeClose + if ($DriverProcess.Id) { + (Get-Process -id $DriverProcess.id ).HasExited | Should -Be $true + } + if ($BrowserProcess.Id) { + (Get-Process -id $BrowserProcess.id).HasExited | Should -Be $true + } + } + } +} + +$BrowserOptHash = $TestCaseSettings[$env:DefaultBrowser].HeadlessOptions +$BrowserOptText = Build-StringFromHash $BrowserOptHash +if ($BrowserOptText){ + SeOpen -Options $BrowserOptHash + Describe "'Headless' mode browser test" { + Context "in $BrowserID with settings ($BrowserOptText)" { + It 're-opened the Browser in "Headless" mode ' { + $DriverProcess = Get-Process *driver | Where-Object {$_.Parent.id -eq $pid} + $BrowserProcess = Get-Process | Where-Object {$_.Parent.id -eq $DriverProcess.id -and $_.Name -ne 'conhost'} + $BrowserProcess.MainWindowHandle | Select-Object -First 1 | Should -Be 0 + } + it 'did a google Search ' { + SeNavigate 'https://www.google.com/ncr' + SeShouldHave -by Name q + SeShouldHave -by ClassName 'gLFyf' + SeShouldHave -By TagName input -With title eq 'Search' -PassThru | + Select-Object -First 1 | + SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru | should -Not -BeNullOrEmpty + + SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | + SeClick -PassThru | should -Not -BeNullOrEmpty + } + It 'closed the browser a third time ' { + SeClose + $Global:SeDriver | Should -BeNullOrEmpty + if ($DriverProcess.Id) { + (Get-Process -id $DriverProcess.id ).HasExited | Should -Be $true + } + if ($BrowserProcess.Id) { + (Get-Process -id $BrowserProcess.id).HasExited | Should -Be $true + } + } + } + } +} \ No newline at end of file diff --git a/Output/Selenium/Examples/DemoSelenium.tests.ps1 b/Output/Selenium/Examples/DemoSelenium.tests.ps1 new file mode 100644 index 0000000..2d94e51 --- /dev/null +++ b/Output/Selenium/Examples/DemoSelenium.tests.ps1 @@ -0,0 +1,54 @@ +<# +.description + This is a reworking of the C# file used for the selenium test in the the mslearn training "Deploy applications with Azure DevOps" at + https://docs.microsoft.com/en-gb/learn/modules/run-functional-tests-azure-pipelines/5-write-ui-tests + The C# File is https://github.com/MicrosoftDocs/mslearn-tailspin-spacegame-web-deploy/blob/selenium/Tailspin.SpaceGame.Web.UITests/HomePageTest.cs + + An improved version of this is included in Combined.tests.ps1 + +#> +#$env:SITE_URL='http://tailspin-spacegame-web.azurewebsites.net' +$ModaltestCases = @( + @{Name = 'Download Page' + linkXPath = '/html/body/div/div/section[2]/div[2]/a' + modalXPath = '//*[@id="pretend-modal"]/div/div' + }, + @{Name = 'Screen Image' + linkXPath = '/html/body/div/div/section[3]/div/ul/li[1]/a' + modalXPath = '/html/body/div[1]/div/div[2]' + }, + @{Name = 'Top Player' + linkXPath = '/html/body/div/div/section[4]/div/div/div[1]/div[2]/div[2]/div/a/div' + modalXPath = '//*[@id="profile-modal-1"]/div/div'} +) + +Function ClickOpensModal { + Param ($linkXPath , $modalXPath) + Find-SeElement -XPath $linkXPath -Driver $Driver | Invoke-SeClick -JavaScriptClick -Driver $driver + Start-Sleep -Seconds 1 + $modal = Find-SeElement -XPath $modalXPath -Driver $Driver + if (-not $Modal.displayed) {Write-Warning -Message 'Modal not displayed'; return $false} + else { + Find-SeElement -Element $modal -ClassName 'close' | invoke-seclick -JavaScriptClick -Driver $Driver + Start-Sleep -Seconds 1 + $null = Find-SeElement -Driver $driver -TagName 'body' + if ($modal.displayed) {Write-Warning -Message 'Modal did not close' ; return $false} + else {return $true} + } +} + +Describe "Testing $env:SITE_URL" { + BeforeAll { + $Driver = Start-SeChrome + Enter-SeUrl -Driver $Driver -Url $env:SITE_URL + } + Context "Testing Modal Dialogs" { + It "Produced the right modal for the " -TestCases $ModaltestCases { + Param ($linkXPath, $modalXPath) + ClickOpensModal $linkXPath $modalXPath | Should -Contain $true + } + } + AfterAll { + Stop-SeDriver $Driver + } +} \ No newline at end of file diff --git a/Output/Selenium/Examples/DemoSelenium2.tests.ps1 b/Output/Selenium/Examples/DemoSelenium2.tests.ps1 new file mode 100644 index 0000000..3f7abfb --- /dev/null +++ b/Output/Selenium/Examples/DemoSelenium2.tests.ps1 @@ -0,0 +1,49 @@ +<# +.description + This is a reworking of the C# file used for the selenium test in the the mslearn training "Deploy applications with Azure DevOps" at + https://docs.microsoft.com/en-gb/learn/modules/run-functional-tests-azure-pipelines/5-write-ui-tests + The C# File is https://github.com/MicrosoftDocs/mslearn-tailspin-spacegame-web-deploy/blob/selenium/Tailspin.SpaceGame.Web.UITests/HomePageTest.cs + +#> +#$env:SITE_URL='http://tailspin-spacegame-web.azurewebsites.net' +$ModaltestCases = @( + @{Name = 'Download Page' + linkXPath = '/html/body/div/div/section[2]/div[2]/a' + modalXPath = '//*[@id="pretend-modal"]/div/div' + }, + @{Name = 'Screen Image' + linkXPath = '/html/body/div/div/section[3]/div/ul/li[1]/a' + modalXPath = '/html/body/div[1]/div/div[2]' + }, + @{Name = 'Top Player' + linkXPath = '/html/body/div/div/section[4]/div/div/div[1]/div[2]/div[2]/div/a/div' + modalXPath = '//*[@id="profile-modal-1"]/div/div'} +) + +Function ClickOpensModal { + Param ($linkXPath , $modalXPath) + Get-SeElement -by XPath $linkXPath | Send-SeClick -JavaScriptClick -SleepSeconds 1 + $modal = SeElement $modalXPath -by XPath + if (-not $modal.displayed) {Write-Warning -Message 'Modal not displayed'; return $false} + else { + $modal | SeElement ClassName 'close' | seclick -Js -Sleep 1 + $null = SeElement TagName 'body' + if ($modal.displayed) {Write-Warning -Message 'Modal did not close'; return $false} + else {return $true} + } +} + +Describe "Testing $env:SITE_URL" { + BeforeAll { Chrome $env:SITE_URL -AsDefaultDriver } + + Context "Testing Modal Dialogs" { + It "Produced the right modal for the " -TestCases $ModaltestCases { + Param ($linkXPath, $modalXPath) + ClickOpensModal $linkXPath $modalXPath | should contain $true + } + } + + #more tests here + + AfterAll {Stop-SeDriver -Default } +} \ No newline at end of file diff --git a/Output/Selenium/Examples/TestPSGallery.ps1 b/Output/Selenium/Examples/TestPSGallery.ps1 new file mode 100644 index 0000000..19a5c6d --- /dev/null +++ b/Output/Selenium/Examples/TestPSGallery.ps1 @@ -0,0 +1,23 @@ + +SeOpen chrome +SeNavigate https://www.powershellgallery.com/ # Open-SeUrl -Url "https://www.powershellgallery.com/" + + +SeElement '//*[@id="search"]' | SeType -keys "selenium{{Enter}}" # $e = Get-SeElement -By XPath '//*[@id="search"]' ; Send-SeKeys -Element $e -Keys "selenium{{Enter}}" +$linkpath = '//*[@id="skippedToContent"]/section/div[1]/div[2]/div[2]/section[1]/div/table/tbody/tr/td[1]/div/div[2]/header/div[1]/h1/a' + +seShouldHave $linkpath TEXT Like "*selenium*" # Long form seShouldHave -Selection $linkpath -By XPath -With TEXT -Operator Like -Value "*selenium*" +seShouldHave $linkpath -with href match "selenium" # LONG form seShouldHave $linkpath -with href -Operator match -Value "selenium" +SeElement $linkPath | seclick # Get-SeElement -By XPath -Selection $linkpath -Driver $global:SeDriver +#Current version should be top of the the version history table +seshouldhave '//*[@id="version-history"]/table/tbody[1]/tr[1]/td[1]/a/b' -with text -match "current" -Verbose +#Project site link should go to the right place +seShouldHave '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' -with text eq "Project Site" +seShouldHave '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' -with href match "selenium" +seelement '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' | seclick + +seShouldHave -url match "github" + + + + diff --git a/Output/Selenium/Examples/comparison.ps1 b/Output/Selenium/Examples/comparison.ps1 new file mode 100644 index 0000000..07c7084 --- /dev/null +++ b/Output/Selenium/Examples/comparison.ps1 @@ -0,0 +1,58 @@ + +<# +public void testClass() throws Exception { + driver.get("http://www.wikipedia.org/") ; + Assert.assertequals("wikipedia", driver.getTitle()); + Assert.assertequals("English", driver.findElement(By.cssselector("strong")).getText()) + driver.findElement(By.cssSetector("strong")).click() ; + Assert.assertEquals("Wikipedia. the free encyclopedia", driver.getTitle()); +} +#> +SeOpen "http://www.wikipedia.org/" +SeShouldHave -Title eq Wikipedia +SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | SeClick +SeShouldHave -Title eq 'Wikipedia, the free encyclopedia' + +<# +line 2 ## SeShouldHave -Title eq Wikipedia +is actutally short for ## SeShouldHave -Title -Operator 'eq' -Value Wikipedia +other values for -operator will translate to "eq", and parameters are defined so you can use -eq -contains, -match etc +so you can use ## SeShouldHave -Title equalTo Wikipedia +or ## SeShouldHave -Title -eq Wikipedia +line 3 ## SeShouldHave 'strong' -By CssSelector Text eq 'English' +This is short for ## SeShouldHave -Selection 'strong' -By CssSelector -With Text -operator "eq" -value 'English' +if the selector is an xPath the -By parameter can be omitted; but if used -By must specified explicitly +The first unnamed parameter will be treated as selection, the second as "with" , the third as operator and the fourth as value. +SeShouldhave can take a -passthru parameter allowing the original lines 3 and 4 to be merged, + +The last line 5 is similar to line 2 but the parameter value has a sppace so must be wrapped in quotes +#> + +<#https://www.guru99.com/first-webdriver-script.html had this +public static void main(String[] args) { + System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe"); + WebDriver driver = new FirefoxDriver(); + //comment the above 2 lines and uncomment below 2 lines to use Chrome + //System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe"); + //WebDriver driver = new ChromeDriver(); + + String baseUrl = "http://demo.guru99.com/test/newtours/"; + driver.get(baseUrl); + + String expectedTitle = "Welcome: Mercury Tours"; + String actualTitle = ""; + actualTitle = driver.getTitle(); + if (actualTitle.contentEquals(expectedTitle)){ + System.out.println("Test Passed!"); + } else { + System.out.println("Test Failed"); + } + + driver.close(); +} +#> + +SeOpen "http://demo.guru99.com/test/newtours/" -In FireFox # or #-in Chrome -in MsEdge -in NewEdge or -in IE +SeShouldHave -Title eq "Welcome: Mercury Tours" +SeClose + diff --git a/Output/Selenium/Examples/test-seremote.ps1 b/Output/Selenium/Examples/test-seremote.ps1 new file mode 100644 index 0000000..922b7db --- /dev/null +++ b/Output/Selenium/Examples/test-seremote.ps1 @@ -0,0 +1,134 @@ +$PSGalleryPage = 'https://www.powershellgallery.com/' +$AlertTestPage = 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' +$SelectTestPage = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' + +#other services at +#https://crossbrowsertesting.com/freetrial / https://help.crossbrowsertesting.com/selenium-testing/getting-started/c-sharp/ +#https://www.browserstack.com/automate/c-sharp + +$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' +$secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' +$RemoteDriverURL = [uri]"http://$key`:$secret@hub.testingbot.com/wd/hub" +$caps = @{ + platform = 'HIGH-SIERRA' + browserName = 'safari' + version = '11' +} + +Start-SeRemote -RemoteAddress $RemoteDriverURL -DesiredCapabilities $caps -AsDefaultDriver -StartURL $PSGalleryPage +$BrowserID = $SeDriver.Capabilities.ToDictionary()["platformName", "browserName", "version"] -join " " + +Describe "All in one Test" { + Context "in $BrowserID with settings ($BrowserOptText)"{ + It 'opened the put the webdriver in a global variable ' { + $Global:SeDriver | Should -Not -BeNullOrEmpty + $Global:SeDriver | Should -BeOfType [OpenQA.Selenium.Remote.RemoteWebDriver] + } + It 'reached the right starting page ' { + #Should have can check alerts, page title, URL or an element on the page + SeShouldHave -URL eq $PSGalleryPage + } + It 'found the "Sign in" link on the home page by partial text ' { + SeShouldHave -By PartialLinkText 'Sign in' -With href match logon + } + It 'found the search box on the home page by ID ' { + SeShouldHave -By Id search + } + It 'found the search box on the home page by Name ' { + SeShouldHave -By Name 'q' + } + It 'found the search box on the home page by css selector ' { + #can write -By <> [-selection] <> + # or [-selection] <> -By <> + SeShouldHave 'input[name=q]' -By CssSelector + } + It 'found the search box on the home page by class name ' { + SeShouldHave -By ClassName "search-box" + } + It 'found the search box on the home page by Tagname and typed in it ' { + #get element, pipe as input element for Typing, pass the element through + #so pester catches 'null or empty' if it was not found + SeElement -By TagName input | + SeType -ClearFirst "selenium{{Enter}}" -PassThru -SleepSeconds 2 | Should -Not -BeNullorEmpty + } + $linkpath = '//*[@id="skippedToContent"]/section/div[1]/div[2]/div[2]/section[1]/div/table/tbody/tr/td[1]/div/div[2]/header/div[1]/h1/a' + It 'searched successfully ' { + SeShouldHave -URL match 'packages\?q=selenium' -Timeout 15 + #Two tests on the same element, second passes it through to click + SeShouldHave $linkpath -With href match selenium + SeShouldHave $linkpath -With Text like *selenium* -PassThru | SeClick -SleepSeconds 5 + } + It 'opened the search result page and found the expected content ' { + #Just to show we can test for the presence of multiple links. Each one is re-tested ... + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' , + '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' -Timeout 15 + + SeShouldHave '//*[@id="version-history"]/table/tbody[1]/tr[1]/ td[1]/a/b' -With text match "current" + + #Can test with "Get-SeElement | where-object <>" rather than "with <> <> <>" + SeElement '//*[@id="skippedToContent"]/section/div/aside/ul[2]/li[1]/a' | + Where-Object {($_.text -like "*Project Site*") -and ($_.GetAttribute('href') -match "selenium") } | + SeClick -PassThru | Should -Not -Benullorempty + } + It 'went to Github from the project link on the search result ' { + SeShouldHave -URL match 'github' -Timeout 30 + } + + It 'navigated back to the start page ' { + SeNavigate -Back + SeNavigate -Back + SeNavigate -Back + SeShouldHave -URL eq $PSGalleryPage -Timeout 30 + } + It 'did a google Search ' { + SeNavigate 'https://www.google.com/ncr' + SeShouldHave -by Name q + SeShouldHave -by ClassName 'gLFyf' + SeShouldHave -By TagName input -With title eq 'Search' -PassThru | + Select-Object -First 1 | + SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru | should -Not -BeNullOrEmpty + + SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | + SeClick -PassThru | should -Not -BeNullOrEmpty + } + It 'opened the the alert test-page ' { + SeNavigate $alertTestPage + SeShouldHave -URL -eq $alertTestPage + } + It 'found and clicked a button in frame 1 ' { + SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult + SeFrame 'iframeResult' + SeElement "/html/body/button" | SeClick -PassThru | Should -Not -BeNullOrEmpty + } + It 'saw and dismissed an alert ' { + #Checking the text of the alert is optional. Dissmiss can pass the alert result through + SeShouldHave -Alert match "box" -PassThru | + SeDismiss -PassThru | Should -Not -BeNullOrEmpty + } + It 'reselected the parent frame ' { + SeFrame -Parent + SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult + } + It 'navigated to a new page, and found the "cars" selection box in frame 1 ' { + SeNavigate $SelectTestPage + SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult + SeFrame 'iframeResult' + SeShouldHave -By Name "cars" -With choice contains "volvo" + } + It 'made selections from the "cars" selection box ' { + $e = SeElement -by Name "cars" + #Values are lower case Text has inital caps comparisons are case sensitve. Index is 0-based + {$e | SeSelection -ByValue "Audi"} | Should -Throw + {$e | SeSelection -ByValue "audi"} | Should -Not -Throw + $e | SeSelection -ByIndex "2" -GetSelected | Should -Be 'Fiat' + $e | SeSelection -ByPartialText "Sa" + } + It 'submitted the form and got the expected response ' { + SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 + SeFrame -Parent + SeFrame 'iframeResult' + SeShouldHave "/html/body/div[1]" -with text match "cars=saab" + } + } +} +SeClose \ No newline at end of file diff --git a/Output/Selenium/README.md b/Output/Selenium/README.md new file mode 100644 index 0000000..f47d20d --- /dev/null +++ b/Output/Selenium/README.md @@ -0,0 +1,123 @@ +# Selenium PowerShell Module + +The Selenium PowerShell module allows you to automate browser interaction using the [Selenium API](https://selenium.dev/). You can navigate to pages, find elements, click buttons, enter text and even take screenshots. + +# Looking for Maintainers + +I haven't been able to able to keep up with the issues on this repo. If you are interested in becoming a maintainer, please let me know. - [Adam](https://github.com/adamdriscoll) + +# About + +- Wraps the C# WebDriver for Selenium +- Easily execute web-based tests +- Works well with Pester + +[![Build Status](https://adamrdriscoll.visualstudio.com/Selenium/_apis/build/status/adamdriscoll.selenium-powershell?branchName=master)](https://adamrdriscoll.visualstudio.com/Selenium/_build/latest?definitionId=25&branchName=master) + +# Installation +`Note: Firefox's Latest Gecko Driver on Windows requires Microsoft Visual Studio Redistributables for the binary to run get them `[Here](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) + + +```powershell +Install-Module Selenium +``` + +OR + +``` +Import-Module "{FullPath}\selenium-powershell\Selenium.psd1" +``` + +# Usage +`Note: in order to use a specific driver you will need to have the brower of the driver installed on your system. +For example if you use Start-SeChrome you will need to have either a Chrome or Chromium browser installed +` + +## Start a Browser Driver +```powershell +# Start a driver for a browser of your choise (Chrome/Firefox/Edge/InternetExplorer) +# To start a Firefox Driver +$Driver = Start-SeFirefox + +# To start a Chrome Driver +$Driver = Start-SeChrome + +# To start an Edge Driver +$Driver = Start-SeEdge +``` + +## Navigate to a URL + +```powershell +$Driver = Start-SeFirefox +Enter-SeUrl https://www.poshud.com -Driver $Driver +``` + +## Find an Element + +```powershell +$Driver = Start-SeFirefox +Enter-SeUrl https://www.poshud.com -Driver $Driver +$Element = Find-SeElement -Driver $Driver -Id "myControl" +``` + +## Click on an Element/Button + +```powershell +$Driver = Start-SeFirefox +Enter-SeUrl https://www.poshud.com -Driver $Driver +$Element = Find-SeElement -Driver $Driver -Id "btnSend" +Invoke-SeClick -Element $Element +``` + +## Send Keystrokes + +```powershell +$Driver = Start-SeFirefox +Enter-SeUrl https://www.poshud.com -Driver $Driver +$Element = Find-SeElement -Driver $Driver -Id "txtEmail" +Send-SeKeys -Element $Element -Keys "adam@poshtools.com" +``` + +## Run Chrome with options + +```powershell +# Run Chrome in Headless mode +$Driver = Start-SeChrome -Headless + +# Run Chrome in incognito mode +$Driver = Start-SeChrome -Incognito + +# Run Chrome with alternative download folder +$Driver = Start-SeChrome -DefaultDownloadPath C:\Temp + +# Run Chrome and go to a URL in one command +$Driver = Start-SeChrome -StartURL 'https://www.google.com/ncr' + +# Run Chrome with multiple Arguments +$Driver = Start-SeChrome -Arguments @('Incognito','start-maximized') + +# Run Chrome with an existing profile. +# The default profile paths are as follows: +# Windows: C:\Users\\AppData\Local\Google\Chrome\User Data +# Linux: /home//.config/google-chrome +# MacOS: /Users//Library/Application Support/Google/Chrome +$Driver = Start-SeChrome -ProfileDirectoryPath '/home//.config/google-chrome' + +``` + +## Find and Wait for an element +```powershell +$Driver = Start-SeChrome +Enter-SeUrl 'https://www.google.com/ncr' -Driver $Driver + +# Please note that with the -Wait parameter only one element can be returned at a time. +Find-SeElement -Driver $d -Wait -Timeout 10 -Css input[name='q'] +Find-SeElement -Driver $d -Wait -Timeout 10 -Name q +``` + +# Maintainers + +- [Adam Driscoll](https://github.com/adamdriscoll) +- [Avri Chen-Roth](https://github.com/the-mentor) +- [Francis Mercier](https://github.com/itfranck) diff --git a/Output/Selenium/Selenium-Binary-Updater.ps1 b/Output/Selenium/Selenium-Binary-Updater.ps1 new file mode 100644 index 0000000..5fbb229 --- /dev/null +++ b/Output/Selenium/Selenium-Binary-Updater.ps1 @@ -0,0 +1,50 @@ +param( + [Parameter(Mandatory=$true)][ValidateSet('Chrome','Firefox','Edge')]$Browser +) + +$TempDir = [System.IO.Path]::GetTempPath() + +switch ($Browser){ + 'Chrome'{ + $LatestChromeStableRelease = Invoke-WebRequest 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE' | Select-Object -ExpandProperty Content + $ChromeBuilds = @('chromedriver_linux64','chromedriver_mac64','chromedriver_win32') + + foreach ($Build in $ChromeBuilds){ + switch($Build){ + 'chromedriver_linux64'{ + $AssembliesDir = "$PSScriptRoot/assemblies/linux" + $BinaryFileName = 'chromedriver' + } + 'chromedriver_mac64'{ + $AssembliesDir = "$PSScriptRoot/assemblies/macos" + $BinaryFileName = 'chromedriver' + } + 'chromedriver_win32'{ + $AssembliesDir = "$PSScriptRoot/assemblies" + $BinaryFileName = 'chromedriver.exe' + } + default{throw 'Incorrect Build Type'} + } + + $BuildFileName = "$Build.zip" + Write-Verbose "Downloading: $BuildFileName" + Invoke-WebRequest -OutFile "$($TempDir + $BuildFileName)" "https://chromedriver.storage.googleapis.com/$LatestChromeStableRelease/$BuildFileName" + + # Expand the ZIP Archive to the correct Assemblies Dir + Write-Verbose "Explanding: $($TempDir + $BuildFileName) to $AssembliesDir" + Expand-Archive -Path "$($TempDir + $BuildFileName)" -DestinationPath $AssembliesDir -Force + + # Generate Hash Files + Write-Verbose "Generating SHA256 Hash File: $AssembliesDir/$BinaryFileName.sha256" + Get-FileHash -Path "$AssembliesDir/$BinaryFileName" -Algorithm SHA256 | Select-Object -ExpandProperty Hash | Set-Content -Path "$AssembliesDir/$BinaryFileName.sha256" -Force + + } + } + 'Firefox'{ + Write-Host 'Not Supported Yet' + + } + 'Edge'{ + Write-Host 'Not Supported Yet' + } +} \ No newline at end of file diff --git a/Output/Selenium/Selenium.psd1 b/Output/Selenium/Selenium.psd1 new file mode 100644 index 0000000..d944cf7 --- /dev/null +++ b/Output/Selenium/Selenium.psd1 @@ -0,0 +1,108 @@ +# +# Module manifest for module 'Selenium' +# +# Generated by: Adam Driscoll +# +# Generated on: 8/31/2018 +# +# Modified James O'Neill 30 Nov 2019 + +@{ + ModuleVersion = '3.0.1' + GUID = 'a3bdb8c3-c150-48a8-b56d-cd4d43f46a26' + Author = 'Adam Driscoll' + CompanyName = 'Unknown' + Copyright = '(c) 2020 Adam Driscoll. All rights reserved.' + Description = 'Web automation using the Selenium Web Driver' + ScriptsToProcess = @('SeleniumClasses.ps1') + RootModule = 'Selenium.psm1' + RequiredAssemblies = @('./assemblies/WebDriver.dll', './assemblies/WebDriver.Support.dll') + FunctionsToExport = @('Clear-SeAlert', 'Get-SeCookie', 'Get-SeElement', 'Get-SeElementAttribute', 'Get-SeElementCssValue', 'Get-SeKeys', 'Get-SeSelectionOption', 'Get-SeWindow', 'Invoke-SeClick', 'Invoke-SeScreenshot', 'New-SeScreenshot', 'Open-SeUrl', 'Remove-SeCookie', 'Save-SeScreenshot', 'Send-SeClick', 'Send-SeKeys', 'SeOpen', 'SeShouldHave', 'Set-SeCookie', 'SeType', 'Start-SeChrome', 'Start-SeEdge', 'Start-SeFirefox', 'Start-SeInternetExplorer', 'Start-SeNewEdge', 'Start-SeRemote', 'Stop-SeDriver', 'Switch-SeFrame', 'Switch-SeWindow') + AliasesToExport = @( + 'SeChrome' , + 'SeFirefox', + 'SeIE' , 'SeInternetExplorer' , + 'CrEdge' , 'NewEdge', + 'MSEdge' , 'LegacyEdge', 'Start-SeLegacyEdge', + 'Enter-SeUrl' , + 'Find-SeElement', + 'SeAccept', + 'SeDismiss', + 'SeClick', + 'SeClose', + 'SeElement', + 'SeFrame', + 'SeNavigate', + 'SeScreenshot', + 'SeSelection') + CmdletsToExport = @() + VariablesToExport = @() + DscResourcesToExport = @() + FileList = @('.\assemblies', + '.\Examples', + '.\ChangeLog.md', + '.\README.md', + '.\Selenium.psm1' + '.\Selenium.tests.ps1' + '.\Selenium-Binary-Updater.ps1') + + PrivateData = @{ + PSData = @{ + Tags = @('selenium', 'automation', 'web') + LicenseUri = 'https://github.com/adamdriscoll/selenium-powershell/blob/master/LICENSE' + ProjectUri = 'https://github.com/adamdriscoll/selenium-powershell' + ReleaseNotes = 'Updating WebDrivers for Selenium' + + # A URL to an icon representing this module. + # IconUri = '' + # Prerelease = 'beta2' + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # Supported PSEditions + # CompatiblePSEditions = @() + + # Minimum version of the Windows PowerShell engine required by this module + # PowerShellVersion = '' + + # Name of the Windows PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the Windows PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # CLRVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # List of all modules packaged with this module + # ModuleList = @() + + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + +} diff --git a/Output/Selenium/Selenium.psm1 b/Output/Selenium/Selenium.psm1 new file mode 100644 index 0000000..97cff2d Binary files /dev/null and b/Output/Selenium/Selenium.psm1 differ diff --git a/Output/Selenium/Selenium.tests.ps1 b/Output/Selenium/Selenium.tests.ps1 new file mode 100644 index 0000000..3d181eb --- /dev/null +++ b/Output/Selenium/Selenium.tests.ps1 @@ -0,0 +1,224 @@ +Import-Module (Join-Path $PSScriptRoot "Selenium.psd1") -Force + +Describe "Verify the Binaries SHA256 Hash" { + It "Check WebDriver.dll Hash"{ + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/0ee619b1786cf5971c0f9c6ee1859497aecba93a4953cf92fea998e8eefadf3c/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\WebDriver.dll).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\WebDriver.dll.sha256) + } + + It "Check WebDriver.Support.dll Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/b59ba7d0cffe43e722b13ad737cf596f030788b86b5b557cb479f0b6957cce8a/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\WebDriver.Support.dll).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\WebDriver.Support.dll.sha256) + } + + It "Check ChromeDriver.exe Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/c5c852d8f0890eb8c0b77fed623a3c36f50434552e9623e47fadf1e445f2f772/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\chromedriver.exe).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\chromedriver.exe.sha256) + } + + It "Check ChromeDriver Linux Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/ed50bce67a54727b7bf323d588d62be699233a75300d24c92409499a9329b2e6/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\linux\chromedriver).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\linux\chromedriver.sha256) + } + + It "Check ChromeDriver MacOS Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/6bb2996ebdeea6b2d10e6a9397ff53c394ebbaa8388087f134a4bc10f532863c/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\macos\chromedriver).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\macos\chromedriver.sha256) + } + + It "Check GeckoDriver.exe Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/255c9d3571c86841213f49b26d176a6ad440be8c720e3c2d9226076adf4f603d/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\geckodriver.exe).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\geckodriver.exe.sha256) + } + + It "Check GeckoDriver Linux Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/6590e3b9d9bf292c8df50b6df5bcf8a5191d999f9e48f68aa2055eb5746b2c05/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\linux\geckodriver).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\linux\geckodriver.sha256) + } + + It "Check GeckoDriver MacOS Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/d62c2178377addeb1bb860426b2c9b10b68d2eeabf0c521529a4a6a7b1e208c4/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\macos\geckodriver).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\macos\geckodriver.sha256) + } + + It "Check IEDriverServer.exe Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/a1e26b0e8cb5f8db1cd784bac71bbf540485d81e697293b0b4586e25a31a8187/detection - this driver seems to have 2 false positives and is marked as clean in the comments + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\IEDriverServer.exe).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\IEDriverServer.exe.sha256) + } + + It "Check MicrosoftWebDriver.exe Hash" { + # VirusTotal Scan URL = https://www.virustotal.com/gui/file/6e8182697ea5189491b5519d8496a3392e43741b7c0515130f2f8205881d208e/detection + $Hash = (Get-FileHash -Algorithm SHA256 -Path $PSScriptRoot\assemblies\MicrosoftWebDriver.exe).Hash + $Hash | Should -Be (Get-Content -Path $PSScriptRoot\assemblies\MicrosoftWebDriver.exe.sha256) + } +} + +Describe "Start-SeChrome" { + Context "Should Start Chrome Driver" { + $Driver = Start-SeChrome + Stop-SeDriver $Driver + } +} + +Describe "Start-SeChrome with Options" { + Context "Should Start Chrome Driver with different startup options" { + It "Start Chrome with StartURL" { + $Driver = Start-SeChrome -StartURL 'https://github.com/adamdriscoll/selenium-powershell' + Stop-SeDriver $Driver + } + + It "Start Chrome in Headless mode" { + $Driver = Start-SeChrome -Headless + Stop-SeDriver $Driver + } + + It "Start Chrome Minimize" { + $Driver = Start-SeChrome -Minimize + Stop-SeDriver $Driver + } + + It "Start Chrome Maximized" { + $Driver = Start-SeChrome -Maximized + Stop-SeDriver $Driver + } + + It "Start Chrome Incognito" { + $Driver = Start-SeChrome -Incognito + Stop-SeDriver $Driver + } + + It "Start Chrome Fullscreen" { + $Driver = Start-SeChrome -Fullscreen + Stop-SeDriver $Driver + } + + It "Start Chrome Maximized and Incognito" { + $Driver = Start-SeChrome -Maximized -Incognito + Stop-SeDriver $Driver + } + + It "Start Chrome with Multiple arguments" { + $Driver = Start-SeChrome -Arguments @('Incognito','start-maximized') + Stop-SeDriver $Driver + } + } +} + +Describe "Start-SeFirefox"{ + Context "Should Start Firefox Driver" { + $Driver = Start-SeFirefox + Stop-SeDriver $Driver + } +} + +Describe "Start-SeFirefox with Options" { + Context "Should Start Firefox Driver with different startup options" { + It "Start Firefox with StartURL" { + $Driver = Start-SeFirefox -StartURL 'https://github.com/adamdriscoll/selenium-powershell' + Stop-SeDriver $Driver + } + + It "Start Firefox in Headless mode" { + $Driver = Start-SeFirefox -Headless + Stop-SeDriver $Driver + } + + It "Start Firefox Minimize" { + $Driver = Start-SeFirefox -Minimize + Stop-SeDriver $Driver + } + + It "Start Firefox Maximized" { + $Driver = Start-SeFirefox -Maximized + Stop-SeDriver $Driver + } + + It "Start Firefox PrivateBrowsing (Incognito)" { + $Driver = Start-SeFirefox -PrivateBrowsing + Stop-SeDriver $Driver + } + + It "Start Firefox Fullscreen" { + $Driver = Start-SeFirefox -Fullscreen + Stop-SeDriver $Driver + } + + It "Start Firefox Maximized and PrivateBrowsing (Incognito)" { + $Driver = Start-SeFirefox -Maximized -PrivateBrowsing + Stop-SeDriver $Driver + } + + It "Start Firefox with Multiple arguments" { + $Driver = Start-SeFirefox -Arguments @('-headless','-private') + Stop-SeDriver $Driver + } + } +} + +Describe "Start-SeEdge" { + Context "Should Start Edge Driver" { + if(!$IsLinux -and !$IsMacOS){ + $Driver = Start-SeEdge + Stop-SeDriver $Driver + } + } +} + +Describe "Start-SeInternetExplorer" { + Context "Should Start InternetExplorer Driver" { + if(!$IsLinux -and !$IsMacOS){ + $Driver = Start-SeInternetExplorer + Stop-SeDriver $Driver + } + } +} + +Describe "Get-SeCookie" { + $Driver = Start-SeFirefox + Context "Should get cookies from google" { + Enter-SeUrl -Driver $Driver -Url "http://www.google.com" + + Get-SeCookie $Driver + } + Stop-SeDriver $Driver +} + +Describe "Send-SeKeys" { + $Driver = Start-SeFirefox + Enter-SeUrl -Driver $Driver -Url "http://www.google.com/ncr" + Context "Find-SeElement" { + It "By Css" { + $SearchInput = Find-SeElement -Driver $Driver -Css "input[name='q']" + Send-SeKeys -Element $SearchInput -Keys "test" + } + } + Stop-SeDriver $Driver +} + +Describe "Find-SeElement Firefox" { + $Driver = Start-SeFirefox + Enter-SeUrl -Driver $Driver -Url "http://www.google.com/ncr" + Context "Find-SeElement" { + It "By Css" { + $SearchInput = Find-SeElement -Driver $Driver -Css "input[name='q']" + } + } + + Context "Find-SeElement -Wait" { + It "By Name"{ + $SearchInput = Find-SeElement -Driver $Driver -Wait -Name q -Timeout 60 + } + } + + Stop-SeDriver $Driver +} + diff --git a/Output/Selenium/SeleniumClasses.ps1 b/Output/Selenium/SeleniumClasses.ps1 new file mode 100644 index 0000000..45d2736 --- /dev/null +++ b/Output/Selenium/SeleniumClasses.ps1 @@ -0,0 +1,123 @@ + +if ('ValidateURIAttribute' -as [type]) { + class ValidateURIAttribute : System.Management.Automation.ValidateArgumentsAttribute { + [void] Validate([object] $arguments , [System.Management.Automation.EngineIntrinsics]$EngineIntrinsics) { + $Out = $null + if ([uri]::TryCreate($arguments, [System.UriKind]::Absolute, [ref]$Out)) { return } + else { throw [System.Management.Automation.ValidationMetadataException]::new('Incorrect StartURL please make sure the URL starts with http:// or https://') } + return + } + } + class ValidateURI : ValidateURIAttribute {} +} + + +if ('ValidateIsWebDriverAttribute' -as [type]) { + class ValidateIsWebDriverAttribute : System.Management.Automation.ValidateArgumentsAttribute { + [void] Validate([object] $arguments , [System.Management.Automation.EngineIntrinsics]$EngineIntrinsics) { + if ($arguments -isnot [OpenQA.Selenium.Remote.RemoteWebDriver]) { + throw [System.Management.Automation.ValidationMetadataException]::new('Target was not a valid web driver') + } + return + } + } + class ValidateIsWebDriver : ValidateIsWebDriverAttribute {} +} + +if ('ByTransformAttribute' -as [type]) { + #Allow BY to shorten cssSelector, ClassName, LinkText, and TagName + class ByTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + [object] Transform([System.Management.Automation.EngineIntrinsics]$EngineIntrinsics, [object] $InputData) { + if ($inputData -match 'CssSelector|Name|Id|ClassName|LinkText|PartialLinkText|TagName|XPath') { + return $InputData + } + switch -regex ($InputData) { + "^css" { return 'CssSelector'; break } + "^class" { return 'ClassName' ; break } + "^link" { return 'LinkText' ; break } + "^tag" { return 'TagName' ; break } + } + return $InputData + } + } + + class ByTransform : ByTransformAttribute {} +} + +if ('OperatorTransformAttribute' -as [type]) { + #Allow operator to use containing, matching, matches, equals etc. + class OperatorTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + [object] Transform([System.Management.Automation.EngineIntrinsics]$EngineIntrinsics, [object] $InputData) { + if ($inputData -match '^(contains|like|notlike|match|notmatch|eq|ne|gt|lt)$#') { + return $InputData + } + switch -regex ($InputData) { + "^contain" { return 'contains' ; break } + "^match" { return 'match' ; break } + "^n\w*match" { return 'notmatch' ; break } + "^eq" { return 'eq' ; break } + "^n\w*eq" { return 'ne' ; break } + } + return $InputData + } + } + + class OperatorTransform : OperatorTransformAttribute {} +} + +$dll1Path = Join-path -path (Join-path -path $PSScriptRoot -ChildPath 'assemblies') -ChildPath 'WebDriver.dll' +$dll2Path = Join-path -path (Join-path -path $PSScriptRoot -ChildPath 'assemblies') -ChildPath 'WebDriver.Support.dll' + +Add-type @" +using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; +using System.Collections.Generic; +namespace SeleniumSelection { + public class Option { + public static bool IsMultiSelect(IWebElement element) { + var selection = new SelectElement(element); + return selection.IsMultiple; + } + public static IList GetOptions(IWebElement element) { + var selection = new SelectElement(element); + return selection.Options; + } + public static void SelectByValue(IWebElement element, string value) { + var selection = new SelectElement(element); + selection.SelectByValue(value); + } + public static void DeselectByValue(IWebElement element, string value) { + var selection = new SelectElement(element); + selection.DeselectByValue(value); + } + public static void SelectByText(IWebElement element, string text, bool partialMatch = false) { + var selection = new SelectElement(element); + selection.SelectByText(text,partialMatch); + } + public static void DeselectByText(IWebElement element, string text) { + var selection = new SelectElement(element); + selection.DeselectByText(text); + } + public static void SelectByIndex(IWebElement element, int index) { + var selection = new SelectElement(element); + selection.SelectByIndex(index); + } + public static void DeselectByIndex(IWebElement element, int index) { + var selection = new SelectElement(element); + selection.DeselectByIndex(index); + } + public static void DeselectAll(IWebElement element) { + var selection = new SelectElement(element); + selection.DeselectAll(); + } + public static IWebElement GetSelectedOption(IWebElement element) { + var selection = new SelectElement(element); + return selection.SelectedOption; + } + public static IList GetAllSelectedOptions(IWebElement element) { + var selection = new SelectElement(element); + return selection.AllSelectedOptions; + } + } +} +"@ -ReferencedAssemblies $dll1Path, $dll2Path, mscorlib \ No newline at end of file diff --git a/Output/Selenium/assemblies/IEDriverServer.exe b/Output/Selenium/assemblies/IEDriverServer.exe new file mode 100644 index 0000000..d4890e2 Binary files /dev/null and b/Output/Selenium/assemblies/IEDriverServer.exe differ diff --git a/Output/Selenium/assemblies/IEDriverServer.exe.sha256 b/Output/Selenium/assemblies/IEDriverServer.exe.sha256 new file mode 100644 index 0000000..9573b7c --- /dev/null +++ b/Output/Selenium/assemblies/IEDriverServer.exe.sha256 @@ -0,0 +1 @@ +A1E26B0E8CB5F8DB1CD784BAC71BBF540485D81E697293B0B4586E25A31A8187 diff --git a/Output/Selenium/assemblies/WebDriver.Support.dll b/Output/Selenium/assemblies/WebDriver.Support.dll new file mode 100644 index 0000000..0f85686 Binary files /dev/null and b/Output/Selenium/assemblies/WebDriver.Support.dll differ diff --git a/Output/Selenium/assemblies/WebDriver.Support.dll.sha256 b/Output/Selenium/assemblies/WebDriver.Support.dll.sha256 new file mode 100644 index 0000000..917d916 --- /dev/null +++ b/Output/Selenium/assemblies/WebDriver.Support.dll.sha256 @@ -0,0 +1 @@ +B59BA7D0CFFE43E722B13AD737CF596F030788B86B5B557CB479F0B6957CCE8A diff --git a/Output/Selenium/assemblies/WebDriver.dll b/Output/Selenium/assemblies/WebDriver.dll new file mode 100644 index 0000000..41d471f Binary files /dev/null and b/Output/Selenium/assemblies/WebDriver.dll differ diff --git a/Output/Selenium/assemblies/WebDriver.dll.sha256 b/Output/Selenium/assemblies/WebDriver.dll.sha256 new file mode 100644 index 0000000..189a3f9 --- /dev/null +++ b/Output/Selenium/assemblies/WebDriver.dll.sha256 @@ -0,0 +1 @@ +0EE619B1786CF5971C0F9C6EE1859497AECBA93A4953CF92FEA998E8EEFADF3C diff --git a/Output/Selenium/assemblies/chromedriver.exe b/Output/Selenium/assemblies/chromedriver.exe new file mode 100644 index 0000000..4850c8d Binary files /dev/null and b/Output/Selenium/assemblies/chromedriver.exe differ diff --git a/Output/Selenium/assemblies/chromedriver.exe.sha256 b/Output/Selenium/assemblies/chromedriver.exe.sha256 new file mode 100644 index 0000000..0f55902 --- /dev/null +++ b/Output/Selenium/assemblies/chromedriver.exe.sha256 @@ -0,0 +1 @@ +55C5203DB4D44D96F4124C60E69AE0823F4372EFA4B5416675D9564A83D6AD2C \ No newline at end of file diff --git a/Output/Selenium/assemblies/geckodriver.exe b/Output/Selenium/assemblies/geckodriver.exe new file mode 100644 index 0000000..9fae8e0 Binary files /dev/null and b/Output/Selenium/assemblies/geckodriver.exe differ diff --git a/Output/Selenium/assemblies/geckodriver.exe.sha256 b/Output/Selenium/assemblies/geckodriver.exe.sha256 new file mode 100644 index 0000000..2b051b9 --- /dev/null +++ b/Output/Selenium/assemblies/geckodriver.exe.sha256 @@ -0,0 +1 @@ +255C9D3571C86841213F49B26D176A6AD440BE8C720E3C2D9226076ADF4F603D diff --git a/Output/Selenium/assemblies/linux/chromedriver b/Output/Selenium/assemblies/linux/chromedriver new file mode 100644 index 0000000..7d7041d Binary files /dev/null and b/Output/Selenium/assemblies/linux/chromedriver differ diff --git a/Output/Selenium/assemblies/linux/chromedriver.sha256 b/Output/Selenium/assemblies/linux/chromedriver.sha256 new file mode 100644 index 0000000..648ed61 --- /dev/null +++ b/Output/Selenium/assemblies/linux/chromedriver.sha256 @@ -0,0 +1 @@ +B561EFE1551F9CB45DDE6BBF804CA2BC06359415CDAC1B6B16556B095A55011F \ No newline at end of file diff --git a/Output/Selenium/assemblies/linux/geckodriver b/Output/Selenium/assemblies/linux/geckodriver new file mode 100644 index 0000000..ff08a41 Binary files /dev/null and b/Output/Selenium/assemblies/linux/geckodriver differ diff --git a/Output/Selenium/assemblies/linux/geckodriver.sha256 b/Output/Selenium/assemblies/linux/geckodriver.sha256 new file mode 100644 index 0000000..6d92a3d --- /dev/null +++ b/Output/Selenium/assemblies/linux/geckodriver.sha256 @@ -0,0 +1 @@ +6590E3B9D9BF292C8DF50B6DF5BCF8A5191D999F9E48F68AA2055EB5746B2C05 diff --git a/Output/Selenium/assemblies/macos/chromedriver b/Output/Selenium/assemblies/macos/chromedriver new file mode 100644 index 0000000..cd12a95 Binary files /dev/null and b/Output/Selenium/assemblies/macos/chromedriver differ diff --git a/Output/Selenium/assemblies/macos/chromedriver.sha256 b/Output/Selenium/assemblies/macos/chromedriver.sha256 new file mode 100644 index 0000000..2e03b89 --- /dev/null +++ b/Output/Selenium/assemblies/macos/chromedriver.sha256 @@ -0,0 +1 @@ +AD35D47CA5CD075939F7F6638188A56B648663D38A0719AF28B3F004BF95E0DD diff --git a/Output/Selenium/assemblies/macos/geckodriver b/Output/Selenium/assemblies/macos/geckodriver new file mode 100644 index 0000000..83a86e1 Binary files /dev/null and b/Output/Selenium/assemblies/macos/geckodriver differ diff --git a/Output/Selenium/assemblies/macos/geckodriver.sha256 b/Output/Selenium/assemblies/macos/geckodriver.sha256 new file mode 100644 index 0000000..449827d --- /dev/null +++ b/Output/Selenium/assemblies/macos/geckodriver.sha256 @@ -0,0 +1 @@ +D62C2178377ADDEB1BB860426B2C9B10B68D2EEABF0C521529A4A6A7B1E208C4 diff --git a/Output/Selenium/assemblies/msedgedriver.exe b/Output/Selenium/assemblies/msedgedriver.exe new file mode 100644 index 0000000..18ab97e Binary files /dev/null and b/Output/Selenium/assemblies/msedgedriver.exe differ diff --git a/Output/Selenium/assemblies/msedgedriver.exe.sha256 b/Output/Selenium/assemblies/msedgedriver.exe.sha256 new file mode 100644 index 0000000..14375a3 --- /dev/null +++ b/Output/Selenium/assemblies/msedgedriver.exe.sha256 @@ -0,0 +1 @@ +509FFD6D321EF78C8319E68B89807D2437D8DB1718000FE2BB7ECACB1529730D diff --git a/Output/Selenium/en-US/Selenium-help.xml b/Output/Selenium/en-US/Selenium-help.xml new file mode 100644 index 0000000..cc30d98 --- /dev/null +++ b/Output/Selenium/en-US/Selenium-help.xml @@ -0,0 +1,7437 @@ + + + + + Clear-SeAlert + Clear + SeAlert + + Accept and clear alert popup + + + + Accept and clear alert popup + + + + Clear-SeAlert + + Alert + + Specify alert window. Seems to be ignored in favor of Target / Default Target. + + Object + + Object + + + None + + + Action + + Action to be performed on the alert popup + + + Accept + Dismiss + + Object + + Object + + + None + + + PassThru + + {{ Fill PassThru Description }} + + + SwitchParameter + + + False + + + + Clear-SeAlert + + Action + + Action to be performed on the alert popup + + + Accept + Dismiss + + Object + + Object + + + None + + + PassThru + + {{ Fill PassThru Description }} + + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + Action + + Action to be performed on the alert popup + + Object + + Object + + + None + + + Alert + + Specify alert window. Seems to be ignored in favor of Target / Default Target. + + Object + + Object + + + None + + + PassThru + + {{ Fill PassThru Description }} + + SwitchParameter + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Get-SeCookie + Get + SeCookie + + List all cookies + + + + List all cookies + + + + Get-SeCookie + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeCookie + + List all cookies of the default webdriver + + + + + + + + Get-SeElement + Get + SeElement + + Finds all IWebElements within the current context using the given mechanism + + + + Finds all IWebElements within the current context using the given mechanism + + + + Get-SeElement + + Selection + + String Identifier of the object to find + + String + + String + + + None + + + Timeout + + Timeout (in seconds) + + Int32 + + Int32 + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + By + + The locating mechanism to use + + + CssSelector + Name + Id + ClassName + LinkText + PartialLinkText + TagName + XPath + + String + + String + + + None + + + Wait + + Set Timeout to 30 seconds (Will not override Timeout value if already defined) + + + SwitchParameter + + + False + + + + + + By + + The locating mechanism to use + + String + + String + + + None + + + Selection + + String Identifier of the object to find + + String + + String + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + Timeout + + Timeout (in seconds) + + Int32 + + Int32 + + + None + + + Wait + + Set Timeout to 30 seconds (Will not override Timeout value if already defined) + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeElement -By Name -Selection 'username' + + Get the username field by name + + + + + + + + Get-SeElementAttribute + Get + SeElementAttribute + + {{ Fill in the Synopsis }} + + + + {{ Fill in the Description }} + + + + Get-SeElementAttribute + + Element + + Target IWebElement + + IWebElement + + IWebElement + + + None + + + Attribute + + {{ Fill Attribute Description }} + + String + + String + + + None + + + + + + Attribute + + {{ Fill Attribute Description }} + + String + + String + + + None + + + Element + + Target IWebElement + + IWebElement + + IWebElement + + + None + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> $Element = Get-SeElement -By Name -Selection 'username' +PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' + + Get the placeholder attribue of the username element. + + + + + + + + Get-SeElementCssValue + Get + SeElementCssValue + + Get CSS value for the specified name of targeted element. + + + + Get CSS value for the specified name of targeted element. + + + + Get-SeElementCssValue + + Element + + Target IWebElement + + IWebElement + + IWebElement + + + None + + + Name + + Name of the CSS attribute to query + + String + + String + + + None + + + + + + Element + + Target IWebElement + + IWebElement + + IWebElement + + + None + + + Name + + Name of the CSS attribute to query + + String + + String + + + None + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeElementCssValue -Element $Element -Name 'padding' + + + + + + + + + + Get-SeKeys + Get + SeKeys + + Return a list of the available special keys + + + + Return a list of the available special keys. These keys can be used with `Send-SeKeys` by using their name in the following format `{{SpecialKeyName}}` + + + + Get-SeKeys + + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeKeys + + + + + + + + + + Get-SeSelectionOption + Get + SeSelectionOption + + Get Selected option from a Select control + + + + Get Selected option from a Select control + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + ByFullText + + {{ Fill ByFullText Description }} + + String + + String + + + None + + + Clear + + Deselect the option first + + + SwitchParameter + + + False + + + GetAllSelected + + All selected options belonging to this select tag + + + SwitchParameter + + + False + + + GetSelected + + Get selected option + + + SwitchParameter + + + False + + + PassThru + + Return IWebElement + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + ByIndex + + {{ Fill ByIndex Description }} + + Int32 + + Int32 + + + None + + + Clear + + Deselect the option first + + + SwitchParameter + + + False + + + GetAllSelected + + All selected options belonging to this select tag + + + SwitchParameter + + + False + + + GetSelected + + Get selected option + + + SwitchParameter + + + False + + + PassThru + + Return IWebElement + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + ByPartialText + + {{ Fill ByPartialText Description }} + + String + + String + + + None + + + GetAllSelected + + All selected options belonging to this select tag + + + SwitchParameter + + + False + + + GetSelected + + Get selected option + + + SwitchParameter + + + False + + + PassThru + + Return IWebElement + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + ByValue + + {{ Fill ByValue Description }} + + String + + String + + + None + + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + Clear + + Deselect the option first + + + SwitchParameter + + + False + + + GetAllSelected + + All selected options belonging to this select tag + + + SwitchParameter + + + False + + + GetSelected + + Get selected option + + + SwitchParameter + + + False + + + PassThru + + Return IWebElement + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + Clear + + Deselect the option first + + + SwitchParameter + + + False + + + ListOptionText + + This parameter is not used + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + GetAllSelected + + All selected options belonging to this select tag + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + GetSelected + + Get selected option + + + SwitchParameter + + + False + + + + Get-SeSelectionOption + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + IsMultiSelect + + To use with multiselect element + + + SwitchParameter + + + False + + + + + + ByFullText + + {{ Fill ByFullText Description }} + + String + + String + + + None + + + ByIndex + + {{ Fill ByIndex Description }} + + Int32 + + Int32 + + + None + + + ByPartialText + + {{ Fill ByPartialText Description }} + + String + + String + + + None + + + ByValue + + {{ Fill ByValue Description }} + + String + + String + + + None + + + Clear + + Deselect the option first + + SwitchParameter + + SwitchParameter + + + False + + + Element + + Targeted IwebElement + + IWebElement + + IWebElement + + + None + + + GetAllSelected + + All selected options belonging to this select tag + + SwitchParameter + + SwitchParameter + + + False + + + GetSelected + + Get selected option + + SwitchParameter + + SwitchParameter + + + False + + + IsMultiSelect + + To use with multiselect element + + SwitchParameter + + SwitchParameter + + + False + + + ListOptionText + + This parameter is not used + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + Return IWebElement + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.String + + + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + System.Int32 + + + + + + + + + + System.Object + + + + + + + + + + + + + + + + + Get-SeWindow + Get + SeWindow + + Gets the window handles of open browser windows + + + + Gets the window handles of open browser windows + + + + Get-SeWindow + + Target + + Target webdriver + + IWebDriver + + IWebDriver + + + None + + + + + + Target + + Target webdriver + + IWebDriver + + IWebDriver + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeWindow + + Gets the window handles of open browser windows. + + + + + + + + Invoke-SeClick + Invoke + SeClick + + Select an element then send a click action on it. + + + + Select an element then send a click action on it. + + + + Invoke-SeClick + + Driver + + Target webdriver + + Object + + Object + + + None + + + Element + + Element for which the click will be performed upon + + IWebElement + + IWebElement + + + None + + + JavaScriptClick + + Use Javascript to perform the click + + + SwitchParameter + + + False + + + + + + Driver + + Target webdriver + + Object + + Object + + + None + + + Element + + Element for which the click will be performed upon + + IWebElement + + IWebElement + + + None + + + JavaScriptClick + + Use Javascript to perform the click + + SwitchParameter + + SwitchParameter + + + False + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + + + + Invoke-SeScreenshot + Invoke + SeScreenshot + + Take a screenshot of the current page + + + + Take a screenshot of the current page + + + + Invoke-SeScreenshot + + Target + + Target webdriver + + Object + + Object + + + None + + + AsBase64EncodedString + + Return image as base64 string + + + SwitchParameter + + + False + + + + + + AsBase64EncodedString + + Return image as base64 string + + SwitchParameter + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + + + + New-SeScreenshot + New + SeScreenshot + + Take a screenshot of the current page + + + + Take a screenshot of the current page + + + + New-SeScreenshot + + AsBase64EncodedString + + Return image as base64 string + + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + New-SeScreenshot + + Path + + Filepath where the image iwll be saved to. + + Object + + Object + + + None + + + ImageFormat + + Set the image format + + + Png + Jpeg + Gif + Tiff + Bmp + + ScreenshotImageFormat + + ScreenshotImageFormat + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + + New-SeScreenshot + + Path + + Filepath where the image iwll be saved to. + + Object + + Object + + + None + + + ImageFormat + + Set the image format + + + Png + Jpeg + Gif + Tiff + Bmp + + ScreenshotImageFormat + + ScreenshotImageFormat + + + None + + + PassThru + + Return the screenshot element + + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + AsBase64EncodedString + + Return image as base64 string + + SwitchParameter + + SwitchParameter + + + False + + + ImageFormat + + Set the image format + + ScreenshotImageFormat + + ScreenshotImageFormat + + + None + + + PassThru + + Return the screenshot element + + SwitchParameter + + SwitchParameter + + + False + + + Path + + Filepath where the image iwll be saved to. + + Object + + Object + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> New-SeScreenshot -Path 'c:\temp\Screenshot.png' -ImageFormat Png + + Save a screenshot in PNG format at the specified location + + + + + + + + Open-SeUrl + Open + SeUrl + + Navigate to URL + + + + Navigate to URL + + + + Open-SeUrl + + Back + + Enables the web browser to click on the back button in the existing browser window. + + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + Open-SeUrl + + Forward + + enables the web browser to click on the forward button in the existing browser window. + + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + Open-SeUrl + + Refresh + + enables the web browser to click on the refresh button in the existing browser window. + + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + + Open-SeUrl + + Url + + Url to navigate to + + String + + String + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + Back + + Enables the web browser to click on the back button in the existing browser window. + + SwitchParameter + + SwitchParameter + + + False + + + Forward + + enables the web browser to click on the forward button in the existing browser window. + + SwitchParameter + + SwitchParameter + + + False + + + Refresh + + enables the web browser to click on the refresh button in the existing browser window. + + SwitchParameter + + SwitchParameter + + + False + + + Target + + Target webdriver + + Object + + Object + + + None + + + Url + + Url to navigate to + + String + + String + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Open-SeUrl -Url 'https://www.google.com' + + Open URL into currently selected Driver + + + + + + + + Remove-SeCookie + Remove + SeCookie + + Delete the named cookie from the current domain + + + + Delete the named cookie from the current domain + + + + Remove-SeCookie + + DeleteAllCookies + + Remove all cookies from webdriver + + + SwitchParameter + + + False + + + Target + + Target webdriver + + IWebDriver + + IWebDriver + + + None + + + + Remove-SeCookie + + Name + + Cookie name to remove + + String + + String + + + None + + + Target + + Target webdriver + + IWebDriver + + IWebDriver + + + None + + + + + + DeleteAllCookies + + Remove all cookies from webdriver + + SwitchParameter + + SwitchParameter + + + False + + + Name + + Cookie name to remove + + String + + String + + + None + + + Target + + Target webdriver + + IWebDriver + + IWebDriver + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Remove-SeCookie -Name 'CookieName' + + Remove cookie from targeted Driver + + + + -------------------------- Example 2 -------------------------- + PS C:\> Remove-SeCookie -DeleteAllCookies + + Remove all cookies from targeted Driver + + + + + + + + Save-SeScreenshot + Save + SeScreenshot + + Take a screenshot of the current page + + + + Take a screenshot of the current page + + + + Save-SeScreenshot + + Screenshot + + Screenshot element + + Screenshot + + Screenshot + + + None + + + Path + + Filepath where the image iwll be saved to. + + String + + String + + + None + + + ImageFormat + + Set the image format + + + Png + Jpeg + Gif + Tiff + Bmp + + ScreenshotImageFormat + + ScreenshotImageFormat + + + None + + + + + + ImageFormat + + Set the image format + + ScreenshotImageFormat + + ScreenshotImageFormat + + + None + + + Path + + Filepath where the image iwll be saved to. + + String + + String + + + None + + + Screenshot + + Screenshot element + + Screenshot + + Screenshot + + + None + + + + + + OpenQA.Selenium.Screenshot + + + + + + + + + + System.Object + + + + + + + + + + + + + + + + + Send-SeClick + Send + SeClick + + Send a click to the targeted element + + + + Send a click to the targeted element + + + + Send-SeClick + + Element + + Element for which the click will be performed upon + + IWebElement + + IWebElement + + + None + + + Driver + + Target webdriver + + Object + + Object + + + None + + + JavaScriptClick + + Use Javascript to perform the click + + + SwitchParameter + + + False + + + PassThru + + Return the IWebElement + + + SwitchParameter + + + False + + + SleepSeconds + + Sleep time in seconds after the click + + Object + + Object + + + None + + + + + + Driver + + Target webdriver + + Object + + Object + + + None + + + Element + + Element for which the click will be performed upon + + IWebElement + + IWebElement + + + None + + + JavaScriptClick + + Use Javascript to perform the click + + SwitchParameter + + SwitchParameter + + + False + + + PassThru + + Return the IWebElement + + SwitchParameter + + SwitchParameter + + + False + + + SleepSeconds + + Sleep time in seconds after the click + + Object + + Object + + + None + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> (Get-SeElement -By Name -Selection 'ButtonX') | Send-SeClick + + Select an element then send a click action on it. + + + + + + + + Send-SeKeys + Send + SeKeys + + Simulates typing text into the element + + + + Simulates typing text into the element. + The text to be typed may include special characters like arrow keys, backspaces, function keys, and so on. Valid special keys are defined in Keys. OpenQA_Selelnium_Keys (https://www.selenium.dev/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Keys.htm) + + + + Send-SeKeys + + Element + + Specify the element where the keys will be typed to + + IWebElement + + IWebElement + + + None + + + Keys + + Text to be typed. Special keys (Enter, arrow down, etc...) can be typed using double brackets (eg: `{{Enter}}`). See cmdlet description for complete list of keys + + String + + String + + + None + + + PassThru + + Return `$Element` + + + SwitchParameter + + + False + + + + + + Element + + Specify the element where the keys will be typed to + + IWebElement + + IWebElement + + + None + + + Keys + + Text to be typed. Special keys (Enter, arrow down, etc...) can be typed using double brackets (eg: `{{Enter}}`). See cmdlet description for complete list of keys + + String + + String + + + None + + + PassThru + + Return `$Element` + + SwitchParameter + + SwitchParameter + + + False + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru + + ype the defined text and a special key - Enter - defined in the special keys. + + + + + + + + Set-SeCookie + Set + SeCookie + + Add a cookie to the current browsing context + + + + Add a cookie to the current browsing context + + + + Set-SeCookie + + Name + + The name of the cookie + + String + + String + + + None + + + Value + + The value of the cookie + + String + + String + + + None + + + Path + + The path of the cookie + + String + + String + + + None + + + Domain + + The domain of the cookie + + String + + String + + + None + + + ExpiryDate + + The expiration date of the cookie + + Object + + Object + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + + + + Domain + + The domain of the cookie + + String + + String + + + None + + + ExpiryDate + + The expiration date of the cookie + + Object + + Object + + + None + + + Name + + The name of the cookie + + String + + String + + + None + + + Path + + The path of the cookie + + String + + String + + + None + + + Target + + Target webdriver + + Object + + Object + + + None + + + Value + + The value of the cookie + + String + + String + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + + + + Start-SeChrome + Start + SeChrome + + Initializes a new instance of the ChromeDriver class. + + + + Initializes a new instance of the ChromeDriver class. + + + + Start-SeChrome + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Chrome.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + DisableAutomationExtension + + Disable AutomationExtension notification + + + SwitchParameter + + + False + + + DisableBuiltInPDFViewer + + Obsolete. Use `-EnablePDFViewer` instead. + + Boolean + + Boolean + + + None + + + EnablePDFViewer + + Enable built in PDF Viewer (By default PDF will always open xternally) + + + SwitchParameter + + + False + + + Fullscreen + + Driver will open browser in a fullscreen state + + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Incognito + + Drive will open an incognito session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + FileInfo + + FileInfo + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + Start-SeChrome + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Chrome.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + DisableAutomationExtension + + Disable AutomationExtension notification + + + SwitchParameter + + + False + + + DisableBuiltInPDFViewer + + Obsolete. Use `-EnablePDFViewer` instead. + + Boolean + + Boolean + + + None + + + EnablePDFViewer + + Enable built in PDF Viewer (By default PDF will always open xternally) + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Incognito + + Drive will open an incognito session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + FileInfo + + FileInfo + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + Start-SeChrome + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Chrome.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + DisableAutomationExtension + + Disable AutomationExtension notification + + + SwitchParameter + + + False + + + DisableBuiltInPDFViewer + + Obsolete. Use `-EnablePDFViewer` instead. + + Boolean + + Boolean + + + None + + + EnablePDFViewer + + Enable built in PDF Viewer (By default PDF will always open xternally) + + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Incognito + + Drive will open an incognito session + + + SwitchParameter + + + False + + + Maximized + + Driver will open browser in a maximized state + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + FileInfo + + FileInfo + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + Start-SeChrome + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Chrome.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + DisableAutomationExtension + + Disable AutomationExtension notification + + + SwitchParameter + + + False + + + DisableBuiltInPDFViewer + + Obsolete. Use `-EnablePDFViewer` instead. + + Boolean + + Boolean + + + None + + + EnablePDFViewer + + Enable built in PDF Viewer (By default PDF will always open xternally) + + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Incognito + + Drive will open an incognito session + + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + FileInfo + + FileInfo + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + + + Arguments + + Adds arguments to be appended to the Chrome.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + + SwitchParameter + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + DisableAutomationExtension + + Disable AutomationExtension notification + + SwitchParameter + + SwitchParameter + + + False + + + DisableBuiltInPDFViewer + + Obsolete. Use `-EnablePDFViewer` instead. + + Boolean + + Boolean + + + None + + + EnablePDFViewer + + Enable built in PDF Viewer (By default PDF will always open xternally) + + SwitchParameter + + SwitchParameter + + + False + + + Fullscreen + + Driver will open browser in a fullscreen state + + SwitchParameter + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + SwitchParameter + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + SwitchParameter + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Incognito + + Drive will open an incognito session + + SwitchParameter + + SwitchParameter + + + False + + + Maximized + + Driver will open browser in a maximized state + + SwitchParameter + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + SwitchParameter + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + FileInfo + + FileInfo + + + None + + + Quiet + + Hide command prompt window + + SwitchParameter + + SwitchParameter + + + False + + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> $Driver = Start-SeChrome + + + + + + -------------------------- Example 2 -------------------------- + PS C:\> $Driver = Start-SeChrome -Incognito + + Run Chrome in incognito mode + + + + -------------------------- Example 3 -------------------------- + PS C:\> $Driver = Start-SeChrome -DefaultDownloadPath C:\Temp -StartURL 'https://www.google.com/ncr' + + Run Chrome with alternative download folder and set a specific starting URL + + + + -------------------------- Example 4 -------------------------- + PS C:\> $Driver = Start-SeChrome -Arguments @('Incognito','start-maximized') + + Run Chrome with multiple Arguments + + + + -------------------------- Example 5 -------------------------- + PS C:\> $Driver = Start-SeChrome -ProfileDirectoryPath '/home/<username>/.config/google-chrome' + + Run Chrome with an existing profile. The default profile paths are as follows: + Windows: C:\Users<username>\AppData\Local\Google\Chrome\User Data + Linux: /home/<username>/.config/google-chrome + MacOS: /Users/<username>/Library/Application Support/Google/Chrome + + + + + + + + Start-SeEdge + Start + SeEdge + + Initializes a new instance of the EdgeDriver class + + + + Initializes a new instance of the EdgeDriver class + + + + Start-SeEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + FullScreen + + Driver will open browser in a fullscreen state + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + + Start-SeEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + + Start-SeEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Minimized + + Driver will open browser in a minimized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + SwitchParameter + + SwitchParameter + + + False + + + FullScreen + + Driver will open browser in a fullscreen state + + SwitchParameter + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + SwitchParameter + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + SwitchParameter + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + SwitchParameter + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + SwitchParameter + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + SwitchParameter + + SwitchParameter + + + False + + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> $Driver = Start-SeEdge + + + + + + + + + + Start-SeFirefox + Start + SeFirefox + + Initializes a new instance of the FirefoxDriver class. + + + + Initializes a new instance of the FirefoxDriver class. + + + + Start-SeFirefox + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Firefox.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + Fullscreen + + Driver will open browser in a fullscreen state + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + SuppressLogging + + Set GeckoDriver log level to Fatal. + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + Start-SeFirefox + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Firefox.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + SuppressLogging + + Set GeckoDriver log level to Fatal. + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + Start-SeFirefox + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Firefox.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + SuppressLogging + + Set GeckoDriver log level to Fatal. + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + Start-SeFirefox + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + Arguments + + Adds arguments to be appended to the Firefox.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Minimized + + Driver will open browser in a minimized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + SuppressLogging + + Set GeckoDriver log level to Fatal. + + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + + + Arguments + + Adds arguments to be appended to the Firefox.exe command line. + + Array + + Array + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + SwitchParameter + + SwitchParameter + + + False + + + DefaultDownloadPath + + Set default download path + + FileInfo + + FileInfo + + + None + + + Fullscreen + + Driver will open browser in a fullscreen state + + SwitchParameter + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + SwitchParameter + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + SwitchParameter + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + SwitchParameter + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + SwitchParameter + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + SwitchParameter + + SwitchParameter + + + False + + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + SuppressLogging + + Set GeckoDriver log level to Fatal. + + SwitchParameter + + SwitchParameter + + + False + + + WebDriverDirectory + + Specify web driver custom service location + + Object + + Object + + + None + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + $Driver = Start-SeFirefox + + + + + + -------------------------- Example 2 -------------------------- + $Driver = Start-SeFirefox -PrivateBrowsing -DefaultDownloadPath 'c:\temp' -StartURL 'https://www.google.ca/ncr' + + Run Firefox in a private widnow using an alternate download path and set the starting URL + + + + + + + + Start-SeInternetExplorer + Start + SeInternetExplorer + + {{ Fill in the Synopsis }} + + + + {{ Fill in the Description }} + + + + Start-SeInternetExplorer + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + FullScreen + + Driver will open browser in a fullscreen state + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + IgnoreProtectedModeSettings + + {{ Fill IgnoreProtectedModeSettings Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeInternetExplorer + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + IgnoreProtectedModeSettings + + {{ Fill IgnoreProtectedModeSettings Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeInternetExplorer + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + IgnoreProtectedModeSettings + + {{ Fill IgnoreProtectedModeSettings Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeInternetExplorer + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + IgnoreProtectedModeSettings + + {{ Fill IgnoreProtectedModeSettings Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Minimized + + Driver will open browser in a minimized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeInternetExplorer + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + IgnoreProtectedModeSettings + + {{ Fill IgnoreProtectedModeSettings Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + SwitchParameter + + SwitchParameter + + + False + + + FullScreen + + Driver will open browser in a fullscreen state + + SwitchParameter + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + SwitchParameter + + SwitchParameter + + + False + + + IgnoreProtectedModeSettings + + {{ Fill IgnoreProtectedModeSettings Description }} + + SwitchParameter + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + SwitchParameter + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + SwitchParameter + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + SwitchParameter + + SwitchParameter + + + False + + + Quiet + + Hide command prompt window + + SwitchParameter + + SwitchParameter + + + False + + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Start-SeNewEdge + Start + SeNewEdge + + Initializes a new instance of the EdgeDriver class + + + + Initializes a new instance of the EdgeDriver class + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + Object + + Object + + + None + + + FullScreen + + Driver will open browser in a fullscreen state + + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + Object + + Object + + + None + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + Object + + Object + + + None + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + Object + + Object + + + None + + + HideVersionHint + + Hide download proper driver version message + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Minimized + + Driver will open browser in a minimized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + + + AsDefaultDriver + + Set $Global:SeDriver ot the current Driver and dispose previously set driver. + + SwitchParameter + + SwitchParameter + + + False + + + BinaryPath + + Set the location of the Chrome browser's binary executable file + + Object + + Object + + + None + + + DefaultDownloadPath + + Set default download path + + Object + + Object + + + None + + + FullScreen + + Driver will open browser in a fullscreen state + + SwitchParameter + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + SwitchParameter + + SwitchParameter + + + False + + + HideVersionHint + + Hide download proper driver version message + + SwitchParameter + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + SwitchParameter + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + SwitchParameter + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + SwitchParameter + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + SwitchParameter + + SwitchParameter + + + False + + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> $Driver = Start-SeNewEdge + + + + + + + + + + Start-SeNewEdge + Start + SeNewEdge + + {{ Fill in the Synopsis }} + + + + {{ Fill in the Description }} + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + Object + + Object + + + None + + + FullScreen + + Driver will open browser in a fullscreen state + + + SwitchParameter + + + False + + + HideVersionHint + + {{ Fill HideVersionHint Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + Object + + Object + + + None + + + Headless + + Start driver without any visual interface + + + SwitchParameter + + + False + + + HideVersionHint + + {{ Fill HideVersionHint Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + Object + + Object + + + None + + + HideVersionHint + + {{ Fill HideVersionHint Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + Start-SeNewEdge + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + + SwitchParameter + + + False + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + Object + + Object + + + None + + + HideVersionHint + + {{ Fill HideVersionHint Description }} + + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Minimized + + Driver will open browser in a minimized state + + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + + SwitchParameter + + + False + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + + + AsDefaultDriver + + {{ Fill AsDefaultDriver Description }} + + SwitchParameter + + SwitchParameter + + + False + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + Object + + Object + + + None + + + FullScreen + + Driver will open browser in a fullscreen state + + SwitchParameter + + SwitchParameter + + + False + + + Headless + + Start driver without any visual interface + + SwitchParameter + + SwitchParameter + + + False + + + HideVersionHint + + {{ Fill HideVersionHint Description }} + + SwitchParameter + + SwitchParameter + + + False + + + ImplicitWait + + Control timeout duration (in seconds) + + Int32 + + Int32 + + + None + + + Maximized + + Driver will open browser in a maximized state + + SwitchParameter + + SwitchParameter + + + False + + + Minimized + + Driver will open browser in a minimized state + + SwitchParameter + + SwitchParameter + + + False + + + PrivateBrowsing + + Driver will open a private session + + SwitchParameter + + SwitchParameter + + + False + + + ProfileDirectoryPath + + Driver will use the specified user profile path + + Object + + Object + + + None + + + Quiet + + Hide command prompt window + + SwitchParameter + + SwitchParameter + + + False + + + StartURL + + Define Driver starting URL + + String + + String + + + None + + + WebDriverDirectory + + {{ Fill WebDriverDirectory Description }} + + Object + + Object + + + None + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Stop-SeDriver + Stop + SeDriver + + Quits this driver, closing every associated window. + + + + Quits this driver, closing every associated window. + + + + Stop-SeDriver + + Target + + Driver to dispose. When `-AsDefaultDriver` is used with the Start-XXDriver cmdlet, this parameter can be omitted. + + IWebDriver + + IWebDriver + + + None + + + + + + Target + + Driver to dispose. When `-AsDefaultDriver` is used with the Start-XXDriver cmdlet, this parameter can be omitted. + + IWebDriver + + IWebDriver + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Stop-SeDriver -Target $Driver + + Stop the specified driver + + + + -------------------------- Example 1 -------------------------- + PS C:\> Start-SeChrome -AsDefaultDriver +PS C:\> Stop-SeDriver + + Stop the default driver, which was defined using the `-AsDefaultDriver` switch. + + + + + + + + Switch-SeFrame + Switch + SeFrame + + Instructs the driver to send future commands to a different frame + + + + Instructs the driver to send future commands to a different frame + + + + Switch-SeFrame + + Frame + + {{ Fill Frame Description }} + + Object + + Object + + + None + + + Target + + {{ Fill Target Description }} + + Object + + Object + + + None + + + + Switch-SeFrame + + Parent + + {{ Fill Parent Description }} + + + SwitchParameter + + + False + + + Target + + {{ Fill Target Description }} + + Object + + Object + + + None + + + + Switch-SeFrame + + Root + + {{ Fill Root Description }} + + + SwitchParameter + + + False + + + Target + + {{ Fill Target Description }} + + Object + + Object + + + None + + + + + + Frame + + {{ Fill Frame Description }} + + Object + + Object + + + None + + + Parent + + {{ Fill Parent Description }} + + SwitchParameter + + SwitchParameter + + + False + + + Root + + {{ Fill Root Description }} + + SwitchParameter + + SwitchParameter + + + False + + + Target + + {{ Fill Target Description }} + + Object + + Object + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Switch-SeWindow + Switch + SeWindow + + Instructs the driver to send future commands to a different window + + + + Instructs the driver to send future commands to a different window + + + + Switch-SeWindow + + Target + + {{ Fill Target Description }} + + IWebDriver + + IWebDriver + + + None + + + Window + + {{ Fill Window Description }} + + Object + + Object + + + None + + + + + + Target + + {{ Fill Target Description }} + + IWebDriver + + IWebDriver + + + None + + + Window + + {{ Fill Window Description }} + + Object + + Object + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + \ No newline at end of file diff --git a/Public/Clear-SeAlert.ps1 b/Public/Clear-SeAlert.ps1 new file mode 100644 index 0000000..8606730 --- /dev/null +++ b/Public/Clear-SeAlert.ps1 @@ -0,0 +1,23 @@ +function Clear-SeAlert { + [Alias('SeAccept', 'SeDismiss')] + param ( + [parameter(ParameterSetName = 'Alert', Position = 0, ValueFromPipeline = $true)] + $Alert, + [parameter(ParameterSetName = 'Driver')] + [ValidateIsWebDriverAttribute()] + [Alias("Driver")] + $Target = $Global:SeDriver, + [ValidateSet('Accept', 'Dismiss')] + $Action = 'Dismiss', + [Alias('PT')] + [switch]$PassThru + ) + if ($Target) { + try { $Alert = $Target.SwitchTo().alert() } + catch { Write-Warning 'No alert was displayed'; return } + } + if (-not $PSBoundParameters.ContainsKey('Action') -and + $MyInvocation.InvocationName -match 'Accept') { $Action = 'Accept' } + if ($Alert) { $alert.$action() } + if ($PassThru) { $Alert } +} \ No newline at end of file diff --git a/Public/Get-SeCookie.ps1 b/Public/Get-SeCookie.ps1 new file mode 100644 index 0000000..27908e3 --- /dev/null +++ b/Public/Get-SeCookie.ps1 @@ -0,0 +1,9 @@ +function Get-SeCookie { + param( + [Parameter(Mandatory = $false, ValueFromPipeline = $true)] + [Alias("Driver")] + [ValidateIsWebDriverAttribute()] + $Target = $Global:SeDriver + ) + $Target.Manage().Cookies.AllCookies.GetEnumerator() +} \ No newline at end of file diff --git a/Public/Get-SeElement.ps1 b/Public/Get-SeElement.ps1 new file mode 100644 index 0000000..cb1e07c --- /dev/null +++ b/Public/Get-SeElement.ps1 @@ -0,0 +1,48 @@ +function Get-SeElement { + [Alias('Find-SeElement', 'SeElement')] + param( + #Specifies whether the selction text is to select by name, ID, Xpath etc + [ValidateSet("CssSelector", "Name", "Id", "ClassName", "LinkText", "PartialLinkText", "TagName", "XPath")] + [ByTransformAttribute()] + [string]$By = "XPath", + #Text to select on + [Alias("CssSelector", "Name", "Id", "ClassName", "LinkText", "PartialLinkText", "TagName", "XPath")] + [Parameter(Position = 1, Mandatory = $true)] + [string]$Selection, + #Specifies a time out + [Parameter(Position = 2)] + [Int]$Timeout = 0, + #The driver or Element where the search should be performed. + [Parameter(Position = 3, ValueFromPipeline = $true)] + [Alias('Element', 'Driver')] + $Target = $Global:SeDriver, + + [parameter(DontShow)] + [Switch]$Wait + + ) + process { + #if one of the old parameter names was used and BY was NIT specified, look for + # [anything which doesn't mean end of command] -Param + # capture Param and set it as the value for by + $mi = $MyInvocation.InvocationName + if (-not $PSBoundParameters.ContainsKey("By") -and + ($MyInvocation.Line -match "$mi[^>\|;]*-(CssSelector|Name|Id|ClassName|LinkText|PartialLinkText|TagName|XPath)")) { + $By = $Matches[1] + } + if ($wait -and $Timeout -eq 0) { $Timeout = 30 } + + if ($TimeOut -and $Target -is [OpenQA.Selenium.Remote.RemoteWebDriver]) { + $TargetElement = [OpenQA.Selenium.By]::$By($Selection) + $WebDriverWait = [OpenQA.Selenium.Support.UI.WebDriverWait]::new($Target, (New-TimeSpan -Seconds $Timeout)) + $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists($TargetElement) + $WebDriverWait.Until($Condition) + } + elseif ($Target -is [OpenQA.Selenium.Remote.RemoteWebElement] -or + $Target -is [OpenQA.Selenium.Remote.RemoteWebDriver]) { + if ($Timeout) { Write-Warning "Timeout does not apply when searching an Element" } + $Target.FindElements([OpenQA.Selenium.By]::$By($Selection)) + } + else { throw "No valid target was provided." } + } +} \ No newline at end of file diff --git a/Public/Get-SeElementAttribute.ps1 b/Public/Get-SeElementAttribute.ps1 new file mode 100644 index 0000000..c0c984b --- /dev/null +++ b/Public/Get-SeElementAttribute.ps1 @@ -0,0 +1,11 @@ +function Get-SeElementAttribute { + param( + [Parameter(ValueFromPipeline = $true, Mandatory = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [Parameter(Mandatory = $true)] + [string]$Attribute + ) + process { + $Element.GetAttribute($Attribute) + } +} \ No newline at end of file diff --git a/Public/Get-SeElementCssValue.ps1 b/Public/Get-SeElementCssValue.ps1 new file mode 100644 index 0000000..5045bb1 --- /dev/null +++ b/Public/Get-SeElementCssValue.ps1 @@ -0,0 +1,12 @@ +function Get-SeElementCssValue { + param( + [Parameter(ValueFromPipeline = $true, Mandatory = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [Parameter(Mandatory = $true)] + [string]$Name + ) + + Process { + $Element.GetCssValue($Name) + } +} \ No newline at end of file diff --git a/Public/Get-SeKeys.ps1 b/Public/Get-SeKeys.ps1 new file mode 100644 index 0000000..1517a2b --- /dev/null +++ b/Public/Get-SeKeys.ps1 @@ -0,0 +1,3 @@ +function Get-SeKeys { + [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } +} \ No newline at end of file diff --git a/Public/Get-SeSelectionOption.ps1 b/Public/Get-SeSelectionOption.ps1 new file mode 100644 index 0000000..f9667cf --- /dev/null +++ b/Public/Get-SeSelectionOption.ps1 @@ -0,0 +1,90 @@ +function Get-SeSelectionOption { + [Alias('SeSelection')] + [cmdletbinding(DefaultParameterSetName = 'default')] + param ( + + [Parameter(Mandatory = $true, ParameterSetName = 'byValue', Position = 0, ValueFromPipelineByPropertyName = $true)] + [String]$ByValue, + + [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)] + [OpenQA.Selenium.IWebElement]$Element, + + [Parameter(Mandatory = $true, ParameterSetName = 'byText', ValueFromPipelineByPropertyName = $true)] + [String]$ByFullText, + + [Parameter(Mandatory = $true, ParameterSetName = 'bypart', ValueFromPipelineByPropertyName = $true)] + [String]$ByPartialText, + + [Parameter(Mandatory = $true, ParameterSetName = 'byIndex', ValueFromPipelineByPropertyName = $true)] + [int]$ByIndex, + + [Parameter(Mandatory = $false, ParameterSetName = 'default')] + [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] + [Parameter(Mandatory = $false, ParameterSetName = 'byText')] + [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] + [switch]$Clear, + + [Parameter(Mandatory = $false, ParameterSetName = 'default')] + [switch]$ListOptionText, + + [Parameter(Mandatory = $true, ParameterSetName = 'multi')] + [switch]$IsMultiSelect, + + [Parameter(Mandatory = $true, ParameterSetName = 'selected')] + [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] + [Parameter(Mandatory = $false, ParameterSetName = 'byText')] + [Parameter(Mandatory = $false, ParameterSetName = 'bypart')] + [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] + [switch]$GetSelected, + + [Parameter(Mandatory = $true, ParameterSetName = 'allSelected')] + [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] + [Parameter(Mandatory = $false, ParameterSetName = 'byText')] + [Parameter(Mandatory = $false, ParameterSetName = 'bypart')] + [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] + [switch]$GetAllSelected, + + [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] + [Parameter(Mandatory = $false, ParameterSetName = 'byText')] + [Parameter(Mandatory = $false, ParameterSetName = 'bypart')] + [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] + [Alias('PT')] + [switch]$PassThru + ) + try { + #byindex can be 0, but ByText and ByValue can't be empty strings + if ($ByFullText -or $ByPartialText -or $ByValue -or $PSBoundParameters.ContainsKey('ByIndex')) { + if ($Clear) { + if ($ByText) { [SeleniumSelection.Option]::DeselectByText($Element, $ByText) } + elseif ($ByValue) { [SeleniumSelection.Option]::DeselectByValue($Element, $ByValue) } + else { [SeleniumSelection.Option]::DeselectByIndex($Element, $ByIndex) } + } + else { + if ($ByText) { [SeleniumSelection.Option]::SelectByText($Element, $ByText, $false) } + if ($ByPartialText) { [SeleniumSelection.Option]::SelectByText($Element, $ByPartialText, $true) } + elseif ($ByValue) { [SeleniumSelection.Option]::SelectByValue($Element, $ByValue) } + else { [SeleniumSelection.Option]::SelectByIndex($Element, $ByIndex) } + } + } + elseif ($Clear) { [SeleniumSelection.Option]::DeselectAll($Element) } + if ($IsMultiSelect) { + return [SeleniumSelection.Option]::IsMultiSelect($Element) + } + if ($PassThru -and ($GetAllSelected -or $GetAllSelected)) { + Write-Warning -Message "-Passthru option ignored because other values are returned" + } + if ($GetSelected) { + return [SeleniumSelection.Option]::GetSelectedOption($Element).text + } + if ($GetAllSelected) { + return [SeleniumSelection.Option]::GetAllSelectedOptions($Element).text + } + if ($PSCmdlet.ParameterSetName -eq 'default') { + [SeleniumSelection.Option]::GetOptions($Element) | Select-Object -ExpandProperty Text + } + elseif ($PassThru) { $Element } + } + catch { + throw "An error occured checking the selection box, the message was:`r`n $($_.exception.message)" + } +} \ No newline at end of file diff --git a/Public/Get-SeWindow.ps1 b/Public/Get-SeWindow.ps1 new file mode 100644 index 0000000..c35a32a --- /dev/null +++ b/Public/Get-SeWindow.ps1 @@ -0,0 +1,12 @@ +function Get-SeWindow { + param( + [Parameter(Mandatory = $false, ValueFromPipeline = $true)] + [Alias('Driver')] + [OpenQA.Selenium.IWebDriver] + $Target = $Global:SeDriver + ) + + process { + $Target.WindowHandles + } +} \ No newline at end of file diff --git a/Public/Invoke-SeClick.ps1 b/Public/Invoke-SeClick.ps1 new file mode 100644 index 0000000..fcf1b19 --- /dev/null +++ b/Public/Invoke-SeClick.ps1 @@ -0,0 +1,28 @@ +function Invoke-SeClick { + [CmdletBinding(DefaultParameterSetName = 'Default')] + param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Default')] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'JavaScript')] + [OpenQA.Selenium.IWebElement]$Element, + + [Parameter(Mandatory = $true, ParameterSetName = 'JavaScript')] + [Switch]$JavaScriptClick, + + [Parameter(ParameterSetName = 'JavaScript')] + [ValidateIsWebDriverAttribute()] + $Driver = $global:SeDriver + ) + + if ($JavaScriptClick) { + try { + $Driver.ExecuteScript("arguments[0].click()", $Element) + } + catch { + $PSCmdlet.ThrowTerminatingError($_) + } + } + else { + $Element.Click() + } + +} \ No newline at end of file diff --git a/Public/Invoke-SeScreenshot.ps1 b/Public/Invoke-SeScreenshot.ps1 new file mode 100644 index 0000000..534ca33 --- /dev/null +++ b/Public/Invoke-SeScreenshot.ps1 @@ -0,0 +1,18 @@ +function Invoke-SeScreenshot { + param( + [Parameter(ValueFromPipeline = $true)] + [Alias("Driver")] + [ValidateIsWebDriverAttribute()] + $Target = $Global:SeDriver, + + [Parameter(Mandatory = $false)] + [Switch]$AsBase64EncodedString + ) + $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Target) + if ($AsBase64EncodedString) { + $Screenshot.AsBase64EncodedString + } + else { + $Screenshot + } +} \ No newline at end of file diff --git a/Public/New-SeScreenshot.ps1 b/Public/New-SeScreenshot.ps1 new file mode 100644 index 0000000..3173cb4 --- /dev/null +++ b/Public/New-SeScreenshot.ps1 @@ -0,0 +1,32 @@ +function New-SeScreenshot { + [Alias('SeScreenshot')] + [cmdletbinding(DefaultParameterSetName = 'Path')] + param( + [Parameter(ParameterSetName = 'Path' , Position = 0, Mandatory = $true)] + [Parameter(ParameterSetName = 'PassThru', Position = 0)] + $Path, + + [Parameter(ParameterSetName = 'Path', Position = 1)] + [Parameter(ParameterSetName = 'PassThru', Position = 1)] + [OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png, + + [Parameter(ValueFromPipeline = $true)] + [Alias("Driver")] + [ValidateIsWebDriverAttribute()] + $Target = $Global:SeDriver , + + [Parameter(ParameterSetName = 'Base64', Mandatory = $true)] + [Switch]$AsBase64EncodedString, + + [Parameter(ParameterSetName = 'PassThru', Mandatory = $true)] + [Alias('PT')] + [Switch]$PassThru + ) + $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Target) + if ($AsBase64EncodedString) { $Screenshot.AsBase64EncodedString } + elseif ($Path) { + $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) + $Screenshot.SaveAsFile($Path, $ImageFormat) + } + if ($Passthru) { $Screenshot } +} \ No newline at end of file diff --git a/Public/Open-SeUrl.ps1 b/Public/Open-SeUrl.ps1 new file mode 100644 index 0000000..c488579 --- /dev/null +++ b/Public/Open-SeUrl.ps1 @@ -0,0 +1,32 @@ +function Open-SeUrl { + [cmdletbinding(DefaultParameterSetName = 'default')] + [Alias('SeNavigate', "Enter-SeUrl")] + param( + [Parameter(Mandatory = $true, position = 0, ParameterSetName = 'url')] + [ValidateURIAttribute()] + [string]$Url, + + [Parameter(Mandatory = $true, ParameterSetName = 'back')] + [switch]$Back, + + [Parameter(Mandatory = $true, ParameterSetName = 'forward')] + [switch]$Forward, + + [Parameter(Mandatory = $true, ParameterSetName = 'refresh')] + [switch]$Refresh, + + [Parameter(ValueFromPipeline = $true)] + [Alias("Driver")] + [ValidateIsWebDriverAttribute()] + $Target = $Global:SeDriver + ) + + switch ($PSCmdlet.ParameterSetName) { + 'url' { $Target.Navigate().GoToUrl($Url); break } + 'back' { $Target.Navigate().Back(); break } + 'forward' { $Target.Navigate().Forward(); break } + 'refresh' { $Target.Navigate().Refresh(); break } + + default { throw 'Unexpected ParameterSet' } + } +} \ No newline at end of file diff --git a/Public/Remove-SeCookie.ps1 b/Public/Remove-SeCookie.ps1 new file mode 100644 index 0000000..2ca0321 --- /dev/null +++ b/Public/Remove-SeCookie.ps1 @@ -0,0 +1,22 @@ +function Remove-SeCookie { + param( + [Parameter(Mandatory = $false, ValueFromPipeline = $true)] + [Alias('Driver')] + [OpenQA.Selenium.IWebDriver] + $Target = $Global:SeDriver, + + [Parameter(Mandatory = $true, ParameterSetName = 'DeleteAllCookies')] + [Alias('Purge')] + [switch]$DeleteAllCookies, + + [Parameter(Mandatory = $true, ParameterSetName = 'NamedCookie')] + [string]$Name + ) + + if ($DeleteAllCookies) { + $Target.Manage().Cookies.DeleteAllCookies() + } + else { + $Target.Manage().Cookies.DeleteCookieNamed($Name) + } +} \ No newline at end of file diff --git a/Public/Save-SeScreenshot.ps1 b/Public/Save-SeScreenshot.ps1 new file mode 100644 index 0000000..9ff37ef --- /dev/null +++ b/Public/Save-SeScreenshot.ps1 @@ -0,0 +1,13 @@ +function Save-SeScreenshot { + param( + [Parameter(ValueFromPipeline = $true, Mandatory = $true)] + [OpenQA.Selenium.Screenshot]$Screenshot, + [Parameter(Mandatory = $true)] + [string]$Path, + [Parameter()] + [OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png) + + process { + $Screenshot.SaveAsFile($Path, $ImageFormat) + } +} \ No newline at end of file diff --git a/Public/SeOpen.ps1 b/Public/SeOpen.ps1 new file mode 100644 index 0000000..744c509 --- /dev/null +++ b/Public/SeOpen.ps1 @@ -0,0 +1,37 @@ +function SeOpen { + [CmdletBinding()] + Param( + [ValidateSet('Chrome', 'CrEdge', 'FireFox', 'InternetExplorer', 'IE', 'MSEdge', 'NewEdge')] + $In, + [ValidateURIAttribute()] + [Parameter(Mandatory = $False, Position = 1)] + $URL, + [hashtable]$Options = @{'Quiet' = $true }, + [int]$SleepSeconds + ) + #Allow the browser to specified in an Environment variable if not passed as a parameter + if ($env:DefaultBrowser -and -not $PSBoundParameters.ContainsKey('In')) { + $In = $env:DefaultBrowser + } + #It may have been passed as a parameter, in an environment variable, or a parameter default, but if not, bail out + if (-not $In) { throw 'No Browser was selected' } + $StartParams = @{ } + $StartParams += $Options + $StartParams['AsDefaultDriver'] = $true + $StartParams['Verbose'] = $false + $StartParams['ErrorAction'] = 'Stop' + $StartParams['Quiet'] = $true + if ($url) { + $StartParams['StartUrl'] = $url + } + + switch -regex ($In) { + 'Chrome' { Start-SeChrome @StartParams; continue } + 'FireFox' { Start-SeFirefox @StartParams; continue } + 'MSEdge' { Start-SeEdge @StartParams; continue } + 'Edge$' { Start-SeNewEdge @StartParams; continue } + '^I' { Start-SeInternetExplorer @StartParams; continue } + } + Write-Verbose -Message "Opened $($Global:SeDriver.Capabilities.browsername) $($Global:SeDriver.Capabilities.ToDictionary().browserVersion)" + if ($SleepSeconds) { Start-Sleep -Seconds $SleepSeconds } +} \ No newline at end of file diff --git a/Public/SeShouldHave.ps1 b/Public/SeShouldHave.ps1 new file mode 100644 index 0000000..09873ab --- /dev/null +++ b/Public/SeShouldHave.ps1 @@ -0,0 +1,192 @@ +function SeShouldHave { + [cmdletbinding(DefaultParameterSetName = 'DefaultPS')] + param( + [Parameter(ParameterSetName = 'DefaultPS', Mandatory = $true , Position = 0, ValueFromPipeline = $true)] + [Parameter(ParameterSetName = 'Element' , Mandatory = $true , Position = 0, ValueFromPipeline = $true)] + [string[]]$Selection, + + [Parameter(ParameterSetName = 'DefaultPS', Mandatory = $false)] + [Parameter(ParameterSetName = 'Element' , Mandatory = $false)] + [ValidateSet('CssSelector', 'Name', 'Id', 'ClassName', 'LinkText', 'PartialLinkText', 'TagName', 'XPath')] + [ByTransformAttribute()] + [string]$By = 'XPath', + + [Parameter(ParameterSetName = 'Element' , Mandatory = $true , Position = 1)] + [string]$With, + + [Parameter(ParameterSetName = 'Alert' , Mandatory = $true)] + [switch]$Alert, + [Parameter(ParameterSetName = 'NoAlert' , Mandatory = $true)] + [switch]$NoAlert, + [Parameter(ParameterSetName = 'Title' , Mandatory = $true)] + [switch]$Title, + [Parameter(ParameterSetName = 'URL' , Mandatory = $true)] + [Alias('URI')] + [switch]$URL, + + [Parameter(ParameterSetName = 'Element' , Mandatory = $false, Position = 3)] + [Parameter(ParameterSetName = 'Alert' , Mandatory = $false, Position = 3)] + [Parameter(ParameterSetName = 'Title' , Mandatory = $false, Position = 3)] + [Parameter(ParameterSetName = 'URL' , Mandatory = $false, Position = 3)] + [ValidateSet('like', 'notlike', 'match', 'notmatch', 'contains', 'eq', 'ne', 'gt', 'lt')] + [OperatorTransformAttribute()] + [String]$Operator = 'like', + + [Parameter(ParameterSetName = 'Element' , Mandatory = $false, Position = 4)] + [Parameter(ParameterSetName = 'Alert' , Mandatory = $false, Position = 4)] + [Parameter(ParameterSetName = 'Title' , Mandatory = $true , Position = 4)] + [Parameter(ParameterSetName = 'URL' , Mandatory = $true , Position = 4)] + [Alias('contains', 'like', 'notlike', 'match', 'notmatch', 'eq', 'ne', 'gt', 'lt')] + [AllowEmptyString()] + $Value, + + [Parameter(ParameterSetName = 'DefaultPS')] + [Parameter(ParameterSetName = 'Element')] + [Parameter(ParameterSetName = 'Alert')] + [Alias('PT')] + [switch]$PassThru, + + [Int]$Timeout = 0 + ) + begin { + $endTime = [datetime]::now.AddSeconds($Timeout) + $lineText = $MyInvocation.Line.TrimEnd("$([System.Environment]::NewLine)") + $lineNo = $MyInvocation.ScriptLineNumber + $file = $MyInvocation.ScriptName + Function expandErr { + param ($message) + [Management.Automation.ErrorRecord]::new( + [System.Exception]::new($message), + 'PesterAssertionFailed', + [Management.Automation.ErrorCategory]::InvalidResult, + @{ + Message = $message + File = $file + Line = $lineNo + Linetext = $lineText + } + ) + } + function applyTest { + param( + $Testitems, + $Operator, + $Value + ) + Switch ($Operator) { + 'Contains' { return ($testitems -contains $Value) } + 'eq' { return ($TestItems -eq $Value) } + 'ne' { return ($TestItems -ne $Value) } + 'like' { return ($TestItems -like $Value) } + 'notlike' { return ($TestItems -notlike $Value) } + 'match' { return ($TestItems -match $Value) } + 'notmatch' { return ($TestItems -notmatch $Value) } + 'gt' { return ($TestItems -gt $Value) } + 'le' { return ($TestItems -lt $Value) } + } + } + + #if operator was not passed, allow it to be taken from an alias for the -value + if (-not $PSBoundParameters.ContainsKey('operator') -and $lineText -match ' -(eq|ne|contains|match|notmatch|like|notlike|gt|lt) ') { + $Operator = $matches[1] + } + $Success = $false + $foundElements = @() + } + process { + #If we have been asked to check URL or title get them from the driver. Otherwise call Get-SEElement. + if ($URL) { + do { + $Success = applyTest -testitems $Global:SeDriver.Url -operator $Operator -value $Value + Start-Sleep -Milliseconds 500 + } + until ($Success -or [datetime]::now -gt $endTime) + if (-not $Success) { + throw (expandErr "PageURL was $($Global:SeDriver.Url). The comparison '-$operator $value' failed.") + } + } + elseif ($Title) { + do { + $Success = applyTest -testitems $Global:SeDriver.Title -operator $Operator -value $Value + Start-Sleep -Milliseconds 500 + } + until ($Success -or [datetime]::now -gt $endTime) + if (-not $Success) { + throw (expandErr "Page title was $($Global:SeDriver.Title). The comparison '-$operator $value' failed.") + } + } + elseif ($Alert -or $NoAlert) { + do { + try { + $a = $Global:SeDriver.SwitchTo().alert() + $Success = $true + } + catch { + Start-Sleep -Milliseconds 500 + } + finally { + if ($NoAlert -and $a) { throw (expandErr "Expected no alert but an alert of '$($a.Text)' was displayed") } + } + } + until ($Success -or [datetime]::now -gt $endTime) + + if ($Alert -and -not $Success) { + throw (expandErr "Expected an alert but but none was displayed") + } + elseif ($value -and -not (applyTest -testitems $a.text -operator $Operator -value $value)) { + throw (expandErr "Alert text was $($a.text). The comparison '-$operator $value' failed.") + } + elseif ($PassThru) { return $a } + } + else { + foreach ($s in $Selection) { + $GSEParams = @{By = $By; Selection = $s } + if ($Timeout) { $GSEParams['Timeout'] = $Timeout } + try { $e = Get-SeElement @GSEParams } + catch { throw (expandErr $_.Exception.Message) } + + #throw if we didn't get the element; if were only asked to check it was there, return gracefully + if (-not $e) { throw (expandErr "Didn't find '$s' by $by") } + else { + Write-Verbose "Matched element(s) for $s" + $foundElements += $e + } + } + } + } + end { + if ($PSCmdlet.ParameterSetName -eq "DefaultPS" -and $PassThru) { return $e } + elseif ($PSCmdlet.ParameterSetName -eq "DefaultPS") { return } + else { + foreach ($e in $foundElements) { + switch ($with) { + 'Text' { $testItem = $e.Text } + 'Displayed' { $testItem = $e.Displayed } + 'Enabled' { $testItem = $e.Enabled } + 'TagName' { $testItem = $e.TagName } + 'X' { $testItem = $e.Location.X } + 'Y' { $testItem = $e.Location.Y } + 'Width' { $testItem = $e.Size.Width } + 'Height' { $testItem = $e.Size.Height } + 'Choice' { $testItem = (Get-SeSelectionOption -Element $e -ListOptionText) } + default { $testItem = $e.GetAttribute($with) } + } + if (-not $testItem -and ($Value -ne '' -and $foundElements.count -eq 1)) { + throw (expandErr "Didn't find '$with' on element") + } + if (applyTest -testitems $testItem -operator $Operator -value $Value) { + $Success = $true + if ($PassThru) { $e } + } + } + if (-not $Success) { + if ($foundElements.count -gt 1) { + throw (expandErr "$Selection match $($foundElements.Count) elements, none has a value for $with which passed the comparison '-$operator $value'.") + } + else { + throw (expandErr "$with had a value of $testitem which did not pass the the comparison '-$operator $value'.") + } + } + } + } +} \ No newline at end of file diff --git a/Public/SeType.ps1 b/Public/SeType.ps1 new file mode 100644 index 0000000..ef24913 --- /dev/null +++ b/Public/SeType.ps1 @@ -0,0 +1,27 @@ +function SeType { + param( + [Parameter(Mandatory = $true, Position = 0)] + [string]$Keys, + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [switch]$ClearFirst, + $SleepSeconds = 0 , + [switch]$Submit, + [Alias('PT')] + [switch]$PassThru + ) + begin { + foreach ($Key in $Script:SeKeys.Name) { + $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key + } + } + process { + if ($ClearFirst) { $Element.Clear() } + + $Element.SendKeys($Keys) + + if ($Submit) { $Element.Submit() } + if ($SleepSeconds) { Start-Sleep -Seconds $SleepSeconds } + if ($PassThru) { $Element } + } +} \ No newline at end of file diff --git a/Public/Send-SeClick.ps1 b/Public/Send-SeClick.ps1 new file mode 100644 index 0000000..b69d50b --- /dev/null +++ b/Public/Send-SeClick.ps1 @@ -0,0 +1,20 @@ +function Send-SeClick { + [alias('SeClick')] + param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] + [OpenQA.Selenium.IWebElement]$Element, + [Alias('JS')] + [Switch]$JavaScriptClick, + $SleepSeconds = 0 , + [Parameter(DontShow)] + $Driver, + [Alias('PT')] + [switch]$PassThru + ) + Process { + if ($JavaScriptClick) { $Element.WrappedDriver.ExecuteScript("arguments[0].click()", $Element) } + else { $Element.Click() } + if ($SleepSeconds) { Start-Sleep -Seconds $SleepSeconds } + if ($PassThru) { $Element } + } +} \ No newline at end of file diff --git a/Public/Send-SeKeys.ps1 b/Public/Send-SeKeys.ps1 new file mode 100644 index 0000000..3616381 --- /dev/null +++ b/Public/Send-SeKeys.ps1 @@ -0,0 +1,16 @@ +function Send-SeKeys { + param( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [Parameter(Mandatory = $true, Position = 1)] + [string]$Keys, + [Parameter()] + [Alias('PT')] + [switch]$PassThru + ) + foreach ($Key in $Script:SeKeys.Name) { + $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key + } + $Element.SendKeys($Keys) + if ($PassThru) { $Element } +} \ No newline at end of file diff --git a/Public/Set-SeCookie.ps1 b/Public/Set-SeCookie.ps1 new file mode 100644 index 0000000..56a71d8 --- /dev/null +++ b/Public/Set-SeCookie.ps1 @@ -0,0 +1,65 @@ +function Set-SeCookie { + [cmdletbinding()] + param( + [string]$Name, + [string]$Value, + [string]$Path, + [string]$Domain, + $ExpiryDate, + + [Parameter(ValueFromPipeline = $true)] + [Alias("Driver")] + [ValidateIsWebDriverAttribute()] + $Target = $Global:SeDriver + ) + + <# Selenium Cookie Information + Cookie(String, String) + Initializes a new instance of the Cookie class with a specific name and value. + Cookie(String, String, String) + Initializes a new instance of the Cookie class with a specific name, value, and path. + 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. + #> + + begin { + if ($null -ne $ExpiryDate -and $ExpiryDate.GetType().Name -ne 'DateTime') { + throw '$ExpiryDate can only be $null or TypeName: System.DateTime' + } + } + + process { + if ($Name -and $Value -and (!$Path -and !$Domain -and !$ExpiryDate)) { + $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value) + } + Elseif ($Name -and $Value -and $Path -and (!$Domain -and !$ExpiryDate)) { + $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Path) + } + Elseif ($Name -and $Value -and $Path -and $ExpiryDate -and !$Domain) { + $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Path, $ExpiryDate) + } + Elseif ($Name -and $Value -and $Path -and $Domain -and (!$ExpiryDate -or $ExpiryDate)) { + if ($Target.Url -match $Domain) { + $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Domain, $Path, $ExpiryDate) + } + else { + Throw 'In order to set the cookie the browser needs to be on the cookie domain URL' + } + } + else { + Throw "Incorrect Cookie Layout: + Cookie(String, String) + Initializes a new instance of the Cookie class with a specific name and value. + Cookie(String, String, String) + Initializes a new instance of the Cookie class with a specific name, value, and path. + 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." + } + + $Target.Manage().Cookies.AddCookie($cookie) + } +} \ No newline at end of file diff --git a/Public/Start-SeChrome.ps1 b/Public/Start-SeChrome.ps1 new file mode 100644 index 0000000..c1d4522 --- /dev/null +++ b/Public/Start-SeChrome.ps1 @@ -0,0 +1,121 @@ +function Start-SeChrome { + [cmdletbinding(DefaultParameterSetName = 'default')] + [Alias('SeChrome')] + param( + [ValidateURIAttribute()] + [Parameter(Position = 0)] + [string]$StartURL, + [Parameter(Mandatory = $false)] + [array]$Arguments, + [switch]$HideVersionHint, + [System.IO.FileInfo]$DefaultDownloadPath, + [System.IO.FileInfo]$ProfileDirectoryPath, + [Parameter(DontShow)] + [bool]$DisableBuiltInPDFViewer = $true, + [switch]$EnablePDFViewer, + [Alias('PrivateBrowsing')] + [switch]$Incognito, + [parameter(ParameterSetName = 'Headless', Mandatory = $true)] + [switch]$Headless, + [parameter(ParameterSetName = 'Minimized', Mandatory = $true)] + [switch]$Maximized, + [parameter(ParameterSetName = 'Maximized', Mandatory = $true)] + [switch]$Minimized, + [parameter(ParameterSetName = 'Fullscreen', Mandatory = $true)] + [switch]$Fullscreen, + [switch]$DisableAutomationExtension, + [Alias('ChromeBinaryPath')] + $BinaryPath, + $WebDriverDirectory = $env:ChromeWebDriver, + [switch]$Quiet, + [switch]$AsDefaultDriver, + [int]$ImplicitWait = 10 + ) + + process { + #region chrome set-up options + $Chrome_Options = [OpenQA.Selenium.Chrome.ChromeOptions]::new() + + if ($DefaultDownloadPath) { + Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" + $Chrome_Options.AddUserProfilePreference('download', @{'default_directory' = $($DefaultDownloadPath.FullName); 'prompt_for_download' = $false; }) + } + + if ($ProfileDirectoryPath) { + Write-Verbose "Setting Profile directory: $ProfileDirectoryPath" + $Chrome_Options.AddArgument("user-data-dir=$ProfileDirectoryPath") + } + + if ($BinaryPath) { + Write-Verbose "Setting Chrome Binary directory: $BinaryPath" + $Chrome_Options.BinaryLocation = "$BinaryPath" + } + + if ($DisableBuiltInPDFViewer -and -not $EnablePDFViewer) { + $Chrome_Options.AddUserProfilePreference('plugins', @{'always_open_pdf_externally' = $true; }) + } + + if ($Headless) { + $Chrome_Options.AddArguments('headless') + } + + if ($Incognito) { + $Chrome_Options.AddArguments('Incognito') + } + + if ($Maximized) { + $Chrome_Options.AddArguments('start-maximized') + } + + if ($Fullscreen) { + $Chrome_Options.AddArguments('start-fullscreen') + } + + if ($DisableAutomationExtension) { + $Chrome_Options.AddAdditionalCapability('useAutomationExtension', $false) + $Chrome_Options.AddExcludedArgument('enable-automation') + } + + if ($Arguments) { + foreach ($Argument in $Arguments) { + $Chrome_Options.AddArguments($Argument) + } + } + + if (!$HideVersionHint) { + Write-Verbose "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" + } + + if ($WebDriverDirectory) { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($WebDriverDirectory) } + elseif ($AssembliesPath) { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($AssembliesPath) } + else { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService() } + if ($Quiet) { $service.HideCommandPromptWindow = $true } + #endregion + + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $Chrome_Options) + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + + #region post creation options + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + + if ($Minimized) { + $Driver.Manage().Window.Minimize(); + } + + if ($Headless -and $DefaultDownloadPath) { + $HeadlessDownloadParams = [system.collections.generic.dictionary[[System.String], [System.Object]]]::new() + $HeadlessDownloadParams.Add('behavior', 'allow') + $HeadlessDownloadParams.Add('downloadPath', $DefaultDownloadPath.FullName) + $Driver.ExecuteChromeCommand('Page.setDownloadBehavior', $HeadlessDownloadParams) + } + + if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } + #endregion + + if ($AsDefaultDriver) { + if ($Global:SeDriver) { $Global:SeDriver.Dispose() } + $Global:SeDriver = $Driver + } + else { $Driver } + } +} \ No newline at end of file diff --git a/Public/Start-SeEdge.ps1 b/Public/Start-SeEdge.ps1 new file mode 100644 index 0000000..e5466eb --- /dev/null +++ b/Public/Start-SeEdge.ps1 @@ -0,0 +1,54 @@ +function Start-SeEdge { + [cmdletbinding(DefaultParameterSetName = 'default')] + [Alias('MSEdge', 'LegacyEdge', 'Start-SeLegacyEdge')] + param( + [ValidateURIAttribute()] + [Parameter(Position = 0)] + [string]$StartURL, + [parameter(ParameterSetName = 'Minimized', Mandatory = $true)] + [switch]$Maximized, + [parameter(ParameterSetName = 'Maximized', Mandatory = $true)] + [switch]$Minimized, + [parameter(ParameterSetName = 'Fullscreen', Mandatory = $true)] + [switch]$FullScreen, + [Alias('Incognito')] + [switch]$PrivateBrowsing, + [switch]$Quiet, + [switch]$AsDefaultDriver, + [Parameter(DontShow)] + [switch]$Headless, + [int]$ImplicitWait = 10 + ) + #region Edge set-up options + if ($Headless) { Write-Warning 'Pre-Chromium Edge does not support headless operation; the Headless switch is ignored' } + $service = [OpenQA.Selenium.Edge.EdgeDriverService]::CreateDefaultService() + $options = [OpenQA.Selenium.Edge.EdgeOptions]::new() + if ($Quiet) { $service.HideCommandPromptWindow = $true } + if ($PrivateBrowsing) { $options.UseInPrivateBrowsing = $true } + if ($StartURL) { $options.StartPage = $StartURL } + #endregion + + try { + $Driver = [OpenQA.Selenium.Edge.EdgeDriver]::new($service , $options) + } + catch { + $driverversion = (Get-Item .\assemblies\MicrosoftWebDriver.exe).VersionInfo.ProductVersion + $WindowsVersion = [System.Environment]::OSVersion.Version.ToString() + Write-Warning -Message "Edge driver is $driverversion. Windows is $WindowsVersion. If the driver is out-of-date, update it as a Windows feature,`r`nand then delete $PSScriptRoot\assemblies\MicrosoftWebDriver.exe" + throw $_ ; return + } + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + + #region post creation options + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($Minimized) { $Driver.Manage().Window.Minimize() } + if ($Maximized) { $Driver.Manage().Window.Maximize() } + if ($FullScreen) { $Driver.Manage().Window.FullScreen() } + #endregion + + if ($AsDefaultDriver) { + if ($Global:SeDriver) { $Global:SeDriver.Dispose() } + $Global:SeDriver = $Driver + } + else { $Driver } +} \ No newline at end of file diff --git a/Public/Start-SeFirefox.ps1 b/Public/Start-SeFirefox.ps1 new file mode 100644 index 0000000..1f8fccc --- /dev/null +++ b/Public/Start-SeFirefox.ps1 @@ -0,0 +1,78 @@ +function Start-SeFirefox { + [cmdletbinding(DefaultParameterSetName = 'default')] + [Alias('SeFirefox')] + param( + [ValidateURIAttribute()] + [Parameter(Position = 0)] + [string]$StartURL, + [array]$Arguments, + [System.IO.FileInfo]$DefaultDownloadPath, + [alias('Incognito')] + [switch]$PrivateBrowsing, + [parameter(ParameterSetName = 'Headless', Mandatory = $true)] + [switch]$Headless, + [parameter(ParameterSetName = 'Minimized', Mandatory = $true)] + [switch]$Maximized, + [parameter(ParameterSetName = 'Maximized', Mandatory = $true)] + [switch]$Minimized, + [parameter(ParameterSetName = 'Fullscreen', Mandatory = $true)] + [switch]$Fullscreen, + [switch]$SuppressLogging, + [switch]$Quiet, + [switch]$AsDefaultDriver, + [int]$ImplicitWait = 10, + $WebDriverDirectory = $env:GeckoWebDriver + ) + process { + #region firefox set-up options + $Firefox_Options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new() + + if ($Headless) { + $Firefox_Options.AddArguments('-headless') + } + + if ($DefaultDownloadPath) { + Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" + $Firefox_Options.setPreference("browser.download.folderList", 2); + $Firefox_Options.SetPreference("browser.download.dir", "$DefaultDownloadPath"); + } + + if ($PrivateBrowsing) { + $Firefox_Options.SetPreference("browser.privatebrowsing.autostart", $true) + } + + if ($Arguments) { + foreach ($Argument in $Arguments) { + $Firefox_Options.AddArguments($Argument) + } + } + + if ($SuppressLogging) { + # Sets GeckoDriver log level to Fatal. + $Firefox_Options.LogLevel = 6 + } + + if ($WebDriverDirectory) { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService($WebDriverDirectory) } + elseif ($AssembliesPath) { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService($AssembliesPath) } + else { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService() } + if ($Quiet) { $service.HideCommandPromptWindow = $true } + #endregion + + $Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Firefox_Options) + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + + #region post creation options + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($Minimized) { $Driver.Manage().Window.Minimize() } + if ($Maximized) { $Driver.Manage().Window.Maximize() } + if ($Fullscreen) { $Driver.Manage().Window.FullScreen() } + if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } + #endregion + + if ($AsDefaultDriver) { + if ($Global:SeDriver) { $Global:SeDriver.Dispose() } + $Global:SeDriver = $Driver + } + else { $Driver } + } +} \ No newline at end of file diff --git a/Public/Start-SeInternetExplorer.ps1 b/Public/Start-SeInternetExplorer.ps1 new file mode 100644 index 0000000..3d45065 --- /dev/null +++ b/Public/Start-SeInternetExplorer.ps1 @@ -0,0 +1,62 @@ +function Start-SeInternetExplorer { + [cmdletbinding(DefaultParameterSetName = 'Default')] + [Alias('SeInternetExplorer', 'SeIE')] + param( + [ValidateURIAttribute()] + [Parameter(Position = 0)] + [string]$StartURL, + [switch]$Quiet, + [switch]$AsDefaultDriver, + [parameter(ParameterSetName = 'Maximized', Mandatory = $true)] + [switch]$Maximized, + [parameter(ParameterSetName = 'Minimized', Mandatory = $true)] + [switch]$Minimized, + [parameter(ParameterSetName = 'Fullscreen', Mandatory = $true)] + [switch]$FullScreen, + [Parameter(DontShow)] + [parameter(ParameterSetName = 'Headless', Mandatory = $true)] + [switch]$Headless, + [Parameter(DontShow)] + [Alias('Incognito')] + [switch]$PrivateBrowsing, + [switch]$IgnoreProtectedModeSettings, + [int]$ImplicitWait = 10, + $WebDriverDirectory = $env:IEWebDriver + ) + #region IE set-up options + if ($Headless -or $PrivateBrowsing) { Write-Warning 'The Internet explorer driver does not support headless or Inprivate operation; these switches are ignored' } + + $InternetExplorer_Options = [OpenQA.Selenium.IE.InternetExplorerOptions]::new() + $InternetExplorer_Options.IgnoreZoomLevel = $true + if ($IgnoreProtectedModeSettings) { + $InternetExplorer_Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true + } + + if ($StartURL) { $InternetExplorer_Options.InitialBrowserUrl = $StartURL } + if ($WebDriverDirectory) { $Service = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService($WebDriverDirectory) } + else { $Service = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService() } + if ($Quiet) { $Service.HideCommandPromptWindow = $true } + #endregion + + $Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $InternetExplorer_Options) + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + + #region post creation options + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($Minimized) { + $Driver.Manage().Window.Minimize(); + } + if ($Maximized) { + $Driver.Manage().Window.Maximize() + } + if ($FullScreen) { + $Driver.Manage().Window.FullScreen() + } + #endregion + + if ($AsDefaultDriver) { + if ($Global:SeDriver) { $Global:SeDriver.Dispose() } + $Global:SeDriver = $Driver + } + else { $Driver } +} \ No newline at end of file diff --git a/Public/Start-SeNewEdge.ps1 b/Public/Start-SeNewEdge.ps1 new file mode 100644 index 0000000..72f5bc8 --- /dev/null +++ b/Public/Start-SeNewEdge.ps1 @@ -0,0 +1,121 @@ +function Start-SeNewEdge { + [cmdletbinding(DefaultParameterSetName = 'default')] + [Alias('CrEdge', 'NewEdge')] + param( + [ValidateURIAttribute()] + [Parameter(Position = 0)] + [string]$StartURL, + [switch]$HideVersionHint, + [parameter(ParameterSetName = 'Minimized', Mandatory = $true)] + [switch]$Minimized, + [parameter(ParameterSetName = 'Maximized', Mandatory = $true)] + [switch]$Maximized, + [parameter(ParameterSetName = 'Fullscreen', Mandatory = $true)] + [switch]$FullScreen, + [parameter(ParameterSetName = 'Headless', Mandatory = $true)] + [switch]$Headless, + $BinaryPath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", + $ProfileDirectoryPath, + $DefaultDownloadPath, + [switch]$AsDefaultDriver, + [switch]$Quiet, + [Alias('Incognito')] + [switch]$PrivateBrowsing, + [int]$ImplicitWait = 10, + $WebDriverDirectory = $env:EdgeWebDriver + ) + $OptionSettings = @{ browserName = '' } + #region check / set paths for browser and web driver and edge options + if ($PSBoundParameters['BinaryPath'] -and -not (Test-Path -Path $BinaryPath)) { + throw "Could not find $BinaryPath"; return + } + + #Were we given a driver location and is msedgedriver there ? + #If were were given a location (which might be from an environment variable) is the driver THERE ? + # if not, were we given a path for the browser executable, and is the driver THERE ? + # and if not there either, is there one in the assemblies sub dir ? And if not bail + if ($WebDriverDirectory -and -not (Test-Path -Path (Join-Path -Path $WebDriverDirectory -ChildPath 'msedgedriver.exe'))) { + throw "Could not find msedgedriver.exe in $WebDriverDirectory"; return + } + elseif ($WebDriverDirectory -and (Test-Path (Join-Path -Path $WebDriverDirectory -ChildPath 'msedge.exe'))) { + Write-Verbose -Message "Using browser from $WebDriverDirectory" + $optionsettings['BinaryLocation'] = Join-Path -Path $WebDriverDirectory -ChildPath 'msedge.exe' + } + elseif ($BinaryPath) { + $optionsettings['BinaryLocation'] = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($BinaryPath) + $binaryDir = Split-Path -Path $BinaryPath -Parent + Write-Verbose -Message "Will request $($OptionSettings['BinaryLocation']) as the browser" + } + if (-not $WebDriverDirectory -and $binaryDir -and (Test-Path (Join-Path -Path $binaryDir -ChildPath 'msedgedriver.exe'))) { + $WebDriverDirectory = $binaryDir + } + # No linux or mac driver to test for yet + if (-not $WebDriverDirectory -and (Test-Path (Join-Path -Path "$PSScriptRoot\Assemblies\" -ChildPath 'msedgedriver.exe'))) { + $WebDriverDirectory = "$PSScriptRoot\Assemblies\" + Write-Verbose -Message "Using Web driver from the default location" + } + if (-not $WebDriverDirectory) { throw "Could not find msedgedriver.exe"; return } + + # The "credge" web driver will work with the edge selenium objects, but works better with the chrome ones. + $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($WebDriverDirectory, 'msedgedriver.exe') + $options = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeOptions -Property $OptionSettings + #The command line args may now be --inprivate --headless but msedge driver V81 does not pass them + if ($PrivateBrowsing) { $options.AddArguments('InPrivate') } + if ($Headless) { $options.AddArguments('headless') } + if ($Quiet) { $service.HideCommandPromptWindow = $true } + if ($ProfileDirectoryPath) { + $ProfileDirectoryPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ProfileDirectoryPath) + Write-Verbose "Setting Profile directory: $ProfileDirectoryPath" + $options.AddArgument("user-data-dir=$ProfileDirectoryPath") + } + if ($DefaultDownloadPath) { + $DefaultDownloadPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($DefaultDownloadPath) + Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" + $Options.AddUserProfilePreference('download', @{'default_directory' = $DefaultDownloadPath; 'prompt_for_download' = $false; }) + } + #endregion + + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $options) + + #region post driver checks and option checks If we have a version know to have problems with passing arguments, generate a warning if we tried to send any. + if (-not $Driver) { + Write-Warning "Web driver was not created"; return + } + else { + $driverversion = $Driver.Capabilities.ToDictionary().msedge.msedgedriverVersion -replace '^([\d.]+).*$', '$1' + if (-not $driverversion) { $driverversion = $driver.Capabilities.ToDictionary().chrome.chromedriverVersion -replace '^([\d.]+).*$', '$1' } + Write-Verbose "Web Driver version $driverversion" + Write-Verbose ("Browser: {0,9} {1}" -f $Driver.Capabilities.ToDictionary().browserName, + $Driver.Capabilities.ToDictionary().browserVersion) + if (!$HideVersionHint) { + Write-Verbose "You can download the right webdriver from 'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/'" + } + $browserCmdline = (Get-CimInstance -Verbose:$false -Query ( + "Select * From win32_process " + + "Where parentprocessid = $($service.ProcessId) " + + "And name = 'msedge.exe'")).commandline + $options.arguments | Where-Object { $browserCmdline -notlike "*$_*" } | ForEach-Object { + Write-Warning "Argument $_ was not passed to the Browser. This is a known issue with some web driver versions." + } + } + + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } + + if ($Minimized) { + $Driver.Manage().Window.Minimize(); + } + if ($Maximized) { + $Driver.Manage().Window.Maximize() + } + if ($FullScreen) { + $Driver.Manage().Window.FullScreen() + } + #endregion + + if ($AsDefaultDriver) { + if ($Global:SeDriver) { $Global:SeDriver.Dispose() } + $Global:SeDriver = $Driver + } + else { $Driver } +} \ No newline at end of file diff --git a/Public/Start-SeRemote.ps1 b/Public/Start-SeRemote.ps1 new file mode 100644 index 0000000..2aa072b --- /dev/null +++ b/Public/Start-SeRemote.ps1 @@ -0,0 +1,45 @@ +function Start-SeRemote { + <# + .example + #you can a remote testing account with testing bot at https://testingbot.com/users/sign_up + #Set $key and $secret and then ... + #see also https://crossbrowsertesting.com/freetrial / https://help.crossbrowsertesting.com/selenium-testing/getting-started/c-sharp/ + #and https://www.browserstack.com/automate/c-sharp + $RemoteDriverURL = [uri]"http://$key`:$secret@hub.testingbot.com/wd/hub" + #See https://testingbot.com/support/getting-started/csharp.html for values for different browsers/platforms + $caps = @{ + platform = 'HIGH-SIERRA' + version = '11' + browserName = 'safari' + } + Start-SeRemote -RemoteAddress $remoteDriverUrl -DesiredCapabilties $caps + #> + [cmdletbinding(DefaultParameterSetName = 'default')] + param( + [string]$RemoteAddress, + [hashtable]$DesiredCapabilities, + [ValidateURIAttribute()] + [Parameter(Position = 0)] + [string]$StartURL, + [switch]$AsDefaultDriver, + [int]$ImplicitWait = 10 + ) + + $desired = [OpenQA.Selenium.Remote.DesiredCapabilities]::new() + if (-not $DesiredCapabilities.Name) { + $desired.SetCapability('name', [datetime]::now.tostring("yyyyMMdd-hhmmss")) + } + foreach ($k in $DesiredCapabilities.keys) { $desired.SetCapability($k, $DesiredCapabilities[$k]) } + $Driver = [OpenQA.Selenium.Remote.RemoteWebDriver]::new($RemoteAddress, $desired) + + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($StartURL) { $Driver.Navigate().GotoUrl($StartURL) } + + if ($AsDefaultDriver) { + if ($Global:SeDriver) { $Global:SeDriver.Dispose() } + $Global:SeDriver = $Driver + } + else { $Driver } +} \ No newline at end of file diff --git a/Public/Stop-SeDriver.ps1 b/Public/Stop-SeDriver.ps1 new file mode 100644 index 0000000..96ae194 --- /dev/null +++ b/Public/Stop-SeDriver.ps1 @@ -0,0 +1,18 @@ +function Stop-SeDriver { + [alias('SeClose')] + param( + [Parameter(Mandatory = $false, ValueFromPipeline = $true)] + [Alias('Driver')] + [ValidateNotNullOrEmpty()] + [OpenQA.Selenium.IWebDriver] + $Target = $Global:SeDriver + ) + + if (($null -ne $Target) -and ($Target -is [OpenQA.Selenium.IWebDriver])) { + Write-Verbose -Message "Closing $($Target.Capabilities.browsername)..." + $Target.Close() + $Target.Dispose() + if ($Target -eq $Global:SeDriver) { Remove-Variable -Name SeDriver -Scope global } + } + else { throw "A valid Target must be provided." } +} \ No newline at end of file diff --git a/Public/Switch-SeFrame.ps1 b/Public/Switch-SeFrame.ps1 new file mode 100644 index 0000000..e082272 --- /dev/null +++ b/Public/Switch-SeFrame.ps1 @@ -0,0 +1,23 @@ +function Switch-SeFrame { + [Alias('SeFrame')] + param ( + [Parameter(Mandatory = $true, ParameterSetName = 'Frame', Position = 0)] + $Frame, + + [Parameter(Mandatory = $true, ParameterSetName = 'Parent')] + [switch]$Parent, + + [Parameter(Mandatory = $true, ParameterSetName = 'Root')] + [Alias('defaultContent')] + [switch]$Root, + + [Parameter(ValueFromPipeline = $true)] + [Alias("Driver")] + [ValidateIsWebDriverAttribute()] + $Target = $Global:SeDriver + ) + + if ($frame) { [void]$Target.SwitchTo().Frame($Frame) } + elseif ($Parent) { [void]$Target.SwitchTo().ParentFrame() } + elseif ($Root) { [void]$Target.SwitchTo().defaultContent() } +} \ No newline at end of file diff --git a/Public/Switch-SeWindow.ps1 b/Public/Switch-SeWindow.ps1 new file mode 100644 index 0000000..9a15dd4 --- /dev/null +++ b/Public/Switch-SeWindow.ps1 @@ -0,0 +1,14 @@ +function Switch-SeWindow { + param( + [Parameter(Mandatory = $false, ValueFromPipeline = $true)] + [Alias('Driver')] + [OpenQA.Selenium.IWebDriver] + $Target = $Global:SeDriver, + + [Parameter(Mandatory = $true)]$Window + ) + + process { + $Target.SwitchTo().Window($Window) | Out-Null + } +} \ No newline at end of file diff --git a/Selenium.build.ps1 b/Selenium.build.ps1 new file mode 100644 index 0000000..30851d6 --- /dev/null +++ b/Selenium.build.ps1 @@ -0,0 +1,140 @@ +task . Clean, Build, Tests, UpdateHelp, ExportHelp, Stats +task Tests ImportCompipledModule, Pester +task CreateManifest CopyPSD, UpdatPublicFunctionsToExport, CopyAdditionalFiles +task Build Compile, CreateManifest +task Stats WriteStats + +$script:ModuleName = 'Selenium' # Split-Path -Path $PSScriptRoot -Leaf +$script:ModuleRoot = $PSScriptRoot +$script:OutPutFolder = "$PSScriptRoot\Output" +$script:ModuleOutPutFolder = "$PSScriptRoot\Output\$script:ModuleName" +$script:ImportFolders = @('Public', 'Internal', 'Classes') +$script:PsmPath = Join-Path -Path $PSScriptRoot -ChildPath "Output\$($script:ModuleName)\$($script:ModuleName).psm1" +$script:PsdPath = Join-Path -Path $PSScriptRoot -ChildPath "Output\$($script:ModuleName)\$($script:ModuleName).psd1" +$script:HelpPath = Join-Path -Path $PSScriptRoot -ChildPath "Output\$($script:ModuleName)\en-US" + +$script:PublicFolder = 'Public' +$script:DSCResourceFolder = 'DSCResources' + + +task "Clean" { + if (-not(Test-Path $script:OutPutFolder)) { + New-Item -ItemType Directory -Path $script:OutPutFolder > $null + } + + Remove-Item -Path "$($script:OutPutFolder)\*" -Force -Recurse +} + +$compileParams = @{ + Inputs = { + foreach ($folder in $script:ImportFolders) { + Get-ChildItem -Path $folder -Recurse -File -Filter '*.ps1' + } + } + + Output = { + $script:PsmPath + } +} + +task Compile @compileParams { + if (Test-Path -Path $script:PsmPath) { + Remove-Item -Path $script:PsmPath -Recurse -Force + } + New-Item -Path $script:PsmPath -Force > $null + + foreach ($folder in $script:ImportFolders) { + $currentFolder = Join-Path -Path $script:ModuleRoot -ChildPath $folder + Write-Verbose -Message "Checking folder [$currentFolder]" + + if (Test-Path -Path $currentFolder) { + $files = Get-ChildItem -Path $currentFolder -File -Filter '*.ps1' + foreach ($file in $files) { + Write-Verbose -Message "Adding $($file.FullName)" + Get-Content -Path $file.FullName >> $script:PsmPath + } + } + } + +} + +task CopyPSD { + New-Item -Path (Split-Path $script:PsdPath) -ItemType Directory -ErrorAction 0 + $copy = @{ + Path = "$($script:ModuleName).psd1" + Destination = $script:PsdPath + Force = $true + Verbose = $true + } + Copy-Item @copy +} + +task CopyAdditionalFiles { + + $CopyContainer = @{ + Container = $true + Recurse = $true + } + + $CopyFile = { Param($Name) Copy-Item -Path "$script:ModuleRoot\$Name" -Destination "$script:ModuleOutPutFolder\$Name" -Force -Verbose } + $CopyFolder = { Param($Name) Copy-Item -Path "$script:ModuleRoot\$Name" -Destination "$script:ModuleOutPutFolder" -Force -Verbose -Container -Recurse } + + & $CopyFolder 'assemblies' + & $CopyFolder 'Examples' + + & $CopyFile 'SeleniumClasses.ps1' + & $CopyFile 'Selenium-Binary-Updater.ps1' + + & $CopyFile 'ChangeLog.md' + & $CopyFile 'README.md' + & $CopyFile 'Selenium.tests.ps1' + +} + +task UpdatPublicFunctionsToExport -if (Test-Path -Path $script:PublicFolder) { + $publicFunctions = (Get-ChildItem -Path $script:PublicFolder | + Select-Object -ExpandProperty BaseName) -join "', '" + + $publicFunctions = "FunctionsToExport = @('{0}')" -f $publicFunctions + + (Get-Content -Path $script:PsdPath) -replace "FunctionsToExport\s*?= '\*'", $publicFunctions | + Set-Content -Path $script:PsdPath +} + + + +task ImportCompipledModule -if (Test-Path -Path $script:PsmPath) { + Get-Module -Name $script:ModuleName | + Remove-Module -Force + Import-Module -Name $script:PsdPath -Force +} + +task Pester { + $resultFile = "{0}\testResults{1}.xml" -f $script:OutPutFolder, (Get-date -Format 'yyyyMMdd_hhmmss') + $testFolder = Join-Path -Path $PSScriptRoot -ChildPath 'Tests\*' + Invoke-Pester -Path $testFolder -OutputFile $resultFile -OutputFormat NUnitxml +} + + +task WriteStats { + $folders = Get-ChildItem -Directory | + Where-Object { $PSItem.Name -ne 'Output' } + + $stats = foreach ($folder in $folders) { + $files = Get-ChildItem "$($folder.FullName)\*" -File + if ($files) { + Get-Content -Path $files | + Measure-Object -Word -Line -Character | + Select-Object -Property @{N = "FolderName"; E = { $folder.Name } }, Words, Lines, Characters + } + } + $stats | ConvertTo-Json > "$script:OutPutFolder\stats.json" +} + +task UpdateHelp -if (Test-Path -Path "$Script:ModuleRoot\Help") { + Update-MarkdownHelpModule -Path "$Script:ModuleRoot\Help" -ModulePagePath "$Script:ModuleRoot\Help\README.MD" -RefreshModulePage +} + +task ExportHelp -if (Test-Path -Path "$script:ModuleRoot\Help") { + New-ExternalHelp -Path "$script:ModuleRoot\Help" -OutputPath $script:HelpPath +} \ No newline at end of file diff --git a/Selenium.psd1 b/Selenium.psd1 index 9469943..1ddbcb8 100644 --- a/Selenium.psd1 +++ b/Selenium.psd1 @@ -8,131 +8,101 @@ # Modified James O'Neill 30 Nov 2019 @{ -ModuleVersion = '3.0.1' -GUID = 'a3bdb8c3-c150-48a8-b56d-cd4d43f46a26' -Author = 'Adam Driscoll' -CompanyName = 'Unknown' -Copyright = '(c) 2020 Adam Driscoll. All rights reserved.' -Description = 'Web automation using the Selenium Web Driver' -ScriptsToProcess = @('SeleniumClasses.ps1') -RootModule = 'Selenium.psm1' -RequiredAssemblies = @('./assemblies/WebDriver.dll', './assemblies/WebDriver.Support.dll') -FunctionsToExport = @( - 'Start-SeChrome' , - 'Start-SeEdge' , - 'Start-SeNewEdge' , - 'Start-SeFirefox' , - 'Start-SeInternetExplorer' , - 'Start-SeNewEdge', - 'Start-SeRemote' , - 'Stop-SeDriver' , - 'Invoke-SeClick' , - 'Send-SeClick' , - 'Get-SeCookie' , - 'Remove-SeCookie' , - 'Set-SeCookie' , - 'Get-SeElement', - 'Get-SeElementAttribute' , - 'Get-SeElementCssValue' , - 'Get-SeSelectionOption', - 'Get-SeKeys' , - 'Send-SeKeys' , - 'Save-SeScreenshot' , - 'New-SeScreenshot' - 'Invoke-SeScreenshot' , - 'Open-SeUrl' , - 'Get-SeWindow' , - 'Switch-SeWindow', - 'Switch-SeFrame', - 'Clear-SeAlert', - 'SeOpen', - 'SeType', - 'SeShouldHave' ) -AliasesToExport = @( - 'SeChrome' , - 'SeFirefox', - 'SeIE' , 'SeInternetExplorer' , - 'CrEdge' , 'NewEdge', - 'MSEdge' , 'LegacyEdge', 'Start-SeLegacyEdge', - 'Enter-SeUrl' , - 'Find-SeElement', - 'SeAccept', - 'SeDismiss', - 'SeClick', - 'SeClose', - 'SeElement', - 'SeFrame', - 'SeNavigate', - 'SeScreenshot', - 'SeSelection') -CmdletsToExport = @() -VariablesToExport = @() -DscResourcesToExport = @() -FileList = @('.\assemblies', - '.\Examples', - '.\ChangeLog.md', - '.\README.md', - '.\Selenium.psm1' - '.\Selenium.tests.ps1' - '.\Selenium-Binary-Updater.ps1') - -PrivateData = @{ - PSData = @{ - Tags = @('selenium', 'automation', 'web') - LicenseUri = 'https://github.com/adamdriscoll/selenium-powershell/blob/master/LICENSE' - ProjectUri = 'https://github.com/adamdriscoll/selenium-powershell' - ReleaseNotes = 'Updating WebDrivers for Selenium' - - # A URL to an icon representing this module. - # IconUri = '' - # Prerelease = 'beta2' - } # End of PSData hashtable - -} # End of PrivateData hashtable - -# Supported PSEditions -# CompatiblePSEditions = @() - -# Minimum version of the Windows PowerShell engine required by this module -# PowerShellVersion = '' - -# Name of the Windows PowerShell host required by this module -# PowerShellHostName = '' - -# Minimum version of the Windows PowerShell host required by this module -# PowerShellHostVersion = '' - -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' - -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' - -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' - -# Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() - -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() - -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() - -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() - -# List of all modules packaged with this module -# ModuleList = @() - - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - -# HelpInfo URI of this module -# HelpInfoURI = '' - -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' + ModuleVersion = '3.0.1' + GUID = 'a3bdb8c3-c150-48a8-b56d-cd4d43f46a26' + Author = 'Adam Driscoll' + CompanyName = 'Unknown' + Copyright = '(c) 2020 Adam Driscoll. All rights reserved.' + Description = 'Web automation using the Selenium Web Driver' + ScriptsToProcess = @('SeleniumClasses.ps1') + RootModule = 'Selenium.psm1' + RequiredAssemblies = @('./assemblies/WebDriver.dll', './assemblies/WebDriver.Support.dll') + FunctionsToExport = '*' + AliasesToExport = @( + 'SeChrome' , + 'SeFirefox', + 'SeIE' , 'SeInternetExplorer' , + 'CrEdge' , 'NewEdge', + 'MSEdge' , 'LegacyEdge', 'Start-SeLegacyEdge', + 'Enter-SeUrl' , + 'Find-SeElement', + 'SeAccept', + 'SeDismiss', + 'SeClick', + 'SeClose', + 'SeElement', + 'SeFrame', + 'SeNavigate', + 'SeScreenshot', + 'SeSelection') + CmdletsToExport = @() + VariablesToExport = @() + DscResourcesToExport = @() + FileList = @('.\assemblies', + '.\Examples', + '.\ChangeLog.md', + '.\README.md', + '.\Selenium.psm1' + '.\Selenium.tests.ps1' + '.\Selenium-Binary-Updater.ps1') + + PrivateData = @{ + PSData = @{ + Tags = @('selenium', 'automation', 'web') + LicenseUri = 'https://github.com/adamdriscoll/selenium-powershell/blob/master/LICENSE' + ProjectUri = 'https://github.com/adamdriscoll/selenium-powershell' + ReleaseNotes = 'Updating WebDrivers for Selenium' + + # A URL to an icon representing this module. + # IconUri = '' + # Prerelease = 'beta2' + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # Supported PSEditions + # CompatiblePSEditions = @() + + # Minimum version of the Windows PowerShell engine required by this module + # PowerShellVersion = '' + + # Name of the Windows PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the Windows PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # CLRVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # List of all modules packaged with this module + # ModuleList = @() + + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' } diff --git a/Selenium.psm1 b/Selenium.psm1 index 72f43db..6d34c1f 100644 --- a/Selenium.psm1 +++ b/Selenium.psm1 @@ -1,1460 +1,18 @@ -$Script:SeKeys = [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | - Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } - -#region Set path to assemblies on Linux and MacOS and Grant Execution permissions on them -if ($IsLinux) { - $AssembliesPath = "$PSScriptRoot/assemblies/linux" -} -elseif ($IsMacOS) { - $AssembliesPath = "$PSScriptRoot/assemblies/macos" -} - -# Grant Execution permission to assemblies on Linux and MacOS -if ($AssembliesPath) { - # Check if powershell is NOT running as root - Get-Item -Path "$AssembliesPath/chromedriver", "$AssembliesPath/geckodriver" | ForEach-Object { - if ($IsLinux) { $FileMod = stat -c "%a" $_.FullName } - elseif ($IsMacOS) { $FileMod = /usr/bin/stat -f "%A" $_.FullName } - Write-Verbose "$($_.FullName) $Filemod" - if ($FileMod[2] -ne '5' -and $FileMod[2] -ne '7') { - Write-Host "Granting $($AssemblieFile.fullname) Execution Permissions ..." - chmod +x $_.fullname - } - } -} - -#endregion -function ValidateURL { - [Alias("Validate-Url")] - param( - [Parameter(Mandatory = $true)] - $URL - ) - $Out = $null - [uri]::TryCreate($URL, [System.UriKind]::Absolute, [ref]$Out) -} - -function Start-SeNewEdge { - [cmdletbinding(DefaultParameterSetName = 'default')] - [Alias('CrEdge', 'NewEdge')] - param( - [ValidateURIAttribute()] - [Parameter(Position = 0)] - [string]$StartURL, - [switch]$HideVersionHint, - [parameter(ParameterSetName = 'min', Mandatory = $true)] - [switch]$Minimized, - [parameter(ParameterSetName = 'max', Mandatory = $true)] - [switch]$Maximized, - [parameter(ParameterSetName = 'ful', Mandatory = $true)] - [switch]$FullScreen, - [parameter(ParameterSetName = 'hl', Mandatory = $true)] - [switch]$Headless, - $BinaryPath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", - $ProfileDirectoryPath, - $DefaultDownloadPath, - [switch]$AsDefaultDriver, - [switch]$Quiet, - [Alias('Incognito')] - [switch]$PrivateBrowsing, - [int]$ImplicitWait = 10, - $WebDriverDirectory = $env:EdgeWebDriver - ) - $OptionSettings = @{ browserName = '' } - #region check / set paths for browser and web driver and edge options - if ($PSBoundParameters['BinaryPath'] -and -not (Test-Path -Path $BinaryPath)) { - throw "Could not find $BinaryPath"; return - } - - #Were we given a driver location and is msedgedriver there ? - #If were were given a location (which might be from an environment variable) is the driver THERE ? - # if not, were we given a path for the browser executable, and is the driver THERE ? - # and if not there either, is there one in the assemblies sub dir ? And if not bail - if ($WebDriverDirectory -and -not (Test-Path -Path (Join-Path -Path $WebDriverDirectory -ChildPath 'msedgedriver.exe'))) { - throw "Could not find msedgedriver.exe in $WebDriverDirectory"; return - } - elseif ($WebDriverDirectory -and (Test-Path (Join-Path -Path $WebDriverDirectory -ChildPath 'msedge.exe'))) { - Write-Verbose -Message "Using browser from $WebDriverDirectory" - $optionsettings['BinaryLocation'] = Join-Path -Path $WebDriverDirectory -ChildPath 'msedge.exe' - } - elseif ($BinaryPath) { - $optionsettings['BinaryLocation'] = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($BinaryPath) - $binaryDir = Split-Path -Path $BinaryPath -Parent - Write-Verbose -Message "Will request $($OptionSettings['BinaryLocation']) as the browser" - } - if (-not $WebDriverDirectory -and $binaryDir -and (Test-Path (Join-Path -Path $binaryDir -ChildPath 'msedgedriver.exe'))) { - $WebDriverDirectory = $binaryDir - } - # No linux or mac driver to test for yet - if (-not $WebDriverDirectory -and (Test-Path (Join-Path -Path "$PSScriptRoot\Assemblies\" -ChildPath 'msedgedriver.exe'))) { - $WebDriverDirectory = "$PSScriptRoot\Assemblies\" - Write-Verbose -Message "Using Web driver from the default location" - } - if (-not $WebDriverDirectory) { throw "Could not find msedgedriver.exe"; return } - - # The "credge" web driver will work with the edge selenium objects, but works better with the chrome ones. - $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($WebDriverDirectory, 'msedgedriver.exe') - $options = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeOptions -Property $OptionSettings - #The command line args may now be --inprivate --headless but msedge driver V81 does not pass them - if ($PrivateBrowsing) { $options.AddArguments('InPrivate') } - if ($Headless) { $options.AddArguments('headless') } - if ($Quiet) { $service.HideCommandPromptWindow = $true } - if ($ProfileDirectoryPath) { - $ProfileDirectoryPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ProfileDirectoryPath) - Write-Verbose "Setting Profile directory: $ProfileDirectoryPath" - $options.AddArgument("user-data-dir=$ProfileDirectoryPath") - } - if ($DefaultDownloadPath) { - $DefaultDownloadPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($DefaultDownloadPath) - Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" - $Options.AddUserProfilePreference('download', @{'default_directory' = $DefaultDownloadPath; 'prompt_for_download' = $false; }) - } - #endregion - - $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $options) - - #region post driver checks and option checks If we have a version know to have problems with passing arguments, generate a warning if we tried to send any. - if (-not $Driver) { - Write-Warning "Web driver was not created"; return - } - else { - $driverversion = $Driver.Capabilities.ToDictionary().msedge.msedgedriverVersion -replace '^([\d.]+).*$', '$1' - if (-not $driverversion) { $driverversion = $driver.Capabilities.ToDictionary().chrome.chromedriverVersion -replace '^([\d.]+).*$', '$1' } - Write-Verbose "Web Driver version $driverversion" - Write-Verbose ("Browser: {0,9} {1}" -f $Driver.Capabilities.ToDictionary().browserName, - $Driver.Capabilities.ToDictionary().browserVersion) - if (!$HideVersionHint) { - Write-Verbose "You can download the right webdriver from 'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/'" - } - $browserCmdline = (Get-CimInstance -Verbose:$false -Query ( - "Select * From win32_process " + - "Where parentprocessid = $($service.ProcessId) " + - "And name = 'msedge.exe'")).commandline - $options.arguments | Where-Object { $browserCmdline -notlike "*$_*" } | ForEach-Object { - Write-Warning "Argument $_ was not passed to the Browser. This is a known issue with some web driver versions." - } - } - - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) - if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } - - if ($Minimized) { - $Driver.Manage().Window.Minimize(); - } - if ($Maximized) { - $Driver.Manage().Window.Maximize() - } - if ($FullScreen) { - $Driver.Manage().Window.FullScreen() - } - #endregion - - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } -} - -function Start-SeChrome { - [cmdletbinding(DefaultParameterSetName = 'default')] - [Alias('SeChrome')] - param( - [ValidateURIAttribute()] - [Parameter(Position = 0)] - [string]$StartURL, - [Parameter(Mandatory = $false)] - [array]$Arguments, - [switch]$HideVersionHint, - [System.IO.FileInfo]$DefaultDownloadPath, - [System.IO.FileInfo]$ProfileDirectoryPath, - [Parameter(DontShow)] - [bool]$DisableBuiltInPDFViewer = $true, - [switch]$EnablePDFViewer, - [Alias('PrivateBrowsing')] - [switch]$Incognito, - [parameter(ParameterSetName = 'hl', Mandatory = $true)] - [switch]$Headless, - [parameter(ParameterSetName = 'Min', Mandatory = $true)] - [switch]$Maximized, - [parameter(ParameterSetName = 'Max', Mandatory = $true)] - [switch]$Minimized, - [parameter(ParameterSetName = 'Ful', Mandatory = $true)] - [switch]$Fullscreen, - [switch]$DisableAutomationExtension, - [Alias('ChromeBinaryPath')] - $BinaryPath, - $WebDriverDirectory = $env:ChromeWebDriver, - [switch]$Quiet, - [switch]$AsDefaultDriver, - [int]$ImplicitWait = 10 - ) - - process { - #region chrome set-up options - $Chrome_Options = [OpenQA.Selenium.Chrome.ChromeOptions]::new() - - if ($DefaultDownloadPath) { - Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" - $Chrome_Options.AddUserProfilePreference('download', @{'default_directory' = $($DefaultDownloadPath.FullName); 'prompt_for_download' = $false; }) - } - - if ($ProfileDirectoryPath) { - Write-Verbose "Setting Profile directory: $ProfileDirectoryPath" - $Chrome_Options.AddArgument("user-data-dir=$ProfileDirectoryPath") - } - - if ($BinaryPath) { - Write-Verbose "Setting Chrome Binary directory: $BinaryPath" - $Chrome_Options.BinaryLocation = "$BinaryPath" - } - - if ($DisableBuiltInPDFViewer -and -not $EnablePDFViewer) { - $Chrome_Options.AddUserProfilePreference('plugins', @{'always_open_pdf_externally' = $true; }) - } - - if ($Headless) { - $Chrome_Options.AddArguments('headless') - } - - if ($Incognito) { - $Chrome_Options.AddArguments('Incognito') - } - - if ($Maximized) { - $Chrome_Options.AddArguments('start-maximized') - } - - if ($Fullscreen) { - $Chrome_Options.AddArguments('start-fullscreen') - } - - if ($DisableAutomationExtension) { - $Chrome_Options.AddAdditionalCapability('useAutomationExtension', $false) - $Chrome_Options.AddExcludedArgument('enable-automation') - } - - if ($Arguments) { - foreach ($Argument in $Arguments) { - $Chrome_Options.AddArguments($Argument) - } - } - - if (!$HideVersionHint) { - Write-Verbose "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" - } - - if ($WebDriverDirectory) { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($WebDriverDirectory) } - elseif ($AssembliesPath) { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($AssembliesPath) } - else { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService() } - if ($Quiet) { $service.HideCommandPromptWindow = $true } - #endregion - - $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $Chrome_Options) - if (-not $Driver) { Write-Warning "Web driver was not created"; return } - - #region post creation options - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) - - if ($Minimized) { - $Driver.Manage().Window.Minimize(); - } - - if ($Headless -and $DefaultDownloadPath) { - $HeadlessDownloadParams = [system.collections.generic.dictionary[[System.String], [System.Object]]]::new() - $HeadlessDownloadParams.Add('behavior', 'allow') - $HeadlessDownloadParams.Add('downloadPath', $DefaultDownloadPath.FullName) - $Driver.ExecuteChromeCommand('Page.setDownloadBehavior', $HeadlessDownloadParams) - } - - if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } - #endregion - - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } - } -} - -function Start-SeInternetExplorer { - [cmdletbinding(DefaultParameterSetName = 'Default')] - [Alias('SeInternetExplorer', 'SeIE')] - param( - [ValidateURIAttribute()] - [Parameter(Position = 0)] - [string]$StartURL, - [switch]$Quiet, - [switch]$AsDefaultDriver, - [parameter(ParameterSetName = 'Max', Mandatory = $true)] - [switch]$Maximized, - [parameter(ParameterSetName = 'Min', Mandatory = $true)] - [switch]$Minimized, - [parameter(ParameterSetName = 'Min', Mandatory = $true)] - [switch]$FullScreen, - [Parameter(DontShow)] - [parameter(ParameterSetName = 'HL', Mandatory = $true)] - [switch]$Headless, - [Parameter(DontShow)] - [Alias('Incognito')] - [switch]$PrivateBrowsing, - [switch]$IgnoreProtectedModeSettings, - [int]$ImplicitWait = 10, - $WebDriverDirectory = $env:IEWebDriver - ) - #region IE set-up options - if ($Headless -or $PrivateBrowsing) { Write-Warning 'The Internet explorer driver does not support headless or Inprivate operation; these switches are ignored' } - - $InternetExplorer_Options = [OpenQA.Selenium.IE.InternetExplorerOptions]::new() - $InternetExplorer_Options.IgnoreZoomLevel = $true - if ($IgnoreProtectedModeSettings) { - $InternetExplorer_Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true - } - - if ($StartURL) { $InternetExplorer_Options.InitialBrowserUrl = $StartURL } - if ($WebDriverDirectory) { $Service = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService($WebDriverDirectory) } - else { $Service = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService() } - if ($Quiet) { $Service.HideCommandPromptWindow = $true } - #endregion - - $Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $InternetExplorer_Options) - if (-not $Driver) { Write-Warning "Web driver was not created"; return } - - #region post creation options - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) - if ($Minimized) { - $Driver.Manage().Window.Minimize(); - } - if ($Maximized) { - $Driver.Manage().Window.Maximize() - } - if ($FullScreen) { - $Driver.Manage().Window.FullScreen() - } - #endregion - - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } -} - -function Start-SeEdge { - [cmdletbinding(DefaultParameterSetName = 'default')] - [Alias('MSEdge', 'LegacyEdge', 'Start-SeLegacyEdge')] - param( - [ValidateURIAttribute()] - [Parameter(Position = 0)] - [string]$StartURL, - [parameter(ParameterSetName = 'Min', Mandatory = $true)] - [switch]$Maximized, - [parameter(ParameterSetName = 'Max', Mandatory = $true)] - [switch]$Minimized, - [parameter(ParameterSetName = 'Full', Mandatory = $true)] - [switch]$FullScreen, - [Alias('Incognito')] - [switch]$PrivateBrowsing, - [switch]$Quiet, - [switch]$AsDefaultDriver, - [Parameter(DontShow)] - [switch]$Headless, - [int]$ImplicitWait = 10 - ) - #region Edge set-up options - if ($Headless) { Write-Warning 'Pre-Chromium Edge does not support headless operation; the Headless switch is ignored' } - $service = [OpenQA.Selenium.Edge.EdgeDriverService]::CreateDefaultService() - $options = [OpenQA.Selenium.Edge.EdgeOptions]::new() - if ($Quiet) { $service.HideCommandPromptWindow = $true } - if ($PrivateBrowsing) { $options.UseInPrivateBrowsing = $true } - if ($StartURL) { $options.StartPage = $StartURL } - #endregion - - try { - $Driver = [OpenQA.Selenium.Edge.EdgeDriver]::new($service , $options) - } - catch { - $driverversion = (Get-Item .\assemblies\MicrosoftWebDriver.exe).VersionInfo.ProductVersion - $WindowsVersion = [System.Environment]::OSVersion.Version.ToString() - Write-Warning -Message "Edge driver is $driverversion. Windows is $WindowsVersion. If the driver is out-of-date, update it as a Windows feature,`r`nand then delete $PSScriptRoot\assemblies\MicrosoftWebDriver.exe" - throw $_ ; return - } - if (-not $Driver) { Write-Warning "Web driver was not created"; return } - - #region post creation options - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) - if ($Minimized) { $Driver.Manage().Window.Minimize() } - if ($Maximized) { $Driver.Manage().Window.Maximize() } - if ($FullScreen) { $Driver.Manage().Window.FullScreen() } - #endregion - - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } -} - -function Start-SeFirefox { - [cmdletbinding(DefaultParameterSetName = 'default')] - [Alias('SeFirefox')] - param( - [ValidateURIAttribute()] - [Parameter(Position = 0)] - [string]$StartURL, - [array]$Arguments, - [System.IO.FileInfo]$DefaultDownloadPath, - [alias('Incognito')] - [switch]$PrivateBrowsing, - [parameter(ParameterSetName = 'HL', Mandatory = $true)] - [switch]$Headless, - [parameter(ParameterSetName = 'Min', Mandatory = $true)] - [switch]$Maximized, - [parameter(ParameterSetName = 'Max', Mandatory = $true)] - [switch]$Minimized, - [parameter(ParameterSetName = 'Ful', Mandatory = $true)] - [switch]$Fullscreen, - [switch]$SuppressLogging, - [switch]$Quiet, - [switch]$AsDefaultDriver, - [int]$ImplicitWait = 10, - $WebDriverDirectory = $env:GeckoWebDriver - ) - process { - #region firefox set-up options - $Firefox_Options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new() - - if ($Headless) { - $Firefox_Options.AddArguments('-headless') - } - - if ($DefaultDownloadPath) { - Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" - $Firefox_Options.setPreference("browser.download.folderList", 2); - $Firefox_Options.SetPreference("browser.download.dir", "$DefaultDownloadPath"); - } - - if ($PrivateBrowsing) { - $Firefox_Options.SetPreference("browser.privatebrowsing.autostart", $true) - } - - if ($Arguments) { - foreach ($Argument in $Arguments) { - $Firefox_Options.AddArguments($Argument) - } - } - - if ($SuppressLogging) { - # Sets GeckoDriver log level to Fatal. - $Firefox_Options.LogLevel = 6 - } - - if ($WebDriverDirectory) { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService($WebDriverDirectory) } - elseif ($AssembliesPath) { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService($AssembliesPath) } - else { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService() } - if ($Quiet) { $service.HideCommandPromptWindow = $true } - #endregion - - $Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Firefox_Options) - if (-not $Driver) { Write-Warning "Web driver was not created"; return } - - #region post creation options - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) - if ($Minimized) { $Driver.Manage().Window.Minimize() } - if ($Maximized) { $Driver.Manage().Window.Maximize() } - if ($Fullscreen) { $Driver.Manage().Window.FullScreen() } - if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } - #endregion - - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } - } -} - -function Start-SeRemote { - <# - .example - #you can a remote testing account with testing bot at https://testingbot.com/users/sign_up - #Set $key and $secret and then ... - #see also https://crossbrowsertesting.com/freetrial / https://help.crossbrowsertesting.com/selenium-testing/getting-started/c-sharp/ - #and https://www.browserstack.com/automate/c-sharp - $RemoteDriverURL = [uri]"http://$key`:$secret@hub.testingbot.com/wd/hub" - #See https://testingbot.com/support/getting-started/csharp.html for values for different browsers/platforms - $caps = @{ - platform = 'HIGH-SIERRA' - version = '11' - browserName = 'safari' - } - Start-SeRemote -RemoteAddress $remoteDriverUrl -DesiredCapabilties $caps - #> - [cmdletbinding(DefaultParameterSetName = 'default')] - param( - [string]$RemoteAddress, - [hashtable]$DesiredCapabilities, - [ValidateURIAttribute()] - [Parameter(Position = 0)] - [string]$StartURL, - [switch]$AsDefaultDriver, - [int]$ImplicitWait = 10 - ) - - $desired = [OpenQA.Selenium.Remote.DesiredCapabilities]::new() - if (-not $DesiredCapabilities.Name) { - $desired.SetCapability('name', [datetime]::now.tostring("yyyyMMdd-hhmmss")) - } - foreach ($k in $DesiredCapabilities.keys) { $desired.SetCapability($k, $DesiredCapabilities[$k]) } - $Driver = [OpenQA.Selenium.Remote.RemoteWebDriver]::new($RemoteAddress, $desired) - - if (-not $Driver) { Write-Warning "Web driver was not created"; return } - - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) - if ($StartURL) { $Driver.Navigate().GotoUrl($StartURL) } - - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } -} - -<# -@jhoneill Shouldn't -default be assumed if not feed a webdriver? see alternate below -function Stop-SeDriver { - [alias('SeClose')] - param( - [Parameter(ValueFromPipeline = $true, position = 0, ParameterSetName = 'Driver')] - [ValidateIsWebDriverAttribute()] - $Driver, - [Parameter(Mandatory = $true, ParameterSetName = 'Default')] - [switch]$Default - ) - if (-not $PSBoundParameters.ContainsKey('Driver') -and $Global:SeDriver -and ($Default -or $MyInvocation.InvocationName -eq 'SeClose')) { - Write-Verbose -Message "Closing $($Global:SeDriver.Capabilities.browsername)..." - $Global:SeDriver.Close() - $Global:SeDriver.Dispose() - Remove-Variable -Name SeDriver -Scope global - } - elseif ($Driver) { - $Driver.Close() - $Driver.Dispose() - } - else { Write-Warning -Message 'No Driver Specified' } -} -#> - -function Stop-SeDriver { - [alias('SeClose')] - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [ValidateNotNullOrEmpty()] - [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver - ) - - if (($null -ne $Target) -and ($Target -is [OpenQA.Selenium.IWebDriver])) { - Write-Verbose -Message "Closing $($Target.Capabilities.browsername)..." - $Target.Close() - $Target.Dispose() - if ($Target -eq $Global:SeDriver) { Remove-Variable -Name SeDriver -Scope global } - } - else { throw "A valid Target must be provided." } -} - -<# -function Enter-SeUrl { - param($Driver, $Url) - $Driver.Navigate().GoToUrl($Url) -} -#> - -function Open-SeUrl { - [cmdletbinding(DefaultParameterSetName = 'default')] - [Alias('SeNavigate', "Enter-SeUrl")] - param( - [Parameter(Mandatory = $true, position = 0, ParameterSetName = 'url')] - [ValidateURIAttribute()] - [string]$Url, - - [Parameter(Mandatory = $true, ParameterSetName = 'back')] - [switch]$Back, - - [Parameter(Mandatory = $true, ParameterSetName = 'forward')] - [switch]$Forward, - - [Parameter(Mandatory = $true, ParameterSetName = 'refresh')] - [switch]$Refresh, - - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver - ) - - switch ($PSCmdlet.ParameterSetName) { - 'url' { $Target.Navigate().GoToUrl($Url); break } - 'back' { $Target.Navigate().Back(); break } - 'forward' { $Target.Navigate().Forward(); break } - 'refresh' { $Target.Navigate().Refresh(); break } - - default { throw 'Unexpected ParameterSet' } - } -} - -<# -function Find-SeElement { - param( - [Parameter()] - $Driver, - [Parameter()] - $Element, - [Parameter()][Switch]$Wait, - [Parameter()]$Timeout = 30, - [Parameter(ParameterSetName = "ByCss")] - $Css, - [Parameter(ParameterSetName = "ByName")] - $Name, - [Parameter(ParameterSetName = "ById")] - $Id, - [Parameter(ParameterSetName = "ByClassName")] - $ClassName, - [Parameter(ParameterSetName = "ByLinkText")] - $LinkText, - [Parameter(ParameterSetName = "ByPartialLinkText")] - $PartialLinkText, - [Parameter(ParameterSetName = "ByTagName")] - $TagName, - [Parameter(ParameterSetName = "ByXPath")] - $XPath - ) - - - process { - - if ($null -ne $Driver -and $null -ne $Element) { - throw "Driver and Element may not be specified together." - } - elseif ($null -ne $Driver) { - $Target = $Driver - } - elseif (-ne $Null $Element) { - $Target = $Element - } - else { - "Driver or element must be specified" - } - - if ($Wait) { - if ($PSCmdlet.ParameterSetName -eq "ByName") { - $TargetElement = [OpenQA.Selenium.By]::Name($Name) - } - - if ($PSCmdlet.ParameterSetName -eq "ById") { - $TargetElement = [OpenQA.Selenium.By]::Id($Id) - } - - if ($PSCmdlet.ParameterSetName -eq "ByLinkText") { - $TargetElement = [OpenQA.Selenium.By]::LinkText($LinkText) - } - - if ($PSCmdlet.ParameterSetName -eq "ByPartialLinkText") { - $TargetElement = [OpenQA.Selenium.By]::PartialLinkText($PartialLinkText) - } - - if ($PSCmdlet.ParameterSetName -eq "ByClassName") { - $TargetElement = [OpenQA.Selenium.By]::ClassName($ClassName) - } - - if ($PSCmdlet.ParameterSetName -eq "ByTagName") { - $TargetElement = [OpenQA.Selenium.By]::TagName($TagName) - } - - if ($PSCmdlet.ParameterSetName -eq "ByXPath") { - $TargetElement = [OpenQA.Selenium.By]::XPath($XPath) - } - - 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) - } - else { - if ($PSCmdlet.ParameterSetName -eq "ByName") { - $Target.FindElements([OpenQA.Selenium.By]::Name($Name)) - } - - if ($PSCmdlet.ParameterSetName -eq "ById") { - $Target.FindElements([OpenQA.Selenium.By]::Id($Id)) - } - - if ($PSCmdlet.ParameterSetName -eq "ByLinkText") { - $Target.FindElements([OpenQA.Selenium.By]::LinkText($LinkText)) - } - - if ($PSCmdlet.ParameterSetName -eq "ByPartialLinkText") { - $Target.FindElements([OpenQA.Selenium.By]::PartialLinkText($PartialLinkText)) - } - - if ($PSCmdlet.ParameterSetName -eq "ByClassName") { - $Target.FindElements([OpenQA.Selenium.By]::ClassName($ClassName)) - } - - if ($PSCmdlet.ParameterSetName -eq "ByTagName") { - $Target.FindElements([OpenQA.Selenium.By]::TagName($TagName)) - } - - if ($PSCmdlet.ParameterSetName -eq "ByXPath") { - $Target.FindElements([OpenQA.Selenium.By]::XPath($XPath)) - } - - if ($PSCmdlet.ParameterSetName -eq "ByCss") { - $Target.FindElements([OpenQA.Selenium.By]::CssSelector($Css)) - } - } - } -} -#> - -function Get-SeElement { - [Alias('Find-SeElement', 'SeElement')] - param( - #Specifies whether the selction text is to select by name, ID, Xpath etc - [ValidateSet("CssSelector", "Name", "Id", "ClassName", "LinkText", "PartialLinkText", "TagName", "XPath")] - [ByTransformAttribute()] - [string]$By = "XPath", - #Text to select on - [Alias("CssSelector", "Name", "Id", "ClassName", "LinkText", "PartialLinkText", "TagName", "XPath")] - [Parameter(Position = 1, Mandatory = $true)] - [string]$Selection, - #Specifies a time out - [Parameter(Position = 2)] - [Int]$Timeout = 0, - #The driver or Element where the search should be performed. - [Parameter(Position = 3, ValueFromPipeline = $true)] - [Alias('Element', 'Driver')] - $Target = $Global:SeDriver, - - [parameter(DontShow)] - [Switch]$Wait - - ) - process { - #if one of the old parameter names was used and BY was NIT specified, look for - # [anything which doesn't mean end of command] -Param - # capture Param and set it as the value for by - $mi = $MyInvocation.InvocationName - if (-not $PSBoundParameters.ContainsKey("By") -and - ($MyInvocation.Line -match "$mi[^>\|;]*-(CssSelector|Name|Id|ClassName|LinkText|PartialLinkText|TagName|XPath)")) { - $By = $Matches[1] - } - if ($wait -and $Timeout -eq 0) { $Timeout = 30 } - - if ($TimeOut -and $Target -is [OpenQA.Selenium.Remote.RemoteWebDriver]) { - $TargetElement = [OpenQA.Selenium.By]::$By($Selection) - $WebDriverWait = [OpenQA.Selenium.Support.UI.WebDriverWait]::new($Target, (New-TimeSpan -Seconds $Timeout)) - $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists($TargetElement) - $WebDriverWait.Until($Condition) - } - elseif ($Target -is [OpenQA.Selenium.Remote.RemoteWebElement] -or - $Target -is [OpenQA.Selenium.Remote.RemoteWebDriver]) { - if ($Timeout) { Write-Warning "Timeout does not apply when searching an Element" } - $Target.FindElements([OpenQA.Selenium.By]::$By($Selection)) - } - else { throw "No valid target was provided." } - } -} - -function Invoke-SeClick { - [CmdletBinding(DefaultParameterSetName = 'Default')] - param( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Default')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'JavaScript')] - [OpenQA.Selenium.IWebElement]$Element, - - [Parameter(Mandatory = $true, ParameterSetName = 'JavaScript')] - [Switch]$JavaScriptClick, - - [Parameter(ParameterSetName = 'JavaScript')] - [ValidateIsWebDriverAttribute()] - $Driver = $global:SeDriver - ) - - if ($JavaScriptClick) { - try { - $Driver.ExecuteScript("arguments[0].click()", $Element) - } - catch { - $PSCmdlet.ThrowTerminatingError($_) - } - } - else { - $Element.Click() - } - -} - -function Send-SeClick { - [alias('SeClick')] - param( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] - [OpenQA.Selenium.IWebElement]$Element, - [Alias('JS')] - [Switch]$JavaScriptClick, - $SleepSeconds = 0 , - [Parameter(DontShow)] - $Driver, - [Alias('PT')] - [switch]$PassThru - ) - Process { - if ($JavaScriptClick) { $Element.WrappedDriver.ExecuteScript("arguments[0].click()", $Element) } - else { $Element.Click() } - if ($SleepSeconds) { Start-Sleep -Seconds $SleepSeconds } - if ($PassThru) { $Element } - } -} - -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( - [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] - [OpenQA.Selenium.IWebElement]$Element, - [Parameter(Mandatory = $true, Position = 1)] - [string]$Keys, - [Parameter()] - [Alias('PT')] - [switch]$PassThru - ) - foreach ($Key in $Script:SeKeys.Name) { - $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key - } - $Element.SendKeys($Keys) - if ($PassThru) { $Element } -} - -function Get-SeCookie { - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver - ) - $Target.Manage().Cookies.AllCookies.GetEnumerator() -} - -function Remove-SeCookie { - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver, - - [Parameter(Mandatory = $true, ParameterSetName = 'DeleteAllCookies')] - [Alias('Purge')] - [switch]$DeleteAllCookies, - - [Parameter(Mandatory = $true, ParameterSetName = 'NamedCookie')] - [string]$Name - ) - - if ($DeleteAllCookies) { - $Target.Manage().Cookies.DeleteAllCookies() - } - else { - $Target.Manage().Cookies.DeleteCookieNamed($Name) - } -} - -function Set-SeCookie { - [cmdletbinding()] - param( - [string]$Name, - [string]$Value, - [string]$Path, - [string]$Domain, - $ExpiryDate, - - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver - ) - - <# Selenium Cookie Information - Cookie(String, String) - Initializes a new instance of the Cookie class with a specific name and value. - Cookie(String, String, String) - Initializes a new instance of the Cookie class with a specific name, value, and path. - 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. - #> - - begin { - if ($null -ne $ExpiryDate -and $ExpiryDate.GetType().Name -ne 'DateTime') { - throw '$ExpiryDate can only be $null or TypeName: System.DateTime' - } - } - - process { - if ($Name -and $Value -and (!$Path -and !$Domain -and !$ExpiryDate)) { - $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value) - } - Elseif ($Name -and $Value -and $Path -and (!$Domain -and !$ExpiryDate)) { - $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Path) - } - Elseif ($Name -and $Value -and $Path -and $ExpiryDate -and !$Domain) { - $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Path, $ExpiryDate) - } - Elseif ($Name -and $Value -and $Path -and $Domain -and (!$ExpiryDate -or $ExpiryDate)) { - if ($Target.Url -match $Domain) { - $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Domain, $Path, $ExpiryDate) - } - else { - Throw 'In order to set the cookie the browser needs to be on the cookie domain URL' - } - } - else { - Throw "Incorrect Cookie Layout: - Cookie(String, String) - Initializes a new instance of the Cookie class with a specific name and value. - Cookie(String, String, String) - Initializes a new instance of the Cookie class with a specific name, value, and path. - 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." - } - - $Target.Manage().Cookies.AddCookie($cookie) - } -} - - -function Get-SeElementCssValue { - param( - [Parameter(ValueFromPipeline = $true, Mandatory = $true)] - [OpenQA.Selenium.IWebElement]$Element, - [Parameter(Mandatory = $true)] - [string]$Name - ) - - Process { - $Element.GetCssValue($Name) - } -} - -function Get-SeElementAttribute { - param( - [Parameter(ValueFromPipeline = $true, Mandatory = $true)] - [OpenQA.Selenium.IWebElement]$Element, - [Parameter(Mandatory = $true)] - [string]$Attribute - ) - process { - $Element.GetAttribute($Attribute) - } -} - -function Invoke-SeScreenshot { - param( - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver, - - [Parameter(Mandatory = $false)] - [Switch]$AsBase64EncodedString - ) - $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Target) - if ($AsBase64EncodedString) { - $Screenshot.AsBase64EncodedString - } - else { - $Screenshot - } -} - -function Save-SeScreenshot { - param( - [Parameter(ValueFromPipeline = $true, Mandatory = $true)] - [OpenQA.Selenium.Screenshot]$Screenshot, - [Parameter(Mandatory = $true)] - [string]$Path, - [Parameter()] - [OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png) - - process { - $Screenshot.SaveAsFile($Path, $ImageFormat) - } -} - -function New-SeScreenshot { - [Alias('SeScreenshot')] - [cmdletbinding(DefaultParameterSetName = 'Path')] - param( - [Parameter(ParameterSetName = 'Path' , Position = 0, Mandatory = $true)] - [Parameter(ParameterSetName = 'PassThru', Position = 0)] - $Path, - - [Parameter(ParameterSetName = 'Path', Position = 1)] - [Parameter(ParameterSetName = 'PassThru', Position = 1)] - [OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png, - - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver , - - [Parameter(ParameterSetName = 'Base64', Mandatory = $true)] - [Switch]$AsBase64EncodedString, - - [Parameter(ParameterSetName = 'PassThru', Mandatory = $true)] - [Alias('PT')] - [Switch]$PassThru - ) - $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Target) - if ($AsBase64EncodedString) { $Screenshot.AsBase64EncodedString } - elseif ($Path) { - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Screenshot.SaveAsFile($Path, $ImageFormat) - } - if ($Passthru) { $Screenshot } -} - -function Get-SeWindow { - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver - ) - - process { - $Target.WindowHandles - } -} - -function Switch-SeWindow { - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver, - - [Parameter(Mandatory = $true)]$Window - ) - - process { - $Target.SwitchTo().Window($Window) | Out-Null - } -} - -function Switch-SeFrame { - [Alias('SeFrame')] - param ( - [Parameter(Mandatory = $true, ParameterSetName = 'Frame', Position = 0)] - $Frame, - - [Parameter(Mandatory = $true, ParameterSetName = 'Parent')] - [switch]$Parent, - - [Parameter(Mandatory = $true, ParameterSetName = 'Root')] - [Alias('defaultContent')] - [switch]$Root, - - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver - ) - - if ($frame) { [void]$Target.SwitchTo().Frame($Frame) } - elseif ($Parent) { [void]$Target.SwitchTo().ParentFrame() } - elseif ($Root) { [void]$Target.SwitchTo().defaultContent() } -} - -function Clear-SeAlert { - [Alias('SeAccept', 'SeDismiss')] - param ( - [parameter(ParameterSetName = 'Alert', Position = 0, ValueFromPipeline = $true)] - $Alert, - [parameter(ParameterSetName = 'Driver')] - [ValidateIsWebDriverAttribute()] - [Alias("Driver")] - $Target = $Global:SeDriver, - [ValidateSet('Accept', 'Dismiss')] - $Action = 'Dismiss', - [Alias('PT')] - [switch]$PassThru - ) - if ($Target) { - try { $Alert = $Target.SwitchTo().alert() } - catch { Write-Warning 'No alert was displayed'; return } - } - if (-not $PSBoundParameters.ContainsKey('Action') -and - $MyInvocation.InvocationName -match 'Accept') { $Action = 'Accept' } - if ($Alert) { $alert.$action() } - if ($PassThru) { $Alert } -} - -function SeOpen { - [CmdletBinding()] - Param( - [ValidateSet('Chrome', 'CrEdge', 'FireFox', 'InternetExplorer', 'IE', 'MSEdge', 'NewEdge')] - $In, - [ValidateURIAttribute()] - [Parameter(Mandatory = $False, Position = 1)] - $URL, - [hashtable]$Options = @{'Quiet' = $true }, - [int]$SleepSeconds - ) - #Allow the browser to specified in an Environment variable if not passed as a parameter - if ($env:DefaultBrowser -and -not $PSBoundParameters.ContainsKey('In')) { - $In = $env:DefaultBrowser - } - #It may have been passed as a parameter, in an environment variable, or a parameter default, but if not, bail out - if (-not $In) { throw 'No Browser was selected' } - $StartParams = @{ } - $StartParams += $Options - $StartParams['AsDefaultDriver'] = $true - $StartParams['Verbose'] = $false - $StartParams['ErrorAction'] = 'Stop' - $StartParams['Quiet'] = $true - if ($url) { - $StartParams['StartUrl'] = $url - } - - switch -regex ($In) { - 'Chrome' { Start-SeChrome @StartParams; continue } - 'FireFox' { Start-SeFirefox @StartParams; continue } - 'MSEdge' { Start-SeEdge @StartParams; continue } - 'Edge$' { Start-SeNewEdge @StartParams; continue } - '^I' { Start-SeInternetExplorer @StartParams; continue } - } - Write-Verbose -Message "Opened $($Global:SeDriver.Capabilities.browsername) $($Global:SeDriver.Capabilities.ToDictionary().browserVersion)" - if ($SleepSeconds) { Start-Sleep -Seconds $SleepSeconds } -}` - -function SeType { - param( - [Parameter(Mandatory = $true, Position = 0)] - [string]$Keys, - [Parameter(Mandatory = $true, ValueFromPipeline = $true)] - [OpenQA.Selenium.IWebElement]$Element, - [switch]$ClearFirst, - $SleepSeconds = 0 , - [switch]$Submit, - [Alias('PT')] - [switch]$PassThru - ) - begin { - foreach ($Key in $Script:SeKeys.Name) { - $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key - } - } - process { - if ($ClearFirst) { $Element.Clear() } - - $Element.SendKeys($Keys) - - if ($Submit) { $Element.Submit() } - if ($SleepSeconds) { Start-Sleep -Seconds $SleepSeconds } - if ($PassThru) { $Element } - } -} - -function Get-SeSelectionOption { - [Alias('SeSelection')] - [cmdletbinding(DefaultParameterSetName = 'default')] - param ( - - [Parameter(Mandatory = $true, ParameterSetName = 'byValue', Position = 0, ValueFromPipelineByPropertyName = $true)] - [String]$ByValue, - - [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)] - [OpenQA.Selenium.IWebElement]$Element, - - [Parameter(Mandatory = $true, ParameterSetName = 'byText', ValueFromPipelineByPropertyName = $true)] - [String]$ByFullText, - - [Parameter(Mandatory = $true, ParameterSetName = 'bypart', ValueFromPipelineByPropertyName = $true)] - [String]$ByPartialText, - - [Parameter(Mandatory = $true, ParameterSetName = 'byIndex', ValueFromPipelineByPropertyName = $true)] - [int]$ByIndex, - - [Parameter(Mandatory = $false, ParameterSetName = 'default')] - [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] - [Parameter(Mandatory = $false, ParameterSetName = 'byText')] - [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] - [switch]$Clear, - - [Parameter(Mandatory = $false, ParameterSetName = 'default')] - [switch]$ListOptionText, - - [Parameter(Mandatory = $true, ParameterSetName = 'multi')] - [switch]$IsMultiSelect, - - [Parameter(Mandatory = $true, ParameterSetName = 'selected')] - [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] - [Parameter(Mandatory = $false, ParameterSetName = 'byText')] - [Parameter(Mandatory = $false, ParameterSetName = 'bypart')] - [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] - [switch]$GetSelected, - - [Parameter(Mandatory = $true, ParameterSetName = 'allSelected')] - [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] - [Parameter(Mandatory = $false, ParameterSetName = 'byText')] - [Parameter(Mandatory = $false, ParameterSetName = 'bypart')] - [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] - [switch]$GetAllSelected, - - [Parameter(Mandatory = $false, ParameterSetName = 'byValue')] - [Parameter(Mandatory = $false, ParameterSetName = 'byText')] - [Parameter(Mandatory = $false, ParameterSetName = 'bypart')] - [Parameter(Mandatory = $false, ParameterSetName = 'byIndex')] - [Alias('PT')] - [switch]$PassThru - ) - try { - #byindex can be 0, but ByText and ByValue can't be empty strings - if ($ByFullText -or $ByPartialText -or $ByValue -or $PSBoundParameters.ContainsKey('ByIndex')) { - if ($Clear) { - if ($ByText) { [SeleniumSelection.Option]::DeselectByText($Element, $ByText) } - elseif ($ByValue) { [SeleniumSelection.Option]::DeselectByValue($Element, $ByValue) } - else { [SeleniumSelection.Option]::DeselectByIndex($Element, $ByIndex) } - } - else { - if ($ByText) { [SeleniumSelection.Option]::SelectByText($Element, $ByText, $false) } - if ($ByPartialText) { [SeleniumSelection.Option]::SelectByText($Element, $ByPartialText, $true) } - elseif ($ByValue) { [SeleniumSelection.Option]::SelectByValue($Element, $ByValue) } - else { [SeleniumSelection.Option]::SelectByIndex($Element, $ByIndex) } - } - } - elseif ($Clear) { [SeleniumSelection.Option]::DeselectAll($Element) } - if ($IsMultiSelect) { - return [SeleniumSelection.Option]::IsMultiSelect($Element) - } - if ($PassThru -and ($GetAllSelected -or $GetAllSelected)) { - Write-Warning -Message "-Passthru option ignored because other values are returned" - } - if ($GetSelected) { - return [SeleniumSelection.Option]::GetSelectedOption($Element).text - } - if ($GetAllSelected) { - return [SeleniumSelection.Option]::GetAllSelectedOptions($Element).text - } - if ($PSCmdlet.ParameterSetName -eq 'default') { - [SeleniumSelection.Option]::GetOptions($Element) | Select-Object -ExpandProperty Text - } - elseif ($PassThru) { $Element } - } - catch { - throw "An error occured checking the selection box, the message was:`r`n $($_.exception.message)" - } -} - -function SeShouldHave { - [cmdletbinding(DefaultParameterSetName = 'DefaultPS')] - param( - [Parameter(ParameterSetName = 'DefaultPS', Mandatory = $true , Position = 0, ValueFromPipeline = $true)] - [Parameter(ParameterSetName = 'Element' , Mandatory = $true , Position = 0, ValueFromPipeline = $true)] - [string[]]$Selection, - - [Parameter(ParameterSetName = 'DefaultPS', Mandatory = $false)] - [Parameter(ParameterSetName = 'Element' , Mandatory = $false)] - [ValidateSet('CssSelector', 'Name', 'Id', 'ClassName', 'LinkText', 'PartialLinkText', 'TagName', 'XPath')] - [ByTransformAttribute()] - [string]$By = 'XPath', - - [Parameter(ParameterSetName = 'Element' , Mandatory = $true , Position = 1)] - [string]$With, - - [Parameter(ParameterSetName = 'Alert' , Mandatory = $true)] - [switch]$Alert, - [Parameter(ParameterSetName = 'NoAlert' , Mandatory = $true)] - [switch]$NoAlert, - [Parameter(ParameterSetName = 'Title' , Mandatory = $true)] - [switch]$Title, - [Parameter(ParameterSetName = 'URL' , Mandatory = $true)] - [Alias('URI')] - [switch]$URL, - - [Parameter(ParameterSetName = 'Element' , Mandatory = $false, Position = 3)] - [Parameter(ParameterSetName = 'Alert' , Mandatory = $false, Position = 3)] - [Parameter(ParameterSetName = 'Title' , Mandatory = $false, Position = 3)] - [Parameter(ParameterSetName = 'URL' , Mandatory = $false, Position = 3)] - [ValidateSet('like', 'notlike', 'match', 'notmatch', 'contains', 'eq', 'ne', 'gt', 'lt')] - [OperatorTransformAttribute()] - [String]$Operator = 'like', - - [Parameter(ParameterSetName = 'Element' , Mandatory = $false, Position = 4)] - [Parameter(ParameterSetName = 'Alert' , Mandatory = $false, Position = 4)] - [Parameter(ParameterSetName = 'Title' , Mandatory = $true , Position = 4)] - [Parameter(ParameterSetName = 'URL' , Mandatory = $true , Position = 4)] - [Alias('contains', 'like', 'notlike', 'match', 'notmatch', 'eq', 'ne', 'gt', 'lt')] - [AllowEmptyString()] - $Value, - - [Parameter(ParameterSetName = 'DefaultPS')] - [Parameter(ParameterSetName = 'Element')] - [Parameter(ParameterSetName = 'Alert')] - [Alias('PT')] - [switch]$PassThru, - - [Int]$Timeout = 0 - ) - begin { - $endTime = [datetime]::now.AddSeconds($Timeout) - $lineText = $MyInvocation.Line.TrimEnd("$([System.Environment]::NewLine)") - $lineNo = $MyInvocation.ScriptLineNumber - $file = $MyInvocation.ScriptName - Function expandErr { - param ($message) - [Management.Automation.ErrorRecord]::new( - [System.Exception]::new($message), - 'PesterAssertionFailed', - [Management.Automation.ErrorCategory]::InvalidResult, - @{ - Message = $message - File = $file - Line = $lineNo - Linetext = $lineText - } - ) - } - function applyTest { - param( - $Testitems, - $Operator, - $Value - ) - Switch ($Operator) { - 'Contains' { return ($testitems -contains $Value) } - 'eq' { return ($TestItems -eq $Value) } - 'ne' { return ($TestItems -ne $Value) } - 'like' { return ($TestItems -like $Value) } - 'notlike' { return ($TestItems -notlike $Value) } - 'match' { return ($TestItems -match $Value) } - 'notmatch' { return ($TestItems -notmatch $Value) } - 'gt' { return ($TestItems -gt $Value) } - 'le' { return ($TestItems -lt $Value) } - } - } - - #if operator was not passed, allow it to be taken from an alias for the -value - if (-not $PSBoundParameters.ContainsKey('operator') -and $lineText -match ' -(eq|ne|contains|match|notmatch|like|notlike|gt|lt) ') { - $Operator = $matches[1] - } - $Success = $false - $foundElements = @() - } - process { - #If we have been asked to check URL or title get them from the driver. Otherwise call Get-SEElement. - if ($URL) { - do { - $Success = applyTest -testitems $Global:SeDriver.Url -operator $Operator -value $Value - Start-Sleep -Milliseconds 500 - } - until ($Success -or [datetime]::now -gt $endTime) - if (-not $Success) { - throw (expandErr "PageURL was $($Global:SeDriver.Url). The comparison '-$operator $value' failed.") - } - } - elseif ($Title) { - do { - $Success = applyTest -testitems $Global:SeDriver.Title -operator $Operator -value $Value - Start-Sleep -Milliseconds 500 - } - until ($Success -or [datetime]::now -gt $endTime) - if (-not $Success) { - throw (expandErr "Page title was $($Global:SeDriver.Title). The comparison '-$operator $value' failed.") - } - } - elseif ($Alert -or $NoAlert) { - do { - try { - $a = $Global:SeDriver.SwitchTo().alert() - $Success = $true - } - catch { - Start-Sleep -Milliseconds 500 - } - finally { - if ($NoAlert -and $a) { throw (expandErr "Expected no alert but an alert of '$($a.Text)' was displayed") } - } - } - until ($Success -or [datetime]::now -gt $endTime) - - if ($Alert -and -not $Success) { - throw (expandErr "Expected an alert but but none was displayed") - } - elseif ($value -and -not (applyTest -testitems $a.text -operator $Operator -value $value)) { - throw (expandErr "Alert text was $($a.text). The comparison '-$operator $value' failed.") - } - elseif ($PassThru) { return $a } - } - else { - foreach ($s in $Selection) { - $GSEParams = @{By = $By; Selection = $s } - if ($Timeout) { $GSEParams['Timeout'] = $Timeout } - try { $e = Get-SeElement @GSEParams } - catch { throw (expandErr $_.Exception.Message) } - - #throw if we didn't get the element; if were only asked to check it was there, return gracefully - if (-not $e) { throw (expandErr "Didn't find '$s' by $by") } - else { - Write-Verbose "Matched element(s) for $s" - $foundElements += $e - } - } - } - } - end { - if ($PSCmdlet.ParameterSetName -eq "DefaultPS" -and $PassThru) { return $e } - elseif ($PSCmdlet.ParameterSetName -eq "DefaultPS") { return } - else { - foreach ($e in $foundElements) { - switch ($with) { - 'Text' { $testItem = $e.Text } - 'Displayed' { $testItem = $e.Displayed } - 'Enabled' { $testItem = $e.Enabled } - 'TagName' { $testItem = $e.TagName } - 'X' { $testItem = $e.Location.X } - 'Y' { $testItem = $e.Location.Y } - 'Width' { $testItem = $e.Size.Width } - 'Height' { $testItem = $e.Size.Height } - 'Choice' { $testItem = (Get-SeSelectionOption -Element $e -ListOptionText) } - default { $testItem = $e.GetAttribute($with) } - } - if (-not $testItem -and ($Value -ne '' -and $foundElements.count -eq 1)) { - throw (expandErr "Didn't find '$with' on element") - } - if (applyTest -testitems $testItem -operator $Operator -value $Value) { - $Success = $true - if ($PassThru) { $e } - } - } - if (-not $Success) { - if ($foundElements.count -gt 1) { - throw (expandErr "$Selection match $($foundElements.Count) elements, none has a value for $with which passed the comparison '-$operator $value'.") - } - else { - throw (expandErr "$with had a value of $testitem which did not pass the the comparison '-$operator $value'.") - } - } - } - } -} +$functionFolders = @('Public', 'Internal', 'Classes') +ForEach ($folder in $functionFolders) { + $folderPath = Join-Path -Path $PSScriptRoot -ChildPath $folder + if ($folder -eq 'Internal') { + . $folderPath\init.ps1; + } + If (Test-Path -Path $folderPath) { + + Write-Verbose -Message "Importing from $folder" + $functions = Get-ChildItem -Path $folderPath -Filter '*.ps1' + ForEach ($function in $functions) { + Write-Verbose -Message " Importing $($function.BaseName)" + . $($function.FullName) + } + } +} +$publicFunctions = (Get-ChildItem -Path "$PSScriptRoot\Public" -Filter '*.ps1').BaseName +Export-ModuleMember -Function $publicFunctions diff --git a/SeleniumClasses.ps1 b/SeleniumClasses.ps1 index e2c5e9f..36624da 100644 --- a/SeleniumClasses.ps1 +++ b/SeleniumClasses.ps1 @@ -1,11 +1,10 @@ -if ('ValidateURIAttribute' -as [type]) -{ +if ('ValidateURIAttribute' -as [type]) { class ValidateURIAttribute : System.Management.Automation.ValidateArgumentsAttribute { [void] Validate([object] $arguments , [System.Management.Automation.EngineIntrinsics]$EngineIntrinsics) { $Out = $null - if ([uri]::TryCreate($arguments,[System.UriKind]::Absolute, [ref]$Out)) {return} - else {throw [System.Management.Automation.ValidationMetadataException]::new('Incorrect StartURL please make sure the URL starts with http:// or https://')} + if ([uri]::TryCreate($arguments, [System.UriKind]::Absolute, [ref]$Out)) { return } + else { throw [System.Management.Automation.ValidationMetadataException]::new('Incorrect StartURL please make sure the URL starts with http:// or https://') } return } } @@ -13,12 +12,11 @@ if ('ValidateURIAttribute' -as [type]) } -if ('ValidateIsWebDriverAttribute' -as [type]) -{ +if ('ValidateIsWebDriverAttribute' -as [type]) { class ValidateIsWebDriverAttribute : System.Management.Automation.ValidateArgumentsAttribute { [void] Validate([object] $arguments , [System.Management.Automation.EngineIntrinsics]$EngineIntrinsics) { if ($arguments -isnot [OpenQA.Selenium.Remote.RemoteWebDriver]) { - throw [System.Management.Automation.ValidationMetadataException]::new('Target was not a valid web driver') + throw [System.Management.Automation.ValidationMetadataException]::new('Target was not a valid web driver') } return } @@ -26,19 +24,18 @@ if ('ValidateIsWebDriverAttribute' -as [type]) class ValidateIsWebDriver : ValidateIsWebDriverAttribute {} } -if ('ByTransformAttribute' -as [type]) -{ +if ('ByTransformAttribute' -as [type]) { #Allow BY to shorten cssSelector, ClassName, LinkText, and TagName - class ByTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + class ByTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { [object] Transform([System.Management.Automation.EngineIntrinsics]$EngineIntrinsics, [object] $InputData) { if ($inputData -match 'CssSelector|Name|Id|ClassName|LinkText|PartialLinkText|TagName|XPath') { return $InputData } switch -regex ($InputData) { - "^css" {return 'CssSelector'; break} - "^class" {return 'ClassName' ; break} - "^link" {return 'LinkText' ; break} - "^tag" {return 'TagName' ; break} + "^css" { return 'CssSelector'; break } + "^class" { return 'ClassName' ; break } + "^link" { return 'LinkText' ; break } + "^tag" { return 'TagName' ; break } } return $InputData } @@ -47,20 +44,19 @@ if ('ByTransformAttribute' -as [type]) class ByTransform : ByTransformAttribute {} } -if ('OperatorTransformAttribute' -as [type]) -{ +if ('OperatorTransformAttribute' -as [type]) { #Allow operator to use containing, matching, matches, equals etc. - class OperatorTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + class OperatorTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { [object] Transform([System.Management.Automation.EngineIntrinsics]$EngineIntrinsics, [object] $InputData) { if ($inputData -match '^(contains|like|notlike|match|notmatch|eq|ne|gt|lt)$#') { return $InputData } switch -regex ($InputData) { - "^contain" {return 'contains' ; break} - "^match" {return 'match' ; break} - "^n\w*match" {return 'notmatch' ; break} - "^eq" {return 'eq' ; break} - "^n\w*eq" {return 'ne' ; break} + "^contain" { return 'contains' ; break } + "^match" { return 'match' ; break } + "^n\w*match" { return 'notmatch' ; break } + "^eq" { return 'eq' ; break } + "^n\w*eq" { return 'ne' ; break } } return $InputData } @@ -124,4 +120,4 @@ namespace SeleniumSelection { } } } -"@ -ReferencedAssemblies $dll1Path,$dll2Path, mscorlib \ No newline at end of file +"@ -ReferencedAssemblies $dll1Path, $dll2Path, mscorlib \ No newline at end of file diff --git a/Tests/selenium-powershell.tests.ps1 b/Tests/selenium-powershell.tests.ps1 new file mode 100644 index 0000000..c19b6c2 --- /dev/null +++ b/Tests/selenium-powershell.tests.ps1 @@ -0,0 +1,20 @@ +$moduleRoot = Resolve-Path "$PSScriptRoot\.." +$moduleName = Split-Path $moduleRoot -Leaf + +Describe "General project validation: $moduleName" { + + $scripts = Get-ChildItem $moduleRoot -Include *.ps1, *.psm1, *.psd1 -Recurse + + # TestCases are splatted to the script so we need hashtables + $testCase = $scripts | Foreach-Object {@{file = $_}} + It "Script should be valid powershell" -TestCases $testCase { + param($file) + + $file.fullname | Should Exist + + $contents = Get-Content -Path $file.fullname -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors.Count | Should Be 0 + } +} \ No newline at end of file