What is Selenium
Selenium is a well-known Web application testing tool that can perform tests by simulating the actions of users in a browser, and its API supports java,c#,python,ruby,php,perl,javascript these mainstream programming and scripting languages. Selenium also supports mainstream browsers such as IE, Firefox, and Chrome.
PowerShell How to call selenium directly
PowerShell directly call selenium, in fact similar to PowerShell call C # method. Take IE browser for example, you need at least two files:
1.iedriverserver.exe start IE agent, simulate user operation
2.webdriver.dll exposes the API to the user and controls the browser
Example of pure PowerShell call Selenium
Copy Code code as follows:
Add-type-path. \webdriver.dll
$SeNS = ' Openqa.selenium '
# Initialize IE driver instance
$ieDriver = New-object "$SeNS. Ie.internetexplorerdriver"
$nav = $ieDriver. Navigate ()
$nav. Gotourl (' http://www.jb51.net ')
# Set the value of the text box
$search = $ieDriver. Findelementbyid (' s ')
$search. SendKeys (' Test framework ')
# Submit the form
$search. Submit ()
$ieDriver. Findelementbyclassname (' class ')
$ieDriver. Findelementbyid (' id ')
$ieDriver. Findelementbylinktext (' a link ')
$ieDriver. Findelementbypartiallinktext (' PowerShell ')
$ieDriver. Findelementbyname (' username ')
$ieDriver. Findelementbycssselector (")
# screenshot and save
$screenshot = $ieDriver. Getscreenshot ()
[Io.file]::writeallbytes (' d:\test\a.jpg ', $screenshot.) Asbytearray)
# Close IE process
$ieDriver. Quit ()
Why to use Selenium
Looking at the above call, some of the brothers began to question the Main method is: Find element. Similar to the key approach in the HTML document class in Internetexplorer.application, Byid,byname,byclass,bytag. Think so, yes.
But after I test, if the Web page slightly more complex, internetexplorer.application in addition to getElementById can reluctantly accept, the other way slow mess. Selenium, however, was doing very well.
In addition selenium support CSS selector lookup node, this is undoubtedly the most power, let jquery also into the fight.
The last point of course is the selenium compatibility advantage for browsers.
With the help of selenium PowerShell eXtensions
This is a PowerShell open source extension tool that encapsulates selenium, and if you feel uncomfortable, you can refactor it yourself or rewrite it directly. Code hosted in:
1.GitHub (Http://www.pstips.net/goto/https://github.com/apetrovskiy/STUPS)
2.Codeplex (http://www.pstips.net/goto/http://sepsx.codeplex.com/)