SELENIUM2 supports testing through various driver (firfoxdriver,iternetexplorerdriver,operadriver,chromedriver) to drive real-world browsers.
In fact, selenium is also supported without interface browser operation. such as Htmlunit and PHANTOMJS. They are not real browsers, the runtime will not render the page display content, but support page element lookup, JS execution, etc., because no CSS and GUI rendering, the efficiency is much faster than the real browser.
1.htmlUnit is a Java-implemented class browser program that is included in the selenium server without the need for a driver to instantiate directly.
Use the following: Webdriver Driver =
new htmlunitdriver ();// Webdriver Driver =
new Htmlunitdriver (TRUE);//Support JS 2.PhantomJS is a server-side JavaScript API based on WebKit (WebKit is an open source browser engine, Chrome,Safari is the browser engine ), the main application scenario is: Web testing without browser, page access automation, screen capture, network monitoring Use the following:Webdriver Driver = new Phantomjsdriver (); 3. In order to see whether the above two non-interface browser is suitable for the current project group front-end automation, did some preliminary research, the results are as follows:
Behavior description |
Behavior |
Htmlunitdriver |
Htmlunitdriver (True) |
Phantomjsdriver |
Firefoxdriver |
text box input |
Enter text |
Yes |
Yes |
Yes |
Yes |
Buttons button |
Click the button |
Yes |
Yes |
Yes |
Yes |
Hyperlink A |
Click |
Yes |
Yes |
No |
Yes |
Drop-down list select |
Select options |
Yes |
Yes |
Yes |
Yes |
check box checkbox |
Click |
Yes |
Yes |
Yes |
Yes |
Alert (Displays a warning box with a specified message and an OK button) |
Click |
No |
No |
No |
Yes |
Promprt (displays a dialog box to prompt the user for input) |
Click |
No |
No |
No |
Yes |
The final pre-research results are not suitable for our system because there are many alert in our system4. Summarize the pros and cons of HTMLUNITDRIVER,PHANTOMJS vs Real Browser drivers
Driver type |
Advantages |
Disadvantages |
Application |
Real Browser driver |
Real-world simulation of user behavior |
Low efficiency and stability |
Browser compatibility test |
Htmlunit |
Fast speed |
JS Engine (RHINOJS) is not the mainstream browser support, so the JS support is not good enough |
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 |
Summarize:
If you want to test the page JS is not a lot, and do not need to do a compatibility test, Htmlunitdriver is the best choice
If you need to do a compatibility test, you should still choose the real browser driver (if you want to improve the speed of automation, you can consider using Testng,selenium grid parallel test)
SELENIUM2 supports no interface operation (Htmlunit and PHANTOMJS)