基于Docker Selenium Grid 搭建分布式测试环境

分布式selenium grid 搭建方法:
https://testdriven.io/blog/distributed-testing-with-selenium-grid/

https://blog.csdn.net/ldq_sd/article/details/109893462?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

https://blog.csdn.net/liwei_721/article/details/105109798

SeleniumHQ/docker-selenium github code:
https://github.com/SeleniumHQ/docker-selenium

基于Docker compose Selenium Grid 搭建分布式测试环境
https://techblog.dotdash.com/setting-up-a-selenium-grid-with-docker-containers-for-running-automation-tests-c43aceccd5d9
https://nitinbhardwaj6.medium.com/selenium-grid-with-debug-docker-containers-23eceb6ab17f

version: "3"
services:
  hub:
    image: selenium/hub:3.141.59
    ports:
      - "4444:4444"
    environment:
      GRID_MAX_SESSION: 16
      GRID_BROWSER_TIMEOUT: 3000
      GRID_TIMEOUT: 3000
  chrome:
    image: selenium/node-chrome-debug
    container_name: web-automation_chrome
    depends_on:
      - hub
    environment:
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444
      NODE_MAX_SESSION: 4
      NODE_MAX_INSTANCES: 4
    volumes:
      - /dev/shm:/dev/shm
    ports:
      - "9001:5900"
    links:
      - hub
  firefox:
    image: selenium/node-firefox-debug
    container_name: web-automation_firefox
    depends_on:
      - hub
    environment:
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444
      NODE_MAX_SESSION: 2
      NODE_MAX_INSTANCES: 2
    volumes:
      - /dev/shm:/dev/shm
    ports:
      - "9002:5900"
    links:
      - hub

Docker Selenium Grid Setup:增加 node number and session number
https://dev.to/automationbro/docker-selenium-grid-setup-1lg4

Increasing the MAX_INSTANCES & MAX_SESSIONS for the Grid

So far we just have 1 instance of Chrome & Firefox, however, if you need to run multiple tests together, you'll need more instances spun up. You can do that quite easily by adding the parameters when running the docker container for Chrome and Firefox.

docker run -d --net grid -e HUB_HOST=selenium-hub -e NODE_MAX_INSTANCES=3 -e NODE_MAX_SESSION=3 -v /dev/shm:/dev/shm selenium/node-chrome-debug:3.141.59–20210422

You can pass NODE_MAX_INSTANCES and NODE_MAX_SESSION environment variables to add multiple instances of the browsers.

  • NODE_MAX_INSTANCES: number of instances of the same version of the browser
  • NODE_MAX_SESSION: number of browsers (any versions) that can run in parallel

Once you do that, you will see something like this below :


image.png

https://testdriven.io/blog/distributed-testing-with-selenium-grid/

腾讯官网的doc:
https://cloud.tencent.com/developer/article/1634286

如何安装制定版本额docker-compose
1.查找到响应版本
https://github.com/docker/compose/releases
2.安装的cmd
https://docs.docker.com/compose/install/

清除(关闭全部容器) :docker kill (docker ps -a -q)
再次查看容器情况,运行:docker ps –a 发现整个世界都清净了。

清除(关闭全部容器) :docker kill (docker ps -a | grep selenium)
再次查看容器情况,运行:docker ps –a 发现整个世界都清净了。

Selenium Grid and Docker:
https://nazarkhimin.medium.com/selenium-grid-and-docker-25a79f0b9007

# To execute this docker-compose yml file
# use `docker-compose -f docker-compose.yml up --build --abort-on-container-exit --scale chrome=2 --scale firefox=2`
version: "3"
services:
  firefox:
    image: selenium/node-firefox-debug
    volumes:
      - /dev/shm:/dev/shm
      - /home/admin/selenium/files/Certificate:/home/admin/selenium/files/Certificate
    ports:
      - "5556:5900"
    depends_on:
      - hub
    environment:
      - TZ="UT"
      - http_proxy=http://web-proxy.us.softwaregrp.net:8080
      - https_proxy=http://web-proxy.us.softwaregrp.net:8080
      - HUB_HOST=hub
    networks: ['selenium-grid']
  chrome:
    image: selenium/node-chrome-debug
    volumes:
      - /dev/shm:/dev/shm
      - /home/admin/selenium/files/Certificate:/home/admin/selenium/files/Certificate
    ports:
      - "5557:5900"
    depends_on:
      - hub
    environment:
      - TZ="UT"
      - http_proxy=http://web-proxy.us.softwaregrp.net:8080
      - https_proxy=http://web-proxy.us.softwaregrp.net:8080
      - HUB_HOST=hub
    networks: ['selenium-grid']
  hub:
    image: selenium/hub:3.141.59
    ports:
      - "4444:4444"
    networks: ['selenium-grid']
networks: {selenium-grid: {}}

如何使用docker-compose mount:
https://code.visualstudio.com/remote/advancedcontainers/add-local-file-mount

  • Docker Compose: Update (or extend) your docker-compose.yml with the following for the appropriate service:

    version: '3'
    services:
      your-service-name-here:
        volumes:
          - /local/source/path/goes/here:/target/path/in/container/goes/here:cached
          - ~:/host-home-folder:cached
          - ./data-subfolder:/data:cached
         # ...
    

If you've already built the container and connected to it, run Remote-Containers: Rebuild Container from the Command Palette (F1) to pick up the change. Otherwise run Remote-Containers: Open Folder in Container... to connect to the container.

设置proxy in the container:
https://stackoverflow.com/questions/50149133/how-can-i-setup-a-proxy-in-a-selenium-chrome-container

如何使用K8S 搭建分布式 selenium:
https://github.com/alcounit/selenosis/issues/47
https://github.com/alcounit/selenosis#run-yout-tests

如何使用工具portainer监控host主机的container 状态:
https://levelup.gitconnected.com/portainer-the-easy-way-to-manage-docker-a982a17146c1

你可能感兴趣的:(基于Docker Selenium Grid 搭建分布式测试环境)