PHANTOMJS is a WebKit-based JavaScript API. It uses Qtwebkit as the function of its core browser, using WebKit to compile and interpret the execution of JavaScript code. Anything you can do on a WebKit browser can do it. Not only is it an invisible browser, it provides such things as CSS selectors, web standards support, DOM manipulation, JSON, HTML5, Canvas, SVG, and so on, as well as handling file I/O, so you can read and write files to the operating system. Phantomjs is useful for a wide range of applications, such as network monitoring, Web screenshots, Web tests without browsers, and page access automation.
Its use is also quite simple:
One. Installation
Download webdriverc# class library, http://www.seleniumhq.org/download/
You will also need to download a phantomjs,:http://phantomjs.org/download.html
Here you can search in NuGet for selenium.webdriver and Selenium.PhantomJS.WebDriver to download, but domestic network problems may appear to download not come
Two. References (nuget download ignores this step)
If you are downloading through a link, you can refer to it, Phantomjs.exe put it in the root directory, and then set the property to always copy
Three. Preliminary examination
usingOpenqa.selenium;usingOpenQA.Selenium.PhantomJS;usingSystem;namespacephantomjsdemo{classProgram {Static voidMain (string[] args) { varURL ="https://www.baidu.com"; varDriver =NewPhantomjsdriver (); Driver. Navigate (). Gotourl (URL); Driver. Findelement (By.id ("kw")). SendKeys ("ASP"); Driver. Findelement (By.id ("su")). Click (); Console.WriteLine (Driver. Title); Console.read (); Driver. Quit (); } }}
Driver type |
Advantages |
Disadvantages |
Application |
Real Browser driver |
Real-world simulation of user behavior |
Low efficiency and stability |
Compatibility test |
Htmlunit |
Fast speed |
JS engine is not supported by the mainstream browser |
Page test with a small number of JS |
Phantomjs |
Medium speed, simulated behavior close to reality |
Cannot simulate behavior of different/specific browsers |
Functional testing of non-GUI
|
Webdriver Automation Test Tools (3) Use of the---PHANTOMJS