Nutstone.Selenium.Powershell
1.0.25
See the version list below for details.
dotnet add package Nutstone.Selenium.Powershell --version 1.0.25
NuGet\Install-Package Nutstone.Selenium.Powershell -Version 1.0.25
<PackageReference Include="Nutstone.Selenium.Powershell" Version="1.0.25" />
paket add Nutstone.Selenium.Powershell --version 1.0.25
#r "nuget: Nutstone.Selenium.Powershell, 1.0.25"
// Install Nutstone.Selenium.Powershell as a Cake Addin #addin nuget:?package=Nutstone.Selenium.Powershell&version=1.0.25 // Install Nutstone.Selenium.Powershell as a Cake Tool #tool nuget:?package=Nutstone.Selenium.Powershell&version=1.0.25
Nutstone Selenium Powershell
Powershell implementation of Nutstone.Selenium.Core
This package wraps the nutstone.seleniu.core package in a series of powershell cmdlet's. A selenium session is created and the relevant version of the Chrome driver is downloaded and used for the session.
Only the Chrome driver is (currently) supported.
The powershell cmdlets wrap the core functionalty of the IWebDriverProxy provider implemented in nutstone.selenium.core
The Cmdlets
Open-WebSession
creates a new selenium session and sets up global PS variables used by most other cmdlets in this module. This cmdlet should be the executed before any other selenium-based cmdlets.
Open-WebSession -Headless $false -LeaveBrowserRunning $true --Logfile somefilepath
Get-WebDriver
returns the current instance of IwebDriverProxy. You can then use the methods exposed on this interface to directly communicate with the selenium driver instance
$webDriver = Get-WebDriver
# display available methods on the webdriver
Write-Host ($webDriver | Get-Member | Format-Table | Out-String)
Open-Url
opens a browser at the specified url and waits for it to be 'ready'
Open-Url -Url http://acme:8080/api
Set-Element
populates an html element value (in the browser) from the specified Xpath. Currently supports Action's of Input, Click, Select, SelectMaterial
Set-Element -Xpath "//*[@id='firstname']" -Value "some value" -Action Input
Get-Element
returns an IWebElement object (see selenium docs) that can be used to manipulate the element
$element = Get-Element -Xpath "//*[@id='firstname']"
$element.Click() # maybe
Close-WebSession
Closes the web session and disposes of associated selenium objects
Close-WebSession
Support cmdlets
Utilities
Import-Scripts
Imports into current scope all files called *.ps1 in a directory (and subdirectories) - so you can reference functions etc from all of those ps1 scripts
Import-Scripts -Path C:\somerootPath\scriptdir
"Page" cmdlets
This package supports the idea of a 'Page' (similar to selenium). A page consists of a number of html elements that will be populated. Local powsershell functions/scriptblock's can be used to further enhance/replace the default cmdlet functionality.
Using Pages
New-Page / Add-PageElement
# set surname - this gets called when the element surname is being processed
function setSurname() {
param (
[Parameter(Mandatory)]
$PageModel
)
Set-Element -Xpath $PageModel.Xpath -Value "some surname"
}
# create new page definition and save it to C:\deleteme\ps\SimplePage.Json
New-Page -Name "SimplePage"
| Add-PageElement -Name "TestButton" -Xpath "//*[@id='simpletests']" -Action Click
| Add-PageElement -Name "FirstName" -Xpath "//*[@id='firstname']" -Action Input -Value "Person 1"
| Add-PageElement -Name "Surname" -Xpath "//*[@id='surname']" -Action Code -Function "setSurname"
| Add-PageElement -Name "Sex" -Xpath "//*[@id='sex']" -Action Select -Value "Female"
| Add-PageElement -Name "Date" -Xpath "//*[@id='dob']" -Action Code -Value "22/01/2023"
| Save-Page -Path "C:\Deleteme\ps"
Get-Page / Run-Page
# example scriptblock
$beforeExecution = {
param (
[Parameter(Mandatory)]
$PageModelCollectionObject
)
# do something
}
$afterExecution = {
param (
[Parameter(Mandatory)]
$PageModelCollectionObject
)
# maybe run some assertions
}
# example function
function setDate() {
param (
[Parameter(Mandatory)]
$PageObject
)
# do something ;special
Set-Element
}
# get the PsPageModelCollection Object previously created and saved
$simplePage = Get-Page -Path "C:\Deleteme\ps\SimplePage"
# start the page and populate elements definied in it.
# whenever an -Action of 'code' is encountered - execute the setDate function passing the 'current'
# PsPageModel object
# before the page 'runs' execute the scriptblock (could be a function) $beforeExecution
# after the page has run execute the scriptblock (could be a function) $afterExecution
Start-Page -Page $simplePage -ActionCode ${function:setDate} -BeforeExecution $beforeExecution -AfterExecution $afterExecution
# if you prefer you can use string representations of a function so :-
# Start-Page -Page $simplePage -ActionFunction "somefunction" -BeforeExecutionFunction "someFunction -AfterExecutionFunction "somefunction"
# this will scan existing funtcions (imported or otherwise) and execute the containing script
Examples
Create page and run it
Import-Module Nutstone.Selenium.Powershell
$beforeExecution = {
param (
[Parameter(Mandatory)]
$PageModelCollectionObject
)
# do something
}
$afterExecution = {
param (
[Parameter(Mandatory)]
$PageModelCollectionObject
)
# maybe run some assertions
}
# example function
function setDate() {
param (
[Parameter(Mandatory)]
$PageObject
)
# do something ;special
Set-Element
}
Open-WebSession -Headless $false -LeaveBrowserRunning $true
Open-Url -Url "Http://A-UI-Implementation"
# get previously created page and change a property value
$simplePage = Get-Page -Path "C:\Deleteme\ps\SimplePage" | Alter-Page -Name "FirstName" -Value "tom"
Start-Page -Page $simplePage -ActionFunction "setDate" -BeforeExecution $beforeExecution -AfterExecution $afterExecution
Close-WebSession
Installation
# installs nutstone.selenium.powershell package to the (first) powershell PSModulePath
# NUGET must be installed and available in the enviroment path variable
$packageName = "Nutstone.Selenium.PowerShell"
$location = $env:TEMP
$source = "https://api.nuget.org/v3/index.json"
$latestVersionAll = nuget list $packageName -Source $source
Write-Host "Found Package $($latestVersionAll)"
$latestVersion = ($latestVersionAll -split ' ') | Select-Object -Last 1
# Install latest version to user's temp path
nuget install $packageName -OutputDirectory $location -Version $latestVersion -Source $source -NoCache -DirectDownload
$sourcePath = "$($location)\$($packageName).$($latestVersion)"
Write-Host "Source path $($sourcePath)"
# get first psmodulepath (probably users/documents/windowspowershell)
$psTargetPath = $env:PSModulePath -split(';') | Select-Object -First 1
$targetPath = "$psTargetPath\$packageName"
If (!(Test-Path $targetPath)) {
New-Item -Path $targetPath -ItemType Directory
}
# copy to nutstone.selenium.powershell
Copy-Item -Path "$sourcePath\*" -Destination $targetPath -Recurse -Force -Verbose
# check we can access the new module
Import-module -name Nutstone.Selenium.PowerShell
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.55 | 455 | 4/24/2023 |
1.0.54 | 340 | 4/16/2023 |
1.0.53 | 247 | 4/15/2023 |
1.0.52 | 295 | 4/11/2023 |
1.0.51 | 314 | 4/8/2023 |
1.0.50 | 356 | 4/8/2023 |
1.0.48 | 315 | 4/8/2023 |
1.0.47 | 312 | 4/7/2023 |
1.0.46 | 359 | 4/6/2023 |
1.0.45 | 352 | 4/6/2023 |
1.0.44 | 337 | 4/6/2023 |
1.0.43 | 346 | 4/6/2023 |
1.0.42 | 358 | 4/6/2023 |
1.0.41 | 426 | 4/6/2023 |
1.0.40 | 392 | 4/4/2023 |
1.0.39 | 326 | 4/4/2023 |
1.0.38 | 381 | 4/2/2023 |
1.0.37 | 341 | 4/2/2023 |
1.0.36 | 348 | 4/1/2023 |
1.0.35 | 352 | 4/1/2023 |
1.0.34 | 352 | 4/1/2023 |
1.0.33 | 338 | 3/31/2023 |
1.0.32 | 329 | 3/31/2023 |
1.0.31 | 334 | 3/31/2023 |
1.0.30 | 385 | 3/31/2023 |
1.0.29 | 376 | 3/31/2023 |
1.0.28 | 370 | 3/31/2023 |
1.0.27 | 409 | 3/29/2023 |
1.0.26 | 397 | 3/29/2023 |
1.0.25 | 386 | 3/29/2023 |
1.0.24 | 313 | 3/29/2023 |
1.0.23 | 358 | 3/29/2023 |
1.0.22 | 386 | 3/28/2023 |
1.0.21 | 361 | 3/28/2023 |
1.0.20 | 365 | 3/27/2023 |
1.0.19 | 423 | 3/24/2023 |
1.0.18 | 319 | 3/18/2023 |
1.0.15 | 363 | 3/1/2023 |
1.0.14 | 381 | 3/1/2023 |
1.0.13 | 489 | 3/1/2023 |
1.0.12 | 296 | 2/28/2023 |
1.0.11 | 361 | 2/26/2023 |
1.0.10 | 423 | 2/26/2023 |
1.0.9 | 338 | 2/26/2023 |
1.0.8 | 394 | 2/26/2023 |
1.0.7 | 331 | 2/26/2023 |
1.0.6 | 329 | 2/25/2023 |
1.0.5 | 301 | 2/25/2023 |
1.0.4 | 271 | 2/25/2023 |
1.0.3 | 603 | 2/25/2023 |
1.0.1 | 271 | 2/25/2023 |
1.0.0 | 275 | 2/25/2023 |