UI测试默认的执行器配置包括一个selenium-hub、一个chrome-node、一个firefox-node。
在默认配置下MeterSphereUI用例最大并行数为4,chrome-node最大会话数为6,既chrome-node最大支持6个并发。
在一个chrome-node中并行执行多个用例,即打开多个浏览器窗口时可能会导致页面加载速度变慢,需要给UI测试用例添加前后置等待时间。为了优化并行执行的效率,在服务器资源配置充足的情况下,可以在selenium-hub下部署4个chrome-node,同时使每个chrome-node最大支持一个会话。这样当UI用例并行时,每个chrome-node只执行一条用例,同时整体上也实现了并行,可以提升UI测试并行执行的效率。
以下配置为4个chrome-node,每个chrome-node最大会话数为1的yml配置:
version: "2.1"
services:
chrome1:
image: ${MS_IMAGE_PREFIX}/node-chromium:4.8.3
container_name: selenium-chrome1
shm_size: 2gb
ports:
- "5900:5900" # password: secret
depends_on:
- selenium-hub
entrypoint: bash -c '[ ! -f /home/seluser/language ] && sudo sed -i -e "s/# $$LANG.*/$$LANG UTF-8/" /etc/locale.gen && sudo dpkg-reconfigure --frontend=noninteractive locales && sudo update-locale LANG=$$LANG && touch /home/seluser/language; /opt/bin/entry_point.sh'
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- TZ=Asia/Shanghai
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_NODE_MAX_INSTANCES=1
- SE_NODE_OVERRIDE_MAX_INSTANCES=false
- JAVA_OPTS=-Xmx400m -Dfile.encoding=utf-8
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
- LANGUAGE=zh_CN.UTF-8
- LANG=zh_CN.UTF-8
labels:
- "selenium-hub.placement-constraints==node.labels.env == chrome1" # Place on node with specific label
restart: always
networks:
- ms-network
chrome2:
image: ${MS_IMAGE_PREFIX}/node-chromium:4.8.3
container_name: selenium-chrome2
shm_size: 2gb
ports:
- "5901:5900" # password: secret
depends_on:
- selenium-hub
entrypoint: bash -c '[ ! -f /home/seluser/language ] && sudo sed -i -e "s/# $$LANG.*/$$LANG UTF-8/" /etc/locale.gen && sudo dpkg-reconfigure --frontend=noninteractive locales && sudo update-locale LANG=$$LANG && touch /home/seluser/language; /opt/bin/entry_point.sh'
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- TZ=Asia/Shanghai
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_NODE_MAX_INSTANCES=1
- SE_NODE_OVERRIDE_MAX_INSTANCES=false
- JAVA_OPTS=-Xmx400m -Dfile.encoding=utf-8
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
- LANGUAGE=zh_CN.UTF-8
- LANG=zh_CN.UTF-8
labels:
- "selenium-hub.placement-constraints==node.labels.env == chrome2" # Place on node with specific label
restart: always
networks:
- ms-network
chrome3:
image: ${MS_IMAGE_PREFIX}/node-chromium:4.8.3
container_name: selenium-chrome3
shm_size: 2gb
ports:
- "5902:5900" # password: secret
depends_on:
- selenium-hub
entrypoint: bash -c '[ ! -f /home/seluser/language ] && sudo sed -i -e "s/# $$LANG.*/$$LANG UTF-8/" /etc/locale.gen && sudo dpkg-reconfigure --frontend=noninteractive locales && sudo update-locale LANG=$$LANG && touch /home/seluser/language; /opt/bin/entry_point.sh'
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- TZ=Asia/Shanghai
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_NODE_MAX_INSTANCES=1
- SE_NODE_OVERRIDE_MAX_INSTANCES=false
- JAVA_OPTS=-Xmx400m -Dfile.encoding=utf-8
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
- LANGUAGE=zh_CN.UTF-8
- LANG=zh_CN.UTF-8
labels:
- "selenium-hub.placement-constraints==node.labels.env == chrome3" # Place on node with specific label
restart: always
networks:
- ms-network
chrome4:
image: ${MS_IMAGE_PREFIX}/node-chromium:4.8.3
container_name: selenium-chrome4
shm_size: 2gb
ports:
- "5903:5900" # password: secret
depends_on:
- selenium-hub
entrypoint: bash -c '[ ! -f /home/seluser/language ] && sudo sed -i -e "s/# $$LANG.*/$$LANG UTF-8/" /etc/locale.gen && sudo dpkg-reconfigure --frontend=noninteractive locales && sudo update-locale LANG=$$LANG && touch /home/seluser/language; /opt/bin/entry_point.sh'
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- TZ=Asia/Shanghai
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_NODE_MAX_INSTANCES=1
- SE_NODE_OVERRIDE_MAX_INSTANCES=false
- JAVA_OPTS=-Xmx400m -Dfile.encoding=utf-8
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
- LANGUAGE=zh_CN.UTF-8
- LANG=zh_CN.UTF-8
labels:
- "selenium-hub.placement-constraints==node.labels.env == chrome3" # Place on node with specific label
restart: always
networks:
- ms-network
selenium-hub:
image: ${MS_IMAGE_PREFIX}/selenium-hub:4.8.3
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
restart: always
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:4444" ]
interval: 6s
timeout: 5s
retries: 50
networks:
- ms-network