Skip to content

ConvertTo-Selenium #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 12, 2020
Merged

ConvertTo-Selenium #175

merged 5 commits into from
Oct 12, 2020

Conversation

ili101
Copy link
Contributor

@ili101 ili101 commented Oct 10, 2020

feature request #84
Convert Selenium IDE .side recording file to PowerShell commands.

I implemented this basic commends:

Set-SeUrl
Stop-SeDriver

Get-SeElement
Invoke-SeClick
Invoke-SeKeys
Set-SeSelectValue

Switch-SeFrame -Parent
(Get-SeDriver -Current).SwitchTo().Frame($Index)

If a command is missing it will be added as a comment.

  • We can probably implement some of the other commands, those are the one I usually use.
  • should we output a String or an Array of Strings or ScriptBlock? (Currently it's Array of Strings)
  • other stuff?

output example:

# Project: Example
# Test: Test1
Set-SeUrl -Url "https://automationintesting.com/selenium/testpage/"
# Unsupported command. Command: "setWindowSize", Target: "1936x1056", Value: "", Comment: "".
Get-SeElement -By Id -value "firstname" | Invoke-SeClick
Get-SeElement -By Id -value "firstname" | Invoke-SeKeys -Keys "test"
Get-SeElement -By XPath -value "//form[@id='contactus']/div[2]/div/label/input" | Invoke-SeClick
Get-SeElement -By XPath -value "//form[@id='contactus']/div[2]/div/label/input" | Invoke-SeKeys -Keys "test2"
Get-SeElement -By Id -value "gender" | Invoke-SeClick
Get-SeElement -By Id -value "gender" | Set-SeSelectValue -By Text -value "Male"
Get-SeElement -By Id -value "red" | Invoke-SeClick
Get-SeElement -By CssSelector -value "textarea" | Invoke-SeClick
Get-SeElement -By CssSelector -value "textarea" | Invoke-SeKeys -Keys "text"
# Unsupported command. Command: "addSelection", Target: "id=continent", Value: "label=North America", Comment: "".
Get-SeElement -By Id -value "checkbox1" | Invoke-SeClick
Get-SeElement -By Id -value "submitbutton" | Invoke-SeClick
# Test: Test2
Set-SeUrl -Url "https://automationintesting.com/selenium/testpage/"
# Unsupported command. Command: "setWindowSize", Target: "1936x1056", Value: "", Comment: "".
Get-SeElement -By Id -value "firstname" | Invoke-SeKeys -Keys "test3"
Get-SeElement -By Id -value "firstname" | Invoke-SeKeys -Keys "${KEY_ENTER}"
# Test: Test3
Set-SeUrl -Url "http://www.tagindex.net/html/frame/example_f01.html"
# Unsupported command. Command: "setWindowSize", Target: "1936x1056", Value: "", Comment: "".
$null = (Get-SeDriver -Current).SwitchTo().Frame(0)
Get-SeElement -By CssSelector -value "html" | Invoke-SeClick
Switch-SeFrame -Parent
$null = (Get-SeDriver -Current).SwitchTo().Frame(1)
# Unsupported command. Command: "doubleClick", Target: "css=p", Value: "", Comment: "".
Stop-SeDriver

@itfranck
Copy link
Collaborator

I like that :)
When ready to merge, please do the following:

  • Move the function into the Public folder
  • Move the Example.side in the Examples folder
  • Remove the import statement at the beginning (L1) and the code after the function (L112-L114)

As for your second point, personally I like the idea of getting it as a ScriptBlock.
That way, you can Call .invoke() on the result immediately if you want to.
You can also save it / set the clipboard just like a string or array of string.

@itfranck
Copy link
Collaborator

@ili101 I'll be publishing V4.0 (pre-release) on the gallery tonight. If you are finished by now, let me know and I'll merge your PR. Otherwise, no worries, I'll just release an update whenever it is ready.

The plan is to leave the version as a pre-release for about a month before getting the official release out for real.
That time will allow to collect hopefully more feedback and ensure the release is stable before going forward.

@ili101
Copy link
Contributor Author

ili101 commented Oct 12, 2020

I didn't have the chance to work on it but it will be nice to have it in so we can get some feedback.
I can clean it up now so we can get it in and maybe add more commands support later.

@ili101
Copy link
Contributor Author

ili101 commented Oct 12, 2020

I moved the files and converted to ScriptBlock so now you can do

Import-Module .\Selenium.psd1
$PsCode = ConvertTo-Selenium -Path .\Examples\Example.side
# Run directly:
. $PsCode
# Send to clipboard:
$PsCode | Set-Clipboard

@ili101
Copy link
Contributor Author

ili101 commented Oct 12, 2020

Add Invoke-SeClick -Action DoubleClick and using Switch-SeFrame -Frame $Index + Switch-SeFrame -Frame 0 fix.
There is one more line in this example that is not converted correctly:

Get-SeElement -By Id -value "firstname" | Invoke-SeKeys -Keys "${KEY_ENTER}" 

In C# it's converted to:

driver.FindElement(By.Id("firstname")).SendKeys(Keys.Enter);

Not sure if you want to add this to Invoke-SeKeys or Invoke-SeKeyAction
Also I think Invoke-SeKeyAction -Action is optional but it fails without it, maybe the default action should be sending the key.

@ili101 ili101 changed the title ConvertTo-Selenium WIP ConvertTo-Selenium Oct 12, 2020
@itfranck itfranck merged commit 15bedb8 into adamdriscoll:V4 Oct 12, 2020
@itfranck
Copy link
Collaborator

@ili101 Ah, I was merging around the same time you published your comment so I missed it.
Note, I removed Invoke-SeKeyAction altogether as the implementation was problematic since we would have needed to have some kind of way to build / perform.

Instead, it is cooked in Invoke-SeKeys so if the keys start with a modifier key, it will do a key down on all the modifier keys, then send the remaining and perform a key up.

So Invoke-SeKeys is the way to go.

itfranck pushed a commit that referenced this pull request Oct 13, 2020
@Tomblarom
Copy link

I discovered an major spelling error, wherefore I get "Cmdlet is not recognized"-Error:

Selenium.psd1
20: FunctionsToExport = @(...'ConvertTo-SeSelenium'...)

Selenium.psm1
160: function ConvertTo-Selenium { ...

Version: 4.0.0-preview3 from PS-Gallery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy