diff --git a/CI/CI.ps1 b/CI/CI.ps1 index 00d8145..25ac684 100644 --- a/CI/CI.ps1 +++ b/CI/CI.ps1 @@ -1,37 +1,67 @@ param ( - [string[]]$BrowserList = @('Chrome', 'Firefox') + [String]$ModulePath, + [string[]]$BrowserList = @('Chrome', 'Firefox'), + [Switch]$UseDebugVersion ) + +if ([String]::IsNullOrEmpty($ModulePath)) { $ModulePath = $pwd.path.Replace('\', '/') } +$env:ModulePath = $ModulePath +Write-Host "ModulePath: $ModulePath" +Write-Host "BrowserList: $($BrowserList -join ',')" +$Global:BrowserList = $BrowserList #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 -notlike 'win*') { $Global:HeadlessOnly = $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 .\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 +$ModulePathSuffix = 'Output/Selenium/' +if ($UseDebugVersion) { $ModulePathSuffix = ''; Write-Host 'Debug version will be used' -ForegroundColor Yellow } +Import-Module "$ModulePath/$($ModulePathSuffix)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 } +# $PesterLock = @{MinimumVersion = '4.10.0.0' ; MaximumVersion = '4.99.0.0' } +# $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 @PesterLock +# } +# else { $checkPester | Out-Host } + +#Import-Module Pester -RequiredVersion 4.10.1 +#Import-Module ImportExcel -RequiredVersion 7.1.1 + +if (Test-path "$ModulePath/Modules") { + Import-Module "$ModulePath/Modules/Pester/5.0.3/Pester.psd1" + Import-Module "$ModulePath/Modules/ImportExcel/7.1.1/ImportExcel.psd1" } -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 { + Import-Module -Name Pester -RequiredVersion 5.0.3 + Import-Module -Name ImportExcel -RequiredVersion 7.1.1 } -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. + +Write-verbose -Verbose "Pester $((Get-Module -Name Pester).Version.ToString()) loaded" +Write-verbose -Verbose "ImportExcel $((Get-Module -Name ImportExcel).Version.ToString()) loaded" + +# #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' + Path = "$ModulePath/Examples/Combined.tests.ps1" } foreach ( $b in $BrowserList) { - $env:DefaultBrowser = $b + $Global:DefaultBrowser = $b $RunParameters['OutputFile'] = Join-Path $pwd "TestResults-$platform$b.xml" $RunParameters['WorkSheetName'] = "$B $Platform" $RunParameters | Out-Host @@ -39,31 +69,31 @@ foreach ( $b in $BrowserList) { } #Merge the results sheets into a sheet named 'combined'. -$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 +# $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 -#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 -2..$ws.Dimension.end.Column | ForEach-Object { - if ($ws.Cells[1, $_].value -notmatch '^Name|Result$|PS\dGroup$') { - Set-ExcelColumn -Worksheet $ws -Column $_ -Hid - } - elseif ($ws.Cells[1, $_].value -match 'Result$' ) { - Set-ExcelColumn -Worksheet $ws -Column $_ -Width 17 - 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 '^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 -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 +# #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 +# 2..$ws.Dimension.end.Column | ForEach-Object { +# if ($ws.Cells[1, $_].value -notmatch '^Name|Result$|PS\dGroup$') { +# Set-ExcelColumn -Worksheet $ws -Column $_ -Hid +# } +# elseif ($ws.Cells[1, $_].value -match 'Result$' ) { +# Set-ExcelColumn -Worksheet $ws -Column $_ -Width 17 +# 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 '^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 +# 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/Pester-To-XLSx.ps1 b/CI/Pester-To-XLSx.ps1 index 1f1e865..2939843 100644 --- a/CI/Pester-To-XLSx.ps1 +++ b/CI/Pester-To-XLSx.ps1 @@ -1,66 +1,64 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectComparisonWithNull','',Justification='Intentional use to select non null array items')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectComparisonWithNull', '', Justification = 'Intentional use to select non null array items')] [CmdletBinding(DefaultParameterSetName = 'Default')] param( - [Parameter(Position=0)] - [string]$XLFile, + [Parameter(Position = 0)] + [string]$XLFile, - [Parameter(ParameterSetName='Default',Position=1)] - [Alias('Path', 'relative_path')] - [object[]]$Script = '.', + [Parameter(ParameterSetName = 'Default', Position = 1)] + [String]$Path = '.', - [Parameter(ParameterSetName='Existing',Mandatory=$true)] - [switch] - $UseExisting, + [Parameter(ParameterSetName = 'Existing', Mandatory = $true)] + [switch] + $UseExisting, - [Parameter(ParameterSetName='Default', Position=2)] - [Parameter(ParameterSetName='Existing',Position=2, Mandatory=$true)] - [string]$OutputFile, + [Parameter(ParameterSetName = 'Default', Position = 2)] + [Parameter(ParameterSetName = 'Existing', Position = 2, Mandatory = $true)] + [string]$OutputFile, - [Parameter(ParameterSetName='Default')] - [Alias("Name")] - [string[]]$TestName, + [Parameter(ParameterSetName = 'Default')] + [Alias("Name")] + [string[]]$TestName, - [Parameter(ParameterSetName='Default')] - [switch]$EnableExit, + [Parameter(ParameterSetName = 'Default')] + [switch]$EnableExit, - [Parameter(ParameterSetName='Default')] - [Alias('Tags')] - [string[]]$Tag, - [string[]]$ExcludeTag, + [Parameter(ParameterSetName = 'Default')] + [Alias('Tags')] + [string[]]$Tag, + [string[]]$ExcludeTag, - [Parameter(ParameterSetName='Default')] - [switch]$Strict, + [Parameter(ParameterSetName = 'Default')] + [switch]$Strict, - [string]$WorkSheetName = 'PesterResults', - [switch]$append, - [switch]$Show + [string]$WorkSheetName = 'PesterResults', + [switch]$append, + [switch]$Show ) -$InvokePesterParams = @{OutputFormat = 'NUnitXml'} + $PSBoundParameters -if (-not $InvokePesterParams['OutputFile']) { - $InvokePesterParams['OutputFile'] = Join-Path -ChildPath 'Pester.xml'-Path ([environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments)) -} -if ($InvokePesterParams['Show'] ) {} -if ($InvokePesterParams['XLFile']) {$InvokePesterParams.Remove('XLFile')} -else {$XLFile = $InvokePesterParams['OutputFile'] -replace '.xml$','.xlsx'} +$InvokePesterParams = $PSBoundParameters + +if ($InvokePesterParams['XLFile']) { $InvokePesterParams.Remove('XLFile') } +else { $XLFile = $InvokePesterParams['OutputFile'] -replace '.xml$', '.xlsx' } if (-not $UseExisting) { - $InvokePesterParams.Remove('Append') - $InvokePesterParams.Remove('UseExisting') - $InvokePesterParams.Remove('Show') - $InvokePesterParams.Remove('WorkSheetName') - Invoke-Pester @InvokePesterParams + $InvokePesterParams.Remove('Append') | Out-Null + $InvokePesterParams.Remove('UseExisting') | Out-Null + $InvokePesterParams.Remove('Show') | Out-Null + $InvokePesterParams.Remove('WorkSheetName') | Out-Null + $InvokePesterParams.Remove('OutputFile') | Out-Null + Set-Location $env:ModulePath + Invoke-Pester @InvokePesterParams -CI -Output Detailed -ErrorAction Continue } -if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) { - throw "Could not output file $($InvokePesterParams['OutputFile'])"; return -} +# if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) { +# throw "Could not output file $($InvokePesterParams['OutputFile'])"; return +# } -$resultXML = ([xml](Get-Content $InvokePesterParams['OutputFile'])).'test-results' -$startDate = [datetime]$resultXML.date -$startTime = $resultXML.time -$machine = $resultXML.environment.'machine-name' -#$user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user -$os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.environment.'os-version')" +$resultXML = ([xml](Get-Content -Path (Join-Path $env:ModulePath 'testResults.xml'))).'test-results' +$startDate = [datetime]$resultXML.date +$startTime = $resultXML.time +$machine = $resultXML.environment.'machine-name' +$user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user +$os = $resultXML.environment.platform -replace '\|.*$', " $($resultXML.environment.'os-version')" <#hierarchy goes root, [date], start [time], [Name] (always "Pester"), test results broken down as [total],[errors],[failures],[not-run] etc. Environment (user & machine info) @@ -80,52 +78,54 @@ $os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.e Test-case [description] - name as rendered for display with filled in #> $testResults = foreach ($test in $resultXML.'test-suite'.results.'test-suite') { - $testPs1File = $test.name - #Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case - if ($test.results.'test-suite'.results.'test-suite' -ne $null) { - foreach ($suite in $test.results.'test-suite') { - $Describe = $suite.description - foreach ($subsuite in $suite.results.'test-suite') { - $Context = $subsuite.description - if ($subsuite.results.'test-suite'.results.'test-case') { - $testCases = $subsuite.results.'test-suite'.results.'test-case' - } - else {$testCases = $subsuite.results.'test-case'} - $testCases | ForEach-Object { - New-Object -TypeName psobject -Property ([ordered]@{ - Machine = $machine ; OS = $os - Date = $startDate ; Time = $startTime - Executed = $(if ($_.executed -eq 'True') {1}) - Success = $(if ($_.success -eq 'True') {1}) - Duration = $_.time - File = $testPs1File; Group = $Describe - SubGroup = $Context ; Name =($_.Description -replace '\s{2,}', ' ') - Result = $_.result ; FullDesc = '=Group&" "&SubGroup&" "&Name'}) - } - } + $testPs1File = $test.name + #Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case + if ($test.results.'test-suite'.results.'test-suite' -ne $null) { + foreach ($suite in $test.results.'test-suite') { + $Describe = $suite.description + foreach ($subsuite in $suite.results.'test-suite') { + $Context = $subsuite.description + if ($subsuite.results.'test-suite'.results.'test-case') { + $testCases = $subsuite.results.'test-suite'.results.'test-case' } - } - else { - $test.results.'test-suite' | ForEach-Object { - $Describe = $_.description - $_.results.'test-case'| ForEach-Object { - New-Object -TypeName psobject -Property ([ordered]@{ - Machine = $machine ; OS = $os - Date = $startDate ; Time = $startTime - Executed = $(if ($_.executed -eq 'True') {1}) - Success = $(if ($_.success -eq 'True') {1}) - Duration = $_.time - File = $testPs1File; Group = $Describe - SubGroup = $null ; Name =($_.Description -replace '\s{2,}', ' ') - Result = $_.result ; FullDesc = '=Group&" "&Test'}) - } + else { $testCases = $subsuite.results.'test-case' } + $testCases | ForEach-Object { + New-Object -TypeName psobject -Property ([ordered]@{ + Machine = $machine ; OS = $os + Date = $startDate ; Time = $startTime + Executed = $(if ($_.executed -eq 'True') { 1 }) + Success = $(if ($_.success -eq 'True') { 1 }) + Duration = $_.time + File = $testPs1File; Group = $Describe + SubGroup = $Context ; Name = ($_.Description -replace '\s{2,}', ' ') + Result = $_.result ; FullDesc = '=Group&" "&SubGroup&" "&Name' + }) } + } + } + } + else { + $test.results.'test-suite' | ForEach-Object { + $Describe = $_.description + $_.results.'test-case' | ForEach-Object { + New-Object -TypeName psobject -Property ([ordered]@{ + Machine = $machine ; OS = $os + Date = $startDate ; Time = $startTime + Executed = $(if ($_.executed -eq 'True') { 1 }) + Success = $(if ($_.success -eq 'True') { 1 }) + Duration = $_.time + File = $testPs1File; Group = $Describe + SubGroup = $null ; Name = ($_.Description -replace '\s{2,}', ' ') + Result = $_.result ; FullDesc = '=Group&" "&Test' + }) + } } + } } -if (-not $testResults) {Write-Warning 'No Results found' ; return} +if (-not $testResults) { Write-Warning 'No Results found' ; return } $clearSheet = -not $Append -$excel = $testResults | Export-Excel -Path $xlFile -WorkSheetname $WorkSheetName -ClearSheet:$clearSheet -Append:$append -PassThru -BoldTopRow -FreezeTopRow -AutoSize -AutoFilter -AutoNameRange -$ws = $excel.Workbook.Worksheets[$WorkSheetName] +$excel = $testResults | Export-Excel -Path $xlFile -WorkSheetname $WorkSheetName -ClearSheet:$clearSheet -Append:$append -PassThru -BoldTopRow -FreezeTopRow -AutoSize -AutoFilter -AutoNameRange +$ws = $excel.Workbook.Worksheets[$WorkSheetName] <# Worksheet should look like .. |A |B |C D |E |F |G |H |I |J |K |L |M 1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription @@ -136,7 +136,7 @@ $ws = $excel.Workbook.Worksheets[$WorkSheetName] Set-Column -Worksheet $ws -Column 3 -NumberFormat 'Short Date' # -AutoSize #Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup) -(5..10) | ForEach-Object {Set-ExcelColumn -Worksheet $ws -Column $_ -Hide } +(5..10) | ForEach-Object { Set-ExcelColumn -Worksheet $ws -Column $_ -Hide } #Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save $endRow = $ws.Dimension.End.Row diff --git a/CI/RunTest.yml b/CI/RunTest.yml new file mode 100644 index 0000000..3097588 --- /dev/null +++ b/CI/RunTest.yml @@ -0,0 +1,54 @@ +# https://aka.ms/yaml + +parameters: + - name: Browser + type: string + values: + - Chrome + - Edge + - Firefox + - InternetExplorer + - MSEdge + - name: OS + type: string + default: ubuntu + values: + - ubuntu + - windows + - name: Stack + type: string + default: pwsh + values: + - powershell + - pwsh + +jobs: + - job: "${{ parameters.OS }}_${{ parameters.Browser }}_${{ parameters.Stack }}" + displayName: "${{ parameters.Browser }} - ${{ parameters.OS }} (${{ parameters.Stack }})" + pool: + vmImage: "${{ parameters.OS }}-latest" + steps: + - checkout: none + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: "dependencies_pwsh" + #artifactName: "dependencies_${{ parameters.Stack }}" + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: "checkout" + - ${{ if eq(parameters.Stack, 'Powershell') }}: + - powershell: "$(Pipeline.Workspace)/CI/CI.ps1 -ModulePath '$(Pipeline.Workspace)' -browserlist ${{ parameters.Browser }}" + displayName: "Run ${{ parameters.Browser }} Test on ${{ parameters.OS }} (ps)" + - ${{ if eq(parameters.Stack, 'pwsh') }}: + - pwsh: "$(Pipeline.Workspace)/CI/CI.ps1 -ModulePath '$(Pipeline.Workspace)' -browserlist ${{ parameters.Browser }}" + displayName: "Run ${{ parameters.Browser }} Test on ${{ parameters.OS }} (pwsh)" + - task: PublishPipelineArtifact@1 + inputs: + targetPath: "$(Build.ArtifactStagingDirectory)/results" + artifact: "${{ parameters.OS }} - ${{ parameters.Browser }} - ${{ parameters.Stack }} Results" + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFormat: "NUnit" + testResultsFiles: "$(Pipeline.Workspace)/testResults.xml" + failTaskOnFailedTests: true diff --git a/CI/pipeline.yml b/CI/pipeline.yml index 2118f43..7b036bc 100644 --- a/CI/pipeline.yml +++ b/CI/pipeline.yml @@ -12,37 +12,102 @@ trigger: - ChangeLog.Txt - README.md -jobs: - - job: "Windows" - pool: - 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 +stages: + - stage: Checkout + displayName: "Checkout and dependencies" + jobs: + # - job: "Savedependencies" + # displayName: "Save dependencies" + # pool: + # vmImage: "windows-latest" + # steps: + # - checkout: none + # - powershell: | + # New-Item -ItemType Directory -Path './Modules' + # $Params = @{Path = './Modules';Repository = 'PSGallery'} + # Save-Module -Name Pester -RequiredVersion 4.10.1 @Params + # Save-Module -Name ImportExcel -RequiredVersion 7.1.1 @Params + # displayName: "Upload Powershell dependencies to pipeline" + # - task: CopyFiles@2 + # inputs: + # SourceFolder: $(Build.SourcesDirectory) + # TargetFolder: $(Build.ArtifactStagingDirectory) + # - task: PublishPipelineArtifact@1 + # inputs: + # TargetPath: $(Build.ArtifactStagingDirectory) + # artifact: dependencies_powershell + - job: "SaveCoreDependencies" + displayName: "Save core dependencies" + pool: + vmImage: "ubuntu-latest" + steps: + - checkout: none + - pwsh: | + New-Item -ItemType Directory -Path './Modules' + $Params = @{Path = './Modules';Repository = 'PSGallery'} + Save-Module -Name Pester -RequiredVersion 5.0.3 @Params + Save-Module -Name ImportExcel -RequiredVersion 7.1.1 @Params + displayName: "Upload pwsh dependencies to pipeline" + - task: CopyFiles@2 + inputs: + SourceFolder: $(Build.SourcesDirectory) + TargetFolder: $(Build.ArtifactStagingDirectory) + - task: PublishPipelineArtifact@1 + inputs: + TargetPath: $(Build.ArtifactStagingDirectory) + artifact: dependencies_pwsh + - job: "Checkout" + pool: + vmImage: "ubuntu-latest" + steps: + - checkout: self + - task: CopyFiles@2 + inputs: + SourceFolder: $(Build.SourcesDirectory) + TargetFolder: $(Build.ArtifactStagingDirectory) + - task: PublishPipelineArtifact@1 + inputs: + TargetPath: $(Build.ArtifactStagingDirectory) + artifact: checkout - - job: "Ubuntu" - pool: - 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 + - stage: Tests + jobs: + - template: RunTest.yml + parameters: + Browser: Chrome + - template: RunTest.yml + parameters: + Browser: Firefox + - template: RunTest.yml + parameters: + Browser: Chrome + OS: windows + - template: RunTest.yml + parameters: + Browser: Firefox + OS: windows + - template: RunTest.yml + parameters: + Browser: Chrome + OS: windows + Stack: powershell + - template: RunTest.yml + parameters: + Browser: Firefox + OS: windows + Stack: powershell + - template: RunTest.yml + parameters: + Browser: InternetExplorer + OS: windows + Stack: powershell + # - template: RunTest.yml + # parameters: + # Browser: Edge + # OS: windows + # Stack: powershell + # - template: RunTest.yml + # parameters: + # Browser: MSEdge + # OS: windows + # Stack: powershell diff --git a/ChangeLog.md b/ChangeLog.md index 10d0fdb..fbe293d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,7 +1,65 @@ -# 3.1.0 - Unreleased +#4.0.0 (Unreleased) + + +# 4.0.0-preview1 (Prerelease) +Note: V4 have an enormous amount of breakchanges. Most of the cmdlet have been rewriten in a way or another. + +Duplicate functions have been eliminated along with all aliases that piled up over time. Start-SeDriver provide an unified front to start all the browsers and the $Driver parameter / default driver are no more. Instead, starting a driver make it the active driver. Switching active driver can be accomplished through the Switch-SeDriver cmdlet. ## Added +- Convert-toSeSelenium to convert IDE projects to Selenium-Powershell script +- Update-SeDriver to download the latest driver (Support only Chrome currently) +- Support for UserAgent in Start-SeDriver (#91) +- New view for IwebDriver (#111). IWebDriver will now display as a table in the console by default instead of a list. +- Get-SeElement - New view. Elements will now be returned in a table view to show the essential only. This make it significantly easier to deal with elements in the console interactively (#115) +- Get-SeElement - Bychained support. The cmdlet will now drilldown when multiple by / value are provided to allow for instance the selection of links in a div containing a specific classname. This is an alternative for those less savy with Xpath (#116) +- Get-SeHtml - Allow the retrieval of the html of an element (or driver is no element is provided). Essentially a wrapper around $Element.GetAttribute('xxHTML') (xx: Inner /Outer) (#118) +- New-SeDriverService - Allow the creation of a driver service to be used later on with Start-SeDriver. Only useful if you need to do change to the service parameters native object before starting the driver (#119) +- Invoke-SeMouseAction - Support for interactions (#122) +- Wait-SeDriver / Wait-SeElement expliciti wait support (#125) +- Get-SeElement -Attributes. Allow getting specific attributes (or all using *) to the elements to be returned. Attributes will be available in an Attributes string dictionary attached to each elements. (#133) +- Position / Size parameter for Start-SeDriver. Allow starting the driver at a specified position and size. If no command line available (or not implemented), the driver will start with the default settings and the be moved. (#134) +- Get-SeElement -Single switch added. Define the expectaction that only one element should be returned (#144) +- Get/Set-SeDriverTimeout - Allow changing driver timeouts easily (#150) +- Invoke-SeJavascript - A wrapper around $Driver.ExecuteScript (#151) +- Get-SeFrame, wrapper around Get-SeElement to show iframe along with their name / id in a convenient view (#159) +- New-SeWindow / Remove-SeWindow cmdlet added to complement the existing Get/Switch (#170) +- Get-SeInput (#178) - A wrapper around Get-SeElement to get input element. + + +## Changed +- AsDefaultDriver implementation changed. Instead, Start-SeDriver automatically make the started driver the default. (#93) +- Driver parameter was removed on most cmdleet. It is now expected to use the Switch-SeDriver cmdlet to change the active driver if multiple are open. +- Start-SeChrome and other have been removed in favor of Start-SeDriver -Browser Chrome (#100) +- #98 Removed duplicate functions that performed the same thing or overlapped significantly +- Removed all the aliases everywhere on all the parameter / functions in favor of a more rigid way of writing things (#99) +- Standardize parameters. Some parameters had different names to mean the same thing (#100) +- Revamp Get-SeSelectionOption. The cmdlet have been separated in 3 cmdlet Get/Clear/Set -SeSelectValue. The get cmdlet will also now return the Text & Value of the selected element instead of the text only. (#112) +- Set-SeUrl now have a -Depth parameter to navigate forward or back x times (#124) +- Get-SeElement now returns visible elements by default. To view hidden elements, the All switch parameter need to be used (#126) +- Start-SeDriver -Quiet parameter removal. Quiet is now the default. This remove the extra Selenium verbose and resolves an issue with Driver not being usable in jobs. (#127) +- Get-SeElement now write an error if no element are returned. (#135) +- cmdlet that expect urls will now accept urls without protocol defined. Assumptions in these cases is that the url is https thus google.ca will be treated as https://www.google.ca (#153) +- Get-SeElementAttribute - Accept multiple values and wildcard to load all attributes (#161) +- Get-SeElement - support for multiple classname (#160) +- Get-SeElementCssValue - support for multiple values / wildcard character (#162) +- Sleep / Timeout parameters type changed from int to double (Still seconds, but provide more granularity) +- Invoke-SeScreenshot - support for Element screenshot. You can now easily produce a screenshot of a specific element instead of the whole page. (#168) + + + +## Bugfixes +- Get-SeElement no longer support splatting (#82) +- Getck driver abysmal performance (#113). Gecko service need to be configured to use localhost ::1. Otherwise, it take significantly more time to do everything with it (#113) +- Get-SeElement with Timeout return only the first element instead of the collection (#139) +- Implcit-Wait - Default reduced to 0.3 seconds instead of 10 seconds. One of the problem of implicit wait is that some operation will wait 100% of the defined implicit wait before performing an action. (#146) +- Implicit / Explicit wait management. Some cmdlet (old an new) uses explicit wait. Explicit wait and Implicit wait should not be mixed together. Therefore, when an explicit wait is used, implicit wait (if present) get temporary disabled(#149) + + +# 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) diff --git a/Classes/PointTransformAttribute.ps1 b/Classes/PointTransformAttribute.ps1 new file mode 100644 index 0000000..9e03635 --- /dev/null +++ b/Classes/PointTransformAttribute.ps1 @@ -0,0 +1,27 @@ +class PointTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + # Implement the Transform() method + [object] Transform([System.Management.Automation.EngineIntrinsics]$engineIntrinsics, [object] $inputData) { + <# + The parameter value(s) are passed in here as $inputData. We aren't accepting array input + for our function, but it's good to make these fairly versatile where possible, so that + you can reuse them easily! + #> + $outputData = switch ($inputData) { + { $_ -is [PointTransformAttribute] } { $_ } + { $_ -is [int] } { [System.Drawing.Point]::new($_, $_) } + { $_ -is [string] -and (($_ -split '[,x]').count -eq 2) } { + $sp = $_ -split '[,x]' + [System.Drawing.Point]::new($sp[0], $sp[1]) + } + default { + # If we hit something we can't convert, throw an exception + throw [System.Management.Automation.ArgumentTransformationMetadataException]::new( + "Could not convert input '$_' to a valid Point object." + ) + } + } + + return $OutputData + } + +} \ No newline at end of file diff --git a/Classes/SeDriverConditionsCompleter.ps1 b/Classes/SeDriverConditionsCompleter.ps1 new file mode 100644 index 0000000..741ea6b --- /dev/null +++ b/Classes/SeDriverConditionsCompleter.ps1 @@ -0,0 +1,31 @@ +$Script:SeDriverConditions = @( + [PSCustomObject]@{Text = 'AlertState'; ValueType = [bool]; Tooltip = "A value indicating whether or not an alert should be displayed in order to meet this condition." } + [PSCustomObject]@{Text = 'ScriptBlock'; ValueType = [ScriptBlock]; Tooltip = "A scriptblock to be evaluated." } + [PSCustomObject]@{Text = 'TitleContains'; ValueType = [String]; Tooltip = "An expectation for checking that the title of a page contains a case-sensitive substring." } + [PSCustomObject]@{Text = 'TitleIs'; ValueType = [String]; Tooltip = "An expectation for checking the title of a page." } + [PSCustomObject]@{Text = 'UrlContains'; ValueType = [String]; Tooltip = "An expectation for the URL of the current page to be a specific URL." } + [PSCustomObject]@{Text = 'UrlMatches'; ValueType = [String]; Tooltip = "An expectation for the URL of the current page to be a specific URL." } + [PSCustomObject]@{Text = 'UrlToBe'; ValueType = [String]; Tooltip = "An expectation for the URL of the current page to be a specific URL." } +) + +class SeDriverConditionsCompleter : System.Management.Automation.IArgumentCompleter { + [System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument( + [string] $CommandName , + [string] $ParameterName, + [string] $WordToComplete, + [System.Management.Automation.Language.CommandAst] $CommandAst, + [system.Collections.IDictionary] $FakeBoundParameters + ) { + $wildcard = ("*" + $wordToComplete + "*") + $CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new() + + $Script:SeDriverConditions.where( { $_.Text -like $wildcard }) | + ForEach-Object { + $Valuetype = $_.ValueType + if ($null -eq $ValueType) { $Valuetype = 'None' } + $pvalue = [System.Management.Automation.CompletionResultType]::ParameterValue + $CompletionResults.Add(([System.Management.Automation.CompletionResult]::new($_.Text, $_.Text, $pvalue, "Value: $ValueType`n$($_.Tooltip)") ) ) + } + return $CompletionResults + } +} \ No newline at end of file diff --git a/Classes/SeDriverUserAgentCompleter.ps1 b/Classes/SeDriverUserAgentCompleter.ps1 new file mode 100644 index 0000000..501285d --- /dev/null +++ b/Classes/SeDriverUserAgentCompleter.ps1 @@ -0,0 +1,26 @@ +class SeDriverUserAgentCompleter : System.Management.Automation.IArgumentCompleter { + [System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument( + [string] $CommandName , + [string] $ParameterName, + [string] $WordToComplete, + [System.Management.Automation.Language.CommandAst] $CommandAst, + [system.Collections.IDictionary] $FakeBoundParameters + ) { + $CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new() + + $pvalue = [System.Management.Automation.CompletionResultType]::ParameterValue + + [System.Collections.Generic.List[PSObject]]$Predefined = + [Microsoft.PowerShell.Commands.PSUserAgent].GetProperties() | + Select-Object Name, @{n = 'UserAgent'; e = { [Microsoft.PowerShell.Commands.PSUserAgent]::$($_.Name) } } + + $Predefined.Add([PSCustomObject]@{Name = 'Android'; UserAgent = 'Android' }) + $Predefined.Add([PSCustomObject]@{Name = 'Iphone'; UserAgent = 'Iphone' }) + + $Predefined | + ForEach-Object { + $CompletionResults.Add(([System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, $pvalue, $_.UserAgent) ) ) + } + return $CompletionResults + } +} \ No newline at end of file diff --git a/Classes/SeDriverUserAgentTransformAttribute.ps1 b/Classes/SeDriverUserAgentTransformAttribute.ps1 new file mode 100644 index 0000000..cfb0b53 --- /dev/null +++ b/Classes/SeDriverUserAgentTransformAttribute.ps1 @@ -0,0 +1,25 @@ +class SeDriverUserAgentTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + # Implement the Transform() method + [object] Transform([System.Management.Automation.EngineIntrinsics]$engineIntrinsics, [object] $inputData) { + <# + The parameter value(s) are passed in here as $inputData. We aren't accepting array input + for our function, but it's good to make these fairly versatile where possible, so that + you can reuse them easily! + #> + $outputData = switch ($inputData) { + { $_ -is [string] } { + $output = [Microsoft.PowerShell.Commands.PSUserAgent]::$_ + if ($null -ne $output) { $output } else { $_ } + } + default { + # If we hit something we can't convert, throw an exception + throw [System.Management.Automation.ArgumentTransformationMetadataException]::new( + "Only String attributes are supported." + ) + } + } + + return $OutputData + } + +} \ No newline at end of file diff --git a/Classes/SeElementsConditionsCompleter.ps1 b/Classes/SeElementsConditionsCompleter.ps1 new file mode 100644 index 0000000..bb7374e --- /dev/null +++ b/Classes/SeElementsConditionsCompleter.ps1 @@ -0,0 +1,39 @@ +$Script:SeElementsConditions = @( + [PSCustomObject]@{Text = 'ElementExists'; ValueType = $null; By_Element = 1; Tooltip = 'An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.' } + [PSCustomObject]@{Text = 'ElementIsVisible'; ValueType = $null; By_Element = 1; Tooltip = 'An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.' } + [PSCustomObject]@{Text = 'ElementToBeSelected'; ValueType = [bool]; By_Element = 0; Tooltip = 'An expectation for checking if the given element is selected.' } + [PSCustomObject]@{Text = 'InvisibilityOfElementLocated'; ValueType = [bool]; By_Element = 1; Tooltip = 'An expectation for checking that an element is either invisible or not present on the DOM.' } + [PSCustomObject]@{Text = 'ElementToBeClickable'; ValueType = $null; By_Element = 0; Tooltip = 'An expectation for checking an element is visible and enabled such that you can click it.' } + [PSCustomObject]@{Text = 'InvisibilityOfElementWithText'; ValueType = [string]; By_Element = 1; Tooltip = 'An expectation for checking that an element with text is either invisible or not present on the DOM.' } + [PSCustomObject]@{Text = 'PresenceOfAllElementsLocatedBy'; ValueType = $null; By_Element = 1; Tooltip = 'An expectation for checking that all elements present on the web page that match the locator.' } + [PSCustomObject]@{Text = 'TextToBePresentInElement'; ValueType = [string]; By_Element = 2; Tooltip = 'An expectation for checking if the given text is present in the specified element.' } + [PSCustomObject]@{Text = 'TextToBePresentInElementValue'; ValueType = [string]; By_Element = 0; Tooltip = 'An expectation for checking if the given text is present in the specified elements value attribute.' } + [PSCustomObject]@{Text = 'StalenessOf'; ValueType = $null; By_Element = 2; Tooltip = 'Wait until an element is no longer attached to the DOM.' } +) + +class SeElementsConditionsCompleter : System.Management.Automation.IArgumentCompleter { + [System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument( + [string] $CommandName , + [string] $ParameterName, + [string] $WordToComplete, + [System.Management.Automation.Language.CommandAst] $CommandAst, + [system.Collections.IDictionary] $FakeBoundParameters + ) { + $wildcard = ("*" + $wordToComplete + "*") + $CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new() + + $pvalue = [System.Management.Automation.CompletionResultType]::ParameterValue + $SearchBy = 0 + switch ($true) { + { $fakeBoundParameters.ContainsKey('By') } { $SearchBy = 1; break } + { $fakeBoundParameters.ContainsKey('Element') } { $SearchBy = 2; break } + } + $Script:SeElementsConditions.where( { $_.Text -like $wildcard -and $_.By_Element -in @(0, $SearchBy) }) | + ForEach-Object { + $Valuetype = $_.ValueType + if ($null -eq $ValueType) { $Valuetype = 'None' } + $CompletionResults.Add(([System.Management.Automation.CompletionResult]::new($_.Text, $_.Text, $pvalue, "Value: $ValueType`n$($_.Tooltip)") ) ) + } + return $CompletionResults + } +} \ No newline at end of file diff --git a/Classes/SeMouseActionCompleter.ps1 b/Classes/SeMouseActionCompleter.ps1 new file mode 100644 index 0000000..e9abdaa --- /dev/null +++ b/Classes/SeMouseActionCompleter.ps1 @@ -0,0 +1,29 @@ +class SeMouseActionCompleter : System.Management.Automation.IArgumentCompleter { + [System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument( + [string] $CommandName , + [string] $ParameterName, + [string] $WordToComplete, + [System.Management.Automation.Language.CommandAst] $CommandAst, + [system.Collections.IDictionary] $FakeBoundParameters + ) { + $wildcard = ("*" + $wordToComplete + "*") + $CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new() + + $pvalue = [System.Management.Automation.CompletionResultType]::ParameterValue + + $Script:SeMouseAction.where( { $_.Text -like $wildcard }) | + ForEach-Object { + $Valuetype = $_.ValueType + if ($null -eq $ValueType) { $Valuetype = 'None' } + $ElementRequired = 'N/A' + switch ($_.ElementRequired) { + $true { $ElementRequired = 'Required' } + $false { $ElementRequired = 'Optional' } + } + + + $CompletionResults.Add(([System.Management.Automation.CompletionResult]::new($_.Text, $_.Text, $pvalue, "Element: $ElementRequired`nValue: $ValueType`n$($_.Tooltip)") ) ) + } + return $CompletionResults + } +} \ No newline at end of file diff --git a/Classes/SeMouseClickActionCompleter.ps1 b/Classes/SeMouseClickActionCompleter.ps1 new file mode 100644 index 0000000..c141238 --- /dev/null +++ b/Classes/SeMouseClickActionCompleter.ps1 @@ -0,0 +1,31 @@ +$Script:SeMouseClickAction = @( + New-Condition -Text 'Click' -Tooltip 'Clicks the mouse on the specified element.' + New-Condition -Text 'Click_JS' -ElementRequired $true -Tooltip 'Clicks the mouse on the specified element using Javascript.' + New-Condition -Text 'ClickAndHold' -Tooltip 'Clicks and holds the mouse button down on the specified element.' + New-Condition -Text 'ContextClick' -Tooltip 'Right-clicks the mouse on the specified element.' + New-Condition -Text 'DoubleClick' -Tooltip 'Double-clicks the mouse on the specified element.' + New-Condition -Text 'Release' -Tooltip 'Releases the mouse button at the last known mouse coordinates or specified element.' +) + +class SeMouseClickActionCompleter : System.Management.Automation.IArgumentCompleter { + [System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument( + [string] $CommandName , + [string] $ParameterName, + [string] $WordToComplete, + [System.Management.Automation.Language.CommandAst] $CommandAst, + [system.Collections.IDictionary] $FakeBoundParameters + ) { + $wildcard = ("*" + $wordToComplete + "*") + $CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new() + $pvalue = [System.Management.Automation.CompletionResultType]::ParameterValue + + + $Script:SeMouseClickAction.where( { $_.Text -like $wildcard }) | + ForEach-Object { + $Valuetype = $_.ValueType + if ($null -eq $ValueType) { $Valuetype = 'None' } + $CompletionResults.Add(([System.Management.Automation.CompletionResult]::new($_.Text, $_.Text, $pvalue, $_.Tooltip) ) ) + } + return $CompletionResults + } +} \ No newline at end of file diff --git a/Classes/SizeTransformAttribute.ps1 b/Classes/SizeTransformAttribute.ps1 new file mode 100644 index 0000000..3ee7c48 --- /dev/null +++ b/Classes/SizeTransformAttribute.ps1 @@ -0,0 +1,27 @@ +class SizeTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + # Implement the Transform() method + [object] Transform([System.Management.Automation.EngineIntrinsics]$engineIntrinsics, [object] $inputData) { + <# + The parameter value(s) are passed in here as $inputData. We aren't accepting array input + for our function, but it's good to make these fairly versatile where possible, so that + you can reuse them easily! + #> + $outputData = switch ($inputData) { + { $_ -is [SizeTransformAttribute] } { $_ } + { $_ -is [int] } { [System.Drawing.Size]::new($_, $_) } + { $_ -is [string] -and (($_ -split '[,x]').count -eq 2) } { + $sp = $_ -split '[,x]' + [System.Drawing.Size]::new($sp[0], $sp[1]) + } + default { + # If we hit something we can't convert, throw an exception + throw [System.Management.Automation.ArgumentTransformationMetadataException]::new( + "Could not convert input '$_' to a valid Size object." + ) + } + } + + return $OutputData + } + +} \ No newline at end of file diff --git a/Classes/StringUrlTransformAttribute.ps1 b/Classes/StringUrlTransformAttribute.ps1 new file mode 100644 index 0000000..019dbc8 --- /dev/null +++ b/Classes/StringUrlTransformAttribute.ps1 @@ -0,0 +1,29 @@ +class StringUrlTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { + # Implement the Transform() method + [object] Transform([System.Management.Automation.EngineIntrinsics]$engineIntrinsics, [object] $inputData) { + <# + The parameter value(s) are passed in here as $inputData. We aren't accepting array input + for our function, but it's good to make these fairly versatile where possible, so that + you can reuse them easily! + #> + $outputData = switch ($inputData) { + { $_ -is [string] } { + if ($_ -match '://') { + $_ + } + else { + "https://$_" + } + } + default { + # If we hit something we can't convert, throw an exception + throw [System.Management.Automation.ArgumentTransformationMetadataException]::new( + "Only String attributes are supported." + ) + } + } + + return $OutputData + } + +} \ No newline at end of file diff --git a/Debug/Debug.ps1 b/Debug/Debug.ps1 index dd0d9ee..6f92252 100644 --- a/Debug/Debug.ps1 +++ b/Debug/Debug.ps1 @@ -11,12 +11,21 @@ import-module "$ProjectPath\Selenium.psd1" -Force #Load Compiled version #import-module "$ProjectPath\output\selenium\Selenium.psd1" -Force +# CI tests +. $ProjectPath\CI\CI.ps1 -browserlist Chrome, Firefox # Build module -#invoke-build -File "$ProjectPath\Selenium.build.ps1" +Get-Module pester | Remove-Module; Import-Module pester -RequiredVersion 4.10.1 +invoke-build -File "$ProjectPath\Selenium.build.ps1" + + +# Documentation update only +Update-MarkdownHelpModule -Path "$ProjectPath\Help" -ModulePagePath "$ProjectPath\Help\README.MD" -RefreshModulePage -Verbose #Tests #Invoke-Pester -Script 'C:\Github\selenium-powershell\Examples\Combined.tests.ps1' + + diff --git a/Examples/A-Simple-Google-Search.ps1 b/Examples/A-Simple-Google-Search.ps1 index 4f89044..4c94db1 100644 --- a/Examples/A-Simple-Google-Search.ps1 +++ b/Examples/A-Simple-Google-Search.ps1 @@ -1,70 +1,55 @@ -<# -.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} +Import-Module -Name Selenium # Start the Selenium Chrome Driver -$Driver = Start-SeChrome +Start-SeDriver -Browser Chrome -StartURL 'google.com/ncr' -# 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. +#Getting the Search box - <# This is the HTML code of the search box +<# This is the HTML code of the search box, found using the browser developer tools - #> +#> - # 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 +#Here's a few different ways, all valid, to access that searchbox - # We can also use the class name gLFyf to find the google search box. - $SearchBoxElement = Find-SeElement -Driver $Driver -ClassName 'gLFyf' +# 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 +#The Single parameter will write an error if there's not 1 element. +$Searchbox = Get-SeElement -By Name -value q -Single - # This line will get us all elements with the input TagName also known as - $AllInputElements = Find-SeElement -Driver $Driver -TagName input +# We can also use the class name gLFyf to find the google search box. +$Searchbox = Get-SeElement -ClassName 'gLFyf' - # 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 $_}} +# This line will get us all elements with the input TagName also known as +#The -All parameter (optional) also includes hidden elements. +# The -Attributes parameter will load the specified attribute in the result and make them available through an Attributes property +$AllInputElement = Get-SeElement -By TagName -Value input -All -Attributes title +$AllInputElement | select Attributes +# 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. +$Searchbox = $AllInputElement.Where( { $_.Attributes.title -eq 'Search' }, 'first')[0] - # 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 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' +# Now that we can see all the keys we can send send some keys to the SearchBoxElement +Invoke-SeKeys -Element $Searchbox -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) +# 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 +# To view special keys, use Get-SeKeys +Invoke-SeKeys -Element $Searchbox -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. +# 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' +# 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. +#Note, the value parameter is provided positionally. +$LogoImageElement = Get-SeElement -Timeout 10 -By 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 have the image element we can simulate a mouse click on it using the Invoke-SeClick command. +Invoke-SeClick -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 +# 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 \ No newline at end of file diff --git a/Examples/Combined.tests.ps1 b/Examples/Combined.tests.ps1 index ef68781..f5dc2d1 100644 --- a/Examples/Combined.tests.ps1 +++ b/Examples/Combined.tests.ps1 @@ -1,101 +1,58 @@ -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 +. "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + +$Global:TestCaseSettings = Get-TestCasesSettings +$Global:BrowserOptHash = $Global:TestCaseSettings."$Global:DefaultBrowser".DefaultOptions +$Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash +$Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" Describe "Testing the tailspin toys demo site at $env:SITE_URL" { BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + + $Global:TestCaseSettings = Get-TestCasesSettings + $Global:BrowserOptHash = $Global:TestCaseSettings."$Global:DefaultBrowser".DefaultOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash #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 + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $env:SITE_URL @Global:BrowserOptHash -Verbose 4>&1 -ErrorAction Stop } catch { throw $_ } + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } - Context "in $BrowserID with settings ($BrowserOptText)" { - It "produced the right modal dialog for the " -TestCases $ModaltestCases { + Context "in $($Env:BrowserID) with settings ($Env:BrowserOptText)" { + It "produced the right modal dialog for the " -TestCases (Get-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 $modalXPath -With displayed eq $false -Timeout 10 + SeElement $linkXPath | Invoke-SeClick -Action Click_JS -Sleep 1 + SeElement $modalXPath | SeElement -By ClassName 'close' | Invoke-SeClick -Action Click_JS -Sleep 1 SeShouldHave 'body' -By TagName SeShouldHave $modalXPath -With displayed eq $false } } # Additional tests would be here - AfterAll { SeClose } + AfterAll { Stop-SeDriver } } #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)" { + BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + $PSGalleryPage = 'https://www.powershellgallery.com/' + $Global:TestCaseSettings = Get-TestCasesSettings + $Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].DefaultOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $PSGalleryPage @Global:BrowserOptHash -Verbose 4>&1 -ErrorAction Stop }catch {} + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } + Context "in $Env:BrowserID with settings ($Env: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] + Get-SeDriver -Current | Should -Not -BeNullOrEmpty + Get-SeDriver -Current | 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 @@ -120,15 +77,15 @@ Describe "PsGallery Test" { 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 + Get-SeElement -By TagName -Value 'input' | + Invoke-SeKeys -ClearFirst -Keys "selenium{{Enter}}" -PassThru -Sleep 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 ' { + $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 -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 + SeShouldHave $linkpath -With Text like *selenium* -PassThru | Invoke-SeClick -Action Click_JS -Sleep 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 ... @@ -140,80 +97,91 @@ Describe "PsGallery Test" { #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 + Invoke-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 + Set-SeUrl -Back + Set-SeUrl -Back + Set-SeUrl -Back SeShouldHave -URL eq $PSGalleryPage -Timeout 30 - SeClose - $Global:SeDriver | Should -BeNullOrEmpty + Stop-SeDriver + Get-SeDriver -Current | Should -BeNullOrEmpty } } + AfterAll { Stop-SeDriver } } -$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 + BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + $AlertTestPage = 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' + $SelectTestPage = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' + $Global:TestCaseSettings = Get-TestCasesSettings + $Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].PrivateOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash + + if ($Env:BrowserOptText) { + $Global:NoLabel = [string]::IsNullOrEmpty($Global:TestCaseSettings[$Global:DefaultBrowser].InPrivateLabel) + $wv = $null + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $alertTestPage @BrowserOptHash -WarningVariable wv -ErrorAction Stop }catch {} + if ($wv) { Write-Output "##vso[task.logissue type=warning]$wv" } + } + else { + $Global:NoLabel = $true + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $alertTestPage -ErrorAction Stop } catch {} + + } + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } + Context "in $Env:BrowserID with settings ($Env: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 $Global:TestCaseSettings[$Global:DefaultBrowser].InPrivateLabel + # } -Skip:$Global:NoLabel It 'opened the right page ' { SeShouldHave -URL -eq $alertTestPage } - It 'found and clicked a button in frame 1 ' { + It 'Navigated to the child iframe' { #'triggered and dismissed an alert' 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 ' { + Switch-SeFrame 'iframeResult' + Get-SeElement "/html/body/button" | Should -Not -BeNullOrEmpty #Removed | Invoke-SeClick -PassThru #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 + #{ Wait-SeDriver -Condition AlertState -Value $false -Timeout 15 -ErrorAction Stop } | Should -Not -throw + #Clear-SeAlert -Alert $Alert -Action Dismiss -PassThru | Should -Not -BeNullOrEmpty } It 'reselected the parent frame ' { - SeFrame -Parent + Switch-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 + Set-SeUrl $SelectTestPage SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult - SeFrame 'iframeResult' - SeShouldHave -By Name "cars" -With choice contains "volvo" + Switch-SeFrame 'iframeResult' + $e = SeElement -by Name "cars" + $e | Should -Not -BeNullOrEmpty + (Get-SeSelectValue -Element $e -All).Items.Text | Should -Contain '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" + { $e | Set-SeSelectValue -By Value -value "Audi" } | Should -Throw + { $e | Set-SeSelectValue -By Value -value "audi" } | Should -not -throw + $e | Set-SeSelectValue -By Index -value "2"; (Get-SeSelectValue -Element $e).Text | Should -Be 'Fiat' + $e | Set-SeSelectValue -By Text -value "Sa*" } It 'submitted the form and got the expected response ' { - SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 - SeFrame -Parent - SeFrame 'iframeResult' + Get-SeElement '/html/body/form/input' | Invoke-SeClick -Sleep 5 + Switch-SeFrame -Parent + Switch-SeFrame 'iframeResult' SeShouldHave "/html/body/div[1]" -with text match "cars=saab" } It 'closed the in-private browser instance ' { - SeClose + Stop-SeDriver if ($DriverProcess.Id) { (Get-Process -id $DriverProcess.id ).HasExited | Should -Be $true } @@ -222,40 +190,65 @@ Describe "Alerts and Selection boxes tests" { } } } + AfterAll { Stop-SeDriver } } -$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 ' { + +$Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].HeadlessOptions +$Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash +$Global:SkipTests = [String]::IsNullOrEmpty($Env:BrowserOptText) + +Describe "'Headless' mode browser test" { + BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + $Global:TestCaseSettings = Get-TestCasesSettings + + $Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].HeadlessOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash + $Global:SkipTests = $true + if (![String]::IsNullOrEmpty($Env:BrowserOptText)) { + $Global:SkipTests = $false + try { $Env:BrowserID = Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $env:SITE_URL @BrowserOptHash -ErrorAction Stop }catch {} + } + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } + Context "in $Env:BrowserID with settings ($Env:BrowserOptText)" { + It 're-opened the Browser in "Headless" mode' { + if ($PSVersionTable.PSVersion.Major -eq 5) { + $Processes = Get-CimInstance -Class Win32_Process + $DriverProcess = $Processes | Where { $_.Name -like '*driver.exe' -and $_.ParentProcessId -eq $Pid } + $BrowserProcess = $Processes | Where-Object { $_.ParentProcessId -eq $DriverProcess.ProcessId -and $_.Name -ne 'conhost.exe' } + if ($BrowserProcess -ne $null) { + (Get-process -Id $BrowserProcess.ProcessId).MainWindowHandle | Should -be 0 + } + } + else { $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 + $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 + } + it 'did a google Search ' { + Set-SeUrl 'https://www.google.com/ncr' + SeShouldHave -by Name q + SeShouldHave -by ClassName 'gLFyf' + SeShouldHave -By Name q -PassThru | Where Displayed -eq $true | + Select-Object -First 1 | Invoke-SeKeys -Keys 'Powershell-Selenium{{Enter}}' -PassThru | + should -Not -BeNullOrEmpty - SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | - SeClick -PassThru | should -Not -BeNullOrEmpty + SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | + Invoke-SeClick -PassThru | should -Not -BeNullOrEmpty + } + It 'closed the browser a third time ' { + Stop-SeDriver + Get-SeDriver -Current | Should -BeNullOrEmpty + if ($DriverProcess.Id) { + (Get-Process -id $DriverProcess.id ).HasExited | Should -Be $true } - 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 - } + if ($BrowserProcess.Id) { + (Get-Process -id $BrowserProcess.id).HasExited | Should -Be $true } } - } + } -Skip:$Global:SkipTests + AfterAll { Stop-SeDriver } } \ No newline at end of file diff --git a/Examples/DemoSelenium.tests.ps1 b/Examples/DemoSelenium.tests.ps1 deleted file mode 100644 index 2d94e51..0000000 --- a/Examples/DemoSelenium.tests.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -<# -.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/Examples/DemoSelenium2.tests.ps1 b/Examples/DemoSelenium2.tests.ps1 deleted file mode 100644 index 3f7abfb..0000000 --- a/Examples/DemoSelenium2.tests.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -<# -.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/Examples/Example.side b/Examples/Example.side new file mode 100644 index 0000000..a11d238 --- /dev/null +++ b/Examples/Example.side @@ -0,0 +1,295 @@ +{ + "id": "1a83cd76-e78d-4402-b40e-5805b2403f44", + "version": "2.0", + "name": "Example", + "url": "https://automationintesting.com", + "tests": [{ + "id": "0896d7a2-81f1-4972-bbc3-4880718bc157", + "name": "Test1", + "commands": [{ + "id": "4770f8f0-e2c5-434e-847c-b79ecadebf41", + "comment": "", + "command": "open", + "target": "/selenium/testpage/", + "targets": [], + "value": "" + }, { + "id": "8068ba5f-597f-4d50-834d-b057c2cfb2ea", + "comment": "", + "command": "setWindowSize", + "target": "1936x1056", + "targets": [], + "value": "" + }, { + "id": "90423ff3-98f2-4de8-9998-32088c188647", + "comment": "", + "command": "click", + "target": "id=firstname", + "targets": [ + ["id=firstname", "id"], + ["css=#firstname", "css:finder"], + ["xpath=//input[@id='firstname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div/div/label/input", "xpath:idRelative"], + ["xpath=//input", "xpath:position"] + ], + "value": "" + }, { + "id": "fa88b63a-f245-4374-8db2-284f239c3ee0", + "comment": "", + "command": "type", + "target": "id=firstname", + "targets": [ + ["id=firstname", "id"], + ["css=#firstname", "css:finder"], + ["xpath=//input[@id='firstname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div/div/label/input", "xpath:idRelative"], + ["xpath=//input", "xpath:position"] + ], + "value": "test" + }, { + "id": "2626b60b-2f5b-473d-b342-4f5ec36501b5", + "comment": "", + "command": "click", + "target": "xpath=//form[@id='contactus']/div[2]/div/label/input", + "targets": [ + ["id=surname", "id"], + ["css=#surname", "css:finder"], + ["xpath=//input[@id='surname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[2]/div/label/input", "xpath:idRelative"], + ["xpath=//div[2]/div/label/input", "xpath:position"] + ], + "value": "" + }, { + "id": "65b0a638-0f79-4a43-ac8a-db482d18c3cd", + "comment": "", + "command": "type", + "target": "xpath=//form[@id='contactus']/div[2]/div/label/input", + "targets": [ + ["id=surname", "id"], + ["css=#surname", "css:finder"], + ["xpath=//input[@id='surname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[2]/div/label/input", "xpath:idRelative"], + ["xpath=//div[2]/div/label/input", "xpath:position"] + ], + "value": "test2" + }, { + "id": "e9047045-ede4-4c13-81b5-f8c036cb527c", + "comment": "", + "command": "click", + "target": "id=gender", + "targets": [ + ["id=gender", "id"], + ["css=#gender", "css:finder"], + ["xpath=//select[@id='gender']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[3]/div/label/select", "xpath:idRelative"], + ["xpath=//select", "xpath:position"] + ], + "value": "" + }, { + "id": "f9341c3c-215b-44c1-9fff-fa977a7ba599", + "comment": "", + "command": "select", + "target": "id=gender", + "targets": [], + "value": "label=Male" + }, { + "id": "39458fd5-e6ac-46c7-9e48-b24349314ef0", + "comment": "", + "command": "click", + "target": "id=red", + "targets": [ + ["id=red", "id"], + ["name=colour", "name"], + ["css=#red", "css:finder"], + ["xpath=//input[@id='red']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[4]/div/input", "xpath:idRelative"], + ["xpath=//div/input", "xpath:position"] + ], + "value": "" + }, { + "id": "a1ded097-b395-4bed-b641-7c2ab136d411", + "comment": "", + "command": "click", + "target": "css=textarea", + "targets": [ + ["css=textarea", "css:finder"], + ["xpath=//form[@id='contactus']/div[5]/div/label/textarea", "xpath:idRelative"], + ["xpath=//textarea", "xpath:position"] + ], + "value": "" + }, { + "id": "582f0b4e-2521-404e-a912-39261d867d11", + "comment": "", + "command": "type", + "target": "css=textarea", + "targets": [ + ["css=textarea", "css:finder"], + ["xpath=//form[@id='contactus']/div[5]/div/label/textarea", "xpath:idRelative"], + ["xpath=//textarea", "xpath:position"] + ], + "value": "text" + }, { + "id": "764ae979-42dd-457e-95c5-5dddad91e44d", + "comment": "", + "command": "addSelection", + "target": "id=continent", + "targets": [ + ["id=continent", "id"], + ["css=#continent", "css:finder"], + ["xpath=//select[@id='continent']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[6]/div/label/select", "xpath:idRelative"], + ["xpath=//div[6]/div/label/select", "xpath:position"] + ], + "value": "label=North America" + }, { + "id": "bb929f6f-ee4c-43ad-920b-0806aba3c37d", + "comment": "", + "command": "click", + "target": "id=checkbox1", + "targets": [ + ["id=checkbox1", "id"], + ["css=#checkbox1", "css:finder"], + ["xpath=//input[@id='checkbox1']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[4]/div[2]/input", "xpath:idRelative"], + ["xpath=//div[2]/input", "xpath:position"] + ], + "value": "" + }, { + "id": "542d6958-faab-40e9-9b4b-81f051673c23", + "comment": "", + "command": "click", + "target": "id=submitbutton", + "targets": [ + ["id=submitbutton", "id"], + ["css=#submitbutton", "css:finder"], + ["xpath=//button[@id='submitbutton']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[7]/div/button", "xpath:idRelative"], + ["xpath=//div/button", "xpath:position"], + ["xpath=//button[contains(.,'I do nothing!')]", "xpath:innerText"] + ], + "value": "" + }] + }, { + "id": "c0d8e914-0e45-4d59-be13-b902e026cb6c", + "name": "Test2", + "commands": [{ + "id": "319fa3e0-f697-4963-a879-b358fff62a77", + "comment": "", + "command": "open", + "target": "/selenium/testpage/", + "targets": [], + "value": "" + }, { + "id": "27aa1c23-21c7-45dc-8887-fe3d0e8f592b", + "comment": "", + "command": "setWindowSize", + "target": "1936x1056", + "targets": [], + "value": "" + }, { + "id": "421ace3d-1377-4423-9257-bfc703103beb", + "comment": "", + "command": "sendKeys", + "target": "id=firstname", + "targets": [], + "value": "test3" + }, { + "id": "301e2ba3-8f11-42cd-a41e-8241e158e962", + "comment": "", + "command": "sendKeys", + "target": "id=firstname", + "targets": [ + ["id=firstname", "id"], + ["css=#firstname", "css:finder"], + ["xpath=//input[@id='firstname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div/div/label/input", "xpath:idRelative"], + ["xpath=//input", "xpath:position"] + ], + "value": "${KEY_ENTER}" + }] + }, { + "id": "8b6ff854-fefb-40bc-bd48-d206878b9e64", + "name": "Test3", + "commands": [{ + "id": "a3b6e82e-a847-4ac5-ac72-a05c5150d107", + "comment": "", + "command": "open", + "target": "http://www.tagindex.net/html/frame/example_f01.html", + "targets": [], + "value": "" + }, { + "id": "785d2ca1-c20b-4b96-a03e-43119ad2ecef", + "comment": "", + "command": "setWindowSize", + "target": "1936x1056", + "targets": [], + "value": "" + }, { + "id": "150bc283-671d-4d77-b1a5-b5dd20c2eee3", + "comment": "", + "command": "selectFrame", + "target": "index=0", + "targets": [ + ["index=0"] + ], + "value": "" + }, { + "id": "50809502-afdf-4b1b-943b-40524bbd2420", + "comment": "", + "command": "click", + "target": "css=html", + "targets": [ + ["css=html", "css:finder"], + ["xpath=//html", "xpath:position"] + ], + "value": "" + }, { + "id": "e726cc31-c25f-4cf7-92fe-77d976bb2f91", + "comment": "", + "command": "selectFrame", + "target": "relative=parent", + "targets": [ + ["relative=parent"] + ], + "value": "" + }, { + "id": "71ab81f7-8c7d-413e-a7ed-f68c224b1373", + "comment": "", + "command": "selectFrame", + "target": "index=1", + "targets": [ + ["index=1"] + ], + "value": "" + }, { + "id": "6e01154b-2221-4eef-98db-5760b52063e0", + "comment": "", + "command": "doubleClick", + "target": "css=p", + "targets": [ + ["css=p", "css:finder"], + ["xpath=//div[@id='MainBox']/p", "xpath:idRelative"], + ["xpath=//p", "xpath:position"], + ["xpath=//p[contains(.,'Please return to the previous page using the browsers \"back\" button.')]", "xpath:innerText"] + ], + "value": "" + }, { + "id": "a9f64bfd-1962-4f32-aa85-85d1ae4af91a", + "comment": "", + "command": "close", + "target": "", + "targets": [], + "value": "" + }] + }], + "suites": [{ + "id": "3fb340b3-1af6-4948-ad2a-c689126d9dad", + "name": "Default Suite", + "persistSession": false, + "parallel": false, + "timeout": 300, + "tests": ["0896d7a2-81f1-4972-bbc3-4880718bc157"] + }], + "urls": ["https://automationintesting.com/"], + "plugins": [] +} \ No newline at end of file diff --git a/Examples/TestPSGallery.ps1 b/Examples/TestPSGallery.ps1 deleted file mode 100644 index 19a5c6d..0000000 --- a/Examples/TestPSGallery.ps1 +++ /dev/null @@ -1,23 +0,0 @@ - -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/Examples/_TestDependencies.ps1 b/Examples/_TestDependencies.ps1 new file mode 100644 index 0000000..6425032 --- /dev/null +++ b/Examples/_TestDependencies.ps1 @@ -0,0 +1,70 @@ + +Function Get-DefaultParams() { + if ($null -eq $Global:DefaultBrowser) { $Global:DefaultBrowser = 'Firefox' } + if ($null -eq $env:SITE_URL) { $env:SITE_URL = 'http://tailspin-spacegame-web.azurewebsites.net' } + if ($null -eq $Global:HeadlessOnly) { $Global:HeadlessOnly = $False } +} +Get-DefaultParams + + +Function Get-TestCasesSettings() { + $HeadlessState = if ($Global:HeadlessOnly) { 'Headless' } else { 'Maximized' } + return @{ + 'NewEdge' = @{ + DefaultOptions = @{State = $HeadlessState } + PrivateOptions = @{ + PrivateBrowsing = $true + State = $HeadlessState + } + # InPrivateLabel = 'InPrivate' + } # broken after build 79 of web driver#> + 'Chrome' = @{ + PrivateOptions = @{ + PrivateBrowsing = $true + State = $HeadlessState + } + DefaultOptions = @{State = $HeadlessState } + HeadlessOptions = @{State = 'Headless' } + } + 'Firefox' = @{ + PrivateOptions = @{ + PrivateBrowsing = $true + State = $HeadlessState + } + DefaultOptions = @{State = $HeadlessState } + HeadlessOptions = @{State = 'Headless' } + } + 'MSEdge' = @{ + DefaultOptions = @{State = $HeadlessState } + PrivateOptions = @{PrivateBrowsing = $true } + } + 'InternetExplorer' = @{ + DefaultOptions = @{ImplicitWait = 30 } + PrivateOptions = @{ImplicitWait = 30 } + } + } +} + +function Build-StringFromHash { + param ($Hash) + $(foreach ($k in $Hash.Keys) { "$K`:$($hash[$K])" }) -join '; ' +} + + + +function Get-ModalTestCases() { + return @( + @{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' + } + ) +} diff --git a/Examples/comparison.ps1 b/Examples/comparison.ps1 index 99aa8a2..65e5b76 100644 --- a/Examples/comparison.ps1 +++ b/Examples/comparison.ps1 @@ -8,9 +8,9 @@ public void testClass() throws Exception { Assert.assertEquals("Wikipedia. the free encyclopedia", driver.getTitle()); } #> -SeOpen "http://www.wikipedia.org/" +Start-SeDriver -Browser Chrome -StartURL "https://www.wikipedia.org/" SeShouldHave -Title eq Wikipedia -SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | SeClick +SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | Invoke-SeClick SeShouldHave -Title eq 'Wikipedia, the free encyclopedia' <# @@ -52,7 +52,9 @@ public static void main(String[] args) { } #> -SeOpen "http://demo.guru99.com/test/newtours/" -In FireFox # or #-in Chrome -in MsEdge -in NewEdge or -in IE +Start-SeDriver -Browser Firefox -StartURL "http://demo.guru99.com/test/newtours/" SeShouldHave -Title eq "Welcome: Mercury Tours" -SeClose + +#Stop opened drivers +Get-SeDriver | Stop-SeDriver diff --git a/Examples/test-seremote.ps1 b/Examples/test-seremote.ps1 index 5ce9b13..56bfebb 100644 --- a/Examples/test-seremote.ps1 +++ b/Examples/test-seremote.ps1 @@ -49,14 +49,14 @@ Describe "All in one Test" { #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 + SeType -ClearFirst "selenium{{Enter}}" -PassThru -Sleep 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 + SeShouldHave $linkpath -With Text like *selenium* -PassThru | SeClick -Sleep 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 ... @@ -124,7 +124,7 @@ Describe "All in one Test" { $e | SeSelection -ByPartialText "Sa" } It 'submitted the form and got the expected response ' { - SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 + SeElement '/html/body/form/input' | SeClick -Sleep 5 SeFrame -Parent SeFrame 'iframeResult' SeShouldHave "/html/body/div[1]" -with text match "cars=saab" diff --git a/Help/Clear-SeAlert.md b/Help/Clear-SeAlert.md index fd936ee..449c4b8 100644 --- a/Help/Clear-SeAlert.md +++ b/Help/Clear-SeAlert.md @@ -8,31 +8,25 @@ schema: 2.0.0 # Clear-SeAlert ## SYNOPSIS -Accept and clear alert popup +Clear alert popup by dismissing or accepting it. ## SYNTAX -### Alert ``` -Clear-SeAlert [[-Alert] ] [-Action ] [-PassThru] [] -``` - -### Driver -``` -Clear-SeAlert [-Target ] [-Action ] [-PassThru] [] +Clear-SeAlert [-Action ] [-Alert ] [-PassThru] [] ``` ## DESCRIPTION -Accept and clear alert popup +Clear alert popup by dismissing or accepting it. ## EXAMPLES ### Example 1 ```powershell -PS C:\> {{ Add example code here }} +PS C:\> Clear-SeAlert -Action Dismiss ``` -{{ Add example description here }} +Dismiss an alert on the currently selected driver. ## PARAMETERS @@ -57,38 +51,23 @@ Specify alert window. Seems to be ignored in favor of Target / Default Target. ```yaml Type: Object -Parameter Sets: Alert +Parameter Sets: (All) Aliases: Required: False -Position: 0 +Position: Named Default value: None Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` ### -PassThru -{{ Fill PassThru Description }} +Return Alert object. ```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 +Aliases: Required: False Position: Named diff --git a/Help/Clear-SeSelectValue.md b/Help/Clear-SeSelectValue.md new file mode 100644 index 0000000..75e5f0a --- /dev/null +++ b/Help/Clear-SeSelectValue.md @@ -0,0 +1,60 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Clear-SeSelectValue + +## SYNOPSIS +Clear all selected entries of a SELECT element. + +## SYNTAX + +``` +Clear-SeSelectValue [-Element] [] +``` + +## DESCRIPTION +Clear all selected entries of a SELECT element. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Clear-SeSelectValue -Element $Select +``` + +Clear the selected value from the specified SELECT element. + +## PARAMETERS + +### -Element +Target IWebElement + +```yaml +Type: IWebElement +Parameter Sets: (All) +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 + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/ConvertTo-SeSelenium.md b/Help/ConvertTo-SeSelenium.md new file mode 100644 index 0000000..8afff96 --- /dev/null +++ b/Help/ConvertTo-SeSelenium.md @@ -0,0 +1,57 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# ConvertTo-Selenium + +## SYNOPSIS +Convert Selenium IDE .side recording file to PowerShell commands. + +## SYNTAX + +``` +ConvertTo-Selenium [-Path] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Path +Path to .side file. + +```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 + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeCookie.md b/Help/Get-SeCookie.md index e54cf61..97ecd40 100644 --- a/Help/Get-SeCookie.md +++ b/Help/Get-SeCookie.md @@ -13,7 +13,7 @@ List all cookies ## SYNTAX ``` -Get-SeCookie [[-Target] ] [] +Get-SeCookie [] ``` ## DESCRIPTION @@ -30,21 +30,6 @@ 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). diff --git a/Help/Get-SeDriver.md b/Help/Get-SeDriver.md new file mode 100644 index 0000000..e7f3dfd --- /dev/null +++ b/Help/Get-SeDriver.md @@ -0,0 +1,127 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeDriver + +## SYNOPSIS +Get the list of all active drivers. + +## SYNTAX + +### All (Default) +``` +Get-SeDriver [] +``` + +### Current +``` +Get-SeDriver [-Current] [] +``` + +### ByName +``` +Get-SeDriver [[-Name] ] [] +``` + +### ByBrowser +``` +Get-SeDriver [-Browser ] [] +``` + +## DESCRIPTION +Get the list of all active drivers or drivers matching the specified criterias. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeDriver +``` + +Return the list of all active drivers. + +### Example 2 +```powershell +PS C:\> Get-SeDriver -Current +``` + +Return the currently selected browser. + +### Example 3 +```powershell +PS C:\> Get-SeDriver -Browser Chrome +``` + +Returh the list of all active "Chrome" browsers. + +### Example 3 +```powershell +PS C:\> Get-SeDriver -Name '70c91e0f112dcdbd22b84dd567560b8d' +``` + +Return the driver with the specified name. + +## PARAMETERS + +### -Browser +Filter the list of returned drivers by their Browser type (enum: [SeBrowsers]) + +```yaml +Type: Object +Parameter Sets: ByBrowser +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Current +Return the currently selected browser. Selected browser is the last one started, unless changed via Switch-SeDriver and is always the one that get used in all cmdlet that have an unspecified $Driver. + +```yaml +Type: SwitchParameter +Parameter Sets: Current +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Filter driver returned by its name (SeFriendlyName). + +```yaml +Type: String +Parameter Sets: ByName +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/Get-SeDriverTimeout.md b/Help/Get-SeDriverTimeout.md new file mode 100644 index 0000000..d39b84b --- /dev/null +++ b/Help/Get-SeDriverTimeout.md @@ -0,0 +1,68 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeDriverTimeout + +## SYNOPSIS +Get the specified driver timeout value. + +## SYNTAX + +``` +Get-SeDriverTimeout [[-TimeoutType] ] [] +``` + +## DESCRIPTION +Get the specified driver timeout value. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeDriverTimeout +``` + +Return the currently selected driver implicit wait timeout. + +### Example 2 +```powershell +PS C:\> Get-SeDriverTimeout -TimeoutType PageLoad -Driver $Driver +``` + +Return the specified driver PageLoad timeout. + +## PARAMETERS + +### -TimeoutType +Timeout type to be changed + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: +Accepted values: ImplicitWait, PageLoad, AsynchronousJavaScript + +Required: False +Position: 0 +Default value: ImplicitWait +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/Help/Get-SeElement.md b/Help/Get-SeElement.md index 9f4bdda..c9b1322 100644 --- a/Help/Get-SeElement.md +++ b/Help/Get-SeElement.md @@ -13,33 +13,70 @@ Finds all IWebElements within the current context using the given mechanism ## SYNTAX +### Default (Default) ``` -Get-SeElement [-By ] [-Selection] [[-Timeout] ] [[-Target] ] [-Wait] - [] +Get-SeElement [-By ] [-Value] [[-Timeout] ] [-All] [-Attributes ] + [-Single] [] +``` + +### ByElement +``` +Get-SeElement [-By ] [-Value] [-Element] [-All] + [-Attributes ] [-Single] [] ``` ## DESCRIPTION -Finds all IWebElements within the current context using the given mechanism +Finds all IWebElements within the current context using the given mechanism. ## EXAMPLES ### Example 1 ```powershell -PS C:\> Get-SeElement -By Name -Selection 'username' +PS C:\> Get-SeElement -By XPath '//*[@id="home_text3"]/div[2]' -Value '//*[@id="home_text3"]/div[2]' +#Same but positionally bound +PS C:\> Get-SeElement '//*[@id="home_text3"]/div[2]' +``` + +Get the elements matching the specified XPath selector. + +### Example 2 +```powershell +PS C:\> Get-SeElement -By Name -Value 'username' -Single +``` + +Get the username field by name with the expectation only one element is to be returned. + +### Example 3 +```powershell +PS C:\> Get-SeElement -By Name -Value 'username' -Single +``` + +Get the username field by name with the expectation only one element is to be returned. + +### Example 4 +```powershell +PS C:\> Get-SeElement -By ClassName -Value homeitem -All -Attributes name, id -Timeout 2.5 +#To return all attributes instead: -Attributes * +``` + +Get the elements by classname. Include hidden items `-All` and append an `Attributes` NoteProperty to all the result containing the value for the name and id attribute. The call will also fail if no results are found after 2.5 seconds. + +### Example 5 +```powershell +PS C:\> Get-SeElement -By ClassName,PartialLinkText -Value 'homeitem','The' ``` -Get the username field by name +Get the elements that match the selectors in a sequential manner. This call will return all links that contains the defined text (The) within elements that have a classname of "homeitem". ## PARAMETERS -### -By -The locating mechanism to use +### -All +Return matching hidden items in addition to displayed ones. ```yaml -Type: String +Type: SwitchParameter Parameter Sets: (All) Aliases: -Accepted values: CssSelector, Name, Id, ClassName, LinkText, PartialLinkText, TagName, XPath Required: False Position: Named @@ -48,42 +85,73 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Selection -String Identifier of the object to find +### -Attributes +Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. ```yaml -Type: String +Type: String[] Parameter Sets: (All) -Aliases: CssSelector, Name, Id, ClassName, LinkText, PartialLinkText, TagName, XPath +Aliases: -Required: True -Position: 1 +Required: False +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Target -Target webdriver +### -By +The locating mechanism to use. It is possible to use multiple locator, in which case they will be processed sequentially. ```yaml -Type: Object +Type: SeBySelector[] Parameter Sets: (All) -Aliases: Element, Driver +Aliases: +Accepted values: ClassName, CssSelector, Id, LinkText, PartialLinkText, Name, TagName, XPath Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +Target IWebElement. + +```yaml +Type: IWebElement +Parameter Sets: ByElement +Aliases: + +Required: True Position: 3 Default value: None Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` +### -Single +Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Timeout Timeout (in seconds) ```yaml -Type: Int32 -Parameter Sets: (All) +Type: Double +Parameter Sets: Default Aliases: Required: False @@ -93,16 +161,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Wait -Set Timeout to 30 seconds (Will not override Timeout value if already defined) +### -Value +Locator Value corresponding to the `$By` selector. There should be an equal number of values than `$By` selector provided. ```yaml -Type: SwitchParameter +Type: String[] Parameter Sets: (All) Aliases: -Required: False -Position: Named +Required: True +Position: 1 Default value: None Accept pipeline input: False Accept wildcard characters: False diff --git a/Help/Get-SeElementAttribute.md b/Help/Get-SeElementAttribute.md index 8e1bdf5..46cb79a 100644 --- a/Help/Get-SeElementAttribute.md +++ b/Help/Get-SeElementAttribute.md @@ -8,16 +8,16 @@ schema: 2.0.0 # Get-SeElementAttribute ## SYNOPSIS -{{ Fill in the Synopsis }} +Get the specified attribute from the specified element. ## SYNTAX ``` -Get-SeElementAttribute [-Element] [-Attribute] [] +Get-SeElementAttribute [-Element] [-Name] [] ``` ## DESCRIPTION -{{ Fill in the Description }} +Get the specified attribute from the specified element. ## EXAMPLES @@ -31,33 +31,33 @@ Get the placeholder attribue of the username element. ## PARAMETERS -### -Attribute -{{ Fill Attribute Description }} +### -Element +Target IWebElement ```yaml -Type: String +Type: IWebElement Parameter Sets: (All) Aliases: Required: True -Position: 1 +Position: 0 Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -Element -Target IWebElement +### -Name +{{ Fill Name Description }} ```yaml -Type: IWebElement +Type: String[] Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 1 Default value: None -Accept pipeline input: True (ByValue) +Accept pipeline input: False Accept wildcard characters: False ``` diff --git a/Help/Get-SeElementCssValue.md b/Help/Get-SeElementCssValue.md index b0544cd..fa38693 100644 --- a/Help/Get-SeElementCssValue.md +++ b/Help/Get-SeElementCssValue.md @@ -13,7 +13,7 @@ Get CSS value for the specified name of targeted element. ## SYNTAX ``` -Get-SeElementCssValue [-Element] [-Name] [] +Get-SeElementCssValue [-Element] [-Name] [] ``` ## DESCRIPTION @@ -26,6 +26,8 @@ Get CSS value for the specified name of targeted element. PS C:\> Get-SeElementCssValue -Element $Element -Name 'padding' ``` +Get padding css value for the targeted element. + ## PARAMETERS ### -Element @@ -47,7 +49,7 @@ Accept wildcard characters: False Name of the CSS attribute to query ```yaml -Type: String +Type: String[] Parameter Sets: (All) Aliases: diff --git a/Help/Get-SeFrame.md b/Help/Get-SeFrame.md new file mode 100644 index 0000000..a888024 --- /dev/null +++ b/Help/Get-SeFrame.md @@ -0,0 +1,45 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeFrame + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-SeFrame [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## 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-SeHtml.md b/Help/Get-SeHtml.md new file mode 100644 index 0000000..8e948d5 --- /dev/null +++ b/Help/Get-SeHtml.md @@ -0,0 +1,84 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeHtml + +## SYNOPSIS +Get outer html of the specified element or driver. + +## SYNTAX + +``` +Get-SeHtml [[-Element] ] [-Inner] [] +``` + +## DESCRIPTION +Get outer html of the specified element or driver. +Driver is used by default if no element is specified. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Element = Get-SeElement -By ClassName -Value 'homeitem' +PS C:\> $Element | Get-SeHtml -Inner +``` + +Get inner html for all specified elements. + +### Example 2 +```powershell +PS C:\> Get-SeHtml +``` + +Get html of the current page. Equivalent to $Driver.PageSource + +## PARAMETERS + +### -Element +Target IWebElement. + +```yaml +Type: IWebElement +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Inner +Return inner html instead. + +```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 + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Get-SeInput.md b/Help/Get-SeInput.md new file mode 100644 index 0000000..2461701 --- /dev/null +++ b/Help/Get-SeInput.md @@ -0,0 +1,151 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Get-SeInput + +## SYNOPSIS +Get element with an input tagname matching the specified conditions. + +## SYNTAX + +``` +Get-SeInput [[-Type] ] [-Single] [[-Text] ] [[-Timeout] ] [-All] + [[-Attributes] ] [[-Value] ] [] +``` + +## DESCRIPTION +Get SeElement with an input Tagname + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-SeInput -Attributes placeholder,title -All -Single -Value 'Type to search' +``` + +Get all the input (including hidden) present in the Dom and load the attributes placeholder and title. A single value is expected and it's attribute placeholder should be equals to : "Type to search" + +## PARAMETERS + +### -All +Return matching hidden items in addition to displayed ones. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Attributes +Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Single +Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Text +Text of the input to return + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Timeout +Timeout (in seconds) + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Type +Type of the input + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +Expected value of the first attribute present. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +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/Invoke-SeScreenshot.md b/Help/Get-SeSelectValue.md similarity index 64% rename from Help/Invoke-SeScreenshot.md rename to Help/Get-SeSelectValue.md index d52982d..bee385e 100644 --- a/Help/Invoke-SeScreenshot.md +++ b/Help/Get-SeSelectValue.md @@ -5,26 +5,33 @@ online version: schema: 2.0.0 --- -# Invoke-SeScreenshot +# Get-SeSelectValue ## SYNOPSIS -Take a screenshot of the current page +Get Select element selected value. ## SYNTAX ``` -Invoke-SeScreenshot [[-Target] ] [-AsBase64EncodedString] [] +Get-SeSelectValue [-Element] [-All] [] ``` ## DESCRIPTION -Take a screenshot of the current page +Get Select element selected value. ## EXAMPLES +### Example 1 +```powershell +PS C:\> Get-SeSelectValue -Element $Select +``` + +Get the selected value for the specified element. + ## PARAMETERS -### -AsBase64EncodedString -Return image as base64 string +### -All +Get All selected values (only available when the Select element accept multiple values) ```yaml Type: SwitchParameter @@ -38,16 +45,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Target -Target webdriver +### -Element +Target IWebElement. ```yaml -Type: Object +Type: IWebElement Parameter Sets: (All) -Aliases: Driver +Aliases: -Required: False -Position: 0 +Required: True +Position: 1 Default value: None Accept pipeline input: True (ByValue) Accept wildcard characters: False @@ -58,7 +65,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## INPUTS -### System.Object +### OpenQA.Selenium.IWebElement ## OUTPUTS diff --git a/Help/Get-SeSelectionOption.md b/Help/Get-SeSelectionOption.md deleted file mode 100644 index 72b84ed..0000000 --- a/Help/Get-SeSelectionOption.md +++ /dev/null @@ -1,271 +0,0 @@ ---- -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-SeUrl.md b/Help/Get-SeUrl.md index c033ddc..c069208 100644 --- a/Help/Get-SeUrl.md +++ b/Help/Get-SeUrl.md @@ -13,7 +13,7 @@ Retrieves the current URL of a target webdriver instance. ## SYNTAX ``` -Get-SeUrl [-Stack] [[-Target] ] [] +Get-SeUrl [-Stack] [] ``` ## DESCRIPTION @@ -47,22 +47,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Target -The webdriver instance for which to retrieve the current URL or -internal URL stack. - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: Driver - -Required: False -Position: 1 -Default value: $Global:SeDriver -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). diff --git a/Help/Get-SeWindow.md b/Help/Get-SeWindow.md index 0fa20d3..63ff25b 100644 --- a/Help/Get-SeWindow.md +++ b/Help/Get-SeWindow.md @@ -13,7 +13,7 @@ Gets the window handles of open browser windows ## SYNTAX ``` -Get-SeWindow [[-Target] ] [] +Get-SeWindow [] ``` ## DESCRIPTION @@ -30,21 +30,6 @@ 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). diff --git a/Help/Invoke-SeClick.md b/Help/Invoke-SeClick.md index fb430dd..4cbe3b8 100644 --- a/Help/Invoke-SeClick.md +++ b/Help/Invoke-SeClick.md @@ -8,66 +8,90 @@ schema: 2.0.0 # Invoke-SeClick ## SYNOPSIS -Select an element then send a click action on it. +Perform a click in the browser window or specified element. ## SYNTAX -### Default (Default) ``` -Invoke-SeClick -Element [] -``` - -### JavaScript -``` -Invoke-SeClick -Element [-JavaScriptClick] [-Driver ] [] +Invoke-SeClick [[-Action] ] [[-Element] ] [-Sleep ] [-PassThru] + [] ``` ## DESCRIPTION -Select an element then send a click action on it. +Perform a click in the browser window or specified element. ## EXAMPLES +### Example 1 +```powershell +PS C:\> Invoke-SeClick +``` + +Perform a click in the browser at the current position + +### Example 2 +```powershell +PS C:\> Invoke-SeClick -Action Click_JS -Element $Element +``` + +Perform a javascript click on the specified element. + ## PARAMETERS -### -Driver -Target webdriver +### -Action +test ```yaml Type: Object -Parameter Sets: JavaScript +Parameter Sets: (All) Aliases: Required: False -Position: Named +Position: 0 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` ### -Element -Element for which the click will be performed upon +Target IWebElement. ```yaml Type: IWebElement Parameter Sets: (All) Aliases: -Required: True -Position: Named +Required: False +Position: 1 Default value: None Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -JavaScriptClick -Use Javascript to perform the click +### -PassThru +Return the IWebElement. ```yaml Type: SwitchParameter -Parameter Sets: JavaScript +Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Sleep +Sleep time in second after performing the click action. + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False diff --git a/Help/Invoke-SeJavascript.md b/Help/Invoke-SeJavascript.md new file mode 100644 index 0000000..eef6086 --- /dev/null +++ b/Help/Invoke-SeJavascript.md @@ -0,0 +1,75 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Invoke-SeJavascript + +## SYNOPSIS +Invoke Javascript in the specified Driver. + +## SYNTAX + +``` +Invoke-SeJavascript [[-Script] ] [[-ArgumentList] ] [] +``` + +## DESCRIPTION +Invoke Javascript in the specified Driver. arguments will be passed to the javascript as "argument[0]" (where 0 is the argument position) + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Invoke-SeJavascript -Script 'arguments[0].click()' -ArgumentList $Element +``` + +Perform a javascript click on the specified element. + +## PARAMETERS + +### -ArgumentList +Argument list to be passed down to the script. + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Script +Javascript script to be executed. Arguments passed down can be used in the scripts through `arguments[0],arguments[1]`,etc... + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +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/SeType.md b/Help/Invoke-SeKeys.md similarity index 62% rename from Help/SeType.md rename to Help/Invoke-SeKeys.md index f1816e9..addac71 100644 --- a/Help/SeType.md +++ b/Help/Invoke-SeKeys.md @@ -5,34 +5,35 @@ online version: schema: 2.0.0 --- -# SeType +# Invoke-SeKeys ## SYNOPSIS -{{ Fill in the Synopsis }} +Send the keys to the browser or specified element. ## SYNTAX ``` -SeType [-Keys] -Element [-ClearFirst] [-SleepSeconds ] [-Submit] [-PassThru] +Invoke-SeKeys [[-Element] ] [-Keys] [-ClearFirst] [-Sleep ] [-Submit] [-PassThru] [] ``` ## DESCRIPTION -{{ Fill in the Description }} +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:\> {{ Add example code here }} +PS C:\> $Search = Get-SeElement -By TagName -Value input -Single +PS C:\> Invoke-SeKeys -Element $Search -Keys 'Powershell-Selenium{{Enter}}' ``` -{{ Add example description here }} +Type the defined text and a special key - Enter - defined in the special keys. ## PARAMETERS ### -ClearFirst -{{ Fill ClearFirst Description }} +Clear the element existing text first ```yaml Type: SwitchParameter @@ -47,22 +48,22 @@ Accept wildcard characters: False ``` ### -Element -{{ Fill Element Description }} +Target IWebElement. ```yaml Type: IWebElement Parameter Sets: (All) Aliases: -Required: True -Position: Named +Required: False +Position: 0 Default value: None Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` ### -Keys -{{ Fill Keys Description }} +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 @@ -70,19 +71,19 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 1 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` ### -PassThru -{{ Fill PassThru Description }} +Return the IWebElement or webdriver ```yaml Type: SwitchParameter Parameter Sets: (All) -Aliases: PT +Aliases: Required: False Position: Named @@ -91,11 +92,11 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -SleepSeconds -{{ Fill SleepSeconds Description }} +### -Sleep +Sleep time in second after performing the type action. ```yaml -Type: Object +Type: Double Parameter Sets: (All) Aliases: @@ -107,7 +108,7 @@ Accept wildcard characters: False ``` ### -Submit -{{ Fill Submit Description }} +Call submit on the specified element. ```yaml Type: SwitchParameter diff --git a/Help/Send-SeClick.md b/Help/Invoke-SeMouseAction.md similarity index 52% rename from Help/Send-SeClick.md rename to Help/Invoke-SeMouseAction.md index d05705a..ad7d93e 100644 --- a/Help/Send-SeClick.md +++ b/Help/Invoke-SeMouseAction.md @@ -5,34 +5,33 @@ online version: schema: 2.0.0 --- -# Send-SeClick +# Invoke-SeMouseAction ## SYNOPSIS -Send a click to the targeted element +Perform mouse move & drag actions. ## SYNTAX ``` -Send-SeClick [-Element] [-JavaScriptClick] [-SleepSeconds ] [-Driver ] - [-PassThru] [] +Invoke-SeMouseAction [[-Action] ] [[-Value] ] [[-Element] ] [] ``` ## DESCRIPTION -Send a click to the targeted element +Perform mouse move & drag actions. ## EXAMPLES ### Example 1 ```powershell -PS C:\> (Get-SeElement -By Name -Selection 'ButtonX') | Send-SeClick +PS C:\> Invoke-SeMouseAction -Element $SourceElement -Action DragAndDrop -Value $DestinationElement ``` -Select an element then send a click action on it. +Perform a drag&drop operation from the source element to destination element. ## PARAMETERS -### -Driver -Target webdriver +### -Action +Action to be performed. Intellisense tooltip provide details regarding expected value. ```yaml Type: Object @@ -40,59 +39,29 @@ Parameter Sets: (All) Aliases: Required: False -Position: Named +Position: 0 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` ### -Element -Element for which the click will be performed upon +{{ Fill Element Description }} ```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 +Position: 2 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 pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -SleepSeconds -Sleep time in seconds after the click +### -Value +Value expected by the specified action. ```yaml Type: Object @@ -100,7 +69,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: Named +Position: 1 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -111,7 +80,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## INPUTS -### OpenQA.Selenium.IWebElement +### None ## OUTPUTS diff --git a/Help/New-SeDriverOptions.md b/Help/New-SeDriverOptions.md new file mode 100644 index 0000000..e31dcb2 --- /dev/null +++ b/Help/New-SeDriverOptions.md @@ -0,0 +1,286 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# New-SeDriverOptions + +## SYNOPSIS +Create a driver options object that can be used with `Start-SeDriver` + +## SYNTAX + +``` +New-SeDriverOptions [-Browser ] [[-StartURL] ] [-State ] + [-DefaultDownloadPath ] [-PrivateBrowsing] [-ImplicitWait ] [-Size ] + [-Position ] [-WebDriverPath ] [-BinaryPath ] [-Switches ] + [-Arguments ] [-ProfilePath ] [-LogLevel ] [-UserAgent ] + [] +``` + +## DESCRIPTION +Create a driver options object that can be used with `Start-SeDriver` + +This allow for more flexibility than the Start-SeDriver cmdlet as you can perform additional things with the driver options before starting the driver. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Options = New-SeDriverOptions -Browser Chrome -Position 1920x0 -Size 1920x1080 +PS C:\> $Options.AddAdditionalCapability('useAutomationExtension', $false) +PS C:\> Start-SeDriver -Options $Options +``` + +Create a Chrome driver option object to perform additional things unsupported directly by Start-SeDriver, such as adding an additional capability, then Start a driver instance with the modified Chrome driver options object. + +## PARAMETERS + +### -Arguments +Command line arguments to be passed to the browser. + +```yaml +Type: String[] +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 +``` + +### -Browser +Browser name to be started. + +```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: FileInfo +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Maximum time that the browser will implicitely wait between operations + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LogLevel +{{ Fill LogLevel Description }} + +```yaml +Type: LogLevel +Parameter Sets: (All) +Aliases: +Accepted values: All, Debug, Info, Warning, Severe, Off + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Position +Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. + +```yaml +Type: Point +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Launch the browser in a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProfilePath +{{ Fill ProfilePath Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Size +Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. + +```yaml +Type: Size +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -State +Window state of the browser. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Switches +Special switches (additional legacy options that might appear for some browser ) + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UserAgent +UserAgent to be set. Supported by Chrome & Firefox + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverPath +Location of the web driver to be used. + +```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 + +### OpenQA.Selenium.Chrome.ChromeOptions + +### OpenQA.Selenium.Edge.EdgeOptions + +### OpenQA.Selenium.Firefox.FirefoxOptions + +### OpenQA.Selenium.IE.InternetExplorerOptions + +## NOTES + +## RELATED LINKS diff --git a/Help/New-SeDriverService.md b/Help/New-SeDriverService.md new file mode 100644 index 0000000..3447c0b --- /dev/null +++ b/Help/New-SeDriverService.md @@ -0,0 +1,86 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# New-SeDriverService + +## SYNOPSIS +Create an instance of WebDriver service to be used with Start-SeDriver + +## SYNTAX + +``` +New-SeDriverService [-Browser ] [-WebDriverPath ] [] +``` + +## DESCRIPTION +Create an instance of WebDriver service to be used with Start-SeDriver + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Service = New-SeDriverService -Browser Chrome +PS C:\> $Service.PortServerAddress = 100 +PS C:\> $Options = New-SeDriverOptions -Browser Chrome -Position 1920x0 -Size 1920x1080 +PS C:\> Start-SeDriver -Service $Service -Options $Options +PS C:\> $Service.ProcessId +``` + +Create a new instance of Chrome driver service, set a custom port and start the driver with the modified service instance. + +## PARAMETERS + +### -Browser +Browser name + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverPath +Location of the web driver to be used. + +```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 + +### OpenQA.Selenium.Chrome.ChromeDriverService + +### OpenQA.Selenium.Firefox.FirefoxDriverService + +### OpenQA.Selenium.IE.InternetExplorerDriverService + +### OpenQA.Selenium.Edge.EdgeDriverService + +## NOTES + +## RELATED LINKS diff --git a/Help/New-SeScreenshot.md b/Help/New-SeScreenshot.md index d9589fb..ccf34df 100644 --- a/Help/New-SeScreenshot.md +++ b/Help/New-SeScreenshot.md @@ -14,19 +14,17 @@ Take a screenshot of the current page ### Path (Default) ``` -New-SeScreenshot [-Path] [[-ImageFormat] ] [-Target ] - [] +New-SeScreenshot [-AsBase64EncodedString] [] ``` -### PassThru +### Pipeline ``` -New-SeScreenshot [[-Path] ] [[-ImageFormat] ] [-Target ] [-PassThru] - [] +New-SeScreenshot [-InputObject ] [-AsBase64EncodedString] [] ``` -### Base64 +### Element ``` -New-SeScreenshot [-Target ] [-AsBase64EncodedString] [] +New-SeScreenshot [-AsBase64EncodedString] [-Element ] [] ``` ## DESCRIPTION @@ -48,82 +46,39 @@ Return image as base64 string ```yaml Type: SwitchParameter -Parameter Sets: Base64 +Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -ImageFormat -Set the image format +### -Element +{{ Fill Element Description }} ```yaml -Type: ScreenshotImageFormat -Parameter Sets: Path, PassThru +Type: IWebElement +Parameter Sets: Element 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. +### -InputObject +{{ Fill InputObject Description }} ```yaml Type: Object -Parameter Sets: Path +Parameter Sets: Pipeline 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 diff --git a/Help/New-SeWindow.md b/Help/New-SeWindow.md new file mode 100644 index 0000000..1d2131a --- /dev/null +++ b/Help/New-SeWindow.md @@ -0,0 +1,60 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# New-SeWindow + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +New-SeWindow [[-Url] ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Url +{{ Fill Url Description }} + +```yaml +Type: Object +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 + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Pop-SeUrl.md b/Help/Pop-SeUrl.md index 1757983..471e5c2 100644 --- a/Help/Pop-SeUrl.md +++ b/Help/Pop-SeUrl.md @@ -13,7 +13,7 @@ Navigate back to the most recently pushed URL in the location stack. ## SYNTAX ``` -Pop-SeUrl [[-Target] ] [] +Pop-SeUrl [] ``` ## DESCRIPTION @@ -31,21 +31,6 @@ Retrieves the most recently pushed URL and navigates back to that URL. ## PARAMETERS -### -Target -{{ Fill Target Description }} - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: Driver - -Required: False -Position: 1 -Default value: $Global:SeDriver -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). diff --git a/Help/Push-SeUrl.md b/Help/Push-SeUrl.md index 3d5fcd4..d043e06 100644 --- a/Help/Push-SeUrl.md +++ b/Help/Push-SeUrl.md @@ -14,7 +14,7 @@ navigate to a new URL. ## SYNTAX ``` -Push-SeUrl [[-Url] ] [-Target ] [] +Push-SeUrl [[-Url] ] [] ``` ## DESCRIPTION @@ -55,22 +55,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Target -The webdriver instance that owns the url stack, and will navigate to -a provided new url (if any). - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: Driver - -Required: False -Position: Named -Default value: $Global:SeDriver -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). diff --git a/Help/README.MD b/Help/README.MD index b4e0ba3..bb45ddb 100644 --- a/Help/README.MD +++ b/Help/README.MD @@ -12,26 +12,44 @@ Locale: {{ Update Locale }} ## Selenium Cmdlets ### [Clear-SeAlert](Clear-SeAlert.md) -Accept and clear alert popup +Clear alert popup by dismissing or accepting it. + +### [Clear-SeSelectValue](Clear-SeSelectValue.md) +Clear all selected entries of a SELECT element. ### [Get-SeCookie](Get-SeCookie.md) List all cookies +### [Get-SeDriver](Get-SeDriver.md) +Get the list of all active drivers. + +### [Get-SeDriverTimeout](Get-SeDriverTimeout.md) +Get the specified driver timeout value. + ### [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 the specified attribute from the specified element. ### [Get-SeElementCssValue](Get-SeElementCssValue.md) Get CSS value for the specified name of targeted element. +### [Get-SeFrame](Get-SeFrame.md) +{{ Fill in the Synopsis }} + +### [Get-SeHtml](Get-SeHtml.md) +Get outer html of the specified element or driver. + +### [Get-SeInput](Get-SeInput.md) +Get element with an input tagname matching the specified conditions. + ### [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-SeSelectValue](Get-SeSelectValue.md) +Get Select element selected value. ### [Get-SeUrl](Get-SeUrl.md) Retrieves the current URL of a target webdriver instance. @@ -40,14 +58,29 @@ Retrieves the current URL of a target webdriver instance. Gets the window handles of open browser windows ### [Invoke-SeClick](Invoke-SeClick.md) -Select an element then send a click action on it. +Perform a click in the browser window or specified element. -### [Invoke-SeScreenshot](Invoke-SeScreenshot.md) -Take a screenshot of the current page +### [Invoke-SeJavascript](Invoke-SeJavascript.md) +Invoke Javascript in the specified Driver. + +### [Invoke-SeKeys](Invoke-SeKeys.md) +Send the keys to the browser or specified element. + +### [Invoke-SeMouseAction](Invoke-SeMouseAction.md) +Perform mouse move & drag actions. + +### [New-SeDriverOptions](New-SeDriverOptions.md) +Create a driver options object that can be used with `Start-SeDriver` + +### [New-SeDriverService](New-SeDriverService.md) +Create an instance of WebDriver service to be used with Start-SeDriver ### [New-SeScreenshot](New-SeScreenshot.md) Take a screenshot of the current page +### [New-SeWindow](New-SeWindow.md) +{{ Fill in the Synopsis }} + ### [Pop-SeUrl](Pop-SeUrl.md) Navigate back to the most recently pushed URL in the location stack. @@ -58,45 +91,48 @@ navigate to a new 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 +### [Remove-SeWindow](Remove-SeWindow.md) +{{ Fill in the Synopsis }} -### [Send-SeKeys](Send-SeKeys.md) -Simulates typing text into the element +### [Save-SeScreenshot](Save-SeScreenshot.md) +Save a screenshot on the disk. ### [Set-SeCookie](Set-SeCookie.md) Add a cookie to the current browsing context -### [Set-SeUrl](Set-SeUrl.md) -Navigates to the targeted URL with the selected or default driver. - -### [Start-SeChrome](Start-SeChrome.md) -Initializes a new instance of the **ChromeDriver** class. +### [Set-SeDriverTimeout](Set-SeDriverTimeout.md) +Set the various driver timeouts default. -### [Start-SeEdge](Start-SeEdge.md) -Initializes a new instance of the EdgeDriver class +### [Set-SeSelectValue](Set-SeSelectValue.md) +Set Select element selected value. -### [Start-SeFirefox](Start-SeFirefox.md) -Initializes a new instance of the **FirefoxDriver** class. - -### [Start-SeInternetExplorer](Start-SeInternetExplorer.md) -{{ Fill in the Synopsis }} +### [Set-SeUrl](Set-SeUrl.md) +Navigates to the targeted URL with the selected or default driver. -### [Start-SeNewEdge](Start-SeNewEdge.md) -Initializes a new instance of the EdgeDriver class +### [Start-SeDriver](Start-SeDriver.md) +Launch the specified browser. -### [Start-SeNewEdge](Start-SeNewEdge.md) -{{ Fill in the Synopsis }} +### [Start-SeRemote](Start-SeRemote.md) +Start a remote driver session. ### [Stop-SeDriver](Stop-SeDriver.md) Quits this driver, closing every associated window. +### [Switch-SeDriver](Switch-SeDriver.md) +Select a driver, making it the default to be used with any ulterior calls whenever the driver parameter is not specified. + ### [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 +### [Update-SeDriver](Update-SeDriver.md) +{{ Fill in the Synopsis }} + +### [Wait-SeDriver](Wait-SeDriver.md) +Wait for the driver to be in the desired state. + +### [Wait-SeElement](Wait-SeElement.md) +Wait for an element condition to be met. + diff --git a/Help/Remove-SeCookie.md b/Help/Remove-SeCookie.md index e1635fd..2eab7be 100644 --- a/Help/Remove-SeCookie.md +++ b/Help/Remove-SeCookie.md @@ -12,14 +12,14 @@ Delete the named cookie from the current domain ## SYNTAX -### DeleteAllCookies +### All ``` -Remove-SeCookie [-Target ] [-DeleteAllCookies] [] +Remove-SeCookie [-All] [] ``` ### NamedCookie ``` -Remove-SeCookie [-Target ] -Name [] +Remove-SeCookie -Name [] ``` ## DESCRIPTION @@ -43,13 +43,13 @@ Remove all cookies from targeted Driver ## PARAMETERS -### -DeleteAllCookies -Remove all cookies from webdriver +### -All +Clear all cookies. ```yaml Type: SwitchParameter -Parameter Sets: DeleteAllCookies -Aliases: Purge +Parameter Sets: All +Aliases: Required: True Position: Named @@ -73,21 +73,6 @@ 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). diff --git a/Help/Remove-SeWindow.md b/Help/Remove-SeWindow.md new file mode 100644 index 0000000..2dcc6d2 --- /dev/null +++ b/Help/Remove-SeWindow.md @@ -0,0 +1,60 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Remove-SeWindow + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Remove-SeWindow [[-SwitchToWindow] ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -SwitchToWindow +{{ Fill SwitchToWindow Description }} + +```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 + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Save-SeScreenshot.md b/Help/Save-SeScreenshot.md index 10c2277..d500ff2 100644 --- a/Help/Save-SeScreenshot.md +++ b/Help/Save-SeScreenshot.md @@ -8,24 +8,65 @@ schema: 2.0.0 # Save-SeScreenshot ## SYNOPSIS -Take a screenshot of the current page +Save a screenshot on the disk. ## SYNTAX +### Driver (Default) ``` -Save-SeScreenshot [-Screenshot] [-Path] [[-ImageFormat] ] +Save-SeScreenshot -Path [-ImageFormat ] [] +``` + +### Pipeline +``` +Save-SeScreenshot [-InputObject ] -Path [-ImageFormat ] + [] +``` + +### Screenshot +``` +Save-SeScreenshot -Screenshot -Path [-ImageFormat ] + [] +``` + +### Element +``` +Save-SeScreenshot -Path [-ImageFormat ] -Element [] ``` ## DESCRIPTION -Take a screenshot of the current page +Save the screenshot at the specified location. ## EXAMPLES +### Example 1 +```powershell +PS C:\> $Screenshot = New-SeScreenshot +PS C:\> Save-SeScreenshot -Screenshot $Screenshot -Path 'c:\temp\image.png' -ImageFormat Png +``` + +Create then save a screenshot to disk. + ## PARAMETERS +### -Element +{{ Fill Element Description }} + +```yaml +Type: IWebElement +Parameter Sets: Element +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ImageFormat -Set the image format +Image format for the file to be saved. ```yaml Type: ScreenshotImageFormat @@ -34,14 +75,29 @@ Aliases: Accepted values: Png, Jpeg, Gif, Tiff, Bmp Required: False -Position: 2 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` +### -InputObject +{{ Fill InputObject Description }} + +```yaml +Type: Object +Parameter Sets: Pipeline +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + ### -Path -Filepath where the image iwll be saved to. +Filepath where the image will be saved. ```yaml Type: String @@ -49,24 +105,24 @@ Parameter Sets: (All) Aliases: Required: True -Position: 1 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` ### -Screenshot -Screenshot element +Screenshot object. ```yaml Type: Screenshot -Parameter Sets: (All) +Parameter Sets: Screenshot Aliases: Required: True -Position: 0 +Position: Named Default value: None -Accept pipeline input: True (ByValue) +Accept pipeline input: False Accept wildcard characters: False ``` @@ -75,6 +131,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## INPUTS +### System.Object + ### OpenQA.Selenium.Screenshot ## OUTPUTS diff --git a/Help/Set-SeCookie.md b/Help/Set-SeCookie.md index 812ef7d..ef96844 100644 --- a/Help/Set-SeCookie.md +++ b/Help/Set-SeCookie.md @@ -14,7 +14,7 @@ Add a cookie to the current browsing context ``` Set-SeCookie [[-Name] ] [[-Value] ] [[-Path] ] [[-Domain] ] - [[-ExpiryDate] ] [[-Target] ] [] + [[-ExpiryDate] ] [] ``` ## DESCRIPTION @@ -43,7 +43,7 @@ Accept wildcard characters: False The expiration date of the cookie ```yaml -Type: Object +Type: DateTime Parameter Sets: (All) Aliases: @@ -84,21 +84,6 @@ 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 diff --git a/Help/Set-SeDriverTimeout.md b/Help/Set-SeDriverTimeout.md new file mode 100644 index 0000000..52966bc --- /dev/null +++ b/Help/Set-SeDriverTimeout.md @@ -0,0 +1,76 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Set-SeDriverTimeout + +## SYNOPSIS +Set the various driver timeouts default. + +## SYNTAX + +``` +Set-SeDriverTimeout [[-TimeoutType] ] [[-Timeout] ] [] +``` + +## DESCRIPTION +Set the various driver timeouts default. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Set-SeDriverTimeout -TimeoutType ImplicitWait -Timeout 0 +``` + +Set Implicit wait timeout to 0 + +## PARAMETERS + +### -Timeout +Value in seconds + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TimeoutType +Type of timeout to change. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: +Accepted values: ImplicitWait, PageLoad, AsynchronousJavaScript + +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 + +### OpenQA.Selenium.IWebDriver + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Send-SeKeys.md b/Help/Set-SeSelectValue.md similarity index 55% rename from Help/Send-SeKeys.md rename to Help/Set-SeSelectValue.md index e2199bd..b839863 100644 --- a/Help/Send-SeKeys.md +++ b/Help/Set-SeSelectValue.md @@ -5,70 +5,69 @@ online version: schema: 2.0.0 --- -# Send-SeKeys +# Set-SeSelectValue ## SYNOPSIS -Simulates typing text into the element +Set Select element selected value. ## SYNTAX ``` -Send-SeKeys [-Element] [-Keys] [-PassThru] [] +Set-SeSelectValue [-By ] [-Element] [-value ] [] ``` ## 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) +Set Select element selected value. ## EXAMPLES ### Example 1 ```powershell -PS C:\> SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru +PS C:\> Set-SeSelectValue -By Text -value 'Hello' -Element $Element ``` -ype the defined text and a special key - Enter - defined in the special keys. +Set targeted Select element selected value to 'Hello' (by text) ## PARAMETERS -### -Element -Specify the element where the keys will be typed to +### -By +Selector to be used to set the value. ```yaml -Type: IWebElement +Type: SeBySelect Parameter Sets: (All) Aliases: +Accepted values: Index, Text, Value -Required: True -Position: 0 +Required: False +Position: Named Default value: None -Accept pipeline input: True (ByValue) +Accept pipeline input: False 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 +### -Element +Target IWebElement. ```yaml -Type: String +Type: IWebElement Parameter Sets: (All) Aliases: Required: True Position: 1 Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -PassThru -Return `$Element` +### -value +Value to which the specified element will be set. ```yaml -Type: SwitchParameter +Type: Object Parameter Sets: (All) -Aliases: PT +Aliases: Required: False Position: Named diff --git a/Help/Set-SeUrl.md b/Help/Set-SeUrl.md index a8a8171..ae37bd2 100644 --- a/Help/Set-SeUrl.md +++ b/Help/Set-SeUrl.md @@ -14,27 +14,27 @@ Navigates to the targeted URL with the selected or default driver. ### default (Default) ``` -Set-SeUrl [-Target ] [] +Set-SeUrl [] ``` ### url ``` -Set-SeUrl [-Url] [-Target ] [] +Set-SeUrl [-Url] [] ``` ### back ``` -Set-SeUrl [-Back] [-Target ] [] +Set-SeUrl [-Back] [-Depth ] [] ``` ### forward ``` -Set-SeUrl [-Forward] [-Target ] [] +Set-SeUrl [-Forward] [-Depth ] [] ``` ### refresh ``` -Set-SeUrl [-Refresh] [-Target ] [] +Set-SeUrl [-Refresh] [] ``` ## DESCRIPTION @@ -133,20 +133,18 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Target -The target webdriver to manage navigation for. -Will utilise the -default driver if left unset. +### -Depth +Number of time the action should be performed. ```yaml -Type: Object -Parameter Sets: (All) -Aliases: Driver +Type: Int32 +Parameter Sets: back, forward +Aliases: Required: False Position: Named -Default value: $Global:SeDriver -Accept pipeline input: True (ByValue) +Default value: 1 +Accept pipeline input: False Accept wildcard characters: False ``` diff --git a/Help/Start-SeChrome.md b/Help/Start-SeChrome.md deleted file mode 100644 index 7128b7b..0000000 --- a/Help/Start-SeChrome.md +++ /dev/null @@ -1,384 +0,0 @@ ---- -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-SeDriver.md b/Help/Start-SeDriver.md new file mode 100644 index 0000000..9481e27 --- /dev/null +++ b/Help/Start-SeDriver.md @@ -0,0 +1,340 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Start-SeDriver + +## SYNOPSIS +Launch the specified browser. + +## SYNTAX + +### default (Default) +``` +Start-SeDriver [[-StartURL] ] [-State ] [-DefaultDownloadPath ] + [-PrivateBrowsing] [-ImplicitWait ] [-Size ] [-Position ] [-WebDriverPath ] + [-BinaryPath ] [-Arguments ] [-ProfilePath ] [-LogLevel ] [-Name ] + [-UserAgent ] [] +``` + +### DriverOptions +``` +Start-SeDriver [-Browser ] [[-StartURL] ] [-State ] + [-DefaultDownloadPath ] [-PrivateBrowsing] [-ImplicitWait ] [-Size ] + [-Position ] [-WebDriverPath ] [-BinaryPath ] [-Service ] + -Options [-Arguments ] [-ProfilePath ] [-LogLevel ] + [-Name ] [-UserAgent ] [] +``` + +### Default +``` +Start-SeDriver [-Browser ] [[-StartURL] ] [-State ] + [-DefaultDownloadPath ] [-PrivateBrowsing] [-ImplicitWait ] [-Size ] + [-Position ] [-WebDriverPath ] [-BinaryPath ] [-Switches ] + [-Arguments ] [-ProfilePath ] [-LogLevel ] [-Name ] [-UserAgent ] + [] +``` + +## DESCRIPTION +Launch a driver instance of the specified browser. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Start-SeDriver -Browser Chrome -Position 1920x0 -StartURL 'google.com' +``` + +Start a Chrome browser at the specified position and starting URL + +## PARAMETERS + +### -Arguments +Command line arguments to be passed to the browser. + +```yaml +Type: String[] +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 +``` + +### -Browser +Browser to be started. + +```yaml +Type: Object +Parameter Sets: DriverOptions, Default +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultDownloadPath +{{ Fill DefaultDownloadPath Description }} + +```yaml +Type: FileInfo +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ImplicitWait +Maximum time that the browser will implicitely wait between operations + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LogLevel +{{ Fill LogLevel Description }} + +```yaml +Type: LogLevel +Parameter Sets: (All) +Aliases: +Accepted values: All, Debug, Info, Warning, Severe, Off + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Friendly name of the browser. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Options +Driver Options object + +```yaml +Type: DriverOptions +Parameter Sets: DriverOptions +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Position +Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. + +```yaml +Type: Point +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PrivateBrowsing +Launch the browser in a private session + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProfilePath +{{ Fill ProfilePath Description }} + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Service +DriverService object to be used. + +```yaml +Type: DriverService +Parameter Sets: DriverOptions +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Size +Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. + +```yaml +Type: Size +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartURL +Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -State +Window state of the browser. + +```yaml +Type: SeWindowState +Parameter Sets: (All) +Aliases: +Accepted values: Headless, Default, Minimized, Maximized, Fullscreen + +Required: False +Position: Named +Default value: Default +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Switches +Special switches (additional legacy options that might appear for some browser ) + +```yaml +Type: String[] +Parameter Sets: Default +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UserAgent +UserAgent to be set. Supported by Chrome & Firefox + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebDriverPath +Location of the web driver to be used. + +```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 + +### OpenQA.Selenium.IWebDriver + +## NOTES + +## RELATED LINKS diff --git a/Help/Start-SeEdge.md b/Help/Start-SeEdge.md deleted file mode 100644 index dd40e33..0000000 --- a/Help/Start-SeEdge.md +++ /dev/null @@ -1,198 +0,0 @@ ---- -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 deleted file mode 100644 index 65aa575..0000000 --- a/Help/Start-SeFirefox.md +++ /dev/null @@ -1,276 +0,0 @@ ---- -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 deleted file mode 100644 index 0a90d22..0000000 --- a/Help/Start-SeInternetExplorer.md +++ /dev/null @@ -1,251 +0,0 @@ ---- -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 deleted file mode 100644 index 7f9c62b..0000000 --- a/Help/Start-SeNewEdge.md +++ /dev/null @@ -1,284 +0,0 @@ ---- -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 index 34f680b..47e63b9 100644 --- a/Help/Start-SeRemote.md +++ b/Help/Start-SeRemote.md @@ -5,142 +5,46 @@ online version: schema: 2.0.0 --- -# Start-SeNewEdge +# Start-SeRemote ## SYNOPSIS -{{ Fill in the Synopsis }} +Start a remote driver session. ## 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 ] [] +Start-SeRemote [-RemoteAddress ] [-DesiredCapabilities ] [[-StartURL] ] + [-ImplicitWait ] [-Size ] [-Position ] [] ``` ## DESCRIPTION -{{ Fill in the Description }} +Start a remote driver session. +you can a remote testing account with testing bot at https://testingbot.com/users/sign_up ## EXAMPLES ### Example 1 ```powershell -PS C:\> {{ Add example code here }} +#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 ``` -{{ 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 }} +### -DesiredCapabilities +{{ Fill DesiredCapabilities 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 +Type: Hashtable Parameter Sets: (All) Aliases: @@ -152,10 +56,10 @@ Accept wildcard characters: False ``` ### -ImplicitWait -Control timeout duration (in seconds) +{{ Fill ImplicitWait Description }} ```yaml -Type: Int32 +Type: Double Parameter Sets: (All) Aliases: @@ -166,43 +70,13 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Maximized -Driver will open browser in a maximized state +### -Position +{{ Fill Position Description }} ```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 +Type: Point Parameter Sets: (All) -Aliases: Incognito +Aliases: Required: False Position: Named @@ -211,11 +85,11 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -ProfileDirectoryPath -Driver will use the specified user profile path +### -RemoteAddress +{{ Fill RemoteAddress Description }} ```yaml -Type: Object +Type: String Parameter Sets: (All) Aliases: @@ -226,11 +100,11 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Quiet -Hide command prompt window +### -Size +{{ Fill Size Description }} ```yaml -Type: SwitchParameter +Type: Size Parameter Sets: (All) Aliases: @@ -242,7 +116,7 @@ Accept wildcard characters: False ``` ### -StartURL -Define Driver starting URL +{{ Fill StartURL Description }} ```yaml Type: String @@ -256,21 +130,6 @@ 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). diff --git a/Help/Stop-SeDriver.md b/Help/Stop-SeDriver.md index bb877eb..bdd3f38 100644 --- a/Help/Stop-SeDriver.md +++ b/Help/Stop-SeDriver.md @@ -13,7 +13,7 @@ Quits this driver, closing every associated window. ## SYNTAX ``` -Stop-SeDriver [[-Target] ] [] +Stop-SeDriver [[-Driver] ] [] ``` ## DESCRIPTION @@ -38,13 +38,13 @@ 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. +### -Driver +Target WebDriver ```yaml Type: IWebDriver Parameter Sets: (All) -Aliases: Driver +Aliases: Required: False Position: 0 diff --git a/Help/Switch-SeDriver.md b/Help/Switch-SeDriver.md new file mode 100644 index 0000000..dfb9a59 --- /dev/null +++ b/Help/Switch-SeDriver.md @@ -0,0 +1,89 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Switch-SeDriver + +## SYNOPSIS +Select a driver, making it the default to be used with any ulterior calls whenever the driver parameter is not specified. + +## SYNTAX + +### ByName (Default) +``` +Switch-SeDriver [-Name] [] +``` + +### ByDriver +``` +Switch-SeDriver [-Driver] [] +``` + +## DESCRIPTION +Select a driver, making it the default to be used with any ulterior calls whenever the driver parameter is not specified. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $Driver = Start-SeDriver -Browser Chrome +# Chrome is the only and default driver +PS C:\> Get-SeDriver -Current +PS C:\> Start-SeDriver -Browser Firefox +# Firefox is now the default browser +PS C:\> Get-SeDriver -Current +PS C:\> Switch-SeDriver -Driver $Driver +# Chrome is the default browser again +PS C:\> Get-SeDriver -Current +``` + +This examples show the default browser changing from Chrome to Firefox when the second instance is launched, then set back to Chrome through Switch-SeDriver + +## PARAMETERS + +### -Driver +Target WebDriver + +```yaml +Type: IWebDriver +Parameter Sets: ByDriver +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +SeFriendlyName of the browser to select. + +```yaml +Type: String +Parameter Sets: ByName +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 + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Switch-SeFrame.md b/Help/Switch-SeFrame.md index cb8e374..8946ca1 100644 --- a/Help/Switch-SeFrame.md +++ b/Help/Switch-SeFrame.md @@ -14,17 +14,17 @@ Instructs the driver to send future commands to a different frame ### Frame ``` -Switch-SeFrame [-Frame] [-Target ] [] +Switch-SeFrame [-Frame] [] ``` ### Parent ``` -Switch-SeFrame [-Parent] [-Target ] [] +Switch-SeFrame [-Parent] [] ``` ### Root ``` -Switch-SeFrame [-Root] [-Target ] [] +Switch-SeFrame [-Root] [] ``` ## DESCRIPTION @@ -33,11 +33,6 @@ 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 @@ -77,7 +72,7 @@ Accept wildcard characters: False ```yaml Type: SwitchParameter Parameter Sets: Root -Aliases: defaultContent +Aliases: Required: True Position: Named @@ -86,21 +81,6 @@ 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). diff --git a/Help/Switch-SeWindow.md b/Help/Switch-SeWindow.md index 8c7f6a8..14b5a16 100644 --- a/Help/Switch-SeWindow.md +++ b/Help/Switch-SeWindow.md @@ -13,7 +13,7 @@ Instructs the driver to send future commands to a different window ## SYNTAX ``` -Switch-SeWindow [[-Target] ] [-Window] [] +Switch-SeWindow [-Window] [] ``` ## DESCRIPTION @@ -21,30 +21,8 @@ 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 }} @@ -54,7 +32,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 1 +Position: 0 Default value: None Accept pipeline input: False Accept wildcard characters: False diff --git a/Help/SeOpen.md b/Help/Update-SeDriver.md similarity index 67% rename from Help/SeOpen.md rename to Help/Update-SeDriver.md index 7147780..42eaeee 100644 --- a/Help/SeOpen.md +++ b/Help/Update-SeDriver.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# SeOpen +# Update-SeDriver ## SYNOPSIS {{ Fill in the Synopsis }} @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -SeOpen [-In ] [[-URL] ] [-Options ] [-SleepSeconds ] [] +Update-SeDriver [[-Browser] ] [[-OS] ] [[-Path] ] [] ``` ## DESCRIPTION @@ -30,54 +30,39 @@ PS C:\> {{ Add example code here }} ## PARAMETERS -### -In -{{ Fill In Description }} +### -Browser +{{ Fill Browser Description }} ```yaml Type: Object Parameter Sets: (All) Aliases: -Accepted values: Chrome, CrEdge, FireFox, InternetExplorer, IE, MSEdge, NewEdge Required: False -Position: Named +Position: 0 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Options -{{ Fill Options Description }} +### -OS +{{ Fill OS 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 +Type: Object Parameter Sets: (All) Aliases: +Accepted values: Linux, Mac, Windows Required: False -Position: Named +Position: 1 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -URL -{{ Fill URL Description }} +### -Path +{{ Fill Path Description }} ```yaml Type: Object @@ -85,7 +70,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 1 +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False diff --git a/Help/Wait-SeDriver.md b/Help/Wait-SeDriver.md new file mode 100644 index 0000000..bf7ec25 --- /dev/null +++ b/Help/Wait-SeDriver.md @@ -0,0 +1,90 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Wait-SeDriver + +## SYNOPSIS +Wait for the driver to be in the desired state. + +## SYNTAX + +``` +Wait-SeDriver [-Condition] [-Value] [[-Timeout] ] [] +``` + +## DESCRIPTION +Wait for the driver to be in the desired state. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Wait-SeDriver -Condition UrlContains 'next-' -Timeout 5.5 +``` + +Wait 5.5 seconds for the driver URL to contains text "next-" + +## PARAMETERS + +### -Condition +Condition that is expected to be met. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Timeout +Time delimiter in second for which the operation should succeed. + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +Condition value expected to be met. + +```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 + +### System.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Help/Wait-SeElement.md b/Help/Wait-SeElement.md new file mode 100644 index 0000000..26caa2f --- /dev/null +++ b/Help/Wait-SeElement.md @@ -0,0 +1,144 @@ +--- +external help file: Selenium-help.xml +Module Name: Selenium +online version: +schema: 2.0.0 +--- + +# Wait-SeElement + +## SYNOPSIS +Wait for an element condition to be met. + +## SYNTAX + +### Element (Default) +``` +Wait-SeElement -Element [-Condition ] [-ConditionValue ] [-Timeout ] + [] +``` + +### Locator +``` +Wait-SeElement [[-By] ] [-Value] [-Condition ] [-ConditionValue ] + [-Timeout ] [] +``` + +## DESCRIPTION +Wait for an element condition to be met. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Wait-SeElement -Element $Element -Condition StalenessOf +``` + +Wait for the specified element to not exist anymore in the DOM for 3 seconds (default timeout) + +## PARAMETERS + +### -By +Locator element. + +```yaml +Type: SeBySelector +Parameter Sets: Locator +Aliases: +Accepted values: ClassName, CssSelector, Id, LinkText, PartialLinkText, Name, TagName, XPath + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Condition +Condition expected to be met. Some condition are only available with locator or element. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ConditionValue +Value of the expected condition to be met. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Element +Element that need to meet the condition. + +```yaml +Type: IWebElement +Parameter Sets: Element +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Timeout +Time delimiter in second for which the operation should succeed. + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Value +Value of the locator corresponding to the element that should match the Condition / ConditionValue. + +```yaml +Type: String +Parameter Sets: Locator +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.Object + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Internal/Disable-SeDriverImplicitTimeout.ps1 b/Internal/Disable-SeDriverImplicitTimeout.ps1 new file mode 100644 index 0000000..bd9afba --- /dev/null +++ b/Internal/Disable-SeDriverImplicitTimeout.ps1 @@ -0,0 +1,27 @@ +<# +.SYNOPSIS + Disable Implicitt wait on the specidifed driver +.DESCRIPTION + This cmdlet is used alongside the corresponding Enable cmdlet to temporarily disable + Implicit wait whenever explicit wait are used. +.EXAMPLE + PS C:\> $ImpTimeout = Disable-SeDriverImplicitTimeout -Driver $Driver + Disable implicit wait on the specified driver and return the old timespan. +.INPUTS + Inputs (if any) +.OUTPUTS + Implicit wait Timespan obtained before setting it to 0 +.NOTES + These cmdlet are used because mixing ImplicitWait and ExplicitWait can have unintended consequences. + Thus, implicit wait should always temporarily be disabled when using explicit wait statements. +#> +function Disable-SeDriverImplicitTimeout { + param( + [Parameter(ValueFromPipeline = $true)] + [OpenQA.Selenium.IWebDriver]$Driver + ) + $Output = $Driver.Manage().Timeouts().ImplicitWait + $Driver.Manage().Timeouts().ImplicitWait = 0 + return $Output +} + diff --git a/Internal/Enable-SeDriverImplicitTimeout .ps1 b/Internal/Enable-SeDriverImplicitTimeout .ps1 new file mode 100644 index 0000000..6f203a9 --- /dev/null +++ b/Internal/Enable-SeDriverImplicitTimeout .ps1 @@ -0,0 +1,24 @@ +<# +.SYNOPSIS + Enable ImplicitWait on the specified driver. +.DESCRIPTION + Enable ImplicitWait on the specified driver. See the corresponding Disable cmdlet for more information. +.EXAMPLE + PS C:\> Enable-SeDriverImplicitTimeout -Driver $Driver -Timeout $ImpTimeout + Explanation of what the example does +.INPUTS + Inputs (if any) +.OUTPUTS + Output (if any) +.NOTES + General notes +#> +function Enable-SeDriverImplicitTimeout { + param( + [Parameter(ValueFromPipeline = $true)] + [OpenQA.Selenium.IWebDriver]$Driver, + [timespan]$Timeout + ) + $Driver.Manage().Timeouts().ImplicitWait = $Timeout +} + diff --git a/Internal/Get-DriverProcessId.ps1 b/Internal/Get-DriverProcessId.ps1 new file mode 100644 index 0000000..ffdd7db --- /dev/null +++ b/Internal/Get-DriverProcessId.ps1 @@ -0,0 +1,18 @@ +function Get-DriverProcessId { + [CmdletBinding()] + param ( + $ServiceProcessId + ) + + $IsWindowsPowershell = $PSVersionTable.PSVersion.Major -lt 6 + + if ($IsWindowsPowershell) { + $Processes = Get-CimInstance -Class Win32_Process -Filter "ParentProcessId=$ServiceProcessId" + $BrowserProcess = $Processes.Where( { $_.Name -ne 'conhost.exe' }, 'first').ProcessId + } + else { + $BrowserProcess = (Get-Process).Where( { { $_.Parent.id -eq $ServiceProcessId -and $_.Name -ne 'conhost' } }, 'first').Id + } + return $BrowserProcess + +} \ No newline at end of file diff --git a/Internal/Get-OptionsSwitchValue.ps1 b/Internal/Get-OptionsSwitchValue.ps1 new file mode 100644 index 0000000..8be3b9d --- /dev/null +++ b/Internal/Get-OptionsSwitchValue.ps1 @@ -0,0 +1,5 @@ + +Function Get-OptionsSwitchValue($Switches, $Name) { + if ($null -eq $Switches -or -not $Switches.Contains($Name)) { Return $false } + return $True +} \ No newline at end of file diff --git a/Internal/Get-SeElementsConditionsValueType.ps1 b/Internal/Get-SeElementsConditionsValueType.ps1 new file mode 100644 index 0000000..3047752 --- /dev/null +++ b/Internal/Get-SeElementsConditionsValueType.ps1 @@ -0,0 +1,3 @@ +Function Get-SeElementsConditionsValueType($Text) { + return $Script:SeElementsConditions.Where( { $_.Text -eq $Text }, 'first')[0].ValueType +} \ No newline at end of file diff --git a/Internal/Get-WildcardsIndices.ps1 b/Internal/Get-WildcardsIndices.ps1 new file mode 100644 index 0000000..7ca5edb --- /dev/null +++ b/Internal/Get-WildcardsIndices.ps1 @@ -0,0 +1,16 @@ +Function Get-WildcardsIndices($Value) { + + $Escape = 0 + $Index = -1 + $Value.ToCharArray() | ForEach-Object { + $Index += 1 + $IsWildCard = $false + switch ($_) { + '`' { $Escape += 1; break } + '*' { $IsWildCard = $Escape % 2 -eq 0; $Escape = 0 } + Default { $Escape = 0 } + } + if ($IsWildCard) { return $Index } + + } +} \ No newline at end of file diff --git a/Internal/Init-SeDriver.ps1 b/Internal/Init-SeDriver.ps1 new file mode 100644 index 0000000..d1b15f4 --- /dev/null +++ b/Internal/Init-SeDriver.ps1 @@ -0,0 +1,23 @@ +function Init-SeDriver { + [CmdletBinding()] + param ($Element) + + IF ($null -NE $Element) { + $Driver = ($Element | Select-Object -First 1).WrappedDriver + } + $Driver = Get-SeDriver -Current -ErrorAction Stop + + if ($null -ne $Driver) { + return $Driver + } + else { + Throw [System.ArgumentNullException]::new("An available Driver could not be found.") + } + + + + + +} + + diff --git a/Internal/Start-SeChromeDriver.ps1 b/Internal/Start-SeChromeDriver.ps1 new file mode 100644 index 0000000..aeed245 --- /dev/null +++ b/Internal/Start-SeChromeDriver.ps1 @@ -0,0 +1,123 @@ +function Start-SeChromeDriver { + [cmdletbinding(DefaultParameterSetName = 'default')] + param( + [string]$StartURL, + [SeWindowState]$State, + [System.IO.FileInfo]$DefaultDownloadPath, + [switch]$PrivateBrowsing, + [Double]$ImplicitWait, + [System.Drawing.Size]$Size, + [System.Drawing.Point]$Position, + $WebDriverPath = $env:ChromeWebDriver, + $BinaryPath, + [OpenQA.Selenium.DriverService]$service, + [OpenQA.Selenium.DriverOptions]$Options, + [String[]]$Switches, + [OpenQA.Selenium.LogLevel]$LogLevel, + $UserAgent + + + + # [System.IO.FileInfo]$ProfilePath, + # $BinaryPath, + + # "user-data-dir=$ProfilePath" + + + + ) + + process { + #Additional Switches + $EnablePDFViewer = Get-OptionsSwitchValue -Switches $Switches -Name 'EnablePDFViewer' + $DisableAutomationExtension = Get-OptionsSwitchValue -Switches $Switches -Name 'DisableAutomationExtension' + + #region Process Additional Switches + if ($EnablePDFViewer) { $Options.AddUserProfilePreference('plugins', @{'always_open_pdf_externally' = $true; }) } + + if ($DisableAutomationExtension) { + $Options.AddAdditionalCapability('useAutomationExtension', $false) + $Options.AddExcludedArgument('enable-automation') + } + + #endregion + + if ($DefaultDownloadPath) { + Write-Verbose "Setting Default Download directory: $DefaultDownloadPath" + $Options.AddUserProfilePreference('download', @{'default_directory' = $($DefaultDownloadPath.FullName); 'prompt_for_download' = $false; }) + } + + if ($UserAgent) { + Write-Verbose "Setting User Agent: $UserAgent" + $Options.AddArgument("--user-agent=$UserAgent") + } + + if ($ProfilePath) { + Write-Verbose "Setting Profile directory: $ProfilePath" + $Options.AddArgument("user-data-dir=$ProfilePath") + } + + if ($BinaryPath) { + Write-Verbose "Setting Chrome Binary directory: $BinaryPath" + $Options.BinaryLocation = "$BinaryPath" + } + + if ($PSBoundParameters.ContainsKey('LogLevel')) { + Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)" + } + + + + switch ($State) { + { $_ -eq [SeWindowState]::Headless } { $Options.AddArguments('headless') } + # { $_ -eq [SeWindowState]::Minimized } {} # No switches... Managed after launch + { $_ -eq [SeWindowState]::Maximized } { $Options.AddArguments('start-maximized') } + { $_ -eq [SeWindowState]::Fullscreen } { $Options.AddArguments('start-fullscreen') } + } + + if ($PrivateBrowsing) { + $Options.AddArguments('Incognito') + } + # $Location = @('--window-position=1921,0', '--window-size=1919,1080') + if ($PSBoundParameters.ContainsKey('Size')) { + $Options.AddArguments("--window-size=$($Size.Width),$($Size.Height)") + } + if ($PSBoundParameters.ContainsKey('Position')) { + $Options.AddArguments("--window-position=$($Position.X),$($Position.Y)") + } + + + + if (-not $PSBoundParameters.ContainsKey('Service')) { + $ServiceParams = @{} + if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } + $service = New-SeDriverService -Browser Chrome @ServiceParams + } + + + + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $Options) + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID + #region post creation options + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) + + if ($State -eq '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 + + + return $Driver + } +} + diff --git a/Public/Start-SeNewEdge.ps1 b/Internal/Start-SeEdgeDriver.ps1 similarity index 52% rename from Public/Start-SeNewEdge.ps1 rename to Internal/Start-SeEdgeDriver.ps1 index 72f5bc8..3811ca9 100644 --- a/Public/Start-SeNewEdge.ps1 +++ b/Internal/Start-SeEdgeDriver.ps1 @@ -1,28 +1,21 @@ -function Start-SeNewEdge { - [cmdletbinding(DefaultParameterSetName = 'default')] - [Alias('CrEdge', 'NewEdge')] +function Start-SeEdgeDriver { param( [ValidateURIAttribute()] - [Parameter(Position = 0)] + [Parameter(Position = 1)] [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')] + [SeWindowState]$State, + [System.IO.FileInfo]$DefaultDownloadPath, [switch]$PrivateBrowsing, - [int]$ImplicitWait = 10, - $WebDriverDirectory = $env:EdgeWebDriver + [Double]$ImplicitWait, + [System.Drawing.Size]$Size, + [System.Drawing.Point]$Position, + $WebDriverPath, + $BinaryPath, + [OpenQA.Selenium.DriverService]$service, + [OpenQA.Selenium.DriverOptions]$Options, + [String[]]$Switches, + [OpenQA.Selenium.LogLevel]$LogLevel + ) $OptionSettings = @{ browserName = '' } #region check / set paths for browser and web driver and edge options @@ -30,43 +23,52 @@ function Start-SeNewEdge { throw "Could not find $BinaryPath"; return } + if ($PSBoundParameters.ContainsKey('LogLevel')) { + Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)" + } + #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 + if ($WebDriverPath -and -not (Test-Path -Path (Join-Path -Path $WebDriverPath -ChildPath 'msedgedriver.exe'))) { + throw "Could not find msedgedriver.exe in $WebDriverPath"; 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 ($WebDriverPath -and (Test-Path (Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'))) { + Write-Verbose -Message "Using browser from $WebDriverPath" + $optionsettings['BinaryLocation'] = Join-Path -Path $WebDriverPath -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 + if (-not $WebDriverPath -and $binaryDir -and (Test-Path (Join-Path -Path $binaryDir -ChildPath 'msedgedriver.exe'))) { + $WebDriverPath = $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\" + if (-not $WebDriverPath -and (Test-Path (Join-Path -Path "$PSScriptRoot\Assemblies\" -ChildPath 'msedgedriver.exe'))) { + $WebDriverPath = "$PSScriptRoot\Assemblies\" Write-Verbose -Message "Using Web driver from the default location" } - if (-not $WebDriverDirectory) { throw "Could not find msedgedriver.exe"; return } + if (-not $WebDriverPath) { 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') + + if (-not $PSBoundParameters.ContainsKey('Service')) { + $ServiceParams = @{} + if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } + $service = New-SeDriverService -Browser Edge @ServiceParams + } + $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 ($State -eq [SeWindowState]::Headless) { $options.AddArguments('headless') } + if ($ProfilePath) { + $ProfilePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ProfilePath) + Write-Verbose "Setting Profile directory: $ProfilePath" + $options.AddArgument("user-data-dir=$ProfilePath") } if ($DefaultDownloadPath) { $DefaultDownloadPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($DefaultDownloadPath) @@ -82,14 +84,13 @@ function Start-SeNewEdge { Write-Warning "Web driver was not created"; return } else { + Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID $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) " + @@ -99,23 +100,21 @@ function Start-SeNewEdge { } } - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($PSBoundParameters.ContainsKey('Size')) { $Driver.Manage().Window.Size = $Size } + if ($PSBoundParameters.ContainsKey('Position')) { $Driver.Manage().Window.Position = $Position } + + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } - if ($Minimized) { - $Driver.Manage().Window.Minimize(); - } - if ($Maximized) { - $Driver.Manage().Window.Maximize() - } - if ($FullScreen) { - $Driver.Manage().Window.FullScreen() + + switch ($State) { + { $_ -eq [SeWindowState]::Minimized } { $Driver.Manage().Window.Minimize(); } + { $_ -eq [SeWindowState]::Maximized } { $Driver.Manage().Window.Maximize() } + { $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() } } + + #endregion - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } + return $Driver } \ No newline at end of file diff --git a/Internal/Start-SeFirefoxDriver.ps1 b/Internal/Start-SeFirefoxDriver.ps1 new file mode 100644 index 0000000..f3ba92b --- /dev/null +++ b/Internal/Start-SeFirefoxDriver.ps1 @@ -0,0 +1,76 @@ +function Start-SeFirefoxDriver { + [cmdletbinding(DefaultParameterSetName = 'default')] + param( + [string]$StartURL, + [SeWindowState]$State, + [System.IO.FileInfo]$DefaultDownloadPath, + [switch]$PrivateBrowsing, + [Double]$ImplicitWait, + [System.Drawing.Size]$Size, + [System.Drawing.Point]$Position, + $WebDriverPath = $env:GeckoWebDriver, + $BinaryPath, + [OpenQA.Selenium.DriverService]$service, + [OpenQA.Selenium.DriverOptions]$Options, + [String[]]$Switches, + [OpenQA.Selenium.LogLevel]$LogLevel, + [String]$UserAgent + + ) + process { + #region firefox set-up options + $Firefox_Options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new() + + if ($State -eq [SeWindowState]::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 ($UserAgent) { + Write-Verbose "Setting User Agent: $UserAgent" + $Firefox_Options.SetPreference("general.useragent.override", $UserAgent) + } + + if ($PrivateBrowsing) { + $Firefox_Options.SetPreference("browser.privatebrowsing.autostart", $true) + } + + if ($PSBoundParameters.ContainsKey('LogLevel')) { + Write-Verbose "Setting Firefox LogLevel to $LogLevel" + $Options.LogLevel = $LogLevel + } + + if (-not $PSBoundParameters.ContainsKey('Service')) { + $ServiceParams = @{} + if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } + $service = New-SeDriverService -Browser Firefox @ServiceParams + } + + + $Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Firefox_Options) + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID + #region post creation options + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) + + if ($PSBoundParameters.ContainsKey('Size')) { $Driver.Manage().Window.Size = $Size } + if ($PSBoundParameters.ContainsKey('Position')) { $Driver.Manage().Window.Position = $Position } + + # [SeWindowState] + switch ($State) { + { $_ -eq [SeWindowState]::Minimized } { $Driver.Manage().Window.Minimize(); break } + { $_ -eq [SeWindowState]::Maximized } { $Driver.Manage().Window.Maximize() ; break } + { $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() ; break } + } + + if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } + #endregion + + Return $Driver + } +} diff --git a/Internal/Start-SeInternetExplorerDriver.ps1 b/Internal/Start-SeInternetExplorerDriver.ps1 new file mode 100644 index 0000000..3ea8fb4 --- /dev/null +++ b/Internal/Start-SeInternetExplorerDriver.ps1 @@ -0,0 +1,60 @@ +function Start-SeInternetExplorerDriver { + param( + [string]$StartURL, + [SeWindowState]$State, + [System.IO.FileInfo]$DefaultDownloadPath, + [switch]$PrivateBrowsing, + [Double]$ImplicitWait, + [System.Drawing.Size]$Size, + [System.Drawing.Point]$Position, + $WebDriverPath, + $BinaryPath, + [OpenQA.Selenium.DriverService]$service, + [OpenQA.Selenium.DriverOptions]$Options, + [String[]]$Switches, + [OpenQA.Selenium.LogLevel]$LogLevel + ) + + $IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings' + #region IE set-up options + if ($state -eq [SeWindowState]::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 (-not $PSBoundParameters.ContainsKey('Service')) { + $ServiceParams = @{} + if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } + $service = New-SeDriverService -Browser InternetExplorer @ServiceParams + } + + #endregion + + $Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $InternetExplorer_Options) + if (-not $Driver) { Write-Warning "Web driver was not created"; return } + Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID + if ($PSBoundParameters.ContainsKey('LogLevel')) { + Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)" + } + + #region post creation options + if ($PSBoundParameters.ContainsKey('Size')) { $Driver.Manage().Window.Size = $Size } + if ($PSBoundParameters.ContainsKey('Position')) { $Driver.Manage().Window.Position = $Position } + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) + + + switch ($State) { + { $_ -eq [SeWindowState]::Minimized } { $Driver.Manage().Window.Minimize(); } + { $_ -eq [SeWindowState]::Maximized } { $Driver.Manage().Window.Maximize() } + { $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() } + } + + #endregion + + return $Driver +} \ No newline at end of file diff --git a/Internal/Start-SeMSEdgeDriver.ps1 b/Internal/Start-SeMSEdgeDriver.ps1 new file mode 100644 index 0000000..f702f58 --- /dev/null +++ b/Internal/Start-SeMSEdgeDriver.ps1 @@ -0,0 +1,63 @@ +function Start-SeMSEdgeDriver { + param( + [ValidateURIAttribute()] + [Parameter(Position = 1)] + [string]$StartURL, + [SeWindowState]$State, + [System.IO.FileInfo]$DefaultDownloadPath, + [switch]$PrivateBrowsing, + [Double]$ImplicitWait, + [System.Drawing.Size]$Size, + [System.Drawing.Point]$Position, + $WebDriverPath, + $BinaryPath, + [OpenQA.Selenium.DriverService]$service, + [OpenQA.Selenium.DriverOptions]$Options, + [String[]]$Switches, + [OpenQA.Selenium.LogLevel]$LogLevel + ) + #region Edge set-up options + if ($state -eq [SeWindowState]::Headless) { Write-Warning 'Pre-Chromium Edge does not support headless operation; the Headless switch is ignored' } + + if (-not $PSBoundParameters.ContainsKey('Service')) { + $ServiceParams = @{} + #if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } + $service = New-SeDriverService -Browser MSEdge @ServiceParams + } + + $options = [OpenQA.Selenium.Edge.EdgeOptions]::new() + + if ($PrivateBrowsing) { $options.UseInPrivateBrowsing = $true } + if ($StartURL) { $options.StartPage = $StartURL } + #endregion + + if ($PSBoundParameters.ContainsKey('LogLevel')) { + Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)" + } + + 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 } + Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID + #region post creation options + if ($PSBoundParameters.ContainsKey('Size')) { $Driver.Manage().Window.Size = $Size } + if ($PSBoundParameters.ContainsKey('Position')) { $Driver.Manage().Window.Position = $Position } + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) + + switch ($State) { + { $_ -eq [SeWindowState]::Minimized } { $Driver.Manage().Window.Minimize() } + { $_ -eq [SeWindowState]::Maximized } { $Driver.Manage().Window.Maximize() } + { $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() } + } + + #endregion + + Return $Driver +} \ No newline at end of file diff --git a/Internal/Test-SeDriverConditionsValueValidation.ps1 b/Internal/Test-SeDriverConditionsValueValidation.ps1 new file mode 100644 index 0000000..716be5a --- /dev/null +++ b/Internal/Test-SeDriverConditionsValueValidation.ps1 @@ -0,0 +1,21 @@ +function Test-SeDriverConditionsValueValidation { + [CmdletBinding()] + param ( + $Condition, $Value + ) + + if ($PSBoundParameters.ContainsKey('Condition')) { + $ConditionValueType = $Script:SeDriverConditions.Where( { $_.Text -eq $Condition }, 'first')[0].ValueType + + if ($null -eq $ConditionValueType) { + Throw "The condition $Condition do not accept value" + } + elseif ($Value -isnot $ConditionValueType) { + Throw "The condition $Condition accept only value of type $ConditionValueType. The value provided was of type $($Value.GetType())" + } + else { + return + } + } + +} \ No newline at end of file diff --git a/Internal/Test-SeDriverUserAgent.ps1 b/Internal/Test-SeDriverUserAgent.ps1 new file mode 100644 index 0000000..faab23e --- /dev/null +++ b/Internal/Test-SeDriverUserAgent.ps1 @@ -0,0 +1,18 @@ +function Test-SeDriverUserAgent { + [CmdletBinding()] + param ( + $Browser, [ref]$UserAgent, + $Boundparameters + ) + + $SupportedBrowsers = @('Chrome', 'Firefox') + if ($Browser -in $SupportedBrowsers) { + return + } + else { + Throw ([System.NotImplementedException]::new(@" +UserAgent parameter is only supported by the following browser: $($SupportedBrowsers -join ',') +Selected browser: $Browser +"@)) + } +} \ No newline at end of file diff --git a/Internal/Test-SeElementConditionsValueValidation.ps1 b/Internal/Test-SeElementConditionsValueValidation.ps1 new file mode 100644 index 0000000..798d589 --- /dev/null +++ b/Internal/Test-SeElementConditionsValueValidation.ps1 @@ -0,0 +1,41 @@ +function Test-SeElementConditionsValueValidation { + Param( + $Element, + $By, + $Condition, + $ConditionValue, + $ParameterSetName + ) + # 0: All; + # 1: By + # 2: Element + + $ConditionDetails = $Script:SeElementsConditions.Where( { $_.Text -eq $Condition }, 'first')[0] + + switch ($ParameterSetName) { + 'Locator' { + if ($ConditionDetails.By_Element -eq 2) { + Throw "The condition $Condition can only be used with an element (`$Element)" + } + } + 'Element' { + if ($ConditionDetails.By_Element -eq 1) { + Throw "The condition $Condition can only be used with a locator (`$By & `$Value)" + } + } + } + + + + if ($null -ne $ConditionValue) { + if ($null -eq $ConditionDetails.ValueType) { + Throw "The condition $Condition do not accept value" + } + elseif ($ConditionValue -isnot $ConditionDetails.ValueType) { + Throw "The condition $Condition accept only value of type $($ConditionDetails.ValueType). The value provided was of type $($ConditionValue.GetType())" + } + else { + return + } + } +} \ No newline at end of file diff --git a/Internal/Test-SeMouseActionValueValidation.ps1 b/Internal/Test-SeMouseActionValueValidation.ps1 new file mode 100644 index 0000000..501b7a4 --- /dev/null +++ b/Internal/Test-SeMouseActionValueValidation.ps1 @@ -0,0 +1,20 @@ +function Test-SeMouseActionValueValidation { + [CmdletBinding()] + Param( + $Action, + $ConditionValue + ) + + $ConditionValueType = $Script:SeMouseAction.Where( { $_.Text -eq $Action }, 'first')[0].ValueType + if ($null -eq $ConditionValueType) { + Throw "The condition $Condition do not accept value" + } + elseif ($ConditionValue -isnot $ConditionValueType) { + if ($ConditionValueType.FullName -eq 'System.Drawing.Point' -and $ConditionValue -is [String] -and ($ConditionValue -split '[,x]').Count -eq 2) { return $True } + Throw "The condition $Condition accept only value of type $ConditionValueType. The value provided was of type $($ConditionValue.GetType())" + } + else { + return $true + } + +} \ No newline at end of file diff --git a/Internal/ValidateURL.ps1 b/Internal/ValidateURL.ps1 deleted file mode 100644 index cd334ed..0000000 --- a/Internal/ValidateURL.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -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 index f3b33d1..c731370 100644 --- a/Internal/init.ps1 +++ b/Internal/init.ps1 @@ -1,5 +1,32 @@ using namespace System.Collections.Generic + +if (!$PSCommandPath.EndsWith('init.ps1')) { + $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { + Get-SeDriver | Stop-SeDriver + } + +} + + +Function New-Condition { + Param([Parameter(Mandatory = $true)]$Text, [Type]$ValueType, $Tooltip, [Switch]$OptionalValue, $ElementRequired = $true ) + return [PSCustomObject]@{ + Text = $Text + ValueType = $ValueType + Tooltip = $Tooltip + ElementRequired = $ElementRequired + } +} + +$Script:SeMouseAction = @( + New-Condition -Text 'DragAndDrop' -ValueType ([OpenQA.Selenium.IWebElement]) -Tooltip 'Performs a drag-and-drop operation from one element to another.' + New-Condition -Text 'DragAndDropToOffset' -ValueType ([System.Drawing.Point]) -Tooltip 'Performs a drag-and-drop operation on one element to a specified offset.' + New-Condition -Text 'MoveByOffset' -ValueType ([System.Drawing.Point]) -ElementRequired $null -Tooltip 'Moves the mouse to the specified offset of the last known mouse coordinates.' + New-Condition -Text 'MoveToElement' -ValueType ([System.Drawing.Point]) -OptionalValue -Tooltip 'Moves the mouse to the specified element with offset of the top-left corner of the specified element.' + New-Condition -Text 'Release' -ValueType $null -Tooltip 'Releases the mouse button at the last known mouse coordinates or specified element.' +) + $Script:SeKeys = [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } @@ -27,170 +54,51 @@ if ($AssembliesPath) { } } -#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' } +$Script:SeDriversAdditionalBrowserSwitches = @{ + Chrome = @('DisableAutomationExtension', 'EnablePDFViewer') + Edge = @() + Firefox = @('SuppressLogging') + InternetExplorer = @('IgnoreProtectedModeSettings') + MsEdge = @() } -#> - - -<# -function Enter-SeUrl { - param($Driver, $Url) - $Driver.Navigate().GoToUrl($Url) +# List of suggested command line arguments for each browser +$Script:SeDriversBrowserArguments = @{ + Chrome = @("--user-agent=Android") + Edge = @() + Firefox = @() + InternetExplorer = @() + MsEdge = @() } -#> - - - -<# -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) - } +$Script:SeDrivers = [System.Collections.Generic.List[PSObject]]::new() +$Script:SeDriversCurrent = $null - if ($PSCmdlet.ParameterSetName -eq "ByClassName") { - $TargetElement = [OpenQA.Selenium.By]::ClassName($ClassName) - } - if ($PSCmdlet.ParameterSetName -eq "ByTagName") { - $TargetElement = [OpenQA.Selenium.By]::TagName($TagName) - } +$AdditionalOptionsSwitchesCompletion = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + + if ($fakeBoundParameters.ContainsKey('Browser')) { + $Browser = $fakeBoundParameters.Item('Browser') + + $Output = $Script:SeDriversAdditionalBrowserSwitches."$Browser" + $Output | % { [System.Management.Automation.CompletionResult]::new($_) } + + + } +} - if ($PSCmdlet.ParameterSetName -eq "ByXPath") { - $TargetElement = [OpenQA.Selenium.By]::XPath($XPath) - } - if ($PSCmdlet.ParameterSetName -eq "ByCss") { - $TargetElement = [OpenQA.Selenium.By]::CssSelector($Css) - } +$SeDriversBrowserArgumentsCompletion = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) - $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)) - } - } + if ($fakeBoundParameters.ContainsKey('Browser')) { + $Browser = $fakeBoundParameters.Item('Browser') + $Output = $Script:SeDriversBrowserArguments."$Browser" | Where { $_ -like "*$wordToComplete*" } + $ptext = [System.Management.Automation.CompletionResultType]::ParameterValue + $Output | % { [System.Management.Automation.CompletionResult]::new("'$_'", $_, $ptext, $_) } } } -#> + +Register-ArgumentCompleter -CommandName Start-SeDriver, New-SeDriverOptions -ParameterName Switches -ScriptBlock $AdditionalOptionsSwitchesCompletion +Register-ArgumentCompleter -CommandName Start-SeDriver, New-SeDriverOptions -ParameterName Arguments -ScriptBlock $SeDriversBrowserArgumentsCompletion diff --git a/Output/Selenium/ChangeLog.md b/Output/Selenium/ChangeLog.md index 10d0fdb..fbe293d 100644 --- a/Output/Selenium/ChangeLog.md +++ b/Output/Selenium/ChangeLog.md @@ -1,7 +1,65 @@ -# 3.1.0 - Unreleased +#4.0.0 (Unreleased) + + +# 4.0.0-preview1 (Prerelease) +Note: V4 have an enormous amount of breakchanges. Most of the cmdlet have been rewriten in a way or another. + +Duplicate functions have been eliminated along with all aliases that piled up over time. Start-SeDriver provide an unified front to start all the browsers and the $Driver parameter / default driver are no more. Instead, starting a driver make it the active driver. Switching active driver can be accomplished through the Switch-SeDriver cmdlet. ## Added +- Convert-toSeSelenium to convert IDE projects to Selenium-Powershell script +- Update-SeDriver to download the latest driver (Support only Chrome currently) +- Support for UserAgent in Start-SeDriver (#91) +- New view for IwebDriver (#111). IWebDriver will now display as a table in the console by default instead of a list. +- Get-SeElement - New view. Elements will now be returned in a table view to show the essential only. This make it significantly easier to deal with elements in the console interactively (#115) +- Get-SeElement - Bychained support. The cmdlet will now drilldown when multiple by / value are provided to allow for instance the selection of links in a div containing a specific classname. This is an alternative for those less savy with Xpath (#116) +- Get-SeHtml - Allow the retrieval of the html of an element (or driver is no element is provided). Essentially a wrapper around $Element.GetAttribute('xxHTML') (xx: Inner /Outer) (#118) +- New-SeDriverService - Allow the creation of a driver service to be used later on with Start-SeDriver. Only useful if you need to do change to the service parameters native object before starting the driver (#119) +- Invoke-SeMouseAction - Support for interactions (#122) +- Wait-SeDriver / Wait-SeElement expliciti wait support (#125) +- Get-SeElement -Attributes. Allow getting specific attributes (or all using *) to the elements to be returned. Attributes will be available in an Attributes string dictionary attached to each elements. (#133) +- Position / Size parameter for Start-SeDriver. Allow starting the driver at a specified position and size. If no command line available (or not implemented), the driver will start with the default settings and the be moved. (#134) +- Get-SeElement -Single switch added. Define the expectaction that only one element should be returned (#144) +- Get/Set-SeDriverTimeout - Allow changing driver timeouts easily (#150) +- Invoke-SeJavascript - A wrapper around $Driver.ExecuteScript (#151) +- Get-SeFrame, wrapper around Get-SeElement to show iframe along with their name / id in a convenient view (#159) +- New-SeWindow / Remove-SeWindow cmdlet added to complement the existing Get/Switch (#170) +- Get-SeInput (#178) - A wrapper around Get-SeElement to get input element. + + +## Changed +- AsDefaultDriver implementation changed. Instead, Start-SeDriver automatically make the started driver the default. (#93) +- Driver parameter was removed on most cmdleet. It is now expected to use the Switch-SeDriver cmdlet to change the active driver if multiple are open. +- Start-SeChrome and other have been removed in favor of Start-SeDriver -Browser Chrome (#100) +- #98 Removed duplicate functions that performed the same thing or overlapped significantly +- Removed all the aliases everywhere on all the parameter / functions in favor of a more rigid way of writing things (#99) +- Standardize parameters. Some parameters had different names to mean the same thing (#100) +- Revamp Get-SeSelectionOption. The cmdlet have been separated in 3 cmdlet Get/Clear/Set -SeSelectValue. The get cmdlet will also now return the Text & Value of the selected element instead of the text only. (#112) +- Set-SeUrl now have a -Depth parameter to navigate forward or back x times (#124) +- Get-SeElement now returns visible elements by default. To view hidden elements, the All switch parameter need to be used (#126) +- Start-SeDriver -Quiet parameter removal. Quiet is now the default. This remove the extra Selenium verbose and resolves an issue with Driver not being usable in jobs. (#127) +- Get-SeElement now write an error if no element are returned. (#135) +- cmdlet that expect urls will now accept urls without protocol defined. Assumptions in these cases is that the url is https thus google.ca will be treated as https://www.google.ca (#153) +- Get-SeElementAttribute - Accept multiple values and wildcard to load all attributes (#161) +- Get-SeElement - support for multiple classname (#160) +- Get-SeElementCssValue - support for multiple values / wildcard character (#162) +- Sleep / Timeout parameters type changed from int to double (Still seconds, but provide more granularity) +- Invoke-SeScreenshot - support for Element screenshot. You can now easily produce a screenshot of a specific element instead of the whole page. (#168) + + + +## Bugfixes +- Get-SeElement no longer support splatting (#82) +- Getck driver abysmal performance (#113). Gecko service need to be configured to use localhost ::1. Otherwise, it take significantly more time to do everything with it (#113) +- Get-SeElement with Timeout return only the first element instead of the collection (#139) +- Implcit-Wait - Default reduced to 0.3 seconds instead of 10 seconds. One of the problem of implicit wait is that some operation will wait 100% of the defined implicit wait before performing an action. (#146) +- Implicit / Explicit wait management. Some cmdlet (old an new) uses explicit wait. Explicit wait and Implicit wait should not be mixed together. Therefore, when an explicit wait is used, implicit wait (if present) get temporary disabled(#149) + + +# 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) diff --git a/Output/Selenium/Examples/A-Simple-Google-Search.ps1 b/Output/Selenium/Examples/A-Simple-Google-Search.ps1 index 4f89044..4c94db1 100644 --- a/Output/Selenium/Examples/A-Simple-Google-Search.ps1 +++ b/Output/Selenium/Examples/A-Simple-Google-Search.ps1 @@ -1,70 +1,55 @@ -<# -.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} +Import-Module -Name Selenium # Start the Selenium Chrome Driver -$Driver = Start-SeChrome +Start-SeDriver -Browser Chrome -StartURL 'google.com/ncr' -# 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. +#Getting the Search box - <# This is the HTML code of the search box +<# This is the HTML code of the search box, found using the browser developer tools - #> +#> - # 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 +#Here's a few different ways, all valid, to access that searchbox - # We can also use the class name gLFyf to find the google search box. - $SearchBoxElement = Find-SeElement -Driver $Driver -ClassName 'gLFyf' +# 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 +#The Single parameter will write an error if there's not 1 element. +$Searchbox = Get-SeElement -By Name -value q -Single - # This line will get us all elements with the input TagName also known as - $AllInputElements = Find-SeElement -Driver $Driver -TagName input +# We can also use the class name gLFyf to find the google search box. +$Searchbox = Get-SeElement -ClassName 'gLFyf' - # 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 $_}} +# This line will get us all elements with the input TagName also known as +#The -All parameter (optional) also includes hidden elements. +# The -Attributes parameter will load the specified attribute in the result and make them available through an Attributes property +$AllInputElement = Get-SeElement -By TagName -Value input -All -Attributes title +$AllInputElement | select Attributes +# 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. +$Searchbox = $AllInputElement.Where( { $_.Attributes.title -eq 'Search' }, 'first')[0] - # 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 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' +# Now that we can see all the keys we can send send some keys to the SearchBoxElement +Invoke-SeKeys -Element $Searchbox -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) +# 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 +# To view special keys, use Get-SeKeys +Invoke-SeKeys -Element $Searchbox -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. +# 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' +# 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. +#Note, the value parameter is provided positionally. +$LogoImageElement = Get-SeElement -Timeout 10 -By 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 have the image element we can simulate a mouse click on it using the Invoke-SeClick command. +Invoke-SeClick -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 +# 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 \ No newline at end of file diff --git a/Output/Selenium/Examples/Combined.tests.ps1 b/Output/Selenium/Examples/Combined.tests.ps1 index f88937a..a3abd51 100644 --- a/Output/Selenium/Examples/Combined.tests.ps1 +++ b/Output/Selenium/Examples/Combined.tests.ps1 @@ -1,101 +1,58 @@ -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 +. "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + +$Global:TestCaseSettings = Get-TestCasesSettings +$Global:BrowserOptHash = $Global:TestCaseSettings."$Global:DefaultBrowser".DefaultOptions +$Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash +$Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" Describe "Testing the tailspin toys demo site at $env:SITE_URL" { BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + + $Global:TestCaseSettings = Get-TestCasesSettings + $Global:BrowserOptHash = $Global:TestCaseSettings."$Global:DefaultBrowser".DefaultOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash #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 + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $env:SITE_URL @Global:BrowserOptHash -Verbose 4>&1 -ErrorAction Stop } catch { throw $_ } + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } - Context "in $BrowserID with settings ($BrowserOptText)" { - It "produced the right modal dialog for the " -TestCases $ModaltestCases { + Context "in $($Env:BrowserID) with settings ($Env:BrowserOptText)" { + It "produced the right modal dialog for the " -TestCases (Get-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 $modalXPath -With displayed eq $false -Timeout 10 + SeElement $linkXPath | Invoke-SeClick -Action Click_JS -Sleep 1 + SeElement $modalXPath | SeElement -By ClassName 'close' | Invoke-SeClick -Action Click_JS -Sleep 1 SeShouldHave 'body' -By TagName SeShouldHave $modalXPath -With displayed eq $false } } # Additional tests would be here - AfterAll { SeClose } + AfterAll { Stop-SeDriver } } #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)" { + BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + $PSGalleryPage = 'https://www.powershellgallery.com/' + $Global:TestCaseSettings = Get-TestCasesSettings + $Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].DefaultOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $PSGalleryPage @Global:BrowserOptHash -Verbose 4>&1 -ErrorAction Stop }catch {} + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } + Context "in $Env:BrowserID with settings ($Env: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] + Get-SeDriver -Current | Should -Not -BeNullOrEmpty + Get-SeDriver -Current | 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 @@ -120,15 +77,15 @@ Describe "PsGallery Test" { 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 + Get-SeElement -By TagName -Value 'input' | + Invoke-SeKeys -ClearFirst -Keys "selenium{{Enter}}" -PassThru -Sleep 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 ' { + $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 -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 + SeShouldHave $linkpath -With Text like *selenium* -PassThru | Invoke-SeClick -Action Click_JS -Sleep 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 ... @@ -140,80 +97,91 @@ Describe "PsGallery Test" { #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 + Invoke-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 + Set-SeUrl -Back + Set-SeUrl -Back + Set-SeUrl -Back SeShouldHave -URL eq $PSGalleryPage -Timeout 30 - SeClose - $Global:SeDriver | Should -BeNullOrEmpty + Stop-SeDriver + Get-SeDriver -Current | Should -BeNullOrEmpty } } + AfterAll { Stop-SeDriver } } -$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 + BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + $AlertTestPage = 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert' + $SelectTestPage = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select' + $Global:TestCaseSettings = Get-TestCasesSettings + $Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].PrivateOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash + + if ($Env:BrowserOptText) { + $Global:NoLabel = [string]::IsNullOrEmpty($Global:TestCaseSettings[$Global:DefaultBrowser].InPrivateLabel) + $wv = $null + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $alertTestPage @BrowserOptHash -WarningVariable wv -ErrorAction Stop }catch {} + if ($wv) { Write-Output "##vso[task.logissue type=warning]$wv" } + } + else { + $Global:NoLabel = $true + try { Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $alertTestPage -ErrorAction Stop } catch {} + + } + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } + Context "in $Env:BrowserID with settings ($Env: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 $Global:TestCaseSettings[$Global:DefaultBrowser].InPrivateLabel + # } -Skip:$Global:NoLabel It 'opened the right page ' { SeShouldHave -URL -eq $alertTestPage } - It 'found and clicked a button in frame 1 ' { + It 'Navigated to the child iframe' { #'triggered and dismissed an alert' 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 ' { + Switch-SeFrame 'iframeResult' + Get-SeElement "/html/body/button" | Should -Not -BeNullOrEmpty #Removed | Invoke-SeClick -PassThru #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 + #{ Wait-SeDriver -Condition AlertState -Value $false -Timeout 15 -ErrorAction Stop } | Should -Not -throw + #Clear-SeAlert -Alert $Alert -Action Dismiss -PassThru | Should -Not -BeNullOrEmpty } It 'reselected the parent frame ' { - SeFrame -Parent + Switch-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 + Set-SeUrl $SelectTestPage SeShouldHave -Selection "iframe" -By TagName -with id eq iframeResult - SeFrame 'iframeResult' - SeShouldHave -By Name "cars" -With choice contains "volvo" + Switch-SeFrame 'iframeResult' + $e = SeElement -by Name "cars" + $e | Should -Not -BeNullOrEmpty + (Get-SeSelectValue -Element $e -All).Items.Text | Should -Contain '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" + { $e | Set-SeSelectValue -By Value -value "Audi" } | Should -Throw + { $e | Set-SeSelectValue -By Value -value "audi" } | Should -not -throw + $e | Set-SeSelectValue -By Index -value "2"; (Get-SeSelectValue -Element $e).Text | Should -Be 'Fiat' + $e | Set-SeSelectValue -By Text -value "Sa*" } It 'submitted the form and got the expected response ' { - SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 - SeFrame -Parent - SeFrame 'iframeResult' + Get-SeElement '/html/body/form/input' | Invoke-SeClick -Sleep 5 + Switch-SeFrame -Parent + Switch-SeFrame 'iframeResult' SeShouldHave "/html/body/div[1]" -with text match "cars=saab" } It 'closed the in-private browser instance ' { - SeClose + Stop-SeDriver if ($DriverProcess.Id) { (Get-Process -id $DriverProcess.id ).HasExited | Should -Be $true } @@ -222,40 +190,65 @@ Describe "Alerts and Selection boxes tests" { } } } + AfterAll { Stop-SeDriver } } -$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 ' { + +$Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].HeadlessOptions +$Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash +$Global:SkipTests = [String]::IsNullOrEmpty($Env:BrowserOptText) + +Describe "'Headless' mode browser test" { + BeforeAll { + . "$(Join-Path -Path $PSScriptRoot -ChildPath '_TestDependencies.ps1' )" + $Global:TestCaseSettings = Get-TestCasesSettings + + $Global:BrowserOptHash = $Global:TestCaseSettings[$Global:DefaultBrowser].HeadlessOptions + $Env:BrowserOptText = Build-StringFromHash $Global:BrowserOptHash + $Global:SkipTests = $true + if (![String]::IsNullOrEmpty($Env:BrowserOptText)) { + $Global:SkipTests = $false + try { $Env:BrowserID = Start-SeDriver -Browser $Global:DefaultBrowser -StartURL $env:SITE_URL @BrowserOptHash -ErrorAction Stop }catch {} + } + $Env:BrowserID = "$Global:DefaultBrowser on $([System.Environment]::OSVersion.Platform)" + } + Context "in $Env:BrowserID with settings ($Env:BrowserOptText)" { + It 're-opened the Browser in "Headless" mode' { + if ($PSVersionTable.PSVersion.Major -eq 5) { + $Processes = Get-CimInstance -Class Win32_Process + $DriverProcess = $Processes | Where { $_.Name -like '*driver.exe' -and $_.ParentProcessId -eq $Pid } + $BrowserProcess = $Processes | Where-Object { $_.ParentProcessId -eq $DriverProcess.ProcessId -and $_.Name -ne 'conhost.exe' } + if ($BrowserProcess -ne $null) { + (Get-process -Id $BrowserProcess.ProcessId).MainWindowHandle | Should -be 0 + } + } + else { $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 + $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 + } + it 'did a google Search ' { + Set-SeUrl 'https://www.google.com/ncr' + SeShouldHave -by Name q + SeShouldHave -by ClassName 'gLFyf' + SeShouldHave -By Name q -PassThru | Where Displayed -eq $true | + Select-Object -First 1 | Invoke-SeKeys -Keys 'Powershell-Selenium{{Enter}}' -PassThru | + should -Not -BeNullOrEmpty - SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | - SeClick -PassThru | should -Not -BeNullOrEmpty + SeShouldHave '//*[@id="tsf"]/div[2]/div[1]/div[1]/a' -PassThru | + Invoke-SeClick -PassThru | should -Not -BeNullOrEmpty + } + It 'closed the browser a third time ' { + Stop-SeDriver + Get-SeDriver -Current | Should -BeNullOrEmpty + if ($DriverProcess.Id) { + (Get-Process -id $DriverProcess.id ).HasExited | Should -Be $true } - 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 - } + if ($BrowserProcess.Id) { + (Get-Process -id $BrowserProcess.id).HasExited | Should -Be $true } } - } + } -Skip:$Global:SkipTests + AfterAll { Stop-SeDriver } } \ No newline at end of file diff --git a/Output/Selenium/Examples/DemoSelenium.tests.ps1 b/Output/Selenium/Examples/DemoSelenium.tests.ps1 deleted file mode 100644 index 2d94e51..0000000 --- a/Output/Selenium/Examples/DemoSelenium.tests.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -<# -.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 deleted file mode 100644 index 3f7abfb..0000000 --- a/Output/Selenium/Examples/DemoSelenium2.tests.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -<# -.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/Example.side b/Output/Selenium/Examples/Example.side new file mode 100644 index 0000000..a11d238 --- /dev/null +++ b/Output/Selenium/Examples/Example.side @@ -0,0 +1,295 @@ +{ + "id": "1a83cd76-e78d-4402-b40e-5805b2403f44", + "version": "2.0", + "name": "Example", + "url": "https://automationintesting.com", + "tests": [{ + "id": "0896d7a2-81f1-4972-bbc3-4880718bc157", + "name": "Test1", + "commands": [{ + "id": "4770f8f0-e2c5-434e-847c-b79ecadebf41", + "comment": "", + "command": "open", + "target": "/selenium/testpage/", + "targets": [], + "value": "" + }, { + "id": "8068ba5f-597f-4d50-834d-b057c2cfb2ea", + "comment": "", + "command": "setWindowSize", + "target": "1936x1056", + "targets": [], + "value": "" + }, { + "id": "90423ff3-98f2-4de8-9998-32088c188647", + "comment": "", + "command": "click", + "target": "id=firstname", + "targets": [ + ["id=firstname", "id"], + ["css=#firstname", "css:finder"], + ["xpath=//input[@id='firstname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div/div/label/input", "xpath:idRelative"], + ["xpath=//input", "xpath:position"] + ], + "value": "" + }, { + "id": "fa88b63a-f245-4374-8db2-284f239c3ee0", + "comment": "", + "command": "type", + "target": "id=firstname", + "targets": [ + ["id=firstname", "id"], + ["css=#firstname", "css:finder"], + ["xpath=//input[@id='firstname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div/div/label/input", "xpath:idRelative"], + ["xpath=//input", "xpath:position"] + ], + "value": "test" + }, { + "id": "2626b60b-2f5b-473d-b342-4f5ec36501b5", + "comment": "", + "command": "click", + "target": "xpath=//form[@id='contactus']/div[2]/div/label/input", + "targets": [ + ["id=surname", "id"], + ["css=#surname", "css:finder"], + ["xpath=//input[@id='surname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[2]/div/label/input", "xpath:idRelative"], + ["xpath=//div[2]/div/label/input", "xpath:position"] + ], + "value": "" + }, { + "id": "65b0a638-0f79-4a43-ac8a-db482d18c3cd", + "comment": "", + "command": "type", + "target": "xpath=//form[@id='contactus']/div[2]/div/label/input", + "targets": [ + ["id=surname", "id"], + ["css=#surname", "css:finder"], + ["xpath=//input[@id='surname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[2]/div/label/input", "xpath:idRelative"], + ["xpath=//div[2]/div/label/input", "xpath:position"] + ], + "value": "test2" + }, { + "id": "e9047045-ede4-4c13-81b5-f8c036cb527c", + "comment": "", + "command": "click", + "target": "id=gender", + "targets": [ + ["id=gender", "id"], + ["css=#gender", "css:finder"], + ["xpath=//select[@id='gender']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[3]/div/label/select", "xpath:idRelative"], + ["xpath=//select", "xpath:position"] + ], + "value": "" + }, { + "id": "f9341c3c-215b-44c1-9fff-fa977a7ba599", + "comment": "", + "command": "select", + "target": "id=gender", + "targets": [], + "value": "label=Male" + }, { + "id": "39458fd5-e6ac-46c7-9e48-b24349314ef0", + "comment": "", + "command": "click", + "target": "id=red", + "targets": [ + ["id=red", "id"], + ["name=colour", "name"], + ["css=#red", "css:finder"], + ["xpath=//input[@id='red']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[4]/div/input", "xpath:idRelative"], + ["xpath=//div/input", "xpath:position"] + ], + "value": "" + }, { + "id": "a1ded097-b395-4bed-b641-7c2ab136d411", + "comment": "", + "command": "click", + "target": "css=textarea", + "targets": [ + ["css=textarea", "css:finder"], + ["xpath=//form[@id='contactus']/div[5]/div/label/textarea", "xpath:idRelative"], + ["xpath=//textarea", "xpath:position"] + ], + "value": "" + }, { + "id": "582f0b4e-2521-404e-a912-39261d867d11", + "comment": "", + "command": "type", + "target": "css=textarea", + "targets": [ + ["css=textarea", "css:finder"], + ["xpath=//form[@id='contactus']/div[5]/div/label/textarea", "xpath:idRelative"], + ["xpath=//textarea", "xpath:position"] + ], + "value": "text" + }, { + "id": "764ae979-42dd-457e-95c5-5dddad91e44d", + "comment": "", + "command": "addSelection", + "target": "id=continent", + "targets": [ + ["id=continent", "id"], + ["css=#continent", "css:finder"], + ["xpath=//select[@id='continent']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[6]/div/label/select", "xpath:idRelative"], + ["xpath=//div[6]/div/label/select", "xpath:position"] + ], + "value": "label=North America" + }, { + "id": "bb929f6f-ee4c-43ad-920b-0806aba3c37d", + "comment": "", + "command": "click", + "target": "id=checkbox1", + "targets": [ + ["id=checkbox1", "id"], + ["css=#checkbox1", "css:finder"], + ["xpath=//input[@id='checkbox1']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[4]/div[2]/input", "xpath:idRelative"], + ["xpath=//div[2]/input", "xpath:position"] + ], + "value": "" + }, { + "id": "542d6958-faab-40e9-9b4b-81f051673c23", + "comment": "", + "command": "click", + "target": "id=submitbutton", + "targets": [ + ["id=submitbutton", "id"], + ["css=#submitbutton", "css:finder"], + ["xpath=//button[@id='submitbutton']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div[7]/div/button", "xpath:idRelative"], + ["xpath=//div/button", "xpath:position"], + ["xpath=//button[contains(.,'I do nothing!')]", "xpath:innerText"] + ], + "value": "" + }] + }, { + "id": "c0d8e914-0e45-4d59-be13-b902e026cb6c", + "name": "Test2", + "commands": [{ + "id": "319fa3e0-f697-4963-a879-b358fff62a77", + "comment": "", + "command": "open", + "target": "/selenium/testpage/", + "targets": [], + "value": "" + }, { + "id": "27aa1c23-21c7-45dc-8887-fe3d0e8f592b", + "comment": "", + "command": "setWindowSize", + "target": "1936x1056", + "targets": [], + "value": "" + }, { + "id": "421ace3d-1377-4423-9257-bfc703103beb", + "comment": "", + "command": "sendKeys", + "target": "id=firstname", + "targets": [], + "value": "test3" + }, { + "id": "301e2ba3-8f11-42cd-a41e-8241e158e962", + "comment": "", + "command": "sendKeys", + "target": "id=firstname", + "targets": [ + ["id=firstname", "id"], + ["css=#firstname", "css:finder"], + ["xpath=//input[@id='firstname']", "xpath:attributes"], + ["xpath=//form[@id='contactus']/div/div/label/input", "xpath:idRelative"], + ["xpath=//input", "xpath:position"] + ], + "value": "${KEY_ENTER}" + }] + }, { + "id": "8b6ff854-fefb-40bc-bd48-d206878b9e64", + "name": "Test3", + "commands": [{ + "id": "a3b6e82e-a847-4ac5-ac72-a05c5150d107", + "comment": "", + "command": "open", + "target": "http://www.tagindex.net/html/frame/example_f01.html", + "targets": [], + "value": "" + }, { + "id": "785d2ca1-c20b-4b96-a03e-43119ad2ecef", + "comment": "", + "command": "setWindowSize", + "target": "1936x1056", + "targets": [], + "value": "" + }, { + "id": "150bc283-671d-4d77-b1a5-b5dd20c2eee3", + "comment": "", + "command": "selectFrame", + "target": "index=0", + "targets": [ + ["index=0"] + ], + "value": "" + }, { + "id": "50809502-afdf-4b1b-943b-40524bbd2420", + "comment": "", + "command": "click", + "target": "css=html", + "targets": [ + ["css=html", "css:finder"], + ["xpath=//html", "xpath:position"] + ], + "value": "" + }, { + "id": "e726cc31-c25f-4cf7-92fe-77d976bb2f91", + "comment": "", + "command": "selectFrame", + "target": "relative=parent", + "targets": [ + ["relative=parent"] + ], + "value": "" + }, { + "id": "71ab81f7-8c7d-413e-a7ed-f68c224b1373", + "comment": "", + "command": "selectFrame", + "target": "index=1", + "targets": [ + ["index=1"] + ], + "value": "" + }, { + "id": "6e01154b-2221-4eef-98db-5760b52063e0", + "comment": "", + "command": "doubleClick", + "target": "css=p", + "targets": [ + ["css=p", "css:finder"], + ["xpath=//div[@id='MainBox']/p", "xpath:idRelative"], + ["xpath=//p", "xpath:position"], + ["xpath=//p[contains(.,'Please return to the previous page using the browsers \"back\" button.')]", "xpath:innerText"] + ], + "value": "" + }, { + "id": "a9f64bfd-1962-4f32-aa85-85d1ae4af91a", + "comment": "", + "command": "close", + "target": "", + "targets": [], + "value": "" + }] + }], + "suites": [{ + "id": "3fb340b3-1af6-4948-ad2a-c689126d9dad", + "name": "Default Suite", + "persistSession": false, + "parallel": false, + "timeout": 300, + "tests": ["0896d7a2-81f1-4972-bbc3-4880718bc157"] + }], + "urls": ["https://automationintesting.com/"], + "plugins": [] +} \ No newline at end of file diff --git a/Output/Selenium/Examples/TestPSGallery.ps1 b/Output/Selenium/Examples/TestPSGallery.ps1 deleted file mode 100644 index 19a5c6d..0000000 --- a/Output/Selenium/Examples/TestPSGallery.ps1 +++ /dev/null @@ -1,23 +0,0 @@ - -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/_TestDependencies.ps1 b/Output/Selenium/Examples/_TestDependencies.ps1 new file mode 100644 index 0000000..6425032 --- /dev/null +++ b/Output/Selenium/Examples/_TestDependencies.ps1 @@ -0,0 +1,70 @@ + +Function Get-DefaultParams() { + if ($null -eq $Global:DefaultBrowser) { $Global:DefaultBrowser = 'Firefox' } + if ($null -eq $env:SITE_URL) { $env:SITE_URL = 'http://tailspin-spacegame-web.azurewebsites.net' } + if ($null -eq $Global:HeadlessOnly) { $Global:HeadlessOnly = $False } +} +Get-DefaultParams + + +Function Get-TestCasesSettings() { + $HeadlessState = if ($Global:HeadlessOnly) { 'Headless' } else { 'Maximized' } + return @{ + 'NewEdge' = @{ + DefaultOptions = @{State = $HeadlessState } + PrivateOptions = @{ + PrivateBrowsing = $true + State = $HeadlessState + } + # InPrivateLabel = 'InPrivate' + } # broken after build 79 of web driver#> + 'Chrome' = @{ + PrivateOptions = @{ + PrivateBrowsing = $true + State = $HeadlessState + } + DefaultOptions = @{State = $HeadlessState } + HeadlessOptions = @{State = 'Headless' } + } + 'Firefox' = @{ + PrivateOptions = @{ + PrivateBrowsing = $true + State = $HeadlessState + } + DefaultOptions = @{State = $HeadlessState } + HeadlessOptions = @{State = 'Headless' } + } + 'MSEdge' = @{ + DefaultOptions = @{State = $HeadlessState } + PrivateOptions = @{PrivateBrowsing = $true } + } + 'InternetExplorer' = @{ + DefaultOptions = @{ImplicitWait = 30 } + PrivateOptions = @{ImplicitWait = 30 } + } + } +} + +function Build-StringFromHash { + param ($Hash) + $(foreach ($k in $Hash.Keys) { "$K`:$($hash[$K])" }) -join '; ' +} + + + +function Get-ModalTestCases() { + return @( + @{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' + } + ) +} diff --git a/Output/Selenium/Examples/comparison.ps1 b/Output/Selenium/Examples/comparison.ps1 index 07c7084..0e9f913 100644 --- a/Output/Selenium/Examples/comparison.ps1 +++ b/Output/Selenium/Examples/comparison.ps1 @@ -8,9 +8,9 @@ public void testClass() throws Exception { Assert.assertEquals("Wikipedia. the free encyclopedia", driver.getTitle()); } #> -SeOpen "http://www.wikipedia.org/" +Start-SeDriver -Browser Chrome -StartURL "https://www.wikipedia.org/" SeShouldHave -Title eq Wikipedia -SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | SeClick +SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | Invoke-SeClick SeShouldHave -Title eq 'Wikipedia, the free encyclopedia' <# @@ -52,7 +52,9 @@ public static void main(String[] args) { } #> -SeOpen "http://demo.guru99.com/test/newtours/" -In FireFox # or #-in Chrome -in MsEdge -in NewEdge or -in IE +Start-SeDriver -Browser Firefox -StartURL "http://demo.guru99.com/test/newtours/" SeShouldHave -Title eq "Welcome: Mercury Tours" -SeClose + +#Stop opened drivers +Get-SeDriver | Stop-SeDriver diff --git a/Output/Selenium/Examples/test-seremote.ps1 b/Output/Selenium/Examples/test-seremote.ps1 index 922b7db..e5b1bfe 100644 --- a/Output/Selenium/Examples/test-seremote.ps1 +++ b/Output/Selenium/Examples/test-seremote.ps1 @@ -49,14 +49,14 @@ Describe "All in one Test" { #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 + SeType -ClearFirst "selenium{{Enter}}" -PassThru -Sleep 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 + SeShouldHave $linkpath -With Text like *selenium* -PassThru | SeClick -Sleep 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 ... @@ -124,7 +124,7 @@ Describe "All in one Test" { $e | SeSelection -ByPartialText "Sa" } It 'submitted the form and got the expected response ' { - SeElement '/html/body/form/input' | SeClick -SleepSeconds 5 + SeElement '/html/body/form/input' | SeClick -Sleep 5 SeFrame -Parent SeFrame 'iframeResult' SeShouldHave "/html/body/div[1]" -with text match "cars=saab" diff --git a/Output/Selenium/Selenium.psd1 b/Output/Selenium/Selenium.psd1 index a0facef..2212441 100644 --- a/Output/Selenium/Selenium.psd1 +++ b/Output/Selenium/Selenium.psd1 @@ -8,7 +8,7 @@ # Modified James O'Neill 30 Nov 2019 @{ - ModuleVersion = '3.0.1' + ModuleVersion = '4.0.0' GUID = 'a3bdb8c3-c150-48a8-b56d-cd4d43f46a26' Author = 'Adam Driscoll' CompanyName = 'Unknown' @@ -16,28 +16,9 @@ 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-SeUrl', 'Get-SeWindow', 'Invoke-SeClick', 'Invoke-SeScreenshot', 'New-SeScreenshot', 'Pop-SeUrl', 'Push-SeUrl', 'Remove-SeCookie', 'Save-SeScreenshot', 'Send-SeClick', 'Send-SeKeys', 'SeOpen', 'SeShouldHave', 'Set-SeCookie', 'Set-SeUrl', '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' , 'Open-SeUrl', 'Set-SeLocation' - 'Push-SeLocation', - 'Pop-SeLocation', - 'Get-SeLocation', - 'Find-SeElement', - 'SeAccept', - 'SeDismiss', - 'SeClick', - 'SeClose', - 'SeElement', - 'SeFrame', - 'SeNavigate', - 'SeScreenshot', - 'SeSelection') + RequiredAssemblies = @('./assemblies/WebDriver.dll', './assemblies/WebDriver.Support.dll', 'System.Drawing') + FunctionsToExport = @('Clear-SeAlert', 'Clear-SeSelectValue', 'ConvertTo-SeSelenium', 'Get-SeCookie', 'Get-SeDriver', 'Get-SeDriverTimeout', 'Get-SeElement', 'Get-SeElementAttribute', 'Get-SeElementCssValue', 'Get-SeFrame', 'Get-SeHtml', 'Get-SeInput', 'Get-SeKeys', 'Get-SeSelectValue', 'Get-SeUrl', 'Get-SeWindow', 'Invoke-SeClick', 'Invoke-SeJavascript', 'Invoke-SeKeys', 'Invoke-seMouseAction', 'New-SeDriverOptions', 'New-SeDriverService', 'New-SeScreenshot', 'New-SeWindow', 'Pop-SeUrl', 'Push-SeUrl', 'Remove-SeCookie', 'Remove-SeWindow', 'Save-SeScreenshot', 'SeShouldHave', 'Set-SeCookie', 'Set-SeDriverTimeout', 'Set-SeSelectValue', 'Set-SeUrl', 'Start-SeDriver', 'Start-SeRemote', 'Stop-SeDriver', 'Switch-SeDriver', 'Switch-SeFrame', 'Switch-SeWindow', 'Update-SeDriver', 'Wait-SeDriver', 'Wait-SeElement') + AliasesToExport = @() CmdletsToExport = @() VariablesToExport = @() DscResourcesToExport = @() @@ -87,11 +68,11 @@ # 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 = @() + #Type files (.ps1xml) to be loaded when importing this module + TypesToProcess = @('types/Selenium.types.ps1xml') # Format files (.ps1xml) to be loaded when importing this module - # FormatsToProcess = @() + FormatsToProcess = @('formats/Selenium.format.ps1xml') # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess # NestedModules = @() diff --git a/Output/Selenium/Selenium.psm1 b/Output/Selenium/Selenium.psm1 index 4c4759f..7e77b7d 100644 Binary files a/Output/Selenium/Selenium.psm1 and b/Output/Selenium/Selenium.psm1 differ diff --git a/Output/Selenium/SeleniumClasses.ps1 b/Output/Selenium/SeleniumClasses.ps1 index 45d2736..9031fff 100644 --- a/Output/Selenium/SeleniumClasses.ps1 +++ b/Output/Selenium/SeleniumClasses.ps1 @@ -1,3 +1,7 @@ +using namespace system.Collections +using namespace System.Collections.Generic +using namespace System.Management.Automation +using namespace System.Management.Automation.Language if ('ValidateURIAttribute' -as [type]) { class ValidateURIAttribute : System.Management.Automation.ValidateArgumentsAttribute { @@ -24,31 +28,13 @@ if ('ValidateIsWebDriverAttribute' -as [type]) { 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)$#') { + if ($inputData -match '^(contains|like|notlike|match|notmatch|eq|ne|gt|lt)$') { return $InputData } switch -regex ($InputData) { @@ -57,6 +43,7 @@ if ('OperatorTransformAttribute' -as [type]) { "^n\w*match" { return 'notmatch' ; break } "^eq" { return 'eq' ; break } "^n\w*eq" { return 'ne' ; break } + "^n\w*like" { return 'like' ; break } } return $InputData } @@ -120,4 +107,38 @@ namespace SeleniumSelection { } } } -"@ -ReferencedAssemblies $dll1Path, $dll2Path, mscorlib \ No newline at end of file +"@ -ReferencedAssemblies $dll1Path, $dll2Path, mscorlib + + +enum SeBrowsers { + Chrome + Edge + Firefox + InternetExplorer + MSEdge +} + +enum SeWindowState { + Headless + Default + Minimized + Maximized + Fullscreen +} + +enum SeBySelector { + ClassName + CssSelector + Id + LinkText + PartialLinkText + Name + TagName + XPath +} + +enum SeBySelect { + Index + Text + Value +} \ No newline at end of file diff --git a/Output/Selenium/assemblies/IEDriverServer.exe b/Output/Selenium/assemblies/IEDriverServer.exe index d4890e2..d5d6ada 100644 Binary files a/Output/Selenium/assemblies/IEDriverServer.exe and b/Output/Selenium/assemblies/IEDriverServer.exe differ diff --git a/Output/Selenium/assemblies/IEDriverServer.exe.sha256 b/Output/Selenium/assemblies/IEDriverServer.exe.sha256 index 9573b7c..7a01c45 100644 --- a/Output/Selenium/assemblies/IEDriverServer.exe.sha256 +++ b/Output/Selenium/assemblies/IEDriverServer.exe.sha256 @@ -1 +1 @@ -A1E26B0E8CB5F8DB1CD784BAC71BBF540485D81E697293B0B4586E25A31A8187 +51053574E3BA3AB5D9F47E13EC0E9961AD6C9C9978DC851BE71C0F86A272C74B diff --git a/Output/Selenium/assemblies/chromedriver.exe b/Output/Selenium/assemblies/chromedriver.exe index 4850c8d..c0efae8 100644 Binary files a/Output/Selenium/assemblies/chromedriver.exe and b/Output/Selenium/assemblies/chromedriver.exe differ diff --git a/Output/Selenium/assemblies/chromedriver.exe.sha256 b/Output/Selenium/assemblies/chromedriver.exe.sha256 index 0f55902..c5b4c83 100644 --- a/Output/Selenium/assemblies/chromedriver.exe.sha256 +++ b/Output/Selenium/assemblies/chromedriver.exe.sha256 @@ -1 +1 @@ -55C5203DB4D44D96F4124C60E69AE0823F4372EFA4B5416675D9564A83D6AD2C \ No newline at end of file +5BFEADAEB1182DC068B60377BA34C010317D6AE19DA4934A221B2B1F3A050889 diff --git a/Output/Selenium/assemblies/geckodriver.exe b/Output/Selenium/assemblies/geckodriver.exe index 9fae8e0..4ce451b 100644 Binary files a/Output/Selenium/assemblies/geckodriver.exe and b/Output/Selenium/assemblies/geckodriver.exe differ diff --git a/Output/Selenium/assemblies/geckodriver.exe.sha256 b/Output/Selenium/assemblies/geckodriver.exe.sha256 index 2b051b9..e43d884 100644 --- a/Output/Selenium/assemblies/geckodriver.exe.sha256 +++ b/Output/Selenium/assemblies/geckodriver.exe.sha256 @@ -1 +1 @@ -255C9D3571C86841213F49B26D176A6AD440BE8C720E3C2D9226076ADF4F603D +FAED02EC5B0D6246856843D10EE020CB5121B8261AC939BE761130F21A73D3EE diff --git a/Output/Selenium/assemblies/linux/chromedriver b/Output/Selenium/assemblies/linux/chromedriver index 7d7041d..ca100fd 100644 Binary files a/Output/Selenium/assemblies/linux/chromedriver and b/Output/Selenium/assemblies/linux/chromedriver differ diff --git a/Output/Selenium/assemblies/linux/chromedriver.sha256 b/Output/Selenium/assemblies/linux/chromedriver.sha256 index 648ed61..14067a4 100644 --- a/Output/Selenium/assemblies/linux/chromedriver.sha256 +++ b/Output/Selenium/assemblies/linux/chromedriver.sha256 @@ -1 +1 @@ -B561EFE1551F9CB45DDE6BBF804CA2BC06359415CDAC1B6B16556B095A55011F \ No newline at end of file +D933FAA89173AFEC49B945F11360197117CB37AF3CE7EA16545D349B41869687 diff --git a/Output/Selenium/assemblies/linux/geckodriver b/Output/Selenium/assemblies/linux/geckodriver index ff08a41..bf9538e 100644 Binary files a/Output/Selenium/assemblies/linux/geckodriver and b/Output/Selenium/assemblies/linux/geckodriver differ diff --git a/Output/Selenium/assemblies/linux/geckodriver.sha256 b/Output/Selenium/assemblies/linux/geckodriver.sha256 index 6d92a3d..930beaa 100644 --- a/Output/Selenium/assemblies/linux/geckodriver.sha256 +++ b/Output/Selenium/assemblies/linux/geckodriver.sha256 @@ -1 +1 @@ -6590E3B9D9BF292C8DF50B6DF5BCF8A5191D999F9E48F68AA2055EB5746B2C05 +0B2C9B9791925DCEA2981CBDFAB8274FB4668BF65D6A57C2257E8B57757C394A diff --git a/Output/Selenium/assemblies/macos/chromedriver b/Output/Selenium/assemblies/macos/chromedriver index cd12a95..7471717 100644 Binary files a/Output/Selenium/assemblies/macos/chromedriver and b/Output/Selenium/assemblies/macos/chromedriver differ diff --git a/Output/Selenium/assemblies/macos/chromedriver.sha256 b/Output/Selenium/assemblies/macos/chromedriver.sha256 index 2e03b89..59914ba 100644 --- a/Output/Selenium/assemblies/macos/chromedriver.sha256 +++ b/Output/Selenium/assemblies/macos/chromedriver.sha256 @@ -1 +1 @@ -AD35D47CA5CD075939F7F6638188A56B648663D38A0719AF28B3F004BF95E0DD +9793D91D3448E35061606F37F1EB3EECC7B492CF159E6A318395445FB75B46EC diff --git a/Output/Selenium/assemblies/macos/geckodriver b/Output/Selenium/assemblies/macos/geckodriver index 83a86e1..4a2671f 100644 Binary files a/Output/Selenium/assemblies/macos/geckodriver and b/Output/Selenium/assemblies/macos/geckodriver differ diff --git a/Output/Selenium/assemblies/macos/geckodriver.sha256 b/Output/Selenium/assemblies/macos/geckodriver.sha256 index 449827d..ac73b7f 100644 --- a/Output/Selenium/assemblies/macos/geckodriver.sha256 +++ b/Output/Selenium/assemblies/macos/geckodriver.sha256 @@ -1 +1 @@ -D62C2178377ADDEB1BB860426B2C9B10B68D2EEABF0C521529A4A6A7B1E208C4 +AA2FCE6B96183C9D8FD0AA125F87557FCCEC60301CF7ADD1578B0DA59355AD8B diff --git a/Output/Selenium/assemblies/msedgedriver.exe b/Output/Selenium/assemblies/msedgedriver.exe index 18ab97e..74d70ba 100644 Binary files a/Output/Selenium/assemblies/msedgedriver.exe and b/Output/Selenium/assemblies/msedgedriver.exe differ diff --git a/Output/Selenium/assemblies/msedgedriver.exe.sha256 b/Output/Selenium/assemblies/msedgedriver.exe.sha256 index 14375a3..1d5e296 100644 --- a/Output/Selenium/assemblies/msedgedriver.exe.sha256 +++ b/Output/Selenium/assemblies/msedgedriver.exe.sha256 @@ -1 +1 @@ -509FFD6D321EF78C8319E68B89807D2437D8DB1718000FE2BB7ECACB1529730D +A6EB02FF3EF75079A647F20BD0B6B563648BC4C8563443229C65671AB0BBB6CD diff --git a/Output/Selenium/en-US/Selenium-help.xml b/Output/Selenium/en-US/Selenium-help.xml index f388603..12043e2 100644 --- a/Output/Selenium/en-US/Selenium-help.xml +++ b/Output/Selenium/en-US/Selenium-help.xml @@ -6,27 +6,15 @@ Clear SeAlert - Accept and clear alert popup + Clear alert popup by dismissing or accepting it. - Accept and clear alert popup + Clear alert popup by dismissing or accepting it. Clear-SeAlert - - Alert - - Specify alert window. Seems to be ignored in favor of Target / Default Target. - - Object - - Object - - - None - Action @@ -43,29 +31,11 @@ None - - PassThru - - {{ Fill PassThru Description }} - - - SwitchParameter - - - False - - - - Clear-SeAlert - - Action + + Alert - Action to be performed on the alert popup + Specify alert window. Seems to be ignored in favor of Target / Default Target. - - Accept - Dismiss - Object Object @@ -73,10 +43,10 @@ None - + PassThru - {{ Fill PassThru Description }} + Return Alert object. SwitchParameter @@ -84,18 +54,6 @@ False - - Target - - Target webdriver - - Object - - Object - - - None - @@ -111,7 +69,7 @@ None - + Alert Specify alert window. Seems to be ignored in favor of Target / Default Target. @@ -123,10 +81,10 @@ None - + PassThru - {{ Fill PassThru Description }} + Return Alert object. SwitchParameter @@ -135,18 +93,6 @@ False - - Target - - Target webdriver - - Object - - Object - - - None - @@ -176,9 +122,9 @@ -------------------------- Example 1 -------------------------- - PS C:\> {{ Add example code here }} + PS C:\> Clear-SeAlert -Action Dismiss - {{ Add example description here }} + Dismiss an alert on the currently selected driver. @@ -186,27 +132,27 @@ - Get-SeCookie - Get - SeCookie + Clear-SeSelectValue + Clear + SeSelectValue - List all cookies + Clear all selected entries of a SELECT element. - List all cookies + Clear all selected entries of a SELECT element. - Get-SeCookie - - Target + Clear-SeSelectValue + + Element - Target webdriver + Target IWebElement - Object + IWebElement - Object + IWebElement None @@ -214,14 +160,14 @@ - - Target + + Element - Target webdriver + Target IWebElement - Object + IWebElement - Object + IWebElement None @@ -230,7 +176,7 @@ - System.Object + None @@ -255,9 +201,9 @@ -------------------------- Example 1 -------------------------- - PS C:\> Get-SeCookie + PS C:\> Clear-SeSelectValue -Element $Select - List all cookies of the default webdriver + Clear the selected value from the specified SELECT element. @@ -265,70 +211,24 @@ - Get-SeElement - Get - SeElement + ConvertTo-Selenium + ConvertTo + Selenium - Finds all IWebElements within the current context using the given mechanism + Convert Selenium IDE .side recording file to PowerShell commands. - Finds all IWebElements within the current context using the given mechanism + {{ Fill in the Description }} - 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 + ConvertTo-Selenium + + Path - The locating mechanism to use + Path to .side file. - - CssSelector - Name - Id - ClassName - LinkText - PartialLinkText - TagName - XPath - String String @@ -336,36 +236,13 @@ 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 + + Path - String Identifier of the object to find + Path to .side file. String @@ -374,43 +251,43 @@ 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 - + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Get-SeCookie + Get + SeCookie + + List all cookies + + + + List all cookies + + + + Get-SeCookie + + + @@ -439,9 +316,9 @@ -------------------------- Example 1 -------------------------- - PS C:\> Get-SeElement -By Name -Selection 'username' + PS C:\> Get-SeCookie - Get the username field by name + List all cookies of the default webdriver @@ -449,35 +326,52 @@ - Get-SeElementAttribute + Get-SeDriver Get - SeElementAttribute + SeDriver - {{ Fill in the Synopsis }} + Get the list of all active drivers. - {{ Fill in the Description }} + Get the list of all active drivers or drivers matching the specified criterias. - Get-SeElementAttribute - - Element + Get-SeDriver + + Browser - Target IWebElement + Filter the list of returned drivers by their Browser type (enum: [SeBrowsers]) - IWebElement + Object - IWebElement + Object None - - Attribute + + + Get-SeDriver + + Current - {{ Fill Attribute Description }} + Return the currently selected browser. Selected browser is the last one started, unless changed via Switch-SeDriver and is always the one that get used in all cmdlet that have an unspecified $Driver. + + + SwitchParameter + + + False + + + + Get-SeDriver + + Name + + Filter driver returned by its name (SeFriendlyName). String @@ -489,26 +383,38 @@ - - Attribute + + Browser - {{ Fill Attribute Description }} + Filter the list of returned drivers by their Browser type (enum: [SeBrowsers]) - String + Object - String + Object None - - Element + + Current - Target IWebElement + Return the currently selected browser. Selected browser is the last one started, unless changed via Switch-SeDriver and is always the one that get used in all cmdlet that have an unspecified $Driver. - IWebElement + SwitchParameter - IWebElement + SwitchParameter + + + False + + + Name + + Filter driver returned by its name (SeFriendlyName). + + String + + String None @@ -517,7 +423,7 @@ - OpenQA.Selenium.IWebElement + None @@ -542,10 +448,30 @@ -------------------------- Example 1 -------------------------- - PS C:\> $Element = Get-SeElement -By Name -Selection 'username' -PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' + PS C:\> Get-SeDriver - Get the placeholder attribue of the username element. + Return the list of all active drivers. + + + + -------------------------- Example 2 -------------------------- + PS C:\> Get-SeDriver -Current + + Return the currently selected browser. + + + + -------------------------- Example 3 -------------------------- + PS C:\> Get-SeDriver -Browser Chrome + + Returh the list of all active "Chrome" browsers. + + + + -------------------------- Example 3 -------------------------- + PS C:\> Get-SeDriver -Name '70c91e0f112dcdbd22b84dd567560b8d' + + Return the driver with the specified name. @@ -553,75 +479,56 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Get-SeElementCssValue + Get-SeDriverTimeout Get - SeElementCssValue + SeDriverTimeout - Get CSS value for the specified name of targeted element. + Get the specified driver timeout value. - Get CSS value for the specified name of targeted element. + Get the specified driver timeout value. - Get-SeElementCssValue - - Element - - Target IWebElement - - IWebElement - - IWebElement - - - None - - - Name + Get-SeDriverTimeout + + TimeoutType - Name of the CSS attribute to query + Timeout type to be changed - String + + ImplicitWait + PageLoad + AsynchronousJavaScript + + Object - String + Object - None + ImplicitWait - - Element - - Target IWebElement - - IWebElement - - IWebElement - - - None - - - Name + + TimeoutType - Name of the CSS attribute to query + Timeout type to be changed - String + Object - String + Object - None + ImplicitWait - OpenQA.Selenium.IWebElement + OpenQA.Selenium.IWebDriver @@ -646,63 +553,16 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> Get-SeElementCssValue -Element $Element -Name 'padding' + PS C:\> Get-SeDriverTimeout - + Return the currently selected driver implicit wait timeout. - - - - - - 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 + -------------------------- Example 2 -------------------------- + PS C:\> Get-SeDriverTimeout -TimeoutType PageLoad -Driver $Driver - + Return the specified driver PageLoad timeout. @@ -710,47 +570,47 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Get-SeSelectionOption + Get-SeElement Get - SeSelectionOption + SeElement - Get Selected option from a Select control + Finds all IWebElements within the current context using the given mechanism - Get Selected option from a Select control + Finds all IWebElements within the current context using the given mechanism. - Get-SeSelectionOption - - Element + Get-SeElement + + Value - Targeted IwebElement + Locator Value corresponding to the `$By` selector. There should be an equal number of values than `$By` selector provided. - IWebElement + String[] - IWebElement + String[] None - - ByFullText + + Element - {{ Fill ByFullText Description }} + Target IWebElement. - String + IWebElement - String + IWebElement None - Clear + All - Deselect the option first + Return matching hidden items in addition to displayed ones. SwitchParameter @@ -759,31 +619,43 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - GetAllSelected + Attributes - All selected options belonging to this select tag + Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. + String[] - SwitchParameter + String[] - False + None - GetSelected + By - Get selected option + The locating mechanism to use. It is possible to use multiple locator, in which case they will be processed sequentially. + + ClassName + CssSelector + Id + LinkText + PartialLinkText + Name + TagName + XPath + + SeBySelector[] - SwitchParameter + SeBySelector[] - False + None - - PassThru + + Single - Return IWebElement + Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. SwitchParameter @@ -793,46 +665,35 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Get-SeSelectionOption - - Element + Get-SeElement + + Value - Targeted IwebElement + Locator Value corresponding to the `$By` selector. There should be an equal number of values than `$By` selector provided. - IWebElement + String[] - IWebElement + String[] None - - ByIndex + + Timeout - {{ Fill ByIndex Description }} + Timeout (in seconds) - Int32 + Double - Int32 + Double None - Clear - - Deselect the option first - - - SwitchParameter - - - False - - - GetAllSelected + All - All selected options belonging to this select tag + Return matching hidden items in addition to displayed ones. SwitchParameter @@ -841,266 +702,43 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - GetSelected - - Get selected option - - - SwitchParameter - - - False - - - PassThru - - Return IWebElement - - - SwitchParameter - - - False - - - - Get-SeSelectionOption - - Element - - Targeted IwebElement - - IWebElement - - IWebElement - - - None - - - ByPartialText + Attributes - {{ Fill ByPartialText Description }} + Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. - String + String[] - String + String[] None - GetAllSelected + By - All selected options belonging to this select tag + The locating mechanism to use. It is possible to use multiple locator, in which case they will be processed sequentially. + + ClassName + CssSelector + Id + LinkText + PartialLinkText + Name + TagName + XPath + + SeBySelector[] - SwitchParameter + SeBySelector[] - False + None - GetSelected - - Get selected option - - - SwitchParameter - - - False - - - PassThru + Single - 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 + Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. SwitchParameter @@ -1111,70 +749,46 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - ByFullText - - {{ Fill ByFullText Description }} - - String - - String - - - None - - - ByIndex - - {{ Fill ByIndex Description }} - - Int32 - - Int32 - - - None - - - ByPartialText + + All - {{ Fill ByPartialText Description }} + Return matching hidden items in addition to displayed ones. - String + SwitchParameter - String + SwitchParameter - None + False - - ByValue + + Attributes - {{ Fill ByValue Description }} + Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. - String + String[] - String + String[] None - Clear + By - Deselect the option first + The locating mechanism to use. It is possible to use multiple locator, in which case they will be processed sequentially. - SwitchParameter + SeBySelector[] - SwitchParameter + SeBySelector[] - False + None - + Element - Targeted IwebElement + Target IWebElement. IWebElement @@ -1184,33 +798,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'None - GetAllSelected - - All selected options belonging to this select tag - - SwitchParameter - - SwitchParameter - - - False - - - GetSelected - - Get selected option - - SwitchParameter - - SwitchParameter - - - False - - - IsMultiSelect + Single - To use with multiselect element + Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. SwitchParameter @@ -1219,51 +809,35 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - ListOptionText + + Timeout - This parameter is not used + Timeout (in seconds) - SwitchParameter + Double - SwitchParameter + Double - False + None - - PassThru + + Value - Return IWebElement + Locator Value corresponding to the `$By` selector. There should be an equal number of values than `$By` selector provided. - SwitchParameter + String[] - SwitchParameter + String[] - False + None - System.String - - - - - - - - OpenQA.Selenium.IWebElement - - - - - - - - System.Int32 + System.Object @@ -1285,89 +859,43 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - - - - - Get-SeUrl - Get - SeUrl - - Retrieves the current URL of a target webdriver instance. - - - - Retrieves the current URL of a target webdriver instance, or the currently stored internal location stack. - - - - Get-SeUrl - - Target - - The webdriver instance for which to retrieve the current URL or internal URL stack. - - Object - - Object - - - $Global:SeDriver - - - Stack - - Optionally retrieve the stored URL stack for the target or default webdriver instance. - - - SwitchParameter - - - False - - - - - - Stack - - Optionally retrieve the stored URL stack for the target or default webdriver instance. - - SwitchParameter - - SwitchParameter - - - False - - - Target - - The webdriver instance for which to retrieve the current URL or internal URL stack. - - Object - - Object - - - $Global:SeDriver - - - - - - - When using -Stack, the retrieved stack will not contain any of the driver's history (Back/Forward) data. It only handles locations added with Push-SeUrl. - To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. - - - -------------------------- EXAMPLE 1 -------------------------- - Get-SeUrl + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeElement -By XPath '//*[@id="home_text3"]/div[2]' -Value '//*[@id="home_text3"]/div[2]' +#Same but positionally bound +PS C:\> Get-SeElement '//*[@id="home_text3"]/div[2]' - Retrieves the current URL of the default webdriver instance. + Get the elements matching the specified XPath selector. + + + + -------------------------- Example 2 -------------------------- + PS C:\> Get-SeElement -By Name -Value 'username' -Single + + Get the username field by name with the expectation only one element is to be returned. + + + + -------------------------- Example 3 -------------------------- + PS C:\> Get-SeElement -By Name -Value 'username' -Single + + Get the username field by name with the expectation only one element is to be returned. + + + + -------------------------- Example 4 -------------------------- + PS C:\> Get-SeElement -By ClassName -Value homeitem -All -Attributes name, id -Timeout 2.5 +#To return all attributes instead: -Attributes * + + Get the elements by classname. Include hidden items `-All` and append an `Attributes` NoteProperty to all the result containing the value for the name and id attribute. The call will also fail if no results are found after 2.5 seconds. + + + + -------------------------- Example 5 -------------------------- + PS C:\> Get-SeElement -By ClassName,PartialLinkText -Value 'homeitem','The' + + Get the elements that match the selectors in a sequential manner. This call will return all links that contains the defined text (The) within elements that have a classname of "homeitem". @@ -1375,27 +903,39 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Get-SeWindow + Get-SeElementAttribute Get - SeWindow + SeElementAttribute - Gets the window handles of open browser windows + Get the specified attribute from the specified element. - Gets the window handles of open browser windows + Get the specified attribute from the specified element. - Get-SeWindow - - Target + Get-SeElementAttribute + + Element - Target webdriver + Target IWebElement - IWebDriver + IWebElement - IWebDriver + IWebElement + + + None + + + Name + + {{ Fill Name Description }} + + String[] + + String[] None @@ -1403,14 +943,26 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - Target + + Element - Target webdriver + Target IWebElement - IWebDriver + IWebElement - IWebDriver + IWebElement + + + None + + + Name + + {{ Fill Name Description }} + + String[] + + String[] None @@ -1419,7 +971,7 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - OpenQA.Selenium.IWebDriver + OpenQA.Selenium.IWebElement @@ -1444,9 +996,10 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> Get-SeWindow + PS C:\> $Element = Get-SeElement -By Name -Selection 'username' +PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Gets the window handles of open browser windows. + Get the placeholder attribue of the username element. @@ -1454,35 +1007,23 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Invoke-SeClick - Invoke - SeClick + Get-SeElementCssValue + Get + SeElementCssValue - Select an element then send a click action on it. + Get CSS value for the specified name of targeted element. - Select an element then send a click action on it. + Get CSS value for the specified name of targeted element. - Invoke-SeClick - - Driver - - Target webdriver - - Object - - Object - - - None - - + Get-SeElementCssValue + Element - Element for which the click will be performed upon + Target IWebElement IWebElement @@ -1491,36 +1032,25 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - JavaScriptClick + + Name - Use Javascript to perform the click + Name of the CSS attribute to query + String[] - SwitchParameter + String[] - False + None - - Driver - - Target webdriver - - Object - - Object - - - None - - + Element - Element for which the click will be performed upon + Target IWebElement IWebElement @@ -1529,17 +1059,17 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - JavaScriptClick + + Name - Use Javascript to perform the click + Name of the CSS attribute to query - SwitchParameter + String[] - SwitchParameter + String[] - False + None @@ -1567,79 +1097,39 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeElementCssValue -Element $Element -Name 'padding' + + Get padding css value for the targeted element. + + + - Invoke-SeScreenshot - Invoke - SeScreenshot + Get-SeFrame + Get + SeFrame - Take a screenshot of the current page + {{ Fill in the Synopsis }} - Take a screenshot of the current page + {{ Fill in the Description }} - Invoke-SeScreenshot - - Target - - Target webdriver - - Object - - Object - - - None - - - AsBase64EncodedString - - Return image as base64 string - - - SwitchParameter - - - False - + Get-SeFrame - - - AsBase64EncodedString - - Return image as base64 string - - SwitchParameter - - SwitchParameter - - - False - - - Target - - Target webdriver - - Object - - Object - - - None - - + - System.Object + None @@ -1661,131 +1151,206 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + - New-SeScreenshot - New - SeScreenshot + Get-SeHtml + Get + SeHtml - Take a screenshot of the current page + Get outer html of the specified element or driver. - Take a screenshot of the current page + Get outer html of the specified element or driver. Driver is used by default if no element is specified. - New-SeScreenshot - - AsBase64EncodedString + Get-SeHtml + + Element - Return image as base64 string + Target IWebElement. + IWebElement - SwitchParameter + IWebElement - False + None - - Target + + Inner - Target webdriver + Return inner html instead. - Object - Object + SwitchParameter - None + False + + + + Element + + Target IWebElement. + + IWebElement + + IWebElement + + + None + + + Inner + + Return inner html instead. + + SwitchParameter + + SwitchParameter + + + False + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> $Element = Get-SeElement -By ClassName -Value 'homeitem' +PS C:\> $Element | Get-SeHtml -Inner + + Get inner html for all specified elements. + + + + -------------------------- Example 2 -------------------------- + PS C:\> Get-SeHtml + + Get html of the current page. Equivalent to $Driver.PageSource + + + + + + + + Get-SeInput + Get + SeInput + + Get element with an input tagname matching the specified conditions. + + + + Get SeElement with an input Tagname + + - New-SeScreenshot - - Path + Get-SeInput + + Type - Filepath where the image iwll be saved to. + Type of the input - Object + String - Object + String None - ImageFormat + Text - Set the image format + Text of the input to return - - Png - Jpeg - Gif - Tiff - Bmp - - ScreenshotImageFormat + String - ScreenshotImageFormat + String None - - Target + + Timeout - Target webdriver + Timeout (in seconds) - Object + Double - Object + Double None - - - New-SeScreenshot - - Path + + Attributes - Filepath where the image iwll be saved to. + Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. - Object + String[] - Object + String[] None - - ImageFormat + + Value - Set the image format + Expected value of the first attribute present. - - Png - Jpeg - Gif - Tiff - Bmp - - ScreenshotImageFormat + String - ScreenshotImageFormat + String None - - PassThru + + All - Return the screenshot element + Return matching hidden items in addition to displayed ones. SwitchParameter @@ -1793,25 +1358,24 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - Target + + Single - Target webdriver + Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. - Object - Object + SwitchParameter - None + False - - AsBase64EncodedString + + All - Return image as base64 string + Return matching hidden items in addition to displayed ones. SwitchParameter @@ -1820,22 +1384,22 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - ImageFormat + + Attributes - Set the image format + Append a list of Attributes (case sensitive) to each element returned. Attributes will be available through a dictionary property of the same name. Is the wildcard `*` character is used, all attributes will be queried and appended. - ScreenshotImageFormat + String[] - ScreenshotImageFormat + String[] None - - PassThru + + Single - Return the screenshot element + Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found. SwitchParameter @@ -1844,26 +1408,50 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - Path + + Text - Filepath where the image iwll be saved to. + Text of the input to return - Object + String - Object + String None - - Target + + Timeout - Target webdriver + Timeout (in seconds) - Object + Double - Object + Double + + + None + + + Type + + Type of the input + + String + + String + + + None + + + Value + + Expected value of the first attribute present. + + String + + String None @@ -1872,7 +1460,7 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - System.Object + None @@ -1897,9 +1485,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> New-SeScreenshot -Path 'c:\temp\Screenshot.png' -ImageFormat Png + PS C:\> Get-SeInput -Attributes placeholder,title -All -Single -Value 'Type to search' - Save a screenshot in PNG format at the specified location + Get all the input (including hidden) present in the Dom and load the attributes placeholder and title. A single value is expected and it's attribute placeholder should be equals to : "Type to search" @@ -1907,61 +1495,53 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Pop-SeUrl - Pop - SeUrl + Get-SeKeys + Get + SeKeys - Navigate back to the most recently pushed URL in the location stack. + Return a list of the available special keys - Retrieves the most recently pushed URL from the location stack and navigates to that URL with the specified or default driver. + 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}}` - Pop-SeUrl - - Target - - {{ Fill Target Description }} - - Object - - Object - - - $Global:SeDriver - + Get-SeKeys - - - Target - - {{ Fill Target Description }} - - Object + + + - Object - + None - $Global:SeDriver - - - - + + + + + + + + + System.Object + + + + + + - A separate internal location stack is maintained for each driver instance by the module. This stack is completely separate from the driver's internal Back/Forward history logic. - To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. + - -------------------------- EXAMPLE 1 -------------------------- - Pop-SeUrl + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeKeys - Retrieves the most recently pushed URL and navigates back to that URL. + @@ -1969,92 +1549,216 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Push-SeUrl - Push - SeUrl + Get-SeSelectValue + Get + SeSelectValue - Stores the current URL in the driver's location stack and optionally navigate to a new URL. + Get Select element selected value. - The current driver URL is added to the stack, and if a URL is provided, the driver navigates to the new URL. + Get Select element selected value. - Push-SeUrl - - Url + Get-SeSelectValue + + Element - The new URL to navigate to after storing the current location. + Target IWebElement. - String + IWebElement - String + IWebElement None - - Target + + All - The webdriver instance that owns the url stack, and will navigate to a provided new url (if any). + Get All selected values (only available when the Select element accept multiple values) - Object - Object + SwitchParameter - $Global:SeDriver + False - - Url + + All - The new URL to navigate to after storing the current location. + Get All selected values (only available when the Select element accept multiple values) - String + SwitchParameter - String + SwitchParameter + + + False + + + Element + + Target IWebElement. + + IWebElement + + IWebElement None - - Target + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeSelectValue -Element $Select + + Get the selected value for the specified element. + + + + + + + + Get-SeUrl + Get + SeUrl + + Retrieves the current URL of a target webdriver instance. + + + + Retrieves the current URL of a target webdriver instance, or the currently stored internal location stack. + + + + Get-SeUrl + + Stack + + Optionally retrieve the stored URL stack for the target or default webdriver instance. + + + SwitchParameter + + + False + + + + + + Stack - The webdriver instance that owns the url stack, and will navigate to a provided new url (if any). + Optionally retrieve the stored URL stack for the target or default webdriver instance. - Object + SwitchParameter - Object + SwitchParameter - $Global:SeDriver + False - A separate internal location stack is maintained for each driver instance by the module. This stack is completely separate from the driver's internal Back/Forward history logic. + When using -Stack, the retrieved stack will not contain any of the driver's history (Back/Forward) data. It only handles locations added with Push-SeUrl. To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. -------------------------- EXAMPLE 1 -------------------------- - Push-SeUrl + Get-SeUrl - The current driver URL is added to the location stack. + Retrieves the current URL of the default webdriver instance. + + + + + + Get-SeWindow + Get + SeWindow + + Gets the window handles of open browser windows + + + + Gets the window handles of open browser windows + + + + Get-SeWindow + + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + - -------------------------- EXAMPLE 2 -------------------------- - Push-SeUrl 'https://google.com/' + -------------------------- Example 1 -------------------------- + PS C:\> Get-SeWindow - The current driver URL is added to the location stack, and the driver then navigates to the provided target URL. + Gets the window handles of open browser windows. @@ -2062,65 +1766,62 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Remove-SeCookie - Remove - SeCookie + Invoke-SeClick + Invoke + SeClick - Delete the named cookie from the current domain + Perform a click in the browser window or specified element. - Delete the named cookie from the current domain + Perform a click in the browser window or specified element. - Remove-SeCookie - - DeleteAllCookies + Invoke-SeClick + + Action - Remove all cookies from webdriver + test + Object - SwitchParameter + Object - False + None - - Target + + Element - Target webdriver + Target IWebElement. - IWebDriver + IWebElement - IWebDriver + IWebElement None - - - Remove-SeCookie - - Name + + PassThru - Cookie name to remove + Return the IWebElement. - String - String + SwitchParameter - None + False - - Target + + Sleep - Target webdriver + Sleep time in second after performing the click action. - IWebDriver + Double - IWebDriver + Double None @@ -2128,38 +1829,50 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - DeleteAllCookies + + Action - Remove all cookies from webdriver + test - SwitchParameter + Object - SwitchParameter + Object - False + None - - Name + + Element - Cookie name to remove + Target IWebElement. - String + IWebElement - String + IWebElement None - - Target + + PassThru - Target webdriver + Return the IWebElement. - IWebDriver + SwitchParameter - IWebDriver + SwitchParameter + + + False + + + Sleep + + Sleep time in second after performing the click action. + + Double + + Double None @@ -2168,7 +1881,7 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - OpenQA.Selenium.IWebDriver + OpenQA.Selenium.IWebElement @@ -2193,16 +1906,16 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> Remove-SeCookie -Name 'CookieName' + PS C:\> Invoke-SeClick - Remove cookie from targeted Driver + Perform a click in the browser at the current position -------------------------- Example 2 -------------------------- - PS C:\> Remove-SeCookie -DeleteAllCookies + PS C:\> Invoke-SeClick -Action Click_JS -Element $Element - Remove all cookies from targeted Driver + Perform a javascript click on the specified element. @@ -2210,58 +1923,40 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Save-SeScreenshot - Save - SeScreenshot + Invoke-SeJavascript + Invoke + SeJavascript - Take a screenshot of the current page + Invoke Javascript in the specified Driver. - Take a screenshot of the current page + Invoke Javascript in the specified Driver. arguments will be passed to the javascript as "argument[0]" (where 0 is the argument position) - Save-SeScreenshot - - Screenshot + Invoke-SeJavascript + + Script - Screenshot element + Javascript script to be executed. Arguments passed down can be used in the scripts through `arguments[0],arguments[1]`,etc... + - Screenshot + String - Screenshot + String None - - Path + + ArgumentList - Filepath where the image iwll be saved to. + Argument list to be passed down to the script. - String + Object[] - String - - - None - - - ImageFormat - - Set the image format - - - Png - Jpeg - Gif - Tiff - Bmp - - ScreenshotImageFormat - - ScreenshotImageFormat + Object[] None @@ -2269,22 +1964,23 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - ImageFormat + + ArgumentList - Set the image format + Argument list to be passed down to the script. - ScreenshotImageFormat + Object[] - ScreenshotImageFormat + Object[] None - - Path + + Script - Filepath where the image iwll be saved to. + Javascript script to be executed. Arguments passed down can be used in the scripts through `arguments[0],arguments[1]`,etc... + String @@ -2293,23 +1989,11 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Screenshot - - Screenshot element - - Screenshot - - Screenshot - - - None - - OpenQA.Selenium.Screenshot + OpenQA.Selenium.IWebDriver @@ -2331,28 +2015,36 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - + + + -------------------------- Example 1 -------------------------- + PS C:\> Invoke-SeJavascript -Script 'arguments[0].click()' -ArgumentList $Element + + Perform a javascript click on the specified element. + + + - Send-SeClick - Send - SeClick + Invoke-SeKeys + Invoke + SeKeys - Send a click to the targeted element + Send the keys to the browser or specified element. - Send a click to the targeted 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-SeClick - + Invoke-SeKeys + Element - Element for which the click will be performed upon + Target IWebElement. IWebElement @@ -2361,22 +2053,22 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Driver + + Keys - Target webdriver + 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 - Object + String - Object + String None - - JavaScriptClick + + ClearFirst - Use Javascript to perform the click + Clear the element existing text first SwitchParameter @@ -2384,10 +2076,10 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - + PassThru - Return the IWebElement + Return the IWebElement or webdriver SwitchParameter @@ -2396,36 +2088,47 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - SleepSeconds + Sleep - Sleep time in seconds after the click + Sleep time in second after performing the type action. - Object + Double - Object + Double None + + Submit + + Call submit on the specified element. + + + SwitchParameter + + + False + - Driver + ClearFirst - Target webdriver + Clear the element existing text first - Object + SwitchParameter - Object + SwitchParameter - None + False - + Element - Element for which the click will be performed upon + Target IWebElement. IWebElement @@ -2434,22 +2137,22 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - JavaScriptClick + + Keys - Use Javascript to perform the click + 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 - SwitchParameter + String - SwitchParameter + String - False + None - + PassThru - Return the IWebElement + Return the IWebElement or webdriver SwitchParameter @@ -2459,17 +2162,29 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - SleepSeconds + Sleep - Sleep time in seconds after the click + Sleep time in second after performing the type action. - Object + Double - Object + Double None + + Submit + + Call submit on the specified element. + + SwitchParameter + + SwitchParameter + + + False + @@ -2499,9 +2214,10 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> (Get-SeElement -By Name -Selection 'ButtonX') | Send-SeClick + PS C:\> $Search = Get-SeElement -By TagName -Value input -Single +PS C:\> Invoke-SeKeys -Element $Search -Keys 'Powershell-Selenium{{Enter}}' - Select an element then send a click action on it. + Type the defined text and a special key - Enter - defined in the special keys. @@ -2509,99 +2225,99 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Send-SeKeys - Send - SeKeys + Invoke-SeMouseAction + Invoke + SeMouseAction - Simulates typing text into the element + Perform mouse move & drag actions. - 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) + Perform mouse move & drag actions. - Send-SeKeys - - Element + Invoke-SeMouseAction + + Action - Specify the element where the keys will be typed to + Action to be performed. Intellisense tooltip provide details regarding expected value. - IWebElement + Object - IWebElement + Object None - - Keys + + Value - 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 + Value expected by the specified action. - String + Object - String + Object None - - PassThru + + Element - Return `$Element` + {{ Fill Element Description }} + IWebElement - SwitchParameter + IWebElement - False + None - - Element + + Action - Specify the element where the keys will be typed to + Action to be performed. Intellisense tooltip provide details regarding expected value. - IWebElement + Object - IWebElement + Object None - - Keys + + Element - 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 + {{ Fill Element Description }} - String + IWebElement - String + IWebElement None - - PassThru + + Value - Return `$Element` + Value expected by the specified action. - SwitchParameter + Object - SwitchParameter + Object - False + None - OpenQA.Selenium.IWebElement + None @@ -2626,9 +2342,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> SeType -Keys 'Powershell-Selenium{{Enter}}' -PassThru + PS C:\> Invoke-SeMouseAction -Element $SourceElement -Action DragAndDrop -Value $DestinationElement - ype the defined text and a special key - Enter - defined in the special keys. + Perform a drag&drop operation from the source element to destination element. @@ -2636,23 +2352,24 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Set-SeCookie - Set - SeCookie + New-SeDriverOptions + New + SeDriverOptions - Add a cookie to the current browsing context + Create a driver options object that can be used with `Start-SeDriver` - Add a cookie to the current browsing context + Create a driver options object that can be used with `Start-SeDriver` + This allow for more flexibility than the Start-SeDriver cmdlet as you can perform additional things with the driver options before starting the driver. - Set-SeCookie - - Name + New-SeDriverOptions + + StartURL - The name of the cookie + Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. String @@ -2661,58 +2378,113 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Value + + Arguments - The value of the cookie + Command line arguments to be passed to the browser. - String + String[] - String + String[] None - - Path + + BinaryPath - The path of the cookie + {{ Fill BinaryPath Description }} - String + Object - String + Object None - - Domain + + Browser - The domain of the cookie + Browser name to be started. - String + Object - String + Object None - - ExpiryDate + + DefaultDownloadPath - The expiration date of the cookie + {{ Fill DefaultDownloadPath Description }} - Object + FileInfo - Object + FileInfo + + + None + + + ImplicitWait + + Maximum time that the browser will implicitely wait between operations + + Double + + Double + + + None + + + LogLevel + + {{ Fill LogLevel Description }} + + + All + Debug + Info + Warning + Severe + Off + + LogLevel + + LogLevel + + + None + + + Position + + Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. + + Point + + Point None - - Target + + PrivateBrowsing + + Launch the browser in a private session + + + SwitchParameter + + + False + + + ProfilePath - Target webdriver + {{ Fill ProfilePath Description }} Object @@ -2721,25 +2493,85 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - - - - Domain - - The domain of the cookie - - String - - String + + Size + + Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. + + Size + + Size + + + None + + + State + + Window state of the browser. + + Object + + Object + + + None + + + Switches + + Special switches (additional legacy options that might appear for some browser ) + + String[] + + String[] + + + None + + + UserAgent + + UserAgent to be set. Supported by Chrome & Firefox + + String + + String + + + None + + + WebDriverPath + + Location of the web driver to be used. + + Object + + Object + + + None + + + + + + Arguments + + Command line arguments to be passed to the browser. + + String[] + + String[] None - - ExpiryDate + + BinaryPath - The expiration date of the cookie + {{ Fill BinaryPath Description }} Object @@ -2748,22 +2580,106 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Name + + Browser - The name of the cookie + Browser name to be started. - String + Object - String + Object None - - Path + + DefaultDownloadPath - The path of the cookie + {{ Fill DefaultDownloadPath Description }} + + FileInfo + + FileInfo + + + None + + + ImplicitWait + + Maximum time that the browser will implicitely wait between operations + + Double + + Double + + + None + + + LogLevel + + {{ Fill LogLevel Description }} + + LogLevel + + LogLevel + + + None + + + Position + + Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. + + Point + + Point + + + None + + + PrivateBrowsing + + Launch the browser in a private session + + SwitchParameter + + SwitchParameter + + + False + + + ProfilePath + + {{ Fill ProfilePath Description }} + + Object + + Object + + + None + + + Size + + Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. + + Size + + Size + + + None + + + StartURL + + Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. String @@ -2772,10 +2688,10 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Target + + State - Target webdriver + Window state of the browser. Object @@ -2784,10 +2700,22 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Value + + Switches - The value of the cookie + Special switches (additional legacy options that might appear for some browser ) + + String[] + + String[] + + + None + + + UserAgent + + UserAgent to be set. Supported by Chrome & Firefox String @@ -2796,11 +2724,23 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None + + WebDriverPath + + Location of the web driver to be used. + + Object + + Object + + + None + - System.Object + None @@ -2810,7 +2750,31 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - System.Object + OpenQA.Selenium.Chrome.ChromeOptions + + + + + + + + OpenQA.Selenium.Edge.EdgeOptions + + + + + + + + OpenQA.Selenium.Firefox.FirefoxOptions + + + + + + + + OpenQA.Selenium.IE.InternetExplorerOptions @@ -2822,224 +2786,145 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - + + + -------------------------- Example 1 -------------------------- + PS C:\> $Options = New-SeDriverOptions -Browser Chrome -Position 1920x0 -Size 1920x1080 +PS C:\> $Options.AddAdditionalCapability('useAutomationExtension', $false) +PS C:\> Start-SeDriver -Options $Options + + Create a Chrome driver option object to perform additional things unsupported directly by Start-SeDriver, such as adding an additional capability, then Start a driver instance with the modified Chrome driver options object. + + + - Set-SeUrl - Set - SeUrl + New-SeDriverService + New + SeDriverService - Navigates to the targeted URL with the selected or default driver. + Create an instance of WebDriver service to be used with Start-SeDriver - Used for webdriver navigation commands, either to specific target URLs or for history (Back/Forward) navigation or refreshing the current page. + Create an instance of WebDriver service to be used with Start-SeDriver - Set-SeUrl - - Url - - The target URL for the webdriver to navigate to. - - String - - String - - - None - - - Target - - The target webdriver to manage navigation for. Will utilise the default driver if left unset. - - Object - - Object - - - $Global:SeDriver - - - - Set-SeUrl - - Back - - Trigger the Back history navigation action in the webdriver. - - - SwitchParameter - - - False - - - Target + New-SeDriverService + + Browser - The target webdriver to manage navigation for. Will utilise the default driver if left unset. + Browser name Object Object - $Global:SeDriver - - - - Set-SeUrl - - Forward - - Trigger the Forward history navigation action in the webdriver. - - - SwitchParameter - - - False + None - - Target + + WebDriverPath - The target webdriver to manage navigation for. Will utilise the default driver if left unset. + Location of the web driver to be used. Object Object - $Global:SeDriver - - - - Set-SeUrl - - Refresh - - Refresh the current page in the webdriver. - - - SwitchParameter - - - False - - - Target - - The target webdriver to manage navigation for. Will utilise the default driver if left unset. - - Object - - Object - - - $Global:SeDriver + None - - Url + + Browser - The target URL for the webdriver to navigate to. + Browser name - String + Object - String + Object None - - Back + + WebDriverPath - Trigger the Back history navigation action in the webdriver. + Location of the web driver to be used. - SwitchParameter + Object - SwitchParameter + Object - False + None - - Forward - - Trigger the Forward history navigation action in the webdriver. - - SwitchParameter + + + - SwitchParameter - + None - False - - - Refresh - - Refresh the current page in the webdriver. - - SwitchParameter + + + + + + + - SwitchParameter - + OpenQA.Selenium.Chrome.ChromeDriverService - False - - - Target - - The target webdriver to manage navigation for. Will utilise the default driver if left unset. - - Object + + + + + - Object - + OpenQA.Selenium.Firefox.FirefoxDriverService - $Global:SeDriver - - - - + + + + + + + OpenQA.Selenium.IE.InternetExplorerDriverService + + + + + + + + OpenQA.Selenium.Edge.EdgeDriverService + + + + + + - The Back/Forward/Refresh logic is handled by the webdriver itself. If you need a more granular approach to handling which locations are saved or retrieved, use Push-SeUrl or Pop-SeUrl to utilise a separately managed location stack. + - -------------------------- EXAMPLE 1 -------------------------- - Set-SeUrl 'https://www.google.com/' - - Directs the default driver to navigate to www.google.com. - - - - -------------------------- EXAMPLE 2 -------------------------- - Set-SeUrl -Refresh - - Reloads the current page for the default driver. - - - - -------------------------- EXAMPLE 3 -------------------------- - Set-SeUrl -Target $Driver -Back - - Directs the targeted webdriver instance to navigate Back in its history. - - - - -------------------------- EXAMPLE 4 -------------------------- - Set-SeUrl -Forward + -------------------------- Example 1 -------------------------- + PS C:\> $Service = New-SeDriverService -Browser Chrome +PS C:\> $Service.PortServerAddress = 100 +PS C:\> $Options = New-SeDriverOptions -Browser Chrome -Position 1920x0 -Size 1920x1080 +PS C:\> Start-SeDriver -Service $Service -Options $Options +PS C:\> $Service.ProcessId - Directs the default webdriver to navigate Forward in its history. + Create a new instance of Chrome driver service, set a custom port and start the driver with the modified service instance. @@ -3047,47 +2932,49 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Start-SeChrome - Start - SeChrome + New-SeScreenshot + New + SeScreenshot - Initializes a new instance of the ChromeDriver class. + Take a screenshot of the current page - Initializes a new instance of the ChromeDriver class. + Take a screenshot of the current page - Start-SeChrome - - StartURL + New-SeScreenshot + + AsBase64EncodedString - Define Driver starting URL + Return image as base64 string - String - String + SwitchParameter - None + False - Arguments + Element - Adds arguments to be appended to the Chrome.exe command line. + {{ Fill Element Description }} - Array + IWebElement - Array + IWebElement None + + + New-SeScreenshot - AsDefaultDriver + AsBase64EncodedString - Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + Return image as base64 string SwitchParameter @@ -3095,10 +2982,10 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - BinaryPath + + InputObject - Set the location of the Chrome browser's binary executable file + {{ Fill InputObject Description }} Object @@ -3107,113 +2994,286 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - DefaultDownloadPath + + + + + AsBase64EncodedString + + Return image as base64 string + + SwitchParameter + + SwitchParameter + + + False + + + Element + + {{ Fill Element Description }} + + IWebElement + + IWebElement + + + None + + + InputObject + + {{ Fill InputObject Description }} + + 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 + + + + + + + + New-SeWindow + New + SeWindow + + {{ Fill in the Synopsis }} + + + + {{ Fill in the Description }} + + + + New-SeWindow + + Url - Set default download path + {{ Fill Url Description }} - FileInfo + Object - FileInfo + Object None - - DisableAutomationExtension - - Disable AutomationExtension notification - - - SwitchParameter - - - False - - - DisableBuiltInPDFViewer + + + + + Url + + {{ Fill Url Description }} + + Object + + Object + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Pop-SeUrl + Pop + SeUrl + + Navigate back to the most recently pushed URL in the location stack. + + + + Retrieves the most recently pushed URL from the location stack and navigates to that URL with the specified or default driver. + + + + Pop-SeUrl + + + + + + + + A separate internal location stack is maintained for each driver instance by the module. This stack is completely separate from the driver's internal Back/Forward history logic. + To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. + + + + + -------------------------- EXAMPLE 1 -------------------------- + Pop-SeUrl + + Retrieves the most recently pushed URL and navigates back to that URL. + + + + + + + + Push-SeUrl + Push + SeUrl + + Stores the current URL in the driver's location stack and optionally navigate to a new URL. + + + + The current driver URL is added to the stack, and if a URL is provided, the driver navigates to the new URL. + + + + Push-SeUrl + + Url - Obsolete. Use `-EnablePDFViewer` instead. + The new URL to navigate to after storing the current location. - Boolean + String - Boolean + String None - - EnablePDFViewer - - Enable built in PDF Viewer (By default PDF will always open xternally) - - - SwitchParameter - - - False - + + + + + Url + + The new URL to navigate to after storing the current location. + + String + + String + + + None + + + + + + + A separate internal location stack is maintained for each driver instance by the module. This stack is completely separate from the driver's internal Back/Forward history logic. + To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. + + + + + -------------------------- EXAMPLE 1 -------------------------- + Push-SeUrl + + The current driver URL is added to the location stack. + + + + -------------------------- EXAMPLE 2 -------------------------- + Push-SeUrl 'https://google.com/' + + The current driver URL is added to the location stack, and the driver then navigates to the provided target URL. + + + + + + + + Remove-SeCookie + Remove + SeCookie + + Delete the named cookie from the current domain + + + + Delete the named cookie from the current domain + + + + Remove-SeCookie - 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 + All - Hide command prompt window + Clear all cookies. SwitchParameter @@ -3221,25 +3281,13 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - WebDriverDirectory - - Specify web driver custom service location - - Object - - Object - - - None - - Start-SeChrome - - StartURL + Remove-SeCookie + + Name - Define Driver starting URL + Cookie name to remove String @@ -3248,174 +3296,434 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' 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 + + + + + All + + Clear all cookies. + + SwitchParameter + + SwitchParameter + + + False + + + Name + + Cookie name to remove + + String + + String + + + 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 + + + + + + + + Remove-SeWindow + Remove + SeWindow + + {{ Fill in the Synopsis }} + + + + {{ Fill in the Description }} + + + + Remove-SeWindow + + SwitchToWindow - Set the location of the Chrome browser's binary executable file + {{ Fill SwitchToWindow Description }} - Object + String - Object + String None - - DefaultDownloadPath + + + + + SwitchToWindow + + {{ Fill SwitchToWindow Description }} + + String + + String + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + + + Save-SeScreenshot + Save + SeScreenshot + + Save a screenshot on the disk. + + + + Save the screenshot at the specified location. + + + + Save-SeScreenshot + + Element - Set default download path + {{ Fill Element Description }} - FileInfo + IWebElement - FileInfo + IWebElement None - DisableAutomationExtension - - Disable AutomationExtension notification - - - SwitchParameter - - - False - - - DisableBuiltInPDFViewer + ImageFormat - Obsolete. Use `-EnablePDFViewer` instead. + Image format for the file to be saved. - Boolean + + Png + Jpeg + Gif + Tiff + Bmp + + ScreenshotImageFormat - Boolean + ScreenshotImageFormat None - - EnablePDFViewer - - Enable built in PDF Viewer (By default PDF will always open xternally) - - - SwitchParameter - - - False - - Headless + Path - Start driver without any visual interface + Filepath where the image will be saved. + String - SwitchParameter + String - False + None + + + Save-SeScreenshot - HideVersionHint + ImageFormat - Hide download proper driver version message + Image format for the file to be saved. + + Png + Jpeg + Gif + Tiff + Bmp + + ScreenshotImageFormat - SwitchParameter + ScreenshotImageFormat - False + None - - ImplicitWait + + InputObject - Control timeout duration (in seconds) + {{ Fill InputObject Description }} - Int32 + Object - Int32 + Object None - - Incognito + + Path - Drive will open an incognito session + Filepath where the image will be saved. + String - SwitchParameter + String - False + None + + + Save-SeScreenshot - ProfileDirectoryPath + ImageFormat - Driver will use the specified user profile path + Image format for the file to be saved. - FileInfo + + Png + Jpeg + Gif + Tiff + Bmp + + ScreenshotImageFormat - FileInfo + ScreenshotImageFormat None - - Quiet + + Path - Hide command prompt window + Filepath where the image will be saved. + String - SwitchParameter + String - False + None - - WebDriverDirectory + + Screenshot - Specify web driver custom service location + Screenshot object. - Object + Screenshot - Object + Screenshot None - - Start-SeChrome - - StartURL + + + + Element + + {{ Fill Element Description }} + + IWebElement + + IWebElement + + + None + + + ImageFormat + + Image format for the file to be saved. + + ScreenshotImageFormat + + ScreenshotImageFormat + + + None + + + InputObject + + {{ Fill InputObject Description }} + + Object + + Object + + + None + + + Path + + Filepath where the image will be saved. + + String + + String + + + None + + + Screenshot + + Screenshot object. + + Screenshot + + Screenshot + + + None + + + + + + System.Object + + + + + + + + OpenQA.Selenium.Screenshot + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> $Screenshot = New-SeScreenshot +PS C:\> Save-SeScreenshot -Screenshot $Screenshot -Path 'c:\temp\image.png' -ImageFormat Png + + Create then save a screenshot to disk. + + + + + + + + Set-SeCookie + Set + SeCookie + + Add a cookie to the current browsing context + + + + Add a cookie to the current browsing context + + + + Set-SeCookie + + Name - Define Driver starting URL + The name of the cookie String @@ -3424,159 +3732,302 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Arguments + + Value - Adds arguments to be appended to the Chrome.exe command line. + The value of the cookie - Array + String - Array + String None - - AsDefaultDriver + + Path - Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + The path of the cookie + String - SwitchParameter + String - False + None - - BinaryPath + + Domain - Set the location of the Chrome browser's binary executable file + The domain of the cookie - Object + String - Object + String None - - DefaultDownloadPath + + ExpiryDate - Set default download path + The expiration date of the cookie - FileInfo + DateTime - FileInfo + DateTime None - - DisableAutomationExtension + + + + + Domain + + The domain of the cookie + + String + + String + + + None + + + ExpiryDate + + The expiration date of the cookie + + DateTime + + DateTime + + + None + + + Name + + The name of the cookie + + String + + String + + + None + + + Path + + The path of the cookie + + String + + String + + + None + + + Value + + The value of the cookie + + String + + String + + + None + + + + + + System.Object + + + + + + + + + + System.Object + + + + + + + + + + + + + + + + + Set-SeDriverTimeout + Set + SeDriverTimeout + + Set the various driver timeouts default. + + + + Set the various driver timeouts default. + + + + Set-SeDriverTimeout + + TimeoutType - Disable AutomationExtension notification + Type of timeout to change. + + ImplicitWait + PageLoad + AsynchronousJavaScript + + Object - SwitchParameter + Object - False + None - - DisableBuiltInPDFViewer + + Timeout - Obsolete. Use `-EnablePDFViewer` instead. + Value in seconds - Boolean + Double - Boolean + Double 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 + + + + + Timeout + + Value in seconds + + Double + + Double + + + None + + + TimeoutType + + Type of timeout to change. + + Object + + Object + + + None + + + + + + OpenQA.Selenium.IWebDriver + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Set-SeDriverTimeout -TimeoutType ImplicitWait -Timeout 0 + + Set Implicit wait timeout to 0 + + + + + + + + Set-SeSelectValue + Set + SeSelectValue + + Set Select element selected value. + + + + Set Select element selected value. + + + + Set-SeSelectValue + + Element - Control timeout duration (in seconds) + Target IWebElement. - Int32 + IWebElement - Int32 + IWebElement None - - Incognito - - Drive will open an incognito session - - - SwitchParameter - - - False - - - Maximized - - Driver will open browser in a maximized state - - - SwitchParameter - - - False - - ProfileDirectoryPath + By - Driver will use the specified user profile path + Selector to be used to set the value. - FileInfo + + Index + Text + Value + + SeBySelect - FileInfo + SeBySelect None - Quiet - - Hide command prompt window - - - SwitchParameter - - - False - - - WebDriverDirectory + value - Specify web driver custom service location + Value to which the specified element will be set. Object @@ -3586,12 +4037,100 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'None + + + + By + + Selector to be used to set the value. + + SeBySelect + + SeBySelect + + + None + + + Element + + Target IWebElement. + + IWebElement + + IWebElement + + + None + + + value + + Value to which the specified element will be set. + + Object + + Object + + + None + + + + + + OpenQA.Selenium.IWebElement + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Set-SeSelectValue -By Text -value 'Hello' -Element $Element + + Set targeted Select element selected value to 'Hello' (by text) + + + + + + + + Set-SeUrl + Set + SeUrl + + Navigates to the targeted URL with the selected or default driver. + + + + Used for webdriver navigation commands, either to specific target URLs or for history (Back/Forward) navigation or refreshing the current page. + + - Start-SeChrome - - StartURL + Set-SeUrl + + Url - Define Driver starting URL + The target URL for the webdriver to navigate to. String @@ -3600,57 +4139,65 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Arguments + + + Set-SeUrl + + Back - Adds arguments to be appended to the Chrome.exe command line. + Trigger the Back history navigation action in the webdriver. - Array - Array + SwitchParameter - None + False - AsDefaultDriver + Depth - Set `$Global:SeDriver` ot the current Driver and dispose previously set driver. + Number of time the action should be performed. + Int32 - SwitchParameter + Int32 - False + 1 - - BinaryPath + + + Set-SeUrl + + Forward - Set the location of the Chrome browser's binary executable file + Trigger the Forward history navigation action in the webdriver. - Object - Object + SwitchParameter - None + False - DefaultDownloadPath + Depth - Set default download path + Number of time the action should be performed. - FileInfo + Int32 - FileInfo + Int32 - None + 1 - - DisableAutomationExtension + + + Set-SeUrl + + Refresh - Disable AutomationExtension notification + Refresh the current page in the webdriver. SwitchParameter @@ -3658,90 +4205,256 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - DisableBuiltInPDFViewer - - Obsolete. Use `-EnablePDFViewer` instead. - - Boolean + + + + + Url + + The target URL for the webdriver to navigate to. + + String + + String + + + None + + + Back + + Trigger the Back history navigation action in the webdriver. + + SwitchParameter + + SwitchParameter + + + False + + + Forward + + Trigger the Forward history navigation action in the webdriver. + + SwitchParameter + + SwitchParameter + + + False + + + Refresh + + Refresh the current page in the webdriver. + + SwitchParameter + + SwitchParameter + + + False + + + Depth + + Number of time the action should be performed. + + Int32 + + Int32 + + + 1 + + + + + + + The Back/Forward/Refresh logic is handled by the webdriver itself. If you need a more granular approach to handling which locations are saved or retrieved, use Push-SeUrl or Pop-SeUrl to utilise a separately managed location stack. + + + + + -------------------------- EXAMPLE 1 -------------------------- + Set-SeUrl 'https://www.google.com/' + + Directs the default driver to navigate to www.google.com. + + + + -------------------------- EXAMPLE 2 -------------------------- + Set-SeUrl -Refresh + + Reloads the current page for the default driver. + + + + -------------------------- EXAMPLE 3 -------------------------- + Set-SeUrl -Target $Driver -Back + + Directs the targeted webdriver instance to navigate Back in its history. + + + + -------------------------- EXAMPLE 4 -------------------------- + Set-SeUrl -Forward + + Directs the default webdriver to navigate Forward in its history. + + + + + + + + Start-SeDriver + Start + SeDriver + + Launch the specified browser. + + + + Launch a driver instance of the specified browser. + + + + Start-SeDriver + + StartURL + + Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. + + String - Boolean + String None - EnablePDFViewer + Arguments - Enable built in PDF Viewer (By default PDF will always open xternally) + Command line arguments to be passed to the browser. + String[] - SwitchParameter + String[] - False + None - HideVersionHint + BinaryPath - Hide download proper driver version message + {{ Fill BinaryPath Description }} + Object - SwitchParameter + Object - False + None + + + Browser + + Browser to be started. + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + FileInfo + + FileInfo + + + None ImplicitWait - Control timeout duration (in seconds) + Maximum time that the browser will implicitely wait between operations - Int32 + Double - Int32 + Double None - - Incognito + + LogLevel - Drive will open an incognito session + {{ Fill LogLevel Description }} + + All + Debug + Info + Warning + Severe + Off + + LogLevel - SwitchParameter + LogLevel - False + None + + + Name + + Friendly name of the browser. + + Object + + Object + + + None - Minimized + Options - Driver will open browser in a minimized state + Driver Options object + DriverOptions - SwitchParameter + DriverOptions - False + None - ProfileDirectoryPath + Position - Driver will use the specified user profile path + Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. - FileInfo + Point - FileInfo + Point None - Quiet + PrivateBrowsing - Hide command prompt window + Launch the browser in a private session SwitchParameter @@ -3750,9 +4463,76 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - WebDriverDirectory + ProfilePath + + {{ Fill ProfilePath Description }} + + Object + + Object + + + None + + + Service + + DriverService object to be used. + + DriverService + + DriverService + + + None + + + Size + + Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. + + Size + + Size + + + None + + + State + + Window state of the browser. + + + Headless + Default + Minimized + Maximized + Fullscreen + + SeWindowState + + SeWindowState + + + Default + + + UserAgent + + UserAgent to be set. Supported by Chrome & Firefox + + String + + String + + + None + + + WebDriverPath - Specify web driver custom service location + Location of the web driver to be used. Object @@ -3762,50 +4542,259 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'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 + + Start-SeDriver + + StartURL + + Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. + + String + + String + + + None + + + Arguments + + Command line arguments to be passed to the browser. + + String[] + + String[] + + + None + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + Browser + + Browser to be started. + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + FileInfo + + FileInfo + + + None + + + ImplicitWait + + Maximum time that the browser will implicitely wait between operations + + Double + + Double + + + None + + + LogLevel + + {{ Fill LogLevel Description }} + + + All + Debug + Info + Warning + Severe + Off + + LogLevel + + LogLevel + + + None + + + Name + + Friendly name of the browser. + + Object + + Object + + + None + + + Position + + Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. + + Point + + Point + + + None + + + PrivateBrowsing + + Launch the browser in a private session + + + SwitchParameter + + + False + + + ProfilePath + + {{ Fill ProfilePath Description }} + + Object + + Object + + + None + + + Size + + Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. + + Size + + Size + + + None + + + State + + Window state of the browser. + + + Headless + Default + Minimized + Maximized + Fullscreen + + SeWindowState + + SeWindowState + + + Default + + + Switches + + Special switches (additional legacy options that might appear for some browser ) + + String[] + + String[] + + + None + + + UserAgent + + UserAgent to be set. Supported by Chrome & Firefox + + String + + String + + + None + + + WebDriverPath + + Location of the web driver to be used. + + Object + + Object + + + None + + + + + + Arguments + + Command line arguments to be passed to the browser. + + String[] + + String[] + + + None + + + BinaryPath + + {{ Fill BinaryPath Description }} + + Object + + Object + + + None + + + Browser + + Browser to be started. + + Object + + Object + + + None + + + DefaultDownloadPath + + {{ Fill DefaultDownloadPath Description }} + + FileInfo FileInfo @@ -3813,69 +4802,69 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'None - DisableAutomationExtension + ImplicitWait - Disable AutomationExtension notification + Maximum time that the browser will implicitely wait between operations - SwitchParameter + Double - SwitchParameter + Double - False + None - DisableBuiltInPDFViewer + LogLevel - Obsolete. Use `-EnablePDFViewer` instead. + {{ Fill LogLevel Description }} - Boolean + LogLevel - Boolean + LogLevel None - EnablePDFViewer + Name - Enable built in PDF Viewer (By default PDF will always open xternally) + Friendly name of the browser. - SwitchParameter + Object - SwitchParameter + Object - False + None - Fullscreen + Options - Driver will open browser in a fullscreen state + Driver Options object - SwitchParameter + DriverOptions - SwitchParameter + DriverOptions - False + None - - Headless + + Position - Start driver without any visual interface + Position of the browser to be set on or after launch. Some browser might not support position to be set prior launch and will have their position set after launch. - SwitchParameter + Point - SwitchParameter + Point - False + None - HideVersionHint + PrivateBrowsing - Hide download proper driver version message + Launch the browser in a private session SwitchParameter @@ -3885,81 +4874,81 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - ImplicitWait + ProfilePath - Control timeout duration (in seconds) + {{ Fill ProfilePath Description }} - Int32 + Object - Int32 + Object None - - Incognito + + Service - Drive will open an incognito session + DriverService object to be used. - SwitchParameter + DriverService - SwitchParameter + DriverService - False + None - - Maximized + + Size - Driver will open browser in a maximized state + Size of the browser to be set on or after launch. Some browser might not support size to be set prior launch and will have their size set after launch. - SwitchParameter + Size - SwitchParameter + Size - False + None - - Minimized + + StartURL - Driver will open browser in a minimized state + Start URL to be set immediately after launch. If no protocol is specified, https will be assumed. - SwitchParameter + String - SwitchParameter + String - False + None - ProfileDirectoryPath + State - Driver will use the specified user profile path + Window state of the browser. - FileInfo + SeWindowState - FileInfo + SeWindowState - None + Default - Quiet + Switches - Hide command prompt window + Special switches (additional legacy options that might appear for some browser ) - SwitchParameter + String[] - SwitchParameter + String[] - False + None - - StartURL + + UserAgent - Define Driver starting URL + UserAgent to be set. Supported by Chrome & Firefox String @@ -3969,9 +4958,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'None - WebDriverDirectory + WebDriverPath - Specify web driver custom service location + Location of the web driver to be used. Object @@ -3994,7 +4983,7 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - System.Object + OpenQA.Selenium.IWebDriver @@ -4009,40 +4998,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- 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' + PS C:\> Start-SeDriver -Browser Chrome -Position 1920x0 -StartURL 'google.com' - 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 a Chrome browser at the specified position and starting URL @@ -4050,23 +5008,23 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Start-SeEdge + Start-SeRemote Start - SeEdge + SeRemote - Initializes a new instance of the EdgeDriver class + Start a remote driver session. - Initializes a new instance of the EdgeDriver class + Start a remote driver session. you can a remote testing account with testing bot at https://testingbot.com/users/sign_up - Start-SeEdge + Start-SeRemote StartURL - Define Driver starting URL + {{ Fill StartURL Description }} String @@ -4076,161 +5034,45 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'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 + DesiredCapabilities - Control timeout duration (in seconds) + {{ Fill DesiredCapabilities Description }} - Int32 + Hashtable - Int32 + Hashtable None - - PrivateBrowsing - - Driver will open a private session - - - SwitchParameter - - - False - - Quiet - - Hide command prompt window - - - SwitchParameter - - - False - - - - Start-SeEdge - - StartURL + ImplicitWait - Define Driver starting URL + {{ Fill ImplicitWait Description }} - String + Double - String + Double 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 + Position - Control timeout duration (in seconds) + {{ Fill Position Description }} - Int32 + Point - Int32 + Point 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 + RemoteAddress - Define Driver starting URL + {{ Fill RemoteAddress Description }} String @@ -4240,175 +5082,84 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'None - AsDefaultDriver + Size - Set $Global:SeDriver ot the current Driver and dispose previously set driver. + {{ Fill Size Description }} + Size - SwitchParameter - - - False - - - Headless - - Start driver without any visual interface - - - SwitchParameter - - - False - - - ImplicitWait - - Control timeout duration (in seconds) - - Int32 - - Int32 + Size 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 + DesiredCapabilities - Start driver without any visual interface + {{ Fill DesiredCapabilities Description }} - SwitchParameter + Hashtable - SwitchParameter + Hashtable - False + None ImplicitWait - Control timeout duration (in seconds) + {{ Fill ImplicitWait Description }} - Int32 + Double - Int32 + Double None - - Maximized - - Driver will open browser in a maximized state - - SwitchParameter - - SwitchParameter - - - False - - - Minimized + + Position - Driver will open browser in a minimized state + {{ Fill Position Description }} - SwitchParameter + Point - SwitchParameter + Point - False + None - - PrivateBrowsing + + RemoteAddress - Driver will open a private session + {{ Fill RemoteAddress Description }} - SwitchParameter + String - SwitchParameter + String - False + None - Quiet + Size - Hide command prompt window + {{ Fill Size Description }} - SwitchParameter + Size - SwitchParameter + Size - False + None StartURL - Define Driver starting URL + {{ Fill StartURL Description }} String @@ -4446,7 +5197,17 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> $Driver = Start-SeEdge + #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 @@ -4456,259 +5217,125 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Start-SeFirefox - Start - SeFirefox + Stop-SeDriver + Stop + SeDriver - Initializes a new instance of the FirefoxDriver class. + Quits this driver, closing every associated window. - Initializes a new instance of the FirefoxDriver class. + Quits this driver, closing every associated window. - Start-SeFirefox - - StartURL - - Define Driver starting URL - - String - - String - - - None - - - Arguments + Stop-SeDriver + + Driver - Adds arguments to be appended to the Firefox.exe command line. + Target WebDriver - Array + IWebDriver - 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 + IWebDriver None + + + + Driver + + Target WebDriver + + 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-SeDriver + Switch + SeDriver + + Select a driver, making it the default to be used with any ulterior calls whenever the driver parameter is not specified. + + + + Select a driver, making it the default to be used with any ulterior calls whenever the driver parameter is not specified. + + - 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 + Switch-SeDriver + + Driver - Specify web driver custom service location + Target WebDriver - Object + IWebDriver - Object + IWebDriver None - Start-SeFirefox - - StartURL + Switch-SeDriver + + Name - Define Driver starting URL + SeFriendlyName of the browser to select. String @@ -4717,401 +5344,48 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' 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 + + Driver - Set default download path + Target WebDriver - FileInfo + IWebDriver - FileInfo + IWebDriver None - - Fullscreen - - Driver will open browser in a fullscreen state - - SwitchParameter - - SwitchParameter - - - False - - - Headless - - Start driver without any visual interface - - SwitchParameter - - SwitchParameter - - - False - - - ImplicitWait + + Name - Control timeout duration (in seconds) + SeFriendlyName of the browser to select. - Int32 + String - Int32 + String None - - Maximized - - Driver will open browser in a maximized state - - SwitchParameter + + + - SwitchParameter - + None - 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 + System.Object @@ -5126,16 +5400,17 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - $Driver = Start-SeFirefox + PS C:\> $Driver = Start-SeDriver -Browser Chrome +# Chrome is the only and default driver +PS C:\> Get-SeDriver -Current +PS C:\> Start-SeDriver -Browser Firefox +# Firefox is now the default browser +PS C:\> Get-SeDriver -Current +PS C:\> Switch-SeDriver -Driver $Driver +# Chrome is the default browser again +PS C:\> Get-SeDriver -Current - - - - - -------------------------- 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 + This examples show the default browser changing from Chrome to Firefox when the second instance is launched, then set back to Chrome through Switch-SeDriver @@ -5143,1932 +5418,23 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - Start-SeInternetExplorer - Start - SeInternetExplorer + Switch-SeFrame + Switch + SeFrame - {{ Fill in the Synopsis }} + Instructs the driver to send future commands to a different frame - {{ Fill in the Description }} + Instructs the driver to send future commands to a different frame - - 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 + + Switch-SeFrame + + Frame - Driver will use the specified user profile path + {{ Fill Frame Description }} Object @@ -7077,10 +5443,13 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' None - - Quiet + + + Switch-SeFrame + + Parent - Hide command prompt window + {{ Fill Parent Description }} SwitchParameter @@ -7088,49 +5457,27 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - WebDriverDirectory + + + Switch-SeFrame + + Root - {{ Fill WebDriverDirectory Description }} + {{ Fill Root Description }} - Object - Object + SwitchParameter - None + False - - AsDefaultDriver - - {{ Fill AsDefaultDriver Description }} - - SwitchParameter - - SwitchParameter - - - False - - - BinaryPath - - {{ Fill BinaryPath Description }} - - Object - - Object - - - None - - - DefaultDownloadPath + + Frame - {{ Fill DefaultDownloadPath Description }} + {{ Fill Frame Description }} Object @@ -7140,57 +5487,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'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 + Parent - Driver will open browser in a maximized state + {{ Fill Parent Description }} SwitchParameter @@ -7200,21 +5499,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder'False - Minimized - - Driver will open browser in a minimized state - - SwitchParameter - - SwitchParameter - - - False - - - PrivateBrowsing + Root - Driver will open a private session + {{ Fill Root Description }} SwitchParameter @@ -7223,46 +5510,77 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' False - - ProfileDirectoryPath - - Driver will use the specified user profile path - - Object - - Object - - - None - - - Quiet - - Hide command prompt window - - SwitchParameter + + + - SwitchParameter - + System.Object - False - - - StartURL - - Define Driver starting URL - - String + + + + + + + - String - + System.Object - None - - - WebDriverDirectory + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + + + + + + + + + + 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 + + Window + + {{ Fill Window Description }} + + Object + + Object + + + None + + + + + + Window - {{ Fill WebDriverDirectory Description }} + {{ Fill Window Description }} Object @@ -7275,7 +5593,7 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - None + OpenQA.Selenium.IWebDriver @@ -7297,40 +5615,61 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - - -------------------------- Example 1 -------------------------- - PS C:\> {{ Add example code here }} - - {{ Add example description here }} - - - + - Stop-SeDriver - Stop + Update-SeDriver + Update SeDriver - Quits this driver, closing every associated window. + {{ Fill in the Synopsis }} - Quits this driver, closing every associated window. + {{ Fill in the Description }} - Stop-SeDriver - - Target + Update-SeDriver + + Browser - Driver to dispose. When `-AsDefaultDriver` is used with the Start-XXDriver cmdlet, this parameter can be omitted. + {{ Fill Browser Description }} - IWebDriver + Object - IWebDriver + Object + + + None + + + OS + + {{ Fill OS Description }} + + + Linux + Mac + Windows + + Object + + Object + + + None + + + Path + + {{ Fill Path Description }} + + Object + + Object None @@ -7338,14 +5677,38 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - - Target + + Browser + + {{ Fill Browser Description }} + + Object + + Object + + + None + + + OS - Driver to dispose. When `-AsDefaultDriver` is used with the Start-XXDriver cmdlet, this parameter can be omitted. + {{ Fill OS Description }} - IWebDriver + Object - IWebDriver + Object + + + None + + + Path + + {{ Fill Path Description }} + + Object + + Object None @@ -7354,7 +5717,7 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' - OpenQA.Selenium.IWebDriver + None @@ -7379,17 +5742,9 @@ PS C:\> Get-SeElementAttribute -Element $Element -Attribute 'placeholder' -------------------------- Example 1 -------------------------- - PS C:\> Stop-SeDriver -Target $Driver - - Stop the specified driver - - - - -------------------------- Example 1 -------------------------- - PS C:\> Start-SeChrome -AsDefaultDriver -PS C:\> Stop-SeDriver + PS C:\> {{ Add example code here }} - Stop the default driver, which was defined using the `-AsDefaultDriver` switch. + {{ Add example description here }} @@ -7397,35 +5752,23 @@ PS C:\> Stop-SeDriver - Switch-SeFrame - Switch - SeFrame + Wait-SeDriver + Wait + SeDriver - Instructs the driver to send future commands to a different frame + Wait for the driver to be in the desired state. - Instructs the driver to send future commands to a different frame + Wait for the driver to be in the desired state. - Switch-SeFrame + Wait-SeDriver - Frame - - {{ Fill Frame Description }} - - Object - - Object - - - None - - - Target + Condition - {{ Fill Target Description }} + Condition that is expected to be met. Object @@ -7434,24 +5777,10 @@ PS C:\> Stop-SeDriver None - - - Switch-SeFrame - - Parent - - {{ Fill Parent Description }} - - - SwitchParameter - - - False - - - Target + + Value - {{ Fill Target Description }} + Condition value expected to be met. Object @@ -7460,28 +5789,14 @@ PS C:\> Stop-SeDriver None - - - Switch-SeFrame - - Root - - {{ Fill Root Description }} - - - SwitchParameter - - - False - - - Target + + Timeout - {{ Fill Target Description }} + Time delimiter in second for which the operation should succeed. - Object + Double - Object + Double None @@ -7490,9 +5805,9 @@ PS C:\> Stop-SeDriver - Frame + Condition - {{ Fill Frame Description }} + Condition that is expected to be met. Object @@ -7501,34 +5816,22 @@ PS C:\> Stop-SeDriver None - - Parent - - {{ Fill Parent Description }} - - SwitchParameter - - SwitchParameter - - - False - - - Root + + Timeout - {{ Fill Root Description }} + Time delimiter in second for which the operation should succeed. - SwitchParameter + Double - SwitchParameter + Double - False + None - - Target + + Value - {{ Fill Target Description }} + Condition value expected to be met. Object @@ -7566,9 +5869,9 @@ PS C:\> Stop-SeDriver -------------------------- Example 1 -------------------------- - PS C:\> {{ Add example code here }} + PS C:\> Wait-SeDriver -Condition UrlContains 'next-' -Timeout 5.5 - {{ Add example description here }} + Wait 5.5 seconds for the driver URL to contains text "next-" @@ -7576,35 +5879,108 @@ PS C:\> Stop-SeDriver - Switch-SeWindow - Switch - SeWindow + Wait-SeElement + Wait + SeElement - Instructs the driver to send future commands to a different window + Wait for an element condition to be met. - Instructs the driver to send future commands to a different window + Wait for an element condition to be met. - Switch-SeWindow - - Target + Wait-SeElement + + By - {{ Fill Target Description }} + Locator element. - IWebDriver + + ClassName + CssSelector + Id + LinkText + PartialLinkText + Name + TagName + XPath + + SeBySelector - IWebDriver + SeBySelector None - Window + Value - {{ Fill Window Description }} + Value of the locator corresponding to the element that should match the Condition / ConditionValue. + + String + + String + + + None + + + Condition + + Condition expected to be met. Some condition are only available with locator or element. + + Object + + Object + + + None + + + ConditionValue + + Value of the expected condition to be met. + + Object + + Object + + + None + + + Timeout + + Time delimiter in second for which the operation should succeed. + + Double + + Double + + + None + + + + Wait-SeElement + + Condition + + Condition expected to be met. Some condition are only available with locator or element. + + Object + + Object + + + None + + + ConditionValue + + Value of the expected condition to be met. Object @@ -7613,25 +5989,61 @@ PS C:\> Stop-SeDriver None + + Element + + Element that need to meet the condition. + + IWebElement + + IWebElement + + + None + + + Timeout + + Time delimiter in second for which the operation should succeed. + + Double + + Double + + + None + - - Target + + By - {{ Fill Target Description }} + Locator element. - IWebDriver + SeBySelector - IWebDriver + SeBySelector None - - Window + + Condition - {{ Fill Window Description }} + Condition expected to be met. Some condition are only available with locator or element. + + Object + + Object + + + None + + + ConditionValue + + Value of the expected condition to be met. Object @@ -7640,11 +6052,47 @@ PS C:\> Stop-SeDriver None + + Element + + Element that need to meet the condition. + + IWebElement + + IWebElement + + + None + + + Timeout + + Time delimiter in second for which the operation should succeed. + + Double + + Double + + + None + + + Value + + Value of the locator corresponding to the element that should match the Condition / ConditionValue. + + String + + String + + + None + - OpenQA.Selenium.IWebDriver + System.Object @@ -7669,9 +6117,9 @@ PS C:\> Stop-SeDriver -------------------------- Example 1 -------------------------- - PS C:\> {{ Add example code here }} + PS C:\> Wait-SeElement -Element $Element -Condition StalenessOf - {{ Add example description here }} + Wait for the specified element to not exist anymore in the DOM for 3 seconds (default timeout) diff --git a/Output/Selenium/formats/Selenium.format.ps1xml b/Output/Selenium/formats/Selenium.format.ps1xml new file mode 100644 index 0000000..0fb5aed --- /dev/null +++ b/Output/Selenium/formats/Selenium.format.ps1xml @@ -0,0 +1,161 @@ + + + + + + OpenQA.Selenium.Remote.RemoteWebElement + + OpenQA.Selenium.Remote.RemoteWebElement + + + + + left + 7 + + + left + 7 + + + left + 9 + + + Left + 80 + + + + + + + Tagname + + + Enabled + + + Displayed + + + Text + + + + + + + + OpenQA.Selenium.Remote.RemoteWebElement + + OpenQA.Selenium.Remote.RemoteWebElement + + + + + + + Tagname + + + Text + + + Enabled + + + Selected + + + Location + + + Size + + + Displayed + + + + + + + + selenium-powershell/SeFrame + + selenium-powershell/SeFrame + + + + + + + + + + + + + + + + + + + TagName + + + Enabled + + + $_.Attributes.name + + + $_.Attributes.id + + + + + + + + SeSelectValueInfo + + selenium-powershell/SeSelectValueInfo + + + + + + + IsMultiSelect + + + + + + + ($_.Items.Count -ne 0) + + + + $output = [System.Text.StringBuilder]::new(); + $TextMax = ($_.Items.Text | Measure-Object -Maximum).Maximum.length + $ValueMax = ($_.Items.Value | Measure-Object -Maximum).Maximum.length + [void]($Output.AppendFormat("Index {0} {1} Selected`n", 'Text'.PadRight($TextMax, ' '), 'Value'.PadRight($ValueMax, ' '))) + [void]($Output.AppendFormat("----- {0} {1} --------`n", '----'.PadRight($TextMax, ' '), '-----'.PadRight($ValueMax, ' '))) + foreach ($I in $_.Items) { + $IsSelected = if ($I.Selected) {" *"} else {''} + [Void]($output.AppendFormat("{0} {1} {2} {3}`n", "$($I.Index)".PadLeft(5, ' '), "$($I.Text)".PadRight($TextMax, ' '), "$($I.Value)".PadRight($ValueMax, ' '), $IsSelected)) + }; + $output.ToString().Trim("`n"); + + + + + + + + + diff --git a/Output/Selenium/types/Selenium.types.ps1xml b/Output/Selenium/types/Selenium.types.ps1xml new file mode 100644 index 0000000..a70253c --- /dev/null +++ b/Output/Selenium/types/Selenium.types.ps1xml @@ -0,0 +1,54 @@ + + + + + OpenQA.Selenium.Remote.RemoteWebElement + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Tagname + Enabled + Displayed + Text + + + + + + + + OpenQA.Selenium.Remote.RemoteWebDriver + + + PSStandardMembers + + + DefaultDisplayPropertySet + + SeFriendlyName + SeBrowser + SeTitle + SeUrl + + + + + + SeUrl + + if ($null -ne $this.SessionId) { $this.Url } + + + + SeTitle + + if ($null -ne $this.SessionId) { $this.Title } + + + + + diff --git a/Public/Clear-SeAlert.ps1 b/Public/Clear-SeAlert.ps1 index 8606730..986b4be 100644 --- a/Public/Clear-SeAlert.ps1 +++ b/Public/Clear-SeAlert.ps1 @@ -1,23 +1,36 @@ function Clear-SeAlert { - [Alias('SeAccept', 'SeDismiss')] + [CmdletBinding()] 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')] + [parameter(ParameterSetName = 'Alert', ValueFromPipeline = $true)] + $Alert, [switch]$PassThru ) - if ($Target) { - try { $Alert = $Target.SwitchTo().alert() } - catch { Write-Warning 'No alert was displayed'; return } + Begin { + $Driver = Init-SeDriver -ErrorAction Stop + $ImpTimeout = 0 + } + Process { + if ($Driver) { + try { + $ImpTimeout = Disable-SeDriverImplicitTimeout -Driver $Driver + $WebDriverWait = [OpenQA.Selenium.Support.UI.WebDriverWait]::new($Driver, (New-TimeSpan -Seconds 10)) + $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::AlertIsPresent() + $WebDriverWait.Until($Condition) + $Alert = $Driver.SwitchTo().alert() + } + catch { + Write-Warning 'No alert was displayed' + return + } + Finally { + Enable-SeDriverImplicitTimeout -Driver $Driver -Timeout $ImpTimeout + } + } + if ($Alert) { $alert.$action() } + if ($PassThru) { $Alert } } - 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 + End {} +} + diff --git a/Public/Clear-SeSelectValue.ps1 b/Public/Clear-SeSelectValue.ps1 new file mode 100644 index 0000000..3b57096 --- /dev/null +++ b/Public/Clear-SeSelectValue.ps1 @@ -0,0 +1,10 @@ +function Clear-SeSelectValue { + [Cmdletbinding()] + param ( + [Parameter(Mandatory = $true)] + [OpenQA.Selenium.IWebElement]$Element + ) + [SeleniumSelection.Option]::DeselectAll($Element) + +} + diff --git a/Public/ConvertTo-SeSelenium.ps1 b/Public/ConvertTo-SeSelenium.ps1 new file mode 100644 index 0000000..3a3680a --- /dev/null +++ b/Public/ConvertTo-SeSelenium.ps1 @@ -0,0 +1,111 @@ +function ConvertTo-Selenium { + <# + .SYNOPSIS + Convert Selenium IDE .side recording file to PowerShell commands. + #> + [CmdletBinding()] + param ( + # Path to .side file. + [Parameter(Mandatory)] + [String]$Path + ) + + $ByMap = @{ + id = 'Id' + css = 'CssSelector' + xpath = 'XPath' + linkText = 'LinkText' + label = 'Text' + index = 'Index' + } + function Get-Replace { + <# + .SYNOPSIS + Helper function to convert ScriptBlocks to strings. + + Parameter set 1: + Replace -From [String] with -To [String]. + -QuotesTo adds quotes around -To. + -SplitTo take only the value part from "label=value" of -To. + + Parameter set 2: + -By "label=value" replaces input "-By $By" with "-By -value ''". + * $ByMap is used to map the labels. + #> + [CmdletBinding()] + param ( + [String]$From, + [String]$To, + [String]$By, + [Parameter(ValueFromPipeline)] + $InputObject, + [switch]$QuotesTo, + [switch]$SplitTo + ) + process { + $String = $InputObject.ToString().Trim() + if ($From) { + if ($QuotesTo) { + $To = '"' + $To + '"' + } + if ($SplitTo) { + $To = $To.Split('=', 2)[1] + } + $String = $String.Replace($From, $To) + } + if ($By) { + $String = $String.Replace('-By $By', ('-By {0} -value {1}' -f $ByMap[$By.Split('=', 2)[0]], ('"' + $By.Split('=', 2)[1] + '"'))) + } + $String + } + } + + $ActionMap = @{ + click = { Invoke-SeClick } + doubleClick = { Invoke-SeClick -Action DoubleClick } + sendKeys = { Invoke-SeKeys -Keys $Keys } + type = { Invoke-SeKeys -Keys $Keys } + select = { Set-SeSelectValue -By $By } + } + + $Recording = Get-Content -Path $Path | ConvertFrom-Json + $BaseUrl = [Uri]$Recording.url + $PsCode = $( + '# Project: ' + $Recording.name + foreach ($Test in $Recording.tests) { + '# Test: ' + $Test.name + foreach ($Command in $Test.commands) { + switch ($Command) { + { $_.comment } { '# Description: ' + $_.comment } + { $_.command -eq 'open' } { + $Url = if ([Uri]::IsWellFormedUriString($_.target, [System.UriKind]::Relative)) { + [Uri]::new($BaseUrl, $_.target) + } + else { + $_.target + } + { Set-SeUrl -Url $Url } | Get-Replace -From '$Url' -To $Url -QuotesTo + Break + } + { $_.command -eq 'close' } { { Stop-SeDriver } ; Break } + { $_.command -in $ActionMap.Keys } { + $Action = $ActionMap[$_.command] | Get-Replace -From '$Keys' -To ($_.value.Replace('${KEY_ENTER}', '{{Enter}}')) -QuotesTo -By $_.value + { Get-SeElement -By $By | _Action_ } | Get-Replace -From '_Action_' -To $Action -By $_.target + Break + } + { $_.command -eq 'selectFrame' } { + if ($_.target -eq 'relative=parent') { + { Switch-SeFrame -Parent } + } + else { + { Switch-SeFrame -Frame $Index } | Get-Replace -From '$Index' -To $_.target -SplitTo + } + Break + } + Default { '# Unsupported command. Command: "{0}", Target: "{1}", Value: "{2}", Comment: "{3}".' -f $_.command, $_.target, $_.value, $_.comment } + } + } + } + ) | Get-Replace + [ScriptBlock]::Create($PsCode -join [Environment]::NewLine) +} \ No newline at end of file diff --git a/Public/Get-SeCookie.ps1 b/Public/Get-SeCookie.ps1 index 27908e3..3fd6497 100644 --- a/Public/Get-SeCookie.ps1 +++ b/Public/Get-SeCookie.ps1 @@ -1,9 +1,6 @@ function Get-SeCookie { - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver - ) - $Target.Manage().Cookies.AllCookies.GetEnumerator() + [CmdletBinding()] + param() + $Driver = Init-SeDriver -ErrorAction Stop + $Driver.Manage().Cookies.AllCookies.GetEnumerator() } \ No newline at end of file diff --git a/Public/Get-SeDriver.ps1 b/Public/Get-SeDriver.ps1 new file mode 100644 index 0000000..794db60 --- /dev/null +++ b/Public/Get-SeDriver.ps1 @@ -0,0 +1,50 @@ + +function Get-SeDriver { + [cmdletbinding(DefaultParameterSetName = 'All')] + param( + [parameter(ParameterSetName = 'Current', Mandatory = $false)] + [Switch]$Current, + [parameter(Position = 0, ParameterSetName = 'ByName', Mandatory = $false)] + [String]$Name, + [parameter(ParameterSetName = 'ByBrowser', Mandatory = $false)] + [ArgumentCompleter( { [Enum]::GetNames([SeBrowsers]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBrowsers]) })] + $Browser + + + + ) + + $Output = $null + switch ($PSCmdlet.ParameterSetName) { + 'All' { $Output = $Script:SeDrivers; break } + 'Current' { $Output = $Script:SeDriversCurrent; break } + 'ByName' { $Output = $Script:SeDrivers.Where( { $_.SeFriendlyName -eq $Name }, 'first' ); break } + 'ByBrowser' { $Output = $Script:SeDrivers.Where( { $_.SeBrowser -like "$Browser*" }); break } + } + + if ($null -eq $Output) { return } + + $DriversToClose = [System.Collections.Generic.List[PSObject]]::new() + Foreach ($drv in $Output) { + $Processes = (Get-Process -Id $Drv.SeProcessId, $Drv.SeServiceProcessId -ErrorAction SilentlyContinue ) + if ($Processes.count -eq 2) { Continue } + + if ($Processes.count -eq 0) { + Write-Warning -Message "The driver $($Drv.SeFriendlyName) $($Drv.SeBrowser) processes are not running anymore and have been removed automatically from the list of available drivers." + } + else { + $ProcessType = if ($Processes.id -eq $Drv.SeServiceProcessId) { "driver service" } else { "browser" } + Write-Warning -Message "The driver $($Drv.SeFriendlyName) $($Drv.SeBrowser) $ProcessType is not running anymore and will be removed from the active driver list." + } + $DriversToClose.Add($Drv) + } + + if ($DriversToClose.Count -gt 0) { + foreach ($drv in $DriversToClose) { + $Output = $Output.Where( { $_.SeServiceProcessId -ne $drv.SeServiceProcessId }) + Stop-SeDriver -Driver $drv + } + } + return $Output +} \ No newline at end of file diff --git a/Public/Get-SeDriverTimeout.ps1 b/Public/Get-SeDriverTimeout.ps1 new file mode 100644 index 0000000..1f51a0d --- /dev/null +++ b/Public/Get-SeDriverTimeout.ps1 @@ -0,0 +1,16 @@ +function Get-SeDriverTimeout { + [CmdletBinding()] + param( + [Parameter(Position = 0)] + [ValidateSet('ImplicitWait', 'PageLoad', 'AsynchronousJavaScript')] + $TimeoutType = 'ImplicitWait' + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + Process { + return $Driver.Manage().Timeouts().$TimeoutType + } + End {} +} + diff --git a/Public/Get-SeElement.ps1 b/Public/Get-SeElement.ps1 index cb1e07c..76c27df 100644 --- a/Public/Get-SeElement.ps1 +++ b/Public/Get-SeElement.ps1 @@ -1,48 +1,142 @@ +#TODO Positional binding $Element = Get-SeElement Tagname 'Select' function Get-SeElement { - [Alias('Find-SeElement', 'SeElement')] + [Cmdletbinding(DefaultParameterSetName = 'Default')] 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")] + [ArgumentCompleter( { [Enum]::GetNames([SeBySelector]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBySelector]) })] + [SeBySelector[]]$By = [SeBySelector]::XPath, [Parameter(Position = 1, Mandatory = $true)] - [string]$Selection, + [string[]]$Value, #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(Position = 2, ParameterSetName = 'Default')] + [Double]$Timeout = 0, + [Parameter(Position = 3, ValueFromPipeline = $true, Mandatory = $true, ParameterSetName = 'ByElement')] + [OpenQA.Selenium.IWebElement] + $Element, + [Switch]$All, + [ValidateNotNullOrEmpty()] + [String[]]$Attributes, + [Switch]$Single + ) + Begin { + $Driver = Init-SeDriver -ErrorAction Stop + $ShowAll = $PSBoundParameters.ContainsKey('All') -and $PSBoundParameters.Item('All') -eq $true + if ($By.Count -ne $Value.Count) { + Throw [System.InvalidOperationException]::new("An equal number of `$By element ($($By.Count)) and `$Value ($($Value.Count)) must be provided.") + } + Filter DisplayedFilter([Switch]$All) { + if ($All) { $_ } else { if ($_.Displayed) { $_ } } + } + $Output = $null + $ByCondition = $null - [parameter(DontShow)] - [Switch]$Wait + - ) + if ($by.Count -gt 1) { + $ByChainedArgs = for ($i = 0; $i -lt $by.Count; $i++) { + $cby = $by[$i] + $CValue = $value[$i] + if ($cby -eq ([SeBySelector]::ClassName)) { + $spl = $CValue.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) + if ($spl.count -gt 1) { + $Cby = [SeBySelector]::CssSelector + $CValue = ".$($spl -join '.')" + } + } + [OpenQA.Selenium.By]::$cby($CValue) + } + $ByCondition = [OpenQA.Selenium.Support.PageObjects.ByChained]::new($ByChainedArgs) + } + else { + if ($By[0] -eq ([SeBySelector]::ClassName)) { + $spl = $Value.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) + if ($spl.Count -gt 1) { + $by = [SeBySelector]::CssSelector + $Value = ".$($spl -join '.')" + } + } + $ByCondition = [OpenQA.Selenium.By]::$By($Value) + } + + $ImpTimeout = -1 + if ($By.Count -gt 1 -or $PSBoundParameters.ContainsKey('Timeout')) { + $ImpTimeout = Disable-SeDriverImplicitTimeout -Driver $Driver + } + #Id Should always be considered as Single + if ($By.Contains('Id') -and !$PSBoundParameters.ContainsKey('Single')) { + $PSBoundParameters.Add('Single', $true) + } + } 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 } + + + switch ($PSCmdlet.ParameterSetName) { + 'Default' { + if ($Timeout) { + $WebDriverWait = [OpenQA.Selenium.Support.UI.WebDriverWait]::new($Driver, ([timespan]::FromMilliseconds($Timeout * 1000))) + $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::PresenceOfAllElementsLocatedBy($ByCondition) + $Output = $WebDriverWait.Until($Condition) | DisplayedFilter -All:$ShowAll + } + else { + $Output = $Driver.FindElements($ByCondition) | DisplayedFilter -All:$ShowAll + } + } + 'ByElement' { + Write-Verbose "Searching an Element - Timeout ignored" + $Output = $Element.FindElements($ByCondition) | DisplayedFilter -All:$ShowAll + } + } + + + + if ($PSBoundParameters.ContainsKey('Attributes')) { + $GetAllAttributes = $Attributes.Count -eq 1 -and $Attributes[0] -eq '*' + + if ($GetAllAttributes) { + Foreach ($Item in $Output) { + $AllAttributes = $Driver.ExecuteScript('var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;', $Item) + $AttArray = [System.Collections.Generic.Dictionary[String, String]]::new() - 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." } + Foreach ($AttKey in $AllAttributes.Keys) { + $AttArray.Add($AttKey, $AllAttributes[$AttKey]) + } + + Add-Member -InputObject $Item -Name 'Attributes' -Value $AttArray -MemberType NoteProperty + } + } + else { + foreach ($Item in $Output) { + $AttArray = [System.Collections.Generic.Dictionary[String, String]]::new() + + foreach ($att in $Attributes) { + $Value = $Item.GetAttribute($att) + if ($Value -ne "") { + $AttArray.Add($att, $Item.GetAttribute($att)) + } + + } + Add-Member -InputObject $Item -Name 'Attributes' -Value $AttArray -MemberType NoteProperty + } + } + + } + if ($null -eq $Output) { + $Message = "no such element: Unable to locate element by: $($By -join ',') with value $($Value -join ',')" + Write-Error -Exception ([System.Management.Automation.ItemNotFoundException]::new($Message)) + return + } + elseif ($PSBoundParameters.ContainsKey('Single') -and $Single -eq $true -and $Output.count -gt 1) { + $Message = "A single element was expected but $($Output.count) elements were found using the locator $($By -join ',') with value $($Value -join ',')." + Write-Error -Exception ([System.InvalidOperationException]::new($Message)) + return + } + else { + return $Output + } + } + End { + if ($ImpTimeout -ne -1) { Enable-SeDriverImplicitTimeout -Driver $Driver -Timeout $ImpTimeout } + } } \ No newline at end of file diff --git a/Public/Get-SeElementAttribute.ps1 b/Public/Get-SeElementAttribute.ps1 index c0c984b..6d35003 100644 --- a/Public/Get-SeElementAttribute.ps1 +++ b/Public/Get-SeElementAttribute.ps1 @@ -1,11 +1,44 @@ function Get-SeElementAttribute { + [CmdletBinding()] param( [Parameter(ValueFromPipeline = $true, Mandatory = $true)] [OpenQA.Selenium.IWebElement]$Element, [Parameter(Mandatory = $true)] - [string]$Attribute + [string[]]$Name ) + Begin { + $Script = 'var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;' + } process { - $Element.GetAttribute($Attribute) + $AllAttributes = $Name.Count -eq 1 -and $Name[0] -eq '*' + $ManyAttributes = $Name.Count -gt 1 + + if ($AllAttributes) { + $AllAttributes = $Element.WrappedDriver.ExecuteScript($Script, $Element) + $Output = @{} + + Foreach ($Att in $AllAttributes.Keys) { + $value = $Element.GetAttribute($Att) + if ($value -ne "") { + $Output.$Att = $value + } + } + [PSCustomObject]$Output + } + elseif ($ManyAttributes) { + $Output = @{} + Foreach ($Att in $Name) { + $value = $Element.GetAttribute($Att) + if ($value -ne "") { + $Output.$Att = $value + } + } + [PSCustomObject]$Output + } + else { + $Element.GetAttribute($Name) + } + + } } \ No newline at end of file diff --git a/Public/Get-SeElementCssValue.ps1 b/Public/Get-SeElementCssValue.ps1 index 5045bb1..3c47e96 100644 --- a/Public/Get-SeElementCssValue.ps1 +++ b/Public/Get-SeElementCssValue.ps1 @@ -1,12 +1,53 @@ function Get-SeElementCssValue { + [CmdletBinding()] param( [Parameter(ValueFromPipeline = $true, Mandatory = $true)] [OpenQA.Selenium.IWebElement]$Element, [Parameter(Mandatory = $true)] - [string]$Name + [string[]]$Name ) - + Begin { + $ScriptAllValues = @' + var items = {}; +var o = getComputedStyle(arguments[0]); +for(var i = 0; i < o.length; i++){ + items[o[i]] = o.getPropertyValue(o[i]) +} +return items; +'@ + } Process { - $Element.GetCssValue($Name) + $AllValues = $Name.Count -eq 1 -and $Name[0] -eq '*' + $ManyValues = $Name.Count -gt 1 + + + if ($AllValues) { + + $AllCSSNames = $Element.WrappedDriver.ExecuteScript($ScriptAllValues, $Element) + $Output = @{} + + Foreach ($Att in $AllCSSNames.Keys) { + $value = $Element.GetCssValue($Att) + if ($value -ne "") { + $Output.$Att = $value + } + } + [PSCustomObject]$Output + } + elseif ($ManyValues) { + $Output = @{} + Foreach ($Item in $Name) { + $Value = $Element.GetCssValue($Item) + if ($Value -ne "") { + $Output.$Item = $Value + } + } + [PSCustomObject]$Output + } + else { + $Element.GetCssValue($Name) + } + + } -} \ No newline at end of file +} diff --git a/Public/Get-SeFrame.ps1 b/Public/Get-SeFrame.ps1 new file mode 100644 index 0000000..de164f7 --- /dev/null +++ b/Public/Get-SeFrame.ps1 @@ -0,0 +1,14 @@ +function Get-SeFrame { + [cmdletbinding()] + param() + + $Driver = Init-SeDriver -ErrorAction Stop + + Get-SeElement -By TagName -Value iframe -Attributes name, id -ErrorAction SilentlyContinue | + ForEach-Object { + $_.Psobject.TypeNames.Insert(0, 'selenium-powershell/SeFrame') + $_ + } + +} + diff --git a/Public/Get-SeHtml.ps1 b/Public/Get-SeHtml.ps1 new file mode 100644 index 0000000..bf282f6 --- /dev/null +++ b/Public/Get-SeHtml.ps1 @@ -0,0 +1,22 @@ +function Get-SeHtml { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [switch]$Inner + ) + Begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + Process { + if ($PSBoundParameters.ContainsKey('Element')) { + if ($Inner) { return $Element.GetAttribute('innerHTML') } + return $Element.GetAttribute('outerHTML') + } + else { + $Driver.PageSource + } + + } +} + diff --git a/Public/Get-SeInput.ps1 b/Public/Get-SeInput.ps1 new file mode 100644 index 0000000..af2490e --- /dev/null +++ b/Public/Get-SeInput.ps1 @@ -0,0 +1,48 @@ +function Get-SeInput { + [CmdletBinding()] + param( + [ArgumentCompleter( { @('button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', 'url', 'week') })] + [String]$Type, + [Switch]$Single, + [String]$Text, + [Double]$Timeout, + [Switch]$All, + [String[]]$Attributes, + [String]$Value + + + ) + Begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + Process { + $MyAttributes = @{} + $SelectedAttribute = "" + Filter ConditionFilter($Type, $Text, $Value, $Attribute) { + if ("" -ne $Type) { if ($_.Attributes.type -ne $type) { return } } + if ("" -ne $Text) { if ($_.Text -ne $Text ) { return } } + if ("" -ne $Value -and "" -ne $Attribute) { if ($_.Attributes.$Attribute -ne $Value ) { return } } + $_ + } + + if ($PSBoundParameters.Remove('Attributes')) { + $MyAttributes = @{Attributes = [System.Collections.Generic.List[String]]$Attributes } + if ($Attributes[0] -ne '*') { $SelectedAttribute = $MyAttributes.Attributes[0] } + } + if ($PSBoundParameters.Remove('Type')) { + if ($null -eq $Attributes) { + $MyAttributes = @{Attributes = 'type' } + } + else { + if (-not $Attributes.contains('type') -and -not $Attributes.contains('*')) { + $MyAttributes.Attributes.add('type') + } + } + + + } + [void]($PSBoundParameters.Remove('Value')) + Get-SeElement -By TagName -Value input @PSBoundParameters @MyAttributes | ConditionFilter -Type $Type -Text $Text -Value $Value -Attribute $SelectedAttribute + } +} + diff --git a/Public/Get-SeKeys.ps1 b/Public/Get-SeKeys.ps1 index 1517a2b..7506e41 100644 --- a/Public/Get-SeKeys.ps1 +++ b/Public/Get-SeKeys.ps1 @@ -1,3 +1,5 @@ function Get-SeKeys { - [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } } + [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-SeSelectValue.ps1 b/Public/Get-SeSelectValue.ps1 new file mode 100644 index 0000000..3b3849e --- /dev/null +++ b/Public/Get-SeSelectValue.ps1 @@ -0,0 +1,51 @@ +function Get-SeSelectValue { + [CmdletBinding()] + [cmdletbinding(DefaultParameterSetName = 'default')] + param ( + [Parameter( ValueFromPipeline = $true, Mandatory = $true, Position = 1)] + [OpenQA.Selenium.IWebElement]$Element, + [Switch]$All + ) + try { + $IsMultiSelectResult = [SeleniumSelection.Option]::IsMultiSelect($Element) + + + $SelectStatement = if ($IsMultiSelectResult) { 'GetAllSelectedOptions' } else { 'GetSelectedOption' } + $Selected = [SeleniumSelection.Option]::$SelectStatement($Element) + $Items = @(foreach ($item in $Selected) { + [PSCustomObject]@{ + Text = $Item.text + Value = Get-SeElementAttribute -Element $Item -Name value + } + }) + + if (-not $All) { + return $Items + } + else { + + $Index = 0 + $Options = Get-SeElement -Element $Element -By Tagname -Value option -Attributes value + $Values = foreach ($Opt in $Options) { + [PSCustomObject]@{ + Index = $Index + Text = $Opt.text + Value = $opt.Attributes.value + Selected = $Null -ne $Items.Value -and $Items.Value.Contains($opt.Attributes.value) + } + $Index += 1 + } + return [PSCustomObject]@{ + PSTypeName = 'selenium-powershell/SeSelectValueInfo' + IsMultiSelect = [SeleniumSelection.Option]::IsMultiSelect($Element) + Items = $Values + } + } + + + + } + 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-SeSelectionOption.ps1 b/Public/Get-SeSelectionOption.ps1 deleted file mode 100644 index f9667cf..0000000 --- a/Public/Get-SeSelectionOption.ps1 +++ /dev/null @@ -1,90 +0,0 @@ -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-SeUrl.ps1 b/Public/Get-SeUrl.ps1 index 25315bf..7da597a 100644 --- a/Public/Get-SeUrl.ps1 +++ b/Public/Get-SeUrl.ps1 @@ -20,28 +20,21 @@ function Get-SeUrl { To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. #> [CmdletBinding()] - [Alias('Get-SeLocation')] param( # Optionally retrieve the stored URL stack for the target or default # webdriver instance. [Parameter()] [switch] - $Stack, - - # The webdriver instance for which to retrieve the current URL or - # internal URL stack. - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver + $Stack ) - + $Driver = Init-SeDriver -ErrorAction Stop + if ($Stack) { - if ($Script:SeLocationMap[$Target].Count -gt 0) { - $Script:SeLocationMap[$Target].ToArray() + if ($Script:SeLocationMap[$Driver].Count -gt 0) { + $Script:SeLocationMap[$Driver].ToArray() } } else { - $Target.Url + $Driver.Url } } diff --git a/Public/Get-SeWindow.ps1 b/Public/Get-SeWindow.ps1 index c35a32a..cb65154 100644 --- a/Public/Get-SeWindow.ps1 +++ b/Public/Get-SeWindow.ps1 @@ -1,12 +1,10 @@ function Get-SeWindow { - param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver - ) - + [CmdletBinding()] + param() + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } process { - $Target.WindowHandles + $Driver.WindowHandles } } \ No newline at end of file diff --git a/Public/Invoke-SeClick.ps1 b/Public/Invoke-SeClick.ps1 index fcf1b19..23cc6a3 100644 --- a/Public/Invoke-SeClick.ps1 +++ b/Public/Invoke-SeClick.ps1 @@ -1,28 +1,54 @@ function Invoke-SeClick { - [CmdletBinding(DefaultParameterSetName = 'Default')] + [CmdletBinding()] param( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Default')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'JavaScript')] + [parameter(Position = 0, HelpMessage = 'test')] + [ArgumentCompleter([SeMouseClickActionCompleter])] + [ValidateScript( { $_ -in $Script:SeMouseClickAction.Text })] + $Action = 'Click', + [Parameter( ValueFromPipeline = $true, Position = 1)] + [ValidateNotNull()] [OpenQA.Selenium.IWebElement]$Element, - - [Parameter(Mandatory = $true, ParameterSetName = 'JavaScript')] - [Switch]$JavaScriptClick, - - [Parameter(ParameterSetName = 'JavaScript')] - [ValidateIsWebDriverAttribute()] - $Driver = $global:SeDriver + [Double]$Sleep = 0 , + [switch]$PassThru ) - if ($JavaScriptClick) { - try { - $Driver.ExecuteScript("arguments[0].click()", $Element) - } - catch { - $PSCmdlet.ThrowTerminatingError($_) - } - } - else { - $Element.Click() + begin { + $Driver = Init-SeDriver -ErrorAction Stop + $HasElement = $PSBoundParameters.ContainsKey('Element') -or $PSCmdlet.MyInvocation.ExpectingInput + if ($Action -eq 'Click_JS' -and -not $HasElement) { + Write-Error 'Click_JS can only be performed if an $Element is specified' + return $null + } } + Process { + Write-Verbose "Performing $Action" + switch ($Action) { + 'Click_Js' { + try { $Driver.ExecuteScript("arguments[0].click()", $Element) } + catch { $PSCmdlet.ThrowTerminatingError($_) } + } + Default { + $Interaction = [OpenQA.Selenium.Interactions.Actions]::new($Driver) + if ($PSBoundParameters.ContainsKey('Element')) { + Write-Verbose "On Element: $($Element.Tagname)" + if ($Action -eq 'Click') { + $Element.Click() #Mitigating IE driver issue with statement below. + } + else { + try { $Interaction.$Action($Element).Perform() } + catch { $PSCmdlet.ThrowTerminatingError($_) } + } + } + else { + Write-Verbose "On Driver currently located at: $($Driver.Url)" + try { $Interaction.$Action().Perform() } + catch { $PSCmdlet.ThrowTerminatingError($_) } + } + } + } + if ($Sleep -gt 0) { Start-Sleep -Milliseconds ($Sleep * 1000) } + if ($PassThru) { if ($HasElement) { return $Element } else { return $Driver } } + + } } \ No newline at end of file diff --git a/Public/Invoke-SeJavascript.ps1 b/Public/Invoke-SeJavascript.ps1 new file mode 100644 index 0000000..89b3e76 --- /dev/null +++ b/Public/Invoke-SeJavascript.ps1 @@ -0,0 +1,21 @@ +function Invoke-SeJavascript { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline = $true, Position = 0)] + [String]$Script, + [Parameter(Position = 1)] + [Object[]]$ArgumentList + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + Process { + #Fix #165 + $MYargumentList = Foreach ($item in $ArgumentList) { + $Item -as $Item.GetType() + } + $Driver.ExecuteScript($Script, $MyArgumentList) + } + End {} +} + diff --git a/Public/Invoke-SeKeys.ps1 b/Public/Invoke-SeKeys.ps1 new file mode 100644 index 0000000..dcd0e01 --- /dev/null +++ b/Public/Invoke-SeKeys.ps1 @@ -0,0 +1,84 @@ +$Script:ModifierKeys = @( + 'Control', + 'LeftControl' + 'Alt', + 'LeftAlt' + 'Shift', + 'LeftShift' +) +function Invoke-SeKeys { + [CmdletBinding(DefaultParameterSetName = 'Default')] + param( + [Parameter( Position = 0, ValueFromPipeline = $true)] + [ValidateNotNull()] + [OpenQA.Selenium.IWebElement]$Element , + [Parameter(Mandatory = $true, Position = 1)] + [AllowEmptyString()] + [string]$Keys, + [switch]$ClearFirst, + [Double]$Sleep = 0 , + [switch]$Submit, + [switch]$PassThru + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + + $Regexstr = '(?{{(?.*?)}})' + $MyMatches = [Regex]::Matches($Keys, $Regexstr) + #Treat modifier keys as key down . + $Sequence = [System.Collections.Generic.List[String]]::new() + $UseSequence = $Keys.StartsWith('{{') + + Foreach ($m in $MyMatches) { + $key = $m.Groups.Item('value').value + $Found = $Script:SeKeys.Name.Contains($value) + if ($null -ne $Found) { + if ($UseSequence -and $Key -in $Script:ModifierKeys) { + $Sequence.Add([OpenQA.Selenium.Keys]::$key) + $Keys = $Keys -replace "{{$key}}", '' + } + else { + $Keys = $Keys -replace "{{$key}}", [OpenQA.Selenium.Keys]::$key + } + + } + } + $UseSequence = $UseSequence -and $Sequence.Count -gt 0 + + } + process { + $Action = [OpenQA.Selenium.Interactions.Actions]::new($Driver) + + switch ($PSBoundParameters.ContainsKey('Element')) { + $true { + if ($ClearFirst) { $Element.Clear() } + + if ($UseSequence) { + Foreach ($k in $Sequence) { $Action.KeyDown($Element, $k) } + $Action.SendKeys($Element, $Keys) + Foreach ($k in $Sequence) { $Action.KeyUp($Element, $k) } + $Action.Build().Perform() + } + else { + $Action.SendKeys($Element, $Keys).Perform() + } + + if ($Submit) { $Element.Submit() } + } + $false { + if ($UseSequence) { + Foreach ($k in $Sequence) { $Action.KeyDown($k) } + $Action.SendKeys($Keys) + Foreach ($k in $Sequence) { $Action.KeyUp($k) } + $Action.Build().Perform() + } + else { + $Action.SendKeys($Keys).Perform() + } + } + } + + if ($Sleep) { Start-Sleep -Milliseconds ($Sleep * 1000) } + if ($PassThru) { $Element } + } +} \ No newline at end of file diff --git a/Public/Invoke-SeScreenshot.ps1 b/Public/Invoke-SeScreenshot.ps1 deleted file mode 100644 index 534ca33..0000000 --- a/Public/Invoke-SeScreenshot.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -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/Invoke-seMouseAction.ps1 b/Public/Invoke-seMouseAction.ps1 new file mode 100644 index 0000000..f42d2ff --- /dev/null +++ b/Public/Invoke-seMouseAction.ps1 @@ -0,0 +1,59 @@ +function Invoke-SeMouseAction { + [CmdletBinding()] + param ( + [ArgumentCompleter([SeMouseActionCompleter])] + [ValidateScript( { $_ -in $Script:SeMouseAction.Text })] + $Action, + $Value, + [Parameter(ValueFromPipeline = $true)] + [OpenQA.Selenium.IWebElement]$Element + ) + $Driver = Init-SeDriver -ErrorAction Stop + Test-SeMouseActionValueValidation -Action $Action -ConditionValue $Value -ErrorAction Stop + + + $Value2 = $null + if ($Action -in @('DragAndDropToOffset', 'MoveByOffset', 'MoveToElement') -and $Value -is [String]) { + $Value2 = $Value -split '[,x]' + } + + + $Interaction = [OpenQA.Selenium.Interactions.Actions]::new($Driver) + + $HasElement = $PSBoundParameters.ContainsKey('Element') + $HasValue = $PSBoundParameters.ContainsKey('Value') + + if ($HasElement) { + if ($HasValue) { + if ($null -ne $value2) { + try { $Interaction.$Action($Element, $Value2[0], $value2[1]).Perform() }catch { $PSCmdlet.ThrowTerminatingError($_) } + } + else { + try { $Interaction.$Action($Element, $Value).Perform() }catch { $PSCmdlet.ThrowTerminatingError($_) } + } + } + else { + try { $Interaction.$Action($Element).Perform() }catch { $PSCmdlet.ThrowTerminatingError($_) } + } + } + else { + if ($HasValue) { + if ($null -ne $value2) { + try { $Interaction.$Action($Value2[0], $Value2[1]).Perform() }catch { $PSCmdlet.ThrowTerminatingError($_) } + } + else { + try { $Interaction.$Action($Value).Perform() }catch { $PSCmdlet.ThrowTerminatingError($_) } + } + + + } + else { + try { $Interaction.$Action().Perform() }catch { $PSCmdlet.ThrowTerminatingError($_) } + } + } + + + + + +} \ No newline at end of file diff --git a/Public/New-SeDriverOptions.ps1 b/Public/New-SeDriverOptions.ps1 new file mode 100644 index 0000000..6ed368f --- /dev/null +++ b/Public/New-SeDriverOptions.ps1 @@ -0,0 +1,53 @@ +function New-SeDriverOptions { + [cmdletbinding()] + [OutputType( + [OpenQA.Selenium.Chrome.ChromeOptions], + [OpenQA.Selenium.Edge.EdgeOptions], + [OpenQA.Selenium.Firefox.FirefoxOptions], + [OpenQA.Selenium.IE.InternetExplorerOptions] + )] + param( + [ArgumentCompleter( { [Enum]::GetNames([SeBrowsers]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBrowsers]) })] + [Parameter(ParameterSetName = 'Default')] + $Browser, + [StringUrlTransformAttribute()] + [ValidateURIAttribute()] + [Parameter(Position = 1)] + [string]$StartURL, + [ArgumentCompleter( { [Enum]::GetNames([SeWindowState]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeWindowState]) })] + $State, + [System.IO.FileInfo]$DefaultDownloadPath, + [switch]$PrivateBrowsing, + [Double]$ImplicitWait = 0.3, + [System.Drawing.Size][SizeTransformAttribute()]$Size, + [System.Drawing.Point][PointTransformAttribute()]$Position, + $WebDriverPath, + $BinaryPath, + [String[]]$Switches, + [String[]]$Arguments, + $ProfilePath, + [OpenQA.Selenium.LogLevel]$LogLevel, + [SeDriverUserAgentTransformAttribute()] + [ValidateNotNull()] + [ArgumentCompleter( [SeDriverUserAgentCompleter])] + [String]$UserAgent + ) + if ($PSBoundParameters.ContainsKey('UserAgent')) { Test-SeDriverUserAgent -Browser $Browser -ErrorAction Stop } + # [Enum]::GetNames([sebrowsers]) + $output = $null + switch ($Browser) { + Chrome { $Output = [OpenQA.Selenium.Chrome.ChromeOptions]::new() } + Edge { $Output = [OpenQA.Selenium.Edge.EdgeOptions]::new() } + Firefox { $Output = [OpenQA.Selenium.Firefox.FirefoxOptions]::new() } + InternetExplorer { $Output = [OpenQA.Selenium.IE.InternetExplorerOptions]::new() } + MSEdge { $Output = [OpenQA.Selenium.Edge.EdgeOptions]::new() } + } + + #Add members to be treated by Internal Start cmdlet since Start-SeDriver won't allow their use with Options parameter set. + Add-Member -InputObject $output -MemberType NoteProperty -Name 'SeParams' -Value $PSBoundParameters + + + return $output +} \ No newline at end of file diff --git a/Public/New-SeDriverService.ps1 b/Public/New-SeDriverService.ps1 new file mode 100644 index 0000000..aec87cb --- /dev/null +++ b/Public/New-SeDriverService.ps1 @@ -0,0 +1,52 @@ +function New-SeDriverService { + [cmdletbinding()] + [OutputType( + [OpenQA.Selenium.Chrome.ChromeDriverService], + [OpenQA.Selenium.Firefox.FirefoxDriverService], + [OpenQA.Selenium.IE.InternetExplorerDriverService], + [OpenQA.Selenium.Edge.EdgeDriverService] + )] + param( + [ArgumentCompleter( { [Enum]::GetNames([SeBrowsers]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBrowsers]) })] + [Parameter(ParameterSetName = 'Default')] + $Browser, + $WebDriverPath + ) + + #$AssembliesPath defined in init.ps1 + $service = $null + $ServicePath = $null + + if ($WebDriverPath) { $ServicePath = $WebDriverPath } elseif ($AssembliesPath) { $ServicePath = $AssembliesPath } + + switch ($Browser) { + + Chrome { + if ($ServicePath) { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($ServicePath) } + else { $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService() } + } + Edge { + $service = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($WebDriverPath, 'msedgedriver.exe') + } + Firefox { + if ($ServicePath) { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService($ServicePath) } + else { $service = [OpenQA.Selenium.Firefox.FirefoxDriverService]::CreateDefaultService() } + $service.Host = '::1' + } + InternetExplorer { + if ($WebDriverPath) { $Service = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService($WebDriverPath) } + else { $Service = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService() } + + } + MSEdge { + $service = [OpenQA.Selenium.Edge.EdgeDriverService]::CreateDefaultService() + } + } + + #Set to $true by default; removing it will cause problems in jobs and create a second source of Verbose in the console. + $Service.HideCommandPromptWindow = $true + + return $service +} + diff --git a/Public/New-SeScreenshot.ps1 b/Public/New-SeScreenshot.ps1 index 3173cb4..31bdc2d 100644 --- a/Public/New-SeScreenshot.ps1 +++ b/Public/New-SeScreenshot.ps1 @@ -1,32 +1,43 @@ 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)] + [Parameter(DontShow, ValueFromPipeline = $true, ParameterSetName = 'Pipeline')] + [ValidateScript( { + $Types = @([OpenQA.Selenium.IWebDriver], [OpenQA.Selenium.IWebElement]) + $Found = $false + Foreach ($t in $Types) { if ($_ -is $t) { $Found = $true; break } } + if ($found) { return $true } else { Throw "Input must be of one of the following types $($Types -join ',')" } + })] + $InputObject, [Switch]$AsBase64EncodedString, - - [Parameter(ParameterSetName = 'PassThru', Mandatory = $true)] - [Alias('PT')] - [Switch]$PassThru + [Parameter(ParameterSetName = 'Element')] + [ValidateNotNull()] + [OpenQA.Selenium.IWebElement]$Element ) - $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Target) - if ($AsBase64EncodedString) { $Screenshot.AsBase64EncodedString } - elseif ($Path) { - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Screenshot.SaveAsFile($Path, $ImageFormat) + Begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + Process { + switch ($PSCmdlet.ParameterSetName) { + 'Pipeline' { + switch ($InputObject) { + { $_ -is [OpenQA.Selenium.IWebElement] } { $Screenshot = $InputObject.GetScreenshot() } + { $_ -is [OpenQA.Selenium.IWebDriver] } { $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($InputObject) } + } + } + 'Element' { $Screenshot = $Element.GetScreenshot() } + 'Driver' { $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Driver) } + } + + if ($AsBase64EncodedString) { + return $Screenshot.AsBase64EncodedString + } + else { + return $Screenshot + } } - if ($Passthru) { $Screenshot } + End {} + + } \ No newline at end of file diff --git a/Public/New-SeWindow.ps1 b/Public/New-SeWindow.ps1 new file mode 100644 index 0000000..5b41b9b --- /dev/null +++ b/Public/New-SeWindow.ps1 @@ -0,0 +1,19 @@ +function New-SeWindow { + [CmdletBinding()] + param( + [ValidateURIAttribute()] + [StringUrlTransformAttribute()] + $Url + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + process { + $Windows = Get-SeWindow + $Driver.ExecuteScript('window.open()') + $WindowsNewSet = Get-SeWindow + $NewWindowHandle = (Compare-Object -ReferenceObject $Windows -DifferenceObject $WindowsNewSet).Inputobject + Switch-SeWindow -Window $NewWindowHandle + if ($PSBoundParameters.ContainsKey('Url')) { Set-SeUrl -Url $Url } + } +} \ No newline at end of file diff --git a/Public/Pop-SeUrl.ps1 b/Public/Pop-SeUrl.ps1 index 6ac9b45..69cdbe5 100644 --- a/Public/Pop-SeUrl.ps1 +++ b/Public/Pop-SeUrl.ps1 @@ -20,16 +20,13 @@ function Pop-SeUrl { To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. #> [CmdletBinding()] - [Alias('Pop-SeLocation')] - param( - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver - ) + param() + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } process { - if ($Script:SeLocationMap[$Target].Count -gt 0) { - Set-SeUrl -Url $Script:SeLocationMap[$Target].Pop() -Target $Target + if ($Script:SeLocationMap[$Driver].Count -gt 0) { + Set-SeUrl -Url $Script:SeLocationMap[$Driver].Pop() -Driver $Driver } } } diff --git a/Public/Push-SeUrl.ps1 b/Public/Push-SeUrl.ps1 index 5a801a7..c771811 100644 --- a/Public/Push-SeUrl.ps1 +++ b/Public/Push-SeUrl.ps1 @@ -27,31 +27,23 @@ function Push-SeUrl { To utilise a driver's Back/Forward functionality, instead use Set-SeUrl. #> [CmdletBinding()] - [Alias('Push-SeLocation')] param( # The new URL to navigate to after storing the current location. [Parameter(Position = 0, ParameterSetName = 'url')] [ValidateURIAttribute()] [string] - $Url, - - # The webdriver instance that owns the url stack, and will navigate to - # a provided new url (if any). - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver + $Url ) - - if (-not $Script:SeLocationMap.ContainsKey($Target)) { - $script:SeLocationMap[$Target] = [System.Collections.Generic.Stack[string]]@() + $Driver = Init-SeDriver -ErrorAction Stop + if (-not $Script:SeLocationMap.ContainsKey($Driver)) { + $script:SeLocationMap[$Driver] = [System.Collections.Generic.Stack[string]]@() } # Push the current location to the stack - $script:SeLocationMap[$Target].Push($Target.Url) + $script:SeLocationMap[$Driver].Push($Driver.Url) if ($Url) { # Change the driver current URL to provided URL - Set-SeUrl -Url $Url -Target $Target + Set-SeUrl -Url $Url -Driver $Driver } } diff --git a/Public/Remove-SeCookie.ps1 b/Public/Remove-SeCookie.ps1 index 2ca0321..8e4305f 100644 --- a/Public/Remove-SeCookie.ps1 +++ b/Public/Remove-SeCookie.ps1 @@ -1,22 +1,17 @@ function Remove-SeCookie { + [CmdletBinding()] 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 = 'All')] + [switch]$All, [Parameter(Mandatory = $true, ParameterSetName = 'NamedCookie')] [string]$Name ) - - if ($DeleteAllCookies) { - $Target.Manage().Cookies.DeleteAllCookies() + $Driver = Init-SeDriver -ErrorAction Stop + if ($All) { + $Driver.Manage().Cookies.DeleteAllCookies() } else { - $Target.Manage().Cookies.DeleteCookieNamed($Name) + $Driver.Manage().Cookies.DeleteCookieNamed($Name) } } \ No newline at end of file diff --git a/Public/Remove-SeWindow.ps1 b/Public/Remove-SeWindow.ps1 new file mode 100644 index 0000000..a0312eb --- /dev/null +++ b/Public/Remove-SeWindow.ps1 @@ -0,0 +1,31 @@ +function Remove-SeWindow { + [CmdletBinding()] + param( + [String]$SwitchToWindow + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + process { + try { + $Windows = @(Get-SeWindow) + if ($Windows.Count -eq 1) { Write-Warning -Message 'The driver has only one window left. Operation aborted. Use Stop-Driver instead.' } + + $Driver.Close() + if ($PSBoundParameters.ContainsKey('SwitchTo')) { + Switch-SeWindow -Window $SwitchToWindow + } + else { + $Windows = @(Get-SeWindow) + if ($Windows.count -gt 0) { + Switch-SeWindow -Window $Windows[0] + } + } + } + catch { + Write-Error $_ + } + + + } +} \ No newline at end of file diff --git a/Public/Save-SeScreenshot.ps1 b/Public/Save-SeScreenshot.ps1 index 9ff37ef..3a532d9 100644 --- a/Public/Save-SeScreenshot.ps1 +++ b/Public/Save-SeScreenshot.ps1 @@ -1,13 +1,43 @@ function Save-SeScreenshot { + [CmdletBinding(DefaultParameterSetName = 'Driver')] param( - [Parameter(ValueFromPipeline = $true, Mandatory = $true)] + [Parameter(DontShow, ValueFromPipeline = $true, ParameterSetName = 'Pipeline')] + [ValidateScript( { + $Types = @([OpenQA.Selenium.IWebDriver], [OpenQA.Selenium.IWebElement], [OpenQA.Selenium.Screenshot]) + $Found = $false + Foreach ($t in $Types) { if ($_ -is $t) { $Found = $true; break } } + if ($found) { return $true } else { Throw "Input must be of one of the following types $($Types -join ',')" } + })] + $InputObject, + [Parameter( Mandatory = $true, ParameterSetName = 'Screenshot')] [OpenQA.Selenium.Screenshot]$Screenshot, [Parameter(Mandatory = $true)] [string]$Path, - [Parameter()] - [OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png) + [OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png, + [Parameter(Mandatory = $true, ParameterSetName = 'Element')] + [ValidateNotNull()] + [OpenQA.Selenium.IWebElement]$Element + ) + begin { + if ($PSCmdlet.ParameterSetName -eq 'Driver') { + $Driver = Init-SeDriver -ErrorAction Stop + } + } process { + + switch ($PSCmdlet.ParameterSetName) { + 'Pipeline' { + switch ($InputObject) { + { $_ -is [OpenQA.Selenium.IWebElement] } { $Screenshot = $InputObject.GetScreenshot() } + { $_ -is [OpenQA.Selenium.IWebDriver] } { $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($InputObject) } + { $_ -is [OpenQA.Selenium.Screenshot] } { $Screenshot = $InputObject } + } + } + 'Driver' { $Screenshot = New-SeScreenshot -Driver $Driver } + 'Element' { $Screenshot = New-SeScreenshot -Element $Element } + } + $Screenshot.SaveAsFile($Path, $ImageFormat) } -} \ No newline at end of file +} diff --git a/Public/SeOpen.ps1 b/Public/SeOpen.ps1 deleted file mode 100644 index 744c509..0000000 --- a/Public/SeOpen.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -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 index 09873ab..24989c5 100644 --- a/Public/SeShouldHave.ps1 +++ b/Public/SeShouldHave.ps1 @@ -7,9 +7,9 @@ function SeShouldHave { [Parameter(ParameterSetName = 'DefaultPS', Mandatory = $false)] [Parameter(ParameterSetName = 'Element' , Mandatory = $false)] - [ValidateSet('CssSelector', 'Name', 'Id', 'ClassName', 'LinkText', 'PartialLinkText', 'TagName', 'XPath')] - [ByTransformAttribute()] - [string]$By = 'XPath', + [ArgumentCompleter( { [Enum]::GetNames([SeBySelector]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBySelector]) })] + [string]$By = [SeBySelector]::XPath, [Parameter(ParameterSetName = 'Element' , Mandatory = $true , Position = 1)] [string]$With, @@ -21,9 +21,7 @@ function SeShouldHave { [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)] @@ -43,13 +41,12 @@ function SeShouldHave { [Parameter(ParameterSetName = 'DefaultPS')] [Parameter(ParameterSetName = 'Element')] [Parameter(ParameterSetName = 'Alert')] - [Alias('PT')] [switch]$PassThru, - [Int]$Timeout = 0 + [Double]$Timeout = 0 ) begin { - $endTime = [datetime]::now.AddSeconds($Timeout) + $endTime = [datetime]::now.AddMilliseconds($Timeout * 1000) $lineText = $MyInvocation.Line.TrimEnd("$([System.Environment]::NewLine)") $lineNo = $MyInvocation.ScriptLineNumber $file = $MyInvocation.ScriptName @@ -91,34 +88,35 @@ function SeShouldHave { $Operator = $matches[1] } $Success = $false - $foundElements = @() + $foundElements = [System.Collections.Generic.List[PSObject]]::new() } process { + $Driver = (Get-SeDriver -Current) #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 + $Success = applyTest -testitems $Driver.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.") + throw (expandErr "PageURL was $($Driver.Url). The comparison '-$operator $value' failed.") } } elseif ($Title) { do { - $Success = applyTest -testitems $Global:SeDriver.Title -operator $Operator -value $Value + $Success = applyTest -testitems $Driver.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.") + throw (expandErr "Page title was $($Driver.Title). The comparison '-$operator $value' failed.") } } elseif ($Alert -or $NoAlert) { do { try { - $a = $Global:SeDriver.SwitchTo().alert() + $a = $Driver.SwitchTo().alert() $Success = $true } catch { @@ -140,16 +138,16 @@ function SeShouldHave { } else { foreach ($s in $Selection) { - $GSEParams = @{By = $By; Selection = $s } + $GSEParams = @{By = $By; Value = $s } if ($Timeout) { $GSEParams['Timeout'] = $Timeout } - try { $e = Get-SeElement @GSEParams } + try { $e = Get-SeElement @GSEParams -All } 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 + $foundElements.add($e) } } } @@ -168,7 +166,7 @@ function SeShouldHave { 'Y' { $testItem = $e.Location.Y } 'Width' { $testItem = $e.Size.Width } 'Height' { $testItem = $e.Size.Height } - 'Choice' { $testItem = (Get-SeSelectionOption -Element $e -ListOptionText) } + 'Choice' { $testItem = (Get-SeSelectValue -Element $e -All).Items.Text } default { $testItem = $e.GetAttribute($with) } } if (-not $testItem -and ($Value -ne '' -and $foundElements.count -eq 1)) { diff --git a/Public/SeType.ps1 b/Public/SeType.ps1 deleted file mode 100644 index ef24913..0000000 --- a/Public/SeType.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index b69d50b..0000000 --- a/Public/Send-SeClick.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index d2cf76b..0000000 --- a/Public/Send-SeKeys.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -function Send-SeKeys { - param( - [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] - [OpenQA.Selenium.IWebElement]$Element, - [Parameter(Mandatory = $true, Position = 1)] - [AllowEmptyString()] - [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 index 56a71d8..da06c3f 100644 --- a/Public/Set-SeCookie.ps1 +++ b/Public/Set-SeCookie.ps1 @@ -5,29 +5,10 @@ function Set-SeCookie { [string]$Value, [string]$Path, [string]$Domain, - $ExpiryDate, - - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver + [DateTime]$ExpiryDate ) - - <# 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' - } + $Driver = Init-SeDriver -ErrorAction Stop } process { @@ -41,7 +22,7 @@ function Set-SeCookie { $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) { + if ($Driver.Url -match $Domain) { $cookie = [OpenQA.Selenium.Cookie]::new($Name, $Value, $Domain, $Path, $ExpiryDate) } else { @@ -60,6 +41,6 @@ function Set-SeCookie { Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date." } - $Target.Manage().Cookies.AddCookie($cookie) + $Driver.Manage().Cookies.AddCookie($cookie) } } \ No newline at end of file diff --git a/Public/Set-SeDriverTimeout.ps1 b/Public/Set-SeDriverTimeout.ps1 new file mode 100644 index 0000000..9c4bec6 --- /dev/null +++ b/Public/Set-SeDriverTimeout.ps1 @@ -0,0 +1,18 @@ +function Set-SeDriverTimeout { + [CmdletBinding()] + param( + [Parameter(Position = 0)] + [ValidateSet('ImplicitWait', 'PageLoad', 'AsynchronousJavaScript')] + $TimeoutType = 'ImplicitWait', + [Parameter(Position = 1)] + [Double]$Timeout = 0 + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } + Process { + $Driver.Manage().Timeouts().$TimeoutType = [timespan]::FromMilliseconds($Timeout * 1000) + } + End {} +} + diff --git a/Public/Set-SeSelectValue.ps1 b/Public/Set-SeSelectValue.ps1 new file mode 100644 index 0000000..e623173 --- /dev/null +++ b/Public/Set-SeSelectValue.ps1 @@ -0,0 +1,46 @@ +function Set-SeSelectValue { + [CmdletBinding()] + param ( + [ArgumentCompleter( { [Enum]::GetNames([SeBySelect]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBySelect]) })] + [SeBySelect]$By = [SeBySelect]::Text, + [Parameter( ValueFromPipeline = $true, Position = 1, Mandatory = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [Object]$value + + ) + try { + $IsMultiSelect = [SeleniumSelection.Option]::IsMultiSelect($Element) + + if (-not $IsMultiSelect -and $Value.Count -gt 1) { + Write-Error 'This select control do not accept multiple values' + return $null + } + + #byindex can be 0, but ByText and ByValue can't be empty strings + switch ($By) { + { $_ -eq [SeBySelect]::Text } { + $HaveWildcards = $null -ne (Get-WildcardsIndices -Value $value) + + if ($HaveWildcards) { + $ValuesToSelect = Get-SeSelectValue -Element $Element -All + $ValuesToSelect = $ValuesToSelect.Items | Where-Object { $_.Text -like $Value } + if (! $IsMultiSelect) { $ValuesToSelect = $ValuesToSelect | Select -first 1 } + Foreach ($v in $ValuesToSelect) { + [SeleniumSelection.Option]::SelectByText($Element, $v.Text, $false) + } + } + else { + [SeleniumSelection.Option]::SelectByText($Element, $value, $false) + } + + } + + { $_ -eq [SeBySelect]::Value } { [SeleniumSelection.Option]::SelectByValue($Element, $value) } + { $_ -eq [SeBySelect]::Index } { [SeleniumSelection.Option]::SelectByIndex($Element, $value) } + } + } + 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/Set-SeUrl.ps1 b/Public/Set-SeUrl.ps1 index cbd993e..17df3d2 100644 --- a/Public/Set-SeUrl.ps1 +++ b/Public/Set-SeUrl.ps1 @@ -34,10 +34,10 @@ function Set-SeUrl { location stack. #> [CmdletBinding(DefaultParameterSetName = 'default')] - [Alias('SeNavigate', 'Enter-SeUrl', 'Set-SeLocation', 'Open-SeUrl')] param( # The target URL for the webdriver to navigate to. [Parameter(Mandatory = $true, position = 0, ParameterSetName = 'url')] + [StringUrlTransformAttribute()] [ValidateURIAttribute()] [string]$Url, @@ -52,21 +52,21 @@ function Set-SeUrl { # Refresh the current page in the webdriver. [Parameter(Mandatory = $true, ParameterSetName = 'refresh')] [switch]$Refresh, - - # The target webdriver to manage navigation for. Will utilise the - # default driver if left unset. - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver + + [Parameter(ParameterSetName = 'back')] + [Parameter(ParameterSetName = 'forward', Position = 1)] + [ValidateScript( { $_ -ge 1 })] + [Int]$Depth = 1 ) - - 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' } + $Driver = Init-SeDriver -ErrorAction Stop + for ($i = 0; $i -lt $Depth; $i++) { + switch ($PSCmdlet.ParameterSetName) { + 'url' { $Driver.Navigate().GoToUrl($Url); break } + 'back' { $Driver.Navigate().Back(); break } + 'forward' { $Driver.Navigate().Forward(); break } + 'refresh' { $Driver.Navigate().Refresh(); break } + default { throw 'Unexpected ParameterSet' } + } } + } diff --git a/Public/Start-SeChrome.ps1 b/Public/Start-SeChrome.ps1 deleted file mode 100644 index c1d4522..0000000 --- a/Public/Start-SeChrome.ps1 +++ /dev/null @@ -1,121 +0,0 @@ -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-SeDriver.ps1 b/Public/Start-SeDriver.ps1 new file mode 100644 index 0000000..0e371e4 --- /dev/null +++ b/Public/Start-SeDriver.ps1 @@ -0,0 +1,135 @@ + +function Start-SeDriver { + [cmdletbinding(DefaultParameterSetName = 'default')] + [OutputType([OpenQA.Selenium.IWebDriver])] + param( + #Common to all browsers + [ArgumentCompleter( { [Enum]::GetNames([SeBrowsers]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBrowsers]) })] + [Parameter(ParameterSetName = 'Default')] + [Parameter(ParameterSetName = 'DriverOptions')] + $Browser, + [StringUrlTransformAttribute()] + [ValidateURIAttribute()] + [Parameter(Position = 1)] + [string]$StartURL, + [ArgumentCompleter( { [Enum]::GetNames([SeWindowState]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeWindowState]) })] + [SeWindowState] $State = [SeWindowState]::Default, + [System.IO.FileInfo]$DefaultDownloadPath, + [switch]$PrivateBrowsing, + [Double]$ImplicitWait = 0.2, + [System.Drawing.Size][SizeTransformAttribute()]$Size, + [System.Drawing.Point][PointTransformAttribute()]$Position, + $WebDriverPath, + $BinaryPath, + [Parameter(ParameterSetName = 'DriverOptions', Mandatory = $false)] + [OpenQA.Selenium.DriverService]$Service, + [Parameter(ParameterSetName = 'DriverOptions', Mandatory = $true)] + [OpenQA.Selenium.DriverOptions]$Options, + [Parameter(ParameterSetName = 'Default')] + [String[]]$Switches, + [String[]]$Arguments, + $ProfilePath, + [OpenQA.Selenium.LogLevel]$LogLevel, + [ValidateNotNullOrEmpty()] + $Name, + [SeDriverUserAgentTransformAttribute()] + [ValidateNotNull()] + [ArgumentCompleter( [SeDriverUserAgentCompleter])] + [String]$UserAgent + # See ParametersToRemove to view parameters that should not be passed to browsers internal implementations. + ) + Begin { + if ($PSBoundParameters.ContainsKey('UserAgent')) { Test-SeDriverUserAgent -Browser $Browser -ErrorAction Stop } + } + process { + #Params with default value that need to be pased down to Start-SeXXDriver + $OptionalParams = @('ImplicitWait', 'State') + Foreach ($key in $OptionalParams) { + if (!$PSBoundParameters.ContainsKey($Key)) { + $PSBoundParameters.Add($key, (Get-Variable -Name $key -ValueOnly)) + } + } + # Exclusive parameters to Start-SeDriver we don't want to pass down to anything else. + # Still available through the variable directly within this cmdlet + $ParametersToRemove = @('Arguments', 'Browser', 'Name', 'PassThru') + $SelectedBrowser = $Browser + switch ($PSCmdlet.ParameterSetName) { + 'Default' { + $Options = New-SeDriverOptions -Browser $Browser + $PSBoundParameters.Add('Options', $Options) + + } + 'DriverOptions' { + if ($PSBoundParameters.ContainsKey('Service')) { + $MyService = $PSBoundParameters.Item('Service') + foreach ($Key in $MyService.SeParams.Keys) { + if (! $PSBoundParameters.ContainsKey($Key)) { + $PSBoundParameters.Add($Key, $MyService.SeParams.Item($Key)) + } + } + } + + $Options = $PSBoundParameters.Item('Options') + $SelectedBrowser = $Options.SeParams.Browser + + # Start-SeDrivers params overrides whatever is in the options. + # Any options parameter not specified by Start-SeDriver get added to the psboundparameters + foreach ($Key in $Options.SeParams.Keys) { + if (! $PSBoundParameters.ContainsKey($Key)) { + $PSBoundParameters.Add($Key, $Options.SeParams.Item($Key)) + } + } + + } + } + + if ($PSBoundParameters.ContainsKey('Arguments')) { + foreach ($Argument in $Arguments) { + $Options.AddArguments($Argument) + } + } + + + $FriendlyName = $null + if ($PSBoundParameters.ContainsKey('Name')) { + $FriendlyName = $Name + + $AlreadyExist = $Script:SeDrivers.Where( { $_.SeFriendlyName -eq $FriendlyName }, 'first').Count -gt 0 + if ($AlreadyExist) { + throw "A driver with the name $FriendlyName is already in the active list of started driver." + } + } + + + #Remove params exclusive to this cmdlet before going further. + $ParametersToRemove | ForEach-Object { if ($PSBoundParameters.ContainsKey("$_")) { [void]($PSBoundParameters.Remove("$_")) } } + + switch ($SelectedBrowser) { + 'Chrome' { $Driver = Start-SeChromeDriver @PSBoundParameters; break } + 'Edge' { $Driver = Start-EdgeDriver @PSBoundParameters; break } + 'Firefox' { $Driver = Start-SeFirefoxDriver @PSBoundParameters; break } + 'InternetExplorer' { $Driver = Start-SeInternetExplorerDriver @PSBoundParameters; break } + 'MSEdge' { $Driver = Start-SeMSEdgeDriver @PSBoundParameters; break } + } + if ($null -ne $Driver) { + if ($null -eq $FriendlyName) { $FriendlyName = $Driver.SessionId } + Write-Verbose -Message "Opened $($Driver.Capabilities.browsername) $($Driver.Capabilities.ToDictionary().browserVersion)" + + #Se prefix used to avoid clash with anything from Selenium in the future + #SessionId scriptproperty validation to avoid perfomance cost of checking closed session. + $Headless = if ($state -eq [SeWindowState]::Headless) { " (headless)" } else { "" } + $mp = @{InputObject = $Driver ; MemberType = 'NoteProperty' } + Add-Member @mp -Name 'SeBrowser' -Value "$SelectedBrowser$($Headless)" + Add-Member @mp -Name 'SeFriendlyName' -Value "$FriendlyName" + Add-Member @mp -Name 'SeSelectedElements' -Value $null + Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeProcessId' -Value (Get-DriverProcessId -ServiceProcessId $Driver.SeServiceProcessId) + + $Script:SeDrivers.Add($Driver) + Return Switch-SeDriver -Name $FriendlyName + } + + } +} + diff --git a/Public/Start-SeEdge.ps1 b/Public/Start-SeEdge.ps1 deleted file mode 100644 index e5466eb..0000000 --- a/Public/Start-SeEdge.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -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 deleted file mode 100644 index 1f8fccc..0000000 --- a/Public/Start-SeFirefox.ps1 +++ /dev/null @@ -1,78 +0,0 @@ -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 deleted file mode 100644 index 3d45065..0000000 --- a/Public/Start-SeInternetExplorer.ps1 +++ /dev/null @@ -1,62 +0,0 @@ -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-SeRemote.ps1 b/Public/Start-SeRemote.ps1 index 2aa072b..9b24d44 100644 --- a/Public/Start-SeRemote.ps1 +++ b/Public/Start-SeRemote.ps1 @@ -1,19 +1,4 @@ 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, @@ -21,8 +6,9 @@ function Start-SeRemote { [ValidateURIAttribute()] [Parameter(Position = 0)] [string]$StartURL, - [switch]$AsDefaultDriver, - [int]$ImplicitWait = 10 + [Double]$ImplicitWait = 0.3, + [System.Drawing.Size][SizeTransformAttribute()]$Size, + [System.Drawing.Point][PointTransformAttribute()]$Position ) $desired = [OpenQA.Selenium.Remote.DesiredCapabilities]::new() @@ -34,12 +20,10 @@ function Start-SeRemote { if (-not $Driver) { Write-Warning "Web driver was not created"; return } - $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds($ImplicitWait) + if ($PSBoundParameters.ContainsKey('Size')) { $Driver.Manage().Window.Size = $Size } + if ($PSBoundParameters.ContainsKey('Position')) { $Driver.Manage().Window.Position = $Position } + $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) if ($StartURL) { $Driver.Navigate().GotoUrl($StartURL) } - if ($AsDefaultDriver) { - if ($Global:SeDriver) { $Global:SeDriver.Dispose() } - $Global:SeDriver = $Driver - } - else { $Driver } + return $Driver } \ No newline at end of file diff --git a/Public/Stop-SeDriver.ps1 b/Public/Stop-SeDriver.ps1 index 5ffe3d7..60ea567 100644 --- a/Public/Stop-SeDriver.ps1 +++ b/Public/Stop-SeDriver.ps1 @@ -1,27 +1,43 @@ function Stop-SeDriver { - [alias('SeClose')] + [CmdletBinding()] param( [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [ValidateNotNullOrEmpty()] [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver + $Driver ) - $TextInfo = (Get-Culture).TextInfo - if (($null -ne $Target) -and ($Target -is [OpenQA.Selenium.IWebDriver])) { - $BrowserName = $TextInfo.ToTitleCase($Target.Capabilities.browsername) - - if ($null -eq $Target.SessionId) { - Write-Warning "$BrowserName Driver already closed" - return $null + Begin { + $ElementsToRemove = [System.Collections.Generic.List[PSObject]]::new() + } + Process { + if (! $PSBoundParameters.ContainsKey('Driver')) { + $Driver = Get-SeDriver -Current } - Write-Verbose -Message "Closing $BrowserName..." - $Target.Close() - $Target.Dispose() + if ($null -ne $Driver) { + $Processes = (Get-Process -Id $Driver.SeProcessId, $Driver.SeServiceProcessId -ErrorAction SilentlyContinue ) + + switch ($Processes.Count) { + 2 { + Write-Verbose -Message "Closing $BrowserName $($Driver.SeFriendlyName )..." + $Driver.Close() + $Driver.Dispose() + break + } + 1 { Stop-Process -Id $Processes.Id -ErrorAction SilentlyContinue } + } + $ElementsToRemove.Add($Driver) + } + + } + End { + $ElementsToRemove | ForEach-Object { [void]($script:SeDrivers.Remove($_)) } + if ($script:SeDriversCurrent -notin $script:SeDrivers) { + $script:SeDriversCurrent = $null + } - if ($Target -eq $Global:SeDriver) { Remove-Variable -Name SeDriver -Scope global } } - else { Write-Warning 'A valid must be provided.' } + + + } \ No newline at end of file diff --git a/Public/Switch-SeDriver.ps1 b/Public/Switch-SeDriver.ps1 new file mode 100644 index 0000000..7215e69 --- /dev/null +++ b/Public/Switch-SeDriver.ps1 @@ -0,0 +1,32 @@ +function Switch-SeDriver { + [cmdletbinding(DefaultParameterSetName = 'ByName')] + param( + [parameter(Position = 0, ParameterSetName = 'ByDriver', Mandatory = $True)] + [OpenQA.Selenium.IWebDriver]$Driver, + [parameter(Position = 0, ParameterSetName = 'ByName', Mandatory = $True)] + [String]$Name + ) + + # Remove Selected visual indicator + if ($null -ne $Script:SeDriversCurrent) { + $Script:SeDriversCurrent.SeBrowser = $Script:SeDriversCurrent.SeBrowser -replace ' \*$', '' + } + + switch ($PSCmdlet.ParameterSetName) { + 'ByDriver' { $Script:SeDriversCurrent = $Driver } + 'ByName' { + $Driver = Get-SeDriver -Name $Name + if ($null -eq $Driver) { + $PSCmdlet.ThrowTerminatingError("Driver with Name: $Name not found ") + } + else { + $Script:SeDriversCurrent = $Driver + } + } + } + + $Driver.SeBrowser = "$($Driver.SeBrowser) *" + + return $Driver +} + diff --git a/Public/Switch-SeFrame.ps1 b/Public/Switch-SeFrame.ps1 index e082272..6215abe 100644 --- a/Public/Switch-SeFrame.ps1 +++ b/Public/Switch-SeFrame.ps1 @@ -1,5 +1,5 @@ function Switch-SeFrame { - [Alias('SeFrame')] + [CmdletBinding()] param ( [Parameter(Mandatory = $true, ParameterSetName = 'Frame', Position = 0)] $Frame, @@ -8,16 +8,12 @@ function Switch-SeFrame { [switch]$Parent, [Parameter(Mandatory = $true, ParameterSetName = 'Root')] - [Alias('defaultContent')] - [switch]$Root, - - [Parameter(ValueFromPipeline = $true)] - [Alias("Driver")] - [ValidateIsWebDriverAttribute()] - $Target = $Global:SeDriver + [switch]$Root ) - - if ($frame) { [void]$Target.SwitchTo().Frame($Frame) } - elseif ($Parent) { [void]$Target.SwitchTo().ParentFrame() } - elseif ($Root) { [void]$Target.SwitchTo().defaultContent() } + $Driver = Init-SeDriver -ErrorAction Stop + #TODO Frame validation... Do not try to switch if element does not exist ? + #TODO Review ... Maybe Parent / Root should be a unique parameter : -Level Parent/Root ) + if ($PSBoundParameters.ContainsKey('Frame')) { [void]$Driver.SwitchTo().Frame($Frame) } + elseif ($Parent) { [void]$Driver.SwitchTo().ParentFrame() } + elseif ($Root) { [void]$Driver.SwitchTo().defaultContent() } } \ No newline at end of file diff --git a/Public/Switch-SeWindow.ps1 b/Public/Switch-SeWindow.ps1 index 9a15dd4..0ae60fd 100644 --- a/Public/Switch-SeWindow.ps1 +++ b/Public/Switch-SeWindow.ps1 @@ -1,14 +1,12 @@ function Switch-SeWindow { + [CmdletBinding()] param( - [Parameter(Mandatory = $false, ValueFromPipeline = $true)] - [Alias('Driver')] - [OpenQA.Selenium.IWebDriver] - $Target = $Global:SeDriver, - [Parameter(Mandatory = $true)]$Window ) - + begin { + $Driver = Init-SeDriver -ErrorAction Stop + } process { - $Target.SwitchTo().Window($Window) | Out-Null + $Driver.SwitchTo().Window($Window) | Out-Null } } \ No newline at end of file diff --git a/Public/Update-SeDriver.ps1 b/Public/Update-SeDriver.ps1 new file mode 100644 index 0000000..4361bfc --- /dev/null +++ b/Public/Update-SeDriver.ps1 @@ -0,0 +1,67 @@ +function Update-SeDriver { + [CmdletBinding()] + param ( + [ArgumentCompleter( { [Enum]::GetNames([SeBrowsers]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBrowsers]) })] + $Browser, + [ValidateSet('Linux', 'Mac', 'Windows')] + $OS, + [ValidateScript( { (Test-Path -Path $_) -and ((Get-Item -Path $_) -is [System.IO.DirectoryInfo]) })] + $Path + ) + + if (! $PSBoundParameters.ContainsKey('OS')) { + if ($IsMacOS) { $OS = 'Mac' } elseif ($IsLinux) { $OS = 'Linux' } else { $OS = 'Windows' } + } + + if (! $PSBoundParameters.ContainsKey('Path')) { + $Path = $PSScriptRoot + if ($Path.EndsWith('Public')) { $Path = Split-Path -Path $Path } #Debugging + switch ($OS) { + 'Linux' { $AssembliesDir = Join-Path -Path $Path -ChildPath '/assembiles/linux' } + 'Mac' { $AssembliesDir = Join-Path -Path $Path -ChildPath '/assembiles/macos' } + 'Windows' { $AssembliesDir = Join-Path -Path $Path -ChildPath '/assembiles' } + } + + } + + $TempDir = [System.IO.Path]::GetTempPath() + + switch ($Browser) { + 'Chrome' { + $LatestChromeStableRelease = Invoke-WebRequest 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE' | Select-Object -ExpandProperty Content + $ChromeBuilds = @{ + Linux = 'chromedriver_linux64' + Mac = 'chromedriver_mac64' + Windows = 'chromedriver_win32' + } + + $Build = $ChromeBuilds.$OS + + + $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 + + } + 'Firefox' { + Write-Warning 'Not Supported Yet' + + } + 'Edge' { + Write-Warning 'Not Supported Yet' + } + Default { + Write-Warning 'Not Supported Yet' + } + } + + + + + +} \ No newline at end of file diff --git a/Public/Wait-SeDriver.ps1 b/Public/Wait-SeDriver.ps1 new file mode 100644 index 0000000..7c957b8 --- /dev/null +++ b/Public/Wait-SeDriver.ps1 @@ -0,0 +1,42 @@ +function Wait-SeDriver { + [Cmdletbinding()] + param( + [ArgumentCompleter([SeDriverConditionsCompleter])] + [ValidateScript( { $_ -in $Script:SeDriverConditions.Text })] + [Parameter(Position = 0, Mandatory = $true)] + $Condition, + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + $Value, + #Specifies a time out + [Parameter(Position = 2)] + [Double]$Timeout = 3 + ) + Begin { + $Driver = Init-SeDriver -ErrorAction Stop + $ImpTimeout = -1 + Test-SeDriverConditionsValueValidation -Condition $Condition -Value $Value -Erroraction Stop + } + process { + $ImpTimeout = Disable-SeDriverImplicitTimeout -Driver $Driver + if ($Condition -eq 'ScriptBlock') { + $SeCondition = [System.Func[OpenQA.Selenium.IWebDriver, Bool]]$Value + } + else { + $SeCondition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::$Condition($Value) + } + $WebDriverWait = [OpenQA.Selenium.Support.UI.WebDriverWait]::new($Driver, ([timespan]::FromMilliseconds($Timeout * 1000))) + + try { + [void]($WebDriverWait.Until($SeCondition)) + return $true + } + catch { + Write-Error $_ + return $false + } + Finally { + Enable-SeDriverImplicitTimeout -Driver $Driver -Timeout $ImpTimeout + } + } +} \ No newline at end of file diff --git a/Public/Wait-SeElement.ps1 b/Public/Wait-SeElement.ps1 new file mode 100644 index 0000000..21d331b --- /dev/null +++ b/Public/Wait-SeElement.ps1 @@ -0,0 +1,68 @@ +function Wait-SeElement { + [Cmdletbinding(DefaultParameterSetName = 'Element')] + param( + [ArgumentCompleter( { [Enum]::GetNames([SeBySelector]) })] + [ValidateScript( { $_ -in [Enum]::GetNames([SeBySelector]) })] + [Parameter(ParameterSetName = 'Locator', Position = 0)] + [SeBySelector]$By = [SeBySelector]::XPath, + [Parameter(Position = 1, Mandatory = $true, ParameterSetName = 'Locator')] + [string]$Value, + + [Parameter(ParameterSetName = 'Element', Mandatory = $true)] + [OpenQA.Selenium.IWebElement]$Element, + [ArgumentCompleter([SeElementsConditionsCompleter])] + [ValidateScript( { $_ -in $Script:SeElementsConditions.Text })] + $Condition, + [ValidateNotNull()] + $ConditionValue, + #Specifies a time out + [Double]$Timeout = 3 + + ) + begin { + $Driver = Init-SeDriver -ErrorAction Stop + Test-SeElementConditionsValueValidation -By $By -Element $Element -Condition $Condition -ConditionValue $ConditionValue -ParameterSetName $PSCmdlet.ParameterSetName @Stop + $ImpTimeout = -1 + + $ExpectedValueType = Get-SeElementsConditionsValueType -text $Condition + + } + process { + $ImpTimeout = Disable-SeDriverImplicitTimeout -Driver $Driver + + $WebDriverWait = [OpenQA.Selenium.Support.UI.WebDriverWait]::new($Driver, ([timespan]::FromMilliseconds($Timeout * 1000))) + $NoExtraArg = $null -eq $ExpectedValueType + + if ($PSBoundParameters.ContainsKey('Element')) { + if ($NoExtraArg) { + $SeCondition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::$Condition($Element) + } + else { + $SeCondition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::$Condition($Element, $ConditionValue) + } + } + else { + if ($NoExtraArg) { + $SeCondition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::$Condition([OpenQA.Selenium.By]::$By($Value)) + } + else { + $SeCondition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::$Condition([OpenQA.Selenium.By]::$By($Value), $ConditionValue) + } + } + + try { + [void]($WebDriverWait.Until($SeCondition)) + return $true + } + catch { + Write-Error $_ + return $false + } + Finally { + Enable-SeDriverImplicitTimeout -Driver $Driver -Timeout $ImpTimeout + } + } +} + + + diff --git a/Selenium.EzFormat.ps1 b/Selenium.EzFormat.ps1 new file mode 100644 index 0000000..7a614fe --- /dev/null +++ b/Selenium.EzFormat.ps1 @@ -0,0 +1,66 @@ +#requires -Module EZOut +# Install-Module EZOut or https://github.com/StartAutomating/EZOut +$myFile = $MyInvocation.MyCommand.ScriptBlock.File +$myModuleName = $($myFile | Split-Path -Leaf) -replace '\.ezformat\.ps1', '' -replace '\.ezout\.ps1', '' +$myRoot = $myFile | Split-Path +Push-Location $myRoot +$Type = @{TypeName = 'OpenQA.Selenium.Remote.RemoteWebElement' } +$Typed = @{TypeName = 'OpenQA.Selenium.Remote.RemoteWebDriver' } +$formatting = @( + Write-FormatView @type -Property Tagname, Enabled, Displayed, Text -Width 7, 7, 9, 80 -AlignProperty @{Text = 'Left' } -VirtualProperty @{'Hello' = { 'World' } } + Write-FormatView @type -AsList -Property Tagname, Text, Enabled, Selected, Location, Size, Displayed + + Write-FormatView -TypeName 'selenium-powershell/SeFrame' -Property 'TagName', 'Enabled', 'Name', 'Id' -VirtualProperty @{ + Name = { $_.Attributes.name } + Id = { $_.Attributes.id } + } + + + + # Add your own Write-FormatView here, + # or put them in a Formatting or Views directory + foreach ($potentialDirectory in 'Formatting', 'Views') { + Join-Path $myRoot $potentialDirectory | + Get-ChildItem -ea ignore | + Import-FormatView -FilePath { $_.Fullname } + } +) + +$destinationRoot = $myRoot + +if ($formatting) { + $myFormatFile = Join-Path $destinationRoot "formats/$myModuleName.format.ps1xml" + $formatting | Out-FormatData -Module $MyModuleName | Set-Content $myFormatFile -Encoding UTF8 +} + +$types = @( + Write-TypeView @Type -DefaultDisplay 'Tagname', 'Enabled', 'Displayed', 'Text' + Write-TypeView @Typed -ScriptProperty @{ + SeTitle = { if ($null -ne $this.SessionId) { $this.Title } } + SeUrl = { if ($null -ne $this.SessionId) { $this.Url } } + } -DefaultDisplay 'SeFriendlyName', 'SeBrowser', 'SeTitle', 'SeUrl' + + # Add your own Write-T + #TypeView statements here + # or declare them in the 'Types' directory + Join-Path $myRoot Types | + Get-Item -ea ignore | + Import-TypeView + +) + +if ($types) { + $myTypesFile = Join-Path $destinationRoot "types/$myModuleName.types.ps1xml" + $types | Out-TypeData | Set-Content $myTypesFile -Encoding UTF8 +} +Pop-Location + +$Content = Get-Content -Path $myFormatFile | Select -SkipLast 2 + +$SeSelectViewPath = Join-Path -Path $PSScriptRoot -ChildPath 'views/SeSelectValueInfo.ps1xml' +$EndOfFile = @' + + + +'@ +($Content | Out-String) + (Get-Content -Path $SeSelectViewPath -raw) + $EndOfFile | Out-File -Encoding utf8 $myFormatFile diff --git a/Selenium.build.ps1 b/Selenium.build.ps1 index c2b175b..4945b4a 100644 --- a/Selenium.build.ps1 +++ b/Selenium.build.ps1 @@ -82,6 +82,8 @@ task CopyAdditionalFiles { $CopyFolder = { Param($Name) Copy-Item -Path "$script:ModuleRoot\$Name" -Destination "$script:ModuleOutPutFolder" -Force -Verbose -Container -Recurse } & $CopyFolder 'assemblies' + & $CopyFolder 'types' + & $CopyFolder 'formats' & $CopyFolder 'Examples' & $CopyFile 'SeleniumClasses.ps1' diff --git a/Selenium.psd1 b/Selenium.psd1 index af47e10..84f4494 100644 --- a/Selenium.psd1 +++ b/Selenium.psd1 @@ -8,7 +8,7 @@ # Modified James O'Neill 30 Nov 2019 @{ - ModuleVersion = '3.0.1' + ModuleVersion = '4.0.0' GUID = 'a3bdb8c3-c150-48a8-b56d-cd4d43f46a26' Author = 'Adam Driscoll' CompanyName = 'Unknown' @@ -16,28 +16,9 @@ Description = 'Web automation using the Selenium Web Driver' ScriptsToProcess = @('SeleniumClasses.ps1') RootModule = 'Selenium.psm1' - RequiredAssemblies = @('./assemblies/WebDriver.dll', './assemblies/WebDriver.Support.dll') + RequiredAssemblies = @('./assemblies/WebDriver.dll', './assemblies/WebDriver.Support.dll', 'System.Drawing') FunctionsToExport = '*' - AliasesToExport = @( - 'SeChrome' , - 'SeFirefox', - 'SeIE' , 'SeInternetExplorer' , - 'CrEdge' , 'NewEdge', - 'MSEdge' , 'LegacyEdge', 'Start-SeLegacyEdge', - 'Enter-SeUrl' , 'Open-SeUrl', 'Set-SeLocation' - 'Push-SeLocation', - 'Pop-SeLocation', - 'Get-SeLocation', - 'Find-SeElement', - 'SeAccept', - 'SeDismiss', - 'SeClick', - 'SeClose', - 'SeElement', - 'SeFrame', - 'SeNavigate', - 'SeScreenshot', - 'SeSelection') + AliasesToExport = @() CmdletsToExport = @() VariablesToExport = @() DscResourcesToExport = @() @@ -87,11 +68,11 @@ # 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 = @() + #Type files (.ps1xml) to be loaded when importing this module + TypesToProcess = @('types/Selenium.types.ps1xml') # Format files (.ps1xml) to be loaded when importing this module - # FormatsToProcess = @() + FormatsToProcess = @('formats/Selenium.format.ps1xml') # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess # NestedModules = @() diff --git a/Selenium.psm1 b/Selenium.psm1 index 6d34c1f..4292929 100644 --- a/Selenium.psm1 +++ b/Selenium.psm1 @@ -1,9 +1,8 @@ -$functionFolders = @('Public', 'Internal', 'Classes') +$functionFolders = @('Classes', 'Public', 'Internal') +. (Join-Path -Path $PSScriptRoot -ChildPath 'Internal/init.ps1') 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" @@ -14,5 +13,10 @@ ForEach ($folder in $functionFolders) { } } } + +$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { + Get-SeDriver | Stop-SeDriver +} + $publicFunctions = (Get-ChildItem -Path "$PSScriptRoot\Public" -Filter '*.ps1').BaseName Export-ModuleMember -Function $publicFunctions diff --git a/SeleniumClasses.ps1 b/SeleniumClasses.ps1 index 36624da..baac8df 100644 --- a/SeleniumClasses.ps1 +++ b/SeleniumClasses.ps1 @@ -1,3 +1,7 @@ +using namespace system.Collections +using namespace System.Collections.Generic +using namespace System.Management.Automation +using namespace System.Management.Automation.Language if ('ValidateURIAttribute' -as [type]) { class ValidateURIAttribute : System.Management.Automation.ValidateArgumentsAttribute { @@ -24,31 +28,13 @@ if ('ValidateIsWebDriverAttribute' -as [type]) { 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)$#') { + if ($inputData -match '^(contains|like|notlike|match|notmatch|eq|ne|gt|lt)$') { return $InputData } switch -regex ($InputData) { @@ -57,6 +43,7 @@ if ('OperatorTransformAttribute' -as [type]) { "^n\w*match" { return 'notmatch' ; break } "^eq" { return 'eq' ; break } "^n\w*eq" { return 'ne' ; break } + "^n\w*like" { return 'like' ; break } } return $InputData } @@ -120,4 +107,38 @@ namespace SeleniumSelection { } } } -"@ -ReferencedAssemblies $dll1Path, $dll2Path, mscorlib \ No newline at end of file +"@ -ReferencedAssemblies $dll1Path, $dll2Path, mscorlib + + +enum SeBrowsers { + Chrome + Edge + Firefox + InternetExplorer + MSEdge +} + +enum SeWindowState { + Headless + Default + Minimized + Maximized + Fullscreen +} + +enum SeBySelector { + ClassName + CssSelector + Id + LinkText + PartialLinkText + Name + TagName + XPath +} + +enum SeBySelect { + Index + Text + Value +} \ No newline at end of file diff --git a/Views/SeSelectValueInfo.ps1xml b/Views/SeSelectValueInfo.ps1xml new file mode 100644 index 0000000..cb1b20d --- /dev/null +++ b/Views/SeSelectValueInfo.ps1xml @@ -0,0 +1,38 @@ + + SeSelectValueInfo + + selenium-powershell/SeSelectValueInfo + + + + + + + IsMultiSelect + + + + + + + ($_.Items.Count -ne 0) + + + + $output = [System.Text.StringBuilder]::new(); + $TextMax = ($_.Items.Text | Measure-Object -Maximum).Maximum.length + $ValueMax = ($_.Items.Value | Measure-Object -Maximum).Maximum.length + [void]($Output.AppendFormat("Index {0} {1} Selected`n", 'Text'.PadRight($TextMax, ' '), 'Value'.PadRight($ValueMax, ' '))) + [void]($Output.AppendFormat("----- {0} {1} --------`n", '----'.PadRight($TextMax, ' '), '-----'.PadRight($ValueMax, ' '))) + foreach ($I in $_.Items) { + $IsSelected = if ($I.Selected) {" *"} else {''} + [Void]($output.AppendFormat("{0} {1} {2} {3}`n", "$($I.Index)".PadLeft(5, ' '), "$($I.Text)".PadRight($TextMax, ' '), "$($I.Value)".PadRight($ValueMax, ' '), $IsSelected)) + }; + $output.ToString().Trim("`n"); + + + + + + + \ No newline at end of file diff --git a/assemblies/IEDriverServer.exe b/assemblies/IEDriverServer.exe index d4890e2..d5d6ada 100644 Binary files a/assemblies/IEDriverServer.exe and b/assemblies/IEDriverServer.exe differ diff --git a/assemblies/IEDriverServer.exe.sha256 b/assemblies/IEDriverServer.exe.sha256 index 9573b7c..7a01c45 100644 --- a/assemblies/IEDriverServer.exe.sha256 +++ b/assemblies/IEDriverServer.exe.sha256 @@ -1 +1 @@ -A1E26B0E8CB5F8DB1CD784BAC71BBF540485D81E697293B0B4586E25A31A8187 +51053574E3BA3AB5D9F47E13EC0E9961AD6C9C9978DC851BE71C0F86A272C74B diff --git a/assemblies/chromedriver.exe b/assemblies/chromedriver.exe index 4850c8d..c0efae8 100644 Binary files a/assemblies/chromedriver.exe and b/assemblies/chromedriver.exe differ diff --git a/assemblies/chromedriver.exe.sha256 b/assemblies/chromedriver.exe.sha256 index 0f55902..c5b4c83 100644 --- a/assemblies/chromedriver.exe.sha256 +++ b/assemblies/chromedriver.exe.sha256 @@ -1 +1 @@ -55C5203DB4D44D96F4124C60E69AE0823F4372EFA4B5416675D9564A83D6AD2C \ No newline at end of file +5BFEADAEB1182DC068B60377BA34C010317D6AE19DA4934A221B2B1F3A050889 diff --git a/assemblies/geckodriver.exe b/assemblies/geckodriver.exe index 9fae8e0..4ce451b 100644 Binary files a/assemblies/geckodriver.exe and b/assemblies/geckodriver.exe differ diff --git a/assemblies/geckodriver.exe.sha256 b/assemblies/geckodriver.exe.sha256 index 2b051b9..e43d884 100644 --- a/assemblies/geckodriver.exe.sha256 +++ b/assemblies/geckodriver.exe.sha256 @@ -1 +1 @@ -255C9D3571C86841213F49B26D176A6AD440BE8C720E3C2D9226076ADF4F603D +FAED02EC5B0D6246856843D10EE020CB5121B8261AC939BE761130F21A73D3EE diff --git a/assemblies/linux/chromedriver b/assemblies/linux/chromedriver index 7d7041d..ca100fd 100755 Binary files a/assemblies/linux/chromedriver and b/assemblies/linux/chromedriver differ diff --git a/assemblies/linux/chromedriver.sha256 b/assemblies/linux/chromedriver.sha256 index 648ed61..14067a4 100644 --- a/assemblies/linux/chromedriver.sha256 +++ b/assemblies/linux/chromedriver.sha256 @@ -1 +1 @@ -B561EFE1551F9CB45DDE6BBF804CA2BC06359415CDAC1B6B16556B095A55011F \ No newline at end of file +D933FAA89173AFEC49B945F11360197117CB37AF3CE7EA16545D349B41869687 diff --git a/assemblies/linux/geckodriver b/assemblies/linux/geckodriver index ff08a41..bf9538e 100755 Binary files a/assemblies/linux/geckodriver and b/assemblies/linux/geckodriver differ diff --git a/assemblies/linux/geckodriver.sha256 b/assemblies/linux/geckodriver.sha256 index 6d92a3d..930beaa 100644 --- a/assemblies/linux/geckodriver.sha256 +++ b/assemblies/linux/geckodriver.sha256 @@ -1 +1 @@ -6590E3B9D9BF292C8DF50B6DF5BCF8A5191D999F9E48F68AA2055EB5746B2C05 +0B2C9B9791925DCEA2981CBDFAB8274FB4668BF65D6A57C2257E8B57757C394A diff --git a/assemblies/macos/chromedriver b/assemblies/macos/chromedriver index cd12a95..7471717 100644 Binary files a/assemblies/macos/chromedriver and b/assemblies/macos/chromedriver differ diff --git a/assemblies/macos/chromedriver.sha256 b/assemblies/macos/chromedriver.sha256 index 2e03b89..59914ba 100644 --- a/assemblies/macos/chromedriver.sha256 +++ b/assemblies/macos/chromedriver.sha256 @@ -1 +1 @@ -AD35D47CA5CD075939F7F6638188A56B648663D38A0719AF28B3F004BF95E0DD +9793D91D3448E35061606F37F1EB3EECC7B492CF159E6A318395445FB75B46EC diff --git a/assemblies/macos/geckodriver b/assemblies/macos/geckodriver index 83a86e1..4a2671f 100755 Binary files a/assemblies/macos/geckodriver and b/assemblies/macos/geckodriver differ diff --git a/assemblies/macos/geckodriver.sha256 b/assemblies/macos/geckodriver.sha256 index 449827d..ac73b7f 100644 --- a/assemblies/macos/geckodriver.sha256 +++ b/assemblies/macos/geckodriver.sha256 @@ -1 +1 @@ -D62C2178377ADDEB1BB860426B2C9B10B68D2EEABF0C521529A4A6A7B1E208C4 +AA2FCE6B96183C9D8FD0AA125F87557FCCEC60301CF7ADD1578B0DA59355AD8B diff --git a/assemblies/msedgedriver.exe b/assemblies/msedgedriver.exe index 18ab97e..74d70ba 100644 Binary files a/assemblies/msedgedriver.exe and b/assemblies/msedgedriver.exe differ diff --git a/assemblies/msedgedriver.exe.sha256 b/assemblies/msedgedriver.exe.sha256 index 4abbfcd..96c8978 100644 --- a/assemblies/msedgedriver.exe.sha256 +++ b/assemblies/msedgedriver.exe.sha256 @@ -1 +1 @@ -509FFD6D321EF78C8319E68B89807D2437D8DB1718000FE2BB7ECACB1529730D +A6EB02FF3EF75079A647F20BD0B6B563648BC4C8563443229C65671AB0BBB6CD diff --git a/formats/Selenium.format.ps1xml b/formats/Selenium.format.ps1xml new file mode 100644 index 0000000..0fb5aed --- /dev/null +++ b/formats/Selenium.format.ps1xml @@ -0,0 +1,161 @@ + + + + + + OpenQA.Selenium.Remote.RemoteWebElement + + OpenQA.Selenium.Remote.RemoteWebElement + + + + + left + 7 + + + left + 7 + + + left + 9 + + + Left + 80 + + + + + + + Tagname + + + Enabled + + + Displayed + + + Text + + + + + + + + OpenQA.Selenium.Remote.RemoteWebElement + + OpenQA.Selenium.Remote.RemoteWebElement + + + + + + + Tagname + + + Text + + + Enabled + + + Selected + + + Location + + + Size + + + Displayed + + + + + + + + selenium-powershell/SeFrame + + selenium-powershell/SeFrame + + + + + + + + + + + + + + + + + + + TagName + + + Enabled + + + $_.Attributes.name + + + $_.Attributes.id + + + + + + + + SeSelectValueInfo + + selenium-powershell/SeSelectValueInfo + + + + + + + IsMultiSelect + + + + + + + ($_.Items.Count -ne 0) + + + + $output = [System.Text.StringBuilder]::new(); + $TextMax = ($_.Items.Text | Measure-Object -Maximum).Maximum.length + $ValueMax = ($_.Items.Value | Measure-Object -Maximum).Maximum.length + [void]($Output.AppendFormat("Index {0} {1} Selected`n", 'Text'.PadRight($TextMax, ' '), 'Value'.PadRight($ValueMax, ' '))) + [void]($Output.AppendFormat("----- {0} {1} --------`n", '----'.PadRight($TextMax, ' '), '-----'.PadRight($ValueMax, ' '))) + foreach ($I in $_.Items) { + $IsSelected = if ($I.Selected) {" *"} else {''} + [Void]($output.AppendFormat("{0} {1} {2} {3}`n", "$($I.Index)".PadLeft(5, ' '), "$($I.Text)".PadRight($TextMax, ' '), "$($I.Value)".PadRight($ValueMax, ' '), $IsSelected)) + }; + $output.ToString().Trim("`n"); + + + + + + + + + diff --git a/types/Selenium.Types.ps1xml b/types/Selenium.Types.ps1xml new file mode 100644 index 0000000..a70253c --- /dev/null +++ b/types/Selenium.Types.ps1xml @@ -0,0 +1,54 @@ + + + + + OpenQA.Selenium.Remote.RemoteWebElement + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Tagname + Enabled + Displayed + Text + + + + + + + + OpenQA.Selenium.Remote.RemoteWebDriver + + + PSStandardMembers + + + DefaultDisplayPropertySet + + SeFriendlyName + SeBrowser + SeTitle + SeUrl + + + + + + SeUrl + + if ($null -ne $this.SessionId) { $this.Url } + + + + SeTitle + + if ($null -ne $this.SessionId) { $this.Title } + + + + +