Nutstone.Selenium.Powershell 1.0.55

dotnet add package Nutstone.Selenium.Powershell --version 1.0.55
NuGet\Install-Package Nutstone.Selenium.Powershell -Version 1.0.55
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nutstone.Selenium.Powershell" Version="1.0.55" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nutstone.Selenium.Powershell --version 1.0.55
#r "nuget: Nutstone.Selenium.Powershell, 1.0.55"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Nutstone.Selenium.Powershell as a Cake Addin
#addin nuget:?package=Nutstone.Selenium.Powershell&version=1.0.55

// Install Nutstone.Selenium.Powershell as a Cake Tool
#tool nuget:?package=Nutstone.Selenium.Powershell&version=1.0.55

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
There are no supported framework assets in this package.

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 374 4/24/2023
1.0.54 297 4/16/2023
1.0.53 211 4/15/2023
1.0.52 242 4/11/2023
1.0.51 263 4/8/2023
1.0.50 305 4/8/2023
1.0.48 270 4/8/2023
1.0.47 264 4/7/2023
1.0.46 313 4/6/2023
1.0.45 305 4/6/2023
1.0.44 285 4/6/2023
1.0.43 291 4/6/2023
1.0.42 309 4/6/2023
1.0.41 377 4/6/2023
1.0.40 337 4/4/2023
1.0.39 279 4/4/2023
1.0.38 330 4/2/2023
1.0.37 291 4/2/2023
1.0.36 293 4/1/2023
1.0.35 293 4/1/2023
1.0.34 303 4/1/2023
1.0.33 293 3/31/2023
1.0.32 285 3/31/2023
1.0.31 286 3/31/2023
1.0.30 347 3/31/2023
1.0.29 320 3/31/2023
1.0.28 331 3/31/2023
1.0.27 362 3/29/2023
1.0.26 353 3/29/2023
1.0.25 335 3/29/2023
1.0.24 267 3/29/2023
1.0.23 313 3/29/2023
1.0.22 332 3/28/2023
1.0.21 309 3/28/2023
1.0.20 314 3/27/2023
1.0.19 378 3/24/2023
1.0.18 274 3/18/2023
1.0.15 319 3/1/2023
1.0.14 345 3/1/2023
1.0.13 435 3/1/2023
1.0.12 258 2/28/2023
1.0.11 311 2/26/2023
1.0.10 375 2/26/2023
1.0.9 295 2/26/2023
1.0.8 352 2/26/2023
1.0.7 281 2/26/2023
1.0.6 291 2/25/2023
1.0.5 274 2/25/2023
1.0.4 240 2/25/2023
1.0.3 510 2/25/2023
1.0.1 239 2/25/2023
1.0.0 247 2/25/2023