When compatibility is required for automated testing, the previous practice was to install different versions of browsers on each executor. In fact, this would be a waste of resources. Now we have docker containerization technology, make everything simple
1. First, install a Ubuntu server. You can create a virtual machine in workstations.
2. Use xshell to connect after the virtual machine is created,
2.1 install docker
2.2 obtain an image
Docker pull selenium/hub docker pull selenium/node-Firefox-Debug docker pull selenium/node-chrome-Debug
2.3 use an image to create a container
Docker run-d--P 5555: 4444 -- name selenium_hub registry.docker-cn.com/selenium/hub docker run-D-P 5900: 5900 -- Link selenium_hub: hub -- name chrome_node selenium/node-chrome-Debug docker run-D-P 5901: 5901 -- Link selenium_hub: hub -- name firefox_node selenium/node-Firefox-Debug docker PS-a view the container running status
[email protected]:~$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa3110167a391 selenium/node-chrome-debug "/opt/bin/entry_po..." About an hour ago Up About an hour 0.0.0.0:5902->5900/tcp chrome_nodeb230ed926f09 selenium/node-firefox-debug "/opt/bin/entry_po..." About an hour ago Up About an hour 0.0.0.0:5901->5900/tcp agitated_jepsenac2bd2b8912f registry.docker-cn.com/selenium/hub "/opt/bin/entry_po..." 24 hours ago Up About an hour 0.0.0.0:5555->4444/tcp selenium_hub
You can access the Virtual Machine IP Address: 5555/GRID/console to verify whether the container is started.
Install VNC Viewer is an excellent remote control tool software Official Website: https://www.realvnc.com/en/connect/download/viewer/ after the installation of file-> new connection, in the pop-up interface, enter the node IP and port number, save and double-click Start. The connection requires a password. The default password is
Secret
If this page appears, the connection is successful.
Write a script to test it.
# Coding = utf-8from selenium import webdriverfirefox_capabilities = {"browsername": "Firefox", "version": "62.0.3", # note that the version number must be written to "Platform": "any ", "javascriptenabled": True, "Marionette": True,} browser = WebDriver. remote ("http: // 192.168.179.128: 5555/WD/hub", desired_capabilities = firefox_capabilities) # note that port 5555 is the host machine port number mapped above browser. get ("http://www.baidu.com") browser. find_element_by_id ('kw '). send_keys ('docker') browser. get_screenshot_as_file ("D:/baidu.png") browser. close ()
After running the script, you can view the running interface in VNC in real time.
Building an automated distributed test environment using docker + selenium Grid