PowerShell invoke the Web test tool Selenium Instance _powershell

Source: Internet
Author: User
Tags goto

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/)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.