Selenium docker-compose+selenium 可用分布式的脚本分享

oly · 2018年04月21日 · 最后由 米阳MeYoung 回复于 2018年04月24日 · 1590 次阅读

分享下可运行的 docker-compose.yml
GRID:http://localhost:4444/grid/console?config=true&configDebug=true

目录/work/selenium 下创建如下文件. docker-compose up -d 执行,在 5900-5908 的 vnc 端口可看到启动的 node

名 内容

Dockerfile

FROM wywincl/node-firefox-debug

USER root

RUN apt-get update \
    && apt-get -y install ttf-wqy-microhei ttf-wqy-zenhei \
    && apt-get clean

docker-compose.yml

  hub:
    image: selenium/hub
    container_name: hub
    ports:
      - 5900:5900
      - 4444:4444
    environment:
      GRID_MAX_SESSION: 30
      GRID_TIMEOUT: 60
      GRID_DEBUG: 'true'
      GRID_NEW_SESSION_WAIT_TIMEOUT: 5000
    volumes:
      - /dev/shm/:/dev/shm/
    restart: always
  node1:
##    build: /work/selenium/Dockerfile
    image: wywincl/node-firefox-debug
    ports:
      - 5901:5900
    volumes:
      - /dev/shm:/dev/shm
#    command: /bin/bash -c "apt-get update  && apt-get -y install ttf-wqy-microhei ttf-wqy-zenhei && apt-get clean" 
    links:
     - "hub"
  node2:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5902:5900
    links:
     - "hub"
    restart: always
  node3:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5903:5900
    links:
     - "hub"
    restart: always
  node4:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5904:5900
    links:
     - "hub"
    restart: always
  node5:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5905:5900
    links:
     - "hub"
    restart: always
  node6:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5906:5900
    links:
     - "hub"
    restart: always
  node7:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5907:5900
    links:
     - "hub"
    restart: always
  node8:
    build: /work/selenium/Dockerfile
##    image: wywincl/node-firefox-debug
    ports:
      - 5908:5900
    links:
     - "hub"
    restart: always

共收到 5 条回复 时间 点赞

docker 里面,只能用无头的 driver 吧?

恒温 回复

有头的也行,unix 系统的话装上 xvfb 和一些字库等依赖就好了,再弄个 vnc 就能直接看了,我之前用的那些都是有头的呀,最近也用 docker 做了个 macaca-electron,也可以这样玩

terrychow 回复

赞,可以写个文章分享下不

恒温 回复

好啊 这个月不用怎么加班的话写一下 再加点料

楼主也可以看看 selenoid 和 zalenium :https://www.jianshu.com/p/29c7240e9f48

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册