SeleniumIt is of great help for us to carry out automated Web Testing. If we want to perform a wide range of testing coverage, we can't just run on one or two machines; selenium-grid also provides us with such help. We can easily build a distributed test environment with selenium-grid. Different from other common distributedProgram[Example: Hudson] selenium-grid is an automated distributed test solution for selenium.
ItsAdvantagesYes:
- Quickly build a distributed environment [through simple parameter configuration]
- Automatically allocate test scripts for different environments]
- Only one testCode[No test code is required for the target Testing Machine]
Build the selenium2 Environment
Before setting up selenium-grid, you must first set up the selenium environment on each test machine. [This should be the environment of the proxy node ]. Java is used as an example:
- Install Java [Download]
- Configure the Java environment variable [here]
- Download the driver program for IE and chrome. [Additional download is required if you want to test other browsers. By default, the FF driver is in WebDriver and does not need to be downloaded]
- Put IE and chrome driver programs in system environment variables (for example, system32]
- Install the latest version of the browser, such as ff and chrome]
- Download selenium WebDriver [Download standalone server]
- Code Testing
Local version:
Import Org. openqa. selenium. *; import Org. openqa. selenium. firefox. *; import Org. openqa. selenium. chrome. *; import org.openqa.selenium.html unit. *; import Org. openqa. selenium. IE. *; // WebDriver driver = new chromedriver (); // WebDriver driver = new firefoxdriver (); // WebDriver driver = new htmlunitdriver (); WebDriver driver = new internetexplorerdriver (); driver. get ("http://www.dangdang.com"); system. out. println (driver. getcurrenturl (); driver. quit ();
Remote edition:
Import Org. openqa. selenium. *; import Org. openqa. selenium. remote. desiredcapabilities; import Org. openqa. selenium. remote. remotewebdriver; desiredcapabilities ffdesiredcap = desiredcapabilities. firefox (); desiredcapabilities chromedesiredcap = desiredcapabilities. chrome (); desiredcapabilities iedesiredcap = desiredcapabilities. internetexplorer (); WebDriver WD = new remotewebdriver (new URL ("http: // localhost: 4444/WD/hub"), iedesiredcap); WD. get ("http://www.google.com"); thread. sleep (1, 1200); system. out. println (WD. getcurrenturl (); WD. quit ();
If all the tests are successful, your environment has been successfully set up. In turn, you can set up selenium2 on multiple systems and platforms.
Note:
If IDE is used, the jar package of selenium-standalone-server is referenced to the Project Build path. If the jar package is compiled and executed directly from the command line, the path of the jar package must be specified, otherwise, compilation fails.
Javac-classpath $ home/path/to/selenium-server.jar test. Java-classpath $ home/path/to/selenium-server.jar Test
Build the selenium-Grid Environment
When the selenium2 environment on all the test machines is successfully set up, you can start the Selenium-Grid2 environment. [Working Principle of selenium-grid]
FirstStart a hub:
Java-jar selenium-server-standalone-x.xx.x.jar-role Hub
The machine that starts the hub can be either a test machine or a machine with a Java environment. This is the central node of the whole selenium-grid. All remote tests will be forwarded after it is passed, and then the tests will be executed on the corresponding test machine.
Start the test proxy Node:
Java-jar selenium-server-standalone-x.xx.x.jar-role Node
The test agent must start on the Test Machine [that is, the machine that has previously set up the selenium2 Environment], and its registered address must be the IP address and port of the machine where the hub is located. Multiple proxies can be started on one test machine, provided that the same port is not used. [Of course we do not recommend doing this to avoid unstable factors as much as possible]
View selenium-Grid status
After the hub and all proxy nodes are successfully started, you can view the current selenium-Grid status in the browser and directly access the address http: // localhost: 4444/GRID/console. The page shows the number and type of proxy nodes that can be tested. The displayed quantity and type are related to the configuration parameters when you start the proxy node. When a proxy node is started, it is actually a registration process. The parameters contained during the startup will be remembered by the hub as registration information, therefore, the information displayed on the page is the summary of registration information of each proxy node.