Webdriver Drive Introduction
Because the mobile side of the driver is not currently in contact, so the main introduction of PC end DRIVER,PC end of the driver are browser-based, mainly divided into 2 types:
- One is the real browser Driver:safari, Firefox, ie, Chrome, etc.
For example: Safari, Firefox, ie, Chrome are all through the browser native components to invoke the browser's native API, these driver are directly launched and by invoking the browser's underlying interface to drive the browser, so with the most realistic user scene simulation, Used primarily for web compatibility testing.
- One is pseudo browser driver:htmlunit, PHANTOMJS
Selenium supported pseudo-browsers include Htmlunit, PHANTOMJS; they are not really running in the browser, there is no GUI, but with the support of HTML, JS and other parsing capabilities of the class browser program;
These programs do not render the display of the page, but support the search for page elements, JS execution, and so on, because no CSS and GUI rendering, so the efficiency will be much faster than the real browser, mainly used in functional testing above.
Driven |
Description |
Firefox Driver |
Included in the Selenium (Webdriver) package for each language, which is why you can use Firefox to launch scripts directly after installing selenium. |
Chrome Driver |
Need to download Chromedriver, because Webdriver was originally Google's project, and then merged with selenium, so the support for Chrome is also very good |
IE Driver |
Need to download iedriverserver. |
Opera Driver |
To download Operadriver,operadriver is webdriver maker Opera Software and volunteers developed the Webdriver implementation for opera |
Htmlunit Driver |
Htmlunit is the Java implementation of the class browser program, it will return the document simulation into HTML, so as to simulate the browser run, but not really to start a browser to execute the script contained in the selenium server, without driver, direct instantiation can |
Phantomjs Driver |
PHANTOMJS is an interface-free WebKit with JavaScript APIs that can be viewed as a browser with no interface. PHANTOMJS is a standalone browser app for third parties that can support HTML, JS, CSS, and other execution |
Appium |
Appium can be viewed as a mobile selenium, and it also supports automated testing of multiple platforms (IOS, Android, and Firefoxos) for apps and mobile web |
The following main introduction of the two pseudo-browser simple call method and comparison, followed by a separate description of Firefox and IE browser calls detailed content and various problem solving methods.
Htmlunit Call
Htmlunit Official website: http://htmlunit.sourceforge.net/
This article uses the local API to view the address to test, can refer to: The previous Selenium Python browser call: Firefox article " How to view the Python Selenium API to open the address
Method One:
#Coding=utf-8 fromSeleniumImportWebdriver fromTimeImportCTime fromTimeImportSleep fromSelenium.webdriver.common.desired_capabilitiesImportdesiredcapabilitiesPrintCTime () driver=webdriver. Remote (command_executor="Http://127.0.0.1:5555/wd/hub", desired_capabilities=desiredcapabilities.htmlunit) Driver.get ("http://127.0.0.1:4567") Driver.find_element_by_partial_link_text ("Selenium"). Click ()PrintDriver.titlePrintDriver.current_urlPrintDriver.namePrintCTime () driver.close ( )
Method Two:
#Coding=utf-8 fromSeleniumImportWebdriver fromTimeImportCTime fromTimeImportSleepPrintCTime () driver=Webdriver. Remote (Command_executor='Http://127.0.0.1:5555/wd/hub', Desired_capabilities={'Platform':' any','Browsername':'Htmlunit','version':"','javascriptenabled': True}) Driver.get ("http://127.0.0.1:4567") Driver.find_element_by_partial_link_text ("Selenium"). Click ()PrintDriver.titlePrintDriver.current_urlPrintDriver.namePrintCTime () driver.close ( )
The results are as follows, because the test process has no interface, so the print time, and the page title and URL to determine the execution result:
Wed Oct 17:29:22 2015python:package seleniumhttp://127.0.0.1:4567/selenium.htmlhtmlunitwed Oct 14 17:29:22 2015
You need to start selenium server before running, the startup method is as follows:
1. C:\users\admin>java-jar Selenium-server-standalone-2.45.0.jar-role Hub
2, C:\users\admin>java-jar Selenium-server-standalone-2.45.0.jar node-port 5555-hub Http://127.0.0.1:4444/grid/ Register
PHANTOMJS Call
PHANTOMJS Official website: http://phantomjs.org/
Before making phantomjs, you need to download it first. PHANTOMJS support Windwos, MAC, Linux and other platforms, we can choose the appropriate version according to their own environment to download, download complete decompression will have to phantomjs-2.0.0-windows directory, in the bin The directory will see the Phantomjs.exe program, adding the current directory to the system environment variable path. (or drop the phantomjs.exe directly into the Python installation directory, because we've initially added Python to the system environment variable's path).
The following can be tested using the PHANTOMJS driver.
#Coding=utf-8 fromSeleniumImportWebdriver fromTimeImportCTime fromTimeImportSleepPrintCTime () driver=webdriver. PHANTOMJS (executable_path="C:\\python27\\phantomjs.exe") Driver.get ("http://127.0.0.1:4567") Driver.find_element_by_partial_link_text ("Selenium"). Click ()PrintDriver.titlePrintDriver.current_urlPrintDriver.namedriver.get_screenshot_as_file ("c:\\photo.jpg")PrintCTime () driver.close ( )
The result of the operation is as follows, and the captured picture can be seen in the C-drive, which matches the actual operating interface:
Wed Oct 17:29:50python:package seleniumhttp://127.0.0.1:4567/14 17:29:53 2015
Browser comparison
The following runs the same script in Htmlunit, Phantomjs, and Firefox (using the demo script Htmlunit above)
The time of the three is: htmlunit:0s,phantomjs:3s,firefox:8s
Here's a comparison of the pros and cons of each browser:
Drive type |
Advantages |
Disadvantages |
Application |
Real-World Browser drivers |
Real-world simulation of user behavior |
Low operating efficiency and stability |
The Web Compatibility test uses |
Htmlunit |
Fast running speed |
JS engine non-mainstream browser support |
Page test with a small number of JS |
Phantomjs |
Fast running, simulated behavior close to the real browser |
Cannot impersonate a specific browser behavior |
Functional testing of non-GUI |
Resources
[1],selenium Webdriver's various driver,
http://blog.csdn.net/five3/article/details/19085303
Selenium Python browser call: Pseudo browser