Skip to content

Commit 9c5446e

Browse files
authored
Merge branch 'master' into master
2 parents 6cd6374 + 7489941 commit 9c5446e

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

Selenium.psm1

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ function Start-SeChrome {
1010
)
1111

1212
$Chrome_Options = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeOptions"
13+
1314
if($DefaultDownloadPath){
1415
Write-Host "Setting Default Download directory: $DefaultDownloadPath"
1516
$Chrome_Options.AddUserProfilePreference('download', @{'default_directory' = $($DefaultDownloadPath.FullName); 'prompt_for_download' = $false; })
1617
}
18+
1719
if($DisableBuiltInPDFViewer){
1820
$Chrome_Options.AddUserProfilePreference('plugins', @{'always_open_pdf_externally' = $true;})
1921
}
20-
if($Arguments) {
22+
23+
if ($Arguments) {
2124
$Chrome_Options.AddArguments($Arguments)
2225
}
23-
if(!$HideVersionHint)
24-
{
26+
27+
if (!$HideVersionHint) {
2528
Write-Host "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" -ForegroundColor Yellow
2629
}
2730
New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options
@@ -63,6 +66,8 @@ function Find-SeElement {
6366
$Driver,
6467
[Parameter()]
6568
$Element,
69+
[Parameter(ParameterSetName = "ByCss")]
70+
$Css,
6671
[Parameter(ParameterSetName = "ByName")]
6772
$Name,
6873
[Parameter(ParameterSetName = "ById")]
@@ -124,7 +129,7 @@ function Find-SeElement {
124129
if ($PSCmdlet.ParameterSetName -eq "ByXPath") {
125130
$Target.FindElements([OpenQA.Selenium.By]::XPath($XPath))
126131
}
127-
132+
128133
if ($PSCmdlet.ParameterSetName -eq "ByCss") {
129134
$Target.FindElements([OpenQA.Selenium.By]::CssSelector($Css))
130135
}
@@ -139,11 +144,12 @@ function Invoke-SeClick {
139144
[Switch]$JavaScriptClick,
140145
[Parameter()]
141146
$Driver
142-
)
147+
)
143148

144149
if ($JavaScriptClick) {
145150
$Driver.ExecuteScript("arguments[0].click()", $Element)
146-
} else {
151+
}
152+
else {
147153
$Element.Click()
148154
}
149155

@@ -152,16 +158,16 @@ function Invoke-SeClick {
152158

153159
function Get-SeKeys {
154160

155-
[OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name,@{N = "ObjectString"; E = {"[OpenQA.Selenium.Keys]::$($_.Name)"}}
161+
[OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name, @{N = "ObjectString"; E = { "[OpenQA.Selenium.Keys]::$($_.Name)" } }
156162
}
157163

158164
function Send-SeKeys {
159165
param([OpenQA.Selenium.IWebElement]$Element, [string]$Keys)
160166

161-
foreach($Key in @(Get-SeKeys).Name)
162-
{
167+
foreach ($Key in @(Get-SeKeys).Name) {
163168
$Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key
164169
}
170+
165171
$Element.SendKeys($Keys)
166172
}
167173

@@ -180,16 +186,16 @@ function Remove-SeCookie {
180186
function Set-SeCookie {
181187
param($Driver, $name, $value)
182188

183-
$cookie = New-Object -TypeName OpenQA.Selenium.Cookie -ArgumentList $Name,$value
189+
$cookie = New-Object -TypeName OpenQA.Selenium.Cookie -ArgumentList $Name, $value
184190

185191
$Driver.Manage().Cookies.AddCookie($cookie)
186192
}
187193

188194
function Get-SeElementAttribute {
189195
param(
190-
[Parameter(ValueFromPipeline=$true, Mandatory = $true)]
196+
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
191197
[OpenQA.Selenium.IWebElement]$Element,
192-
[Parameter(Mandatory=$true)]
198+
[Parameter(Mandatory = $true)]
193199
[string]$Attribute
194200
)
195201

@@ -204,7 +210,8 @@ function Invoke-SeScreenshot {
204210
$Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions]::TakeScreenshot($Driver)
205211
if ($AsBase64EncodedString) {
206212
$Screenshot.AsBase64EncodedString
207-
} else {
213+
}
214+
else {
208215
$Screenshot
209216
}
210217
}
@@ -218,9 +225,9 @@ function Save-SeScreenshot {
218225
[Parameter()]
219226
[OpenQA.Selenium.ScreenshotImageFormat]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat]::Png)
220227

221-
Process {
222-
$Screenshot.SaveAsFile($Path, $ImageFormat)
223-
}
228+
Process {
229+
$Screenshot.SaveAsFile($Path, $ImageFormat)
230+
}
224231
}
225232

226233
function Wait-SeElementExists{
@@ -232,12 +239,10 @@ function Wait-SeElementExists{
232239
$TagName,
233240
$ClassName
234241
)
235-
if($Id)
236-
{
242+
if ($Id) {
237243
$TargetElement = [OpenQA.Selenium.By]::Id($Id)
238244
}
239-
elseif($Name)
240-
{
245+
elseif ($Name) {
241246
$TargetElement = [OpenQA.Selenium.By]::Name($Name)
242247
}
243248
elseif($TagName)

Selenium.tests.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
Import-Module (Join-Path $PSScriptRoot "Selenium.psm1")
22

33
Describe "Get-SeCookie" {
4+
$Driver = Start-SeFirefox
45
Context "Should get cookies from google" {
5-
$Driver = Start-SeFirefox
66
Enter-SeUrl -Driver $Driver -Url "http://www.google.com"
77

88
Get-SeCookie $Driver
99
}
10+
Stop-SeDriver $Driver
11+
}
12+
13+
Describe "Send-SeKeys" {
14+
$Driver = Start-SeFirefox
15+
Enter-SeUrl -Driver $Driver -Url "http://www.google.com"
16+
Context "Find-SeElement" {
17+
It "By Css" {
18+
$SearchInput = Find-SeElement -Driver $Driver -Css "input[name='q']"
19+
Send-SeKeys -Element $SearchInput -Keys "test"
20+
}
21+
}
22+
Stop-SeDriver $Driver
1023
}

0 commit comments

Comments
 (0)