1- [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \WebDriver.dll" )
2- [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \WebDriver.Support.dll" )
3-
1+ [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \assemblies\WebDriver.dll" )
2+ [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \assemblies\WebDriver.Support.dll" )
43function Start-SeChrome {
54 New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver"
65}
76
87function Start-SeFirefox {
9- New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver"
8+ param ([Switch ]$Profile )
9+
10+ if ($Profile ) {
11+ # Doesn't work....
12+ $ProfilePath = Join-Path $PSScriptRoot " Assets\ff-profile\rust_mozprofile.YwpEBLY3hCRX"
13+ $firefoxProfile = New-Object OpenQA.Selenium.Firefox.FirefoxProfile - ArgumentList ($ProfilePath )
14+ $firefoxProfile.WriteToDisk ()
15+ New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $firefoxProfile
16+ }
17+ else {
18+ $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver"
19+ $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
20+ $Driver
21+ }
22+
1023}
1124
1225function Stop-SeDriver {
@@ -36,7 +49,9 @@ function Find-SeElement {
3649 [Parameter (ParameterSetName = " ByLinkText" )]
3750 $LinkText ,
3851 [Parameter (ParameterSetName = " ByTagName" )]
39- $TagName )
52+ $TagName ,
53+ [Parameter (ParameterSetName = " ByXPath" )]
54+ $XPath )
4055
4156 Process {
4257
@@ -72,13 +87,30 @@ function Find-SeElement {
7287 if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
7388 $Target.FindElements ([OpenQA.Selenium.By ]::TagName($TagName ))
7489 }
90+
91+ if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
92+ $Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
93+ }
7594 }
7695}
7796
7897function Invoke-SeClick {
79- param ([OpenQA.Selenium.IWebElement ]$Element )
98+ param (
99+ [Parameter (Mandatory = $true , ValueFromPipeline = $true )]
100+ [OpenQA.Selenium.IWebElement ]$Element ,
101+ [Parameter ()]
102+ [Switch ]$JavaScriptClick ,
103+ [Parameter ()]
104+ $Driver
105+ )
106+
107+ if ($JavaScriptClick ) {
108+ $Driver.ExecuteScript (" arguments[0].click()" , $Element )
109+ } else {
110+ $Element.Click ()
111+ }
80112
81- $Element .Click ()
113+
82114}
83115
84116function Send-SeKeys {
@@ -118,4 +150,27 @@ function Get-SeElementAttribute {
118150 Process {
119151 $Element.GetAttribute ($Attribute )
120152 }
121- }
153+ }
154+
155+ function Invoke-SeScreenshot {
156+ param ($Driver , [Switch ]$AsBase64EncodedString )
157+
158+ $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions ]::TakeScreenshot($Driver )
159+ if ($AsBase64String ) {
160+ $Screenshot.AsBase64EncodedString
161+ }
162+ }
163+
164+ function Save-SeScreenshot {
165+ param (
166+ [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
167+ [OpenQA.Selenium.Screenshot ]$Screenshot ,
168+ [Parameter (Mandatory = $true )]
169+ [string ]$Path ,
170+ [Parameter ()]
171+ [OpenQA.Selenium.ScreenshotImageFormat ]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat ]::Png)
172+
173+ Process {
174+ $Screenshot.SaveAsFile ($Path , $ImageFormat )
175+ }
176+ }
0 commit comments