Skip to content

Commit 96bfd94

Browse files
committed
Feature/v4 driverupgrade (#183)
* Driver + rebuild
1 parent 7009ba4 commit 96bfd94

38 files changed

+175
-196
lines changed

Help/ConvertTo-SeSelenium.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
external help file: Selenium-help.xml
3+
Module Name: Selenium
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertTo-Selenium
9+
10+
## SYNOPSIS
11+
Convert Selenium IDE .side recording file to PowerShell commands.
12+
13+
## SYNTAX
14+
15+
```
16+
ConvertTo-Selenium [-Path] <String> [<CommonParameters>]
17+
```
18+
19+
## DESCRIPTION
20+
{{ Fill in the Description }}
21+
22+
## EXAMPLES
23+
24+
### Example 1
25+
```powershell
26+
PS C:\> {{ Add example code here }}
27+
```
28+
29+
{{ Add example description here }}
30+
31+
## PARAMETERS
32+
33+
### -Path
34+
Path to .side file.
35+
36+
```yaml
37+
Type: String
38+
Parameter Sets: (All)
39+
Aliases:
40+
41+
Required: True
42+
Position: 1
43+
Default value: None
44+
Accept pipeline input: False
45+
Accept wildcard characters: False
46+
```
47+
48+
### CommonParameters
49+
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).
50+
51+
## INPUTS
52+
53+
## OUTPUTS
54+
55+
## NOTES
56+
57+
## RELATED LINKS

Output/Selenium/ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#4.0.0 (Unreleased)
22

33

4-
# 4.0.0-beta-1 (Prerelease)
4+
# 4.0.0-preview1 (Prerelease)
55
Note: V4 have an enormous amount of breakchanges. Most of the cmdlet have been rewriten in a way or another.
66

77
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.
Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,55 @@
1-
<#
2-
.VERSION - 0.2
3-
4-
.DESCRIPTION
5-
This is an example script that will show you how to use the Selenium driver to preform a simple google search.
6-
Using this example script you will learn the basic usage of the Selenium powershell module.
7-
Each comment line will explain the line that will come after it so you can follow it in a step by step fashion.
8-
#>
9-
101
# The line below will Import-Module Selenium if it fails it will display the installation command and stop the script.
11-
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}
2+
Import-Module -Name Selenium
123

134
# Start the Selenium Chrome Driver
14-
$Driver = Start-SeChrome
5+
Start-SeDriver -Browser Chrome -StartURL 'google.com/ncr'
156

16-
# 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.
17-
if($Driver){
18-
# Now that we verified that the driver is running we can start doing cool things with it.
197

20-
# 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
21-
# 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.
22-
Enter-SeUrl -Driver $Driver -Url 'https://www.google.com/ncr'
238

24-
# 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.
25-
# We can find elements using different ways like the element id or the Name/ClassName/TagName and a few other ways.
26-
# In the below code we're going to show you a few ways to solve this problem.
9+
#Getting the Search box
2710

28-
<# This is the HTML code of the search box
11+
<# This is the HTML code of the search box, found using the browser developer tools
2912
<input class="gLFyf gsfi" maxlength="2048" name="q" type="text" jsaction="paste:puy29d" aria-autocomplete="both" aria-haspopup="false" autocapitalize="off" autocomplete="off" autocorrect="off" role="combobox" spellcheck="false" title="Search" value="" aria-label="Search">
30-
#>
13+
#>
3114

32-
# 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
33-
$SearchBoxElement = Find-SeElement -Driver $Driver -Name q
15+
#Here's a few different ways, all valid, to access that searchbox
3416

35-
# We can also use the class name gLFyf to find the google search box.
36-
$SearchBoxElement = Find-SeElement -Driver $Driver -ClassName 'gLFyf'
17+
# 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
18+
#The Single parameter will write an error if there's not 1 element.
19+
$Searchbox = Get-SeElement -By Name -value q -Single
3720

38-
# This line will get us all elements with the input TagName also known as <input>
39-
$AllInputElements = Find-SeElement -Driver $Driver -TagName input
21+
# We can also use the class name gLFyf to find the google search box.
22+
$Searchbox = Get-SeElement -ClassName 'gLFyf'
4023

41-
# 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.
42-
# 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.
43-
$SearchBoxElement = $AllInputElements|ForEach-Object{if($_.GetAttribute('title') -eq 'Search'){return $_}}
24+
# This line will get us all elements with the input TagName also known as <input>
25+
#The -All parameter (optional) also includes hidden elements.
26+
# The -Attributes parameter will load the specified attribute in the result and make them available through an Attributes property
27+
$AllInputElement = Get-SeElement -By TagName -Value input -All -Attributes title
28+
$AllInputElement | select Attributes
29+
# 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.
30+
# 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.
31+
$Searchbox = $AllInputElement.Where( { $_.Attributes.title -eq 'Search' }, 'first')[0]
4432

45-
# 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
46-
# We can get the list of all special keyboard keys like enter/backspace etc using the Get-SeKeys command
33+
# 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
34+
# We can get the list of all special keyboard keys like enter/backspace etc using the Get-SeKeys command
4735

48-
# Now that we can see all the keys we can send send some keys to the SearchBoxElement
49-
Send-SeKeys -Element $SearchBoxElement -Keys 'Powershell-Selenium'
36+
# Now that we can see all the keys we can send send some keys to the SearchBoxElement
37+
Invoke-SeKeys -Element $Searchbox -Keys 'Powershell-Selenium'
5038

51-
# 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
52-
Send-SeKeys -Element $SearchBoxElement -Keys ([OpenQA.Selenium.Keys]::Enter)
39+
# 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
40+
# To view special keys, use Get-SeKeys
41+
Invoke-SeKeys -Element $Searchbox -Keys ([OpenQA.Selenium.Keys]::Enter)
5342

54-
# 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.
55-
# The first is to use the Find-SeElement cmdlet with the -Wait switch to wait for the existence of an element in the document.
56-
# 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.
43+
# 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.
44+
# The first is to use the Find-SeElement cmdlet with the -Wait switch to wait for the existence of an element in the document.
45+
# 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.
5746

58-
# 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.
59-
$LogoImageElement = Find-SeElement -Driver $Driver -Wait -Timeout 10 -Id 'logo'
47+
# 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.
48+
#Note, the value parameter is provided positionally.
49+
$LogoImageElement = Get-SeElement -Timeout 10 -By Id 'logo'
6050

61-
# Once we have the image element we can simulate a mouse click on it using the Invoke-SeClick command.
62-
Invoke-SeClick -Driver $Driver -Element $LogoImageElement
51+
# Once we have the image element we can simulate a mouse click on it using the Invoke-SeClick command.
52+
Invoke-SeClick -Element $LogoImageElement
6353

64-
# 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.
65-
Stop-SeDriver -Driver $Driver
66-
}
67-
# if the driver is not running we will enter the script block in the else section and display a message
68-
else{
69-
Write-Host "The selenium driver was not running." -ForegroundColor Yellow
70-
}
54+
# 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.
55+
Stop-SeDriver

Output/Selenium/Examples/DemoSelenium.tests.ps1

Lines changed: 0 additions & 54 deletions
This file was deleted.

Output/Selenium/Examples/DemoSelenium2.tests.ps1

Lines changed: 0 additions & 49 deletions
This file was deleted.

Output/Selenium/Examples/TestPSGallery.ps1

Lines changed: 0 additions & 23 deletions
This file was deleted.

Output/Selenium/Examples/comparison.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public void testClass() throws Exception {
88
Assert.assertEquals("Wikipedia. the free encyclopedia", driver.getTitle());
99
}
1010
#>
11-
SeOpen "http://www.wikipedia.org/"
11+
Start-SeDriver -Browser Chrome -StartURL "https://www.wikipedia.org/"
1212
SeShouldHave -Title eq Wikipedia
13-
SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | SeClick
13+
SeShouldHave 'strong' -By CssSelector -With Text eq 'English' -PassThru | Invoke-SeClick
1414
SeShouldHave -Title eq 'Wikipedia, the free encyclopedia'
1515

1616
<#
@@ -52,7 +52,9 @@ public static void main(String[] args) {
5252
}
5353
#>
5454

55-
SeOpen "http://demo.guru99.com/test/newtours/" -In FireFox # or #-in Chrome -in MsEdge -in NewEdge or -in IE
55+
Start-SeDriver -Browser Firefox -StartURL "http://demo.guru99.com/test/newtours/"
5656
SeShouldHave -Title eq "Welcome: Mercury Tours"
57-
SeClose
57+
58+
#Stop opened drivers
59+
Get-SeDriver | Stop-SeDriver
5860

Output/Selenium/Selenium.psm1

78 Bytes
Binary file not shown.
410 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
A1E26B0E8CB5F8DB1CD784BAC71BBF540485D81E697293B0B4586E25A31A8187
1+
51053574E3BA3AB5D9F47E13EC0E9961AD6C9C9978DC851BE71C0F86A272C74B
104 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0986FA1D2B07F3C755B84BC50D8115A09F246BF2D30BC1B850B957BC394FAD53
1+
5BFEADAEB1182DC068B60377BA34C010317D6AE19DA4934A221B2B1F3A050889
-34 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
255C9D3571C86841213F49B26D176A6AD440BE8C720E3C2D9226076ADF4F603D
1+
FAED02EC5B0D6246856843D10EE020CB5121B8261AC939BE761130F21A73D3EE
260 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6590E3B9D9BF292C8DF50B6DF5BCF8A5191D999F9E48F68AA2055EB5746B2C05
1+
0B2C9B9791925DCEA2981CBDFAB8274FB4668BF65D6A57C2257E8B57757C394A
-20 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
F24498EAF30B191CB79A55903457A8799E2695657C889AF4824390BF2D379F30
1+
9793D91D3448E35061606F37F1EB3EECC7B492CF159E6A318395445FB75B46EC
-543 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
D62C2178377ADDEB1BB860426B2C9B10B68D2EEABF0C521529A4A6A7B1E208C4
1+
AA2FCE6B96183C9D8FD0AA125F87557FCCEC60301CF7ADD1578B0DA59355AD8B
3.28 MB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
509FFD6D321EF78C8319E68B89807D2437D8DB1718000FE2BB7ECACB1529730D
1+
A6EB02FF3EF75079A647F20BD0B6B563648BC4C8563443229C65671AB0BBB6CD

0 commit comments

Comments
 (0)