Selenium Grid
Recently, I am working on to use SELENIUM for automating testing.
A part of my goal is to use SELENIUM for stress test
We want to simulate the registration process to make sure the course system could be working as expected at the next semester when students register their courses.
I use ansible playbook to simplify the build of a selenium grid environment.
The following packages are mandatory.
sudo apt install python-docker pip install docker-py pip uninstall requests pip uninstall urllib3 pip install requests
The script creating a selenium grid:
selenium_grid.yml
--- - hosts: localhost connection: local gather_facts: False vars: nodes: 10 state: started dns: 192.168.100.153 tasks: - name: "{{ '%s hub' | format(state) }}" docker_container: name: hub image: selenium/hub state: "{{ state }}" published_ports: 5555:4444 recreate: yes cleanup: yes dns_servers: "{{ dns }}" - name: "{{ '%s nodes' | format(state) }}" docker_container: name: "{{ 'chrome%02d' | format(item) }}" image: selenium/node-chrome-debug state: "{{ state }}" published_ports: "{{ '59%02d:5900' | format(item) }}" recreate: yes cleanup: yes links: hub:hub dns_servers: "{{ dns }}" loop: "{{ range(1, nodes|int + 1, 1)|list }}"
$ ansible-playbook selenium_grid.yml [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ******************************************************************************************************************* TASK [started hub] ***************************************************************************************************************** changed: [localhost] TASK [started nodes] *************************************************************************************************************** changed: [localhost] => (item=1) changed: [localhost] => (item=2) changed: [localhost] => (item=3) changed: [localhost] => (item=4) changed: [localhost] => (item=5) changed: [localhost] => (item=6) changed: [localhost] => (item=7) changed: [localhost] => (item=8) changed: [localhost] => (item=9) changed: [localhost] => (item=10) PLAY RECAP ************************************************************************************************************************* localhost : ok=2 changed=2 unreachable=0 failed=0 zhangqiaoc@ubuntu01:~/ansible$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4dd9291caf0 selenium/node-chrome-debug "/opt/bin/entry_poin" About a minute ago Up About a minute 0.0.0.0:5910->5900/tcp chrome10 00849df50f3e selenium/node-chrome-debug "/opt/bin/entry_poin" About a minute ago Up About a minute 0.0.0.0:5909->5900/tcp chrome09 76a362efadcc selenium/node-chrome-debug "/opt/bin/entry_poin" About a minute ago Up About a minute 0.0.0.0:5908->5900/tcp chrome08 170eb6cc8193 selenium/node-chrome-debug "/opt/bin/entry_poin" About a minute ago Up About a minute 0.0.0.0:5907->5900/tcp chrome07 9bcf4bd1fb5e selenium/node-chrome-debug "/opt/bin/entry_poin" About a minute ago Up About a minute 0.0.0.0:5906->5900/tcp chrome06 8e3dcb28ac73 selenium/node-chrome-debug "/opt/bin/entry_poin" 2 minutes ago Up About a minute 0.0.0.0:5905->5900/tcp chrome05 8b82403b0e6c selenium/node-chrome-debug "/opt/bin/entry_poin" 2 minutes ago Up 2 minutes 0.0.0.0:5904->5900/tcp chrome04 dd358d28ae29 selenium/node-chrome-debug "/opt/bin/entry_poin" 2 minutes ago Up 2 minutes 0.0.0.0:5903->5900/tcp chrome03 0843057f3900 selenium/node-chrome-debug "/opt/bin/entry_poin" 2 minutes ago Up 2 minutes 0.0.0.0:5902->5900/tcp chrome02 434bf300c0b5 selenium/node-chrome-debug "/opt/bin/entry_poin" 2 minutes ago Up 2 minutes 0.0.0.0:5901->5900/tcp chrome01 4c962835b46c selenium/hub "/opt/bin/entry_poin" 2 minutes ago Up 2 minutes 0.0.0.0:5555->4444/tcp hub 99cd793962e2 oracle/database:18.3.0-ee "/bin/sh -c 'exec $O" 3 weeks ago Exited (137) 2 weeks ago oracle18
You can check the status of the grid by the web interface.
Then, write a python script to call the selenium testing python scripts.
from subprocess import Popen processes = [] cmd_pprd1 = "python main_pprd.py" cmd_pprd2 = "python main_pprd2.py" cmd_pprd3 = "python main_pprd3.py" # processes.append(Popen(cmd_pprd1, shell=True)) # processes.append(Popen(cmd_pprd2, shell=True)) # processes.append(Popen(cmd_pprd3, shell=True)) for n in range(10): processes.append(Popen(cmd_pprd1, shell=True)) print len(processes) for n in range(len(processes)): processes[n].wait()