Run test cases on selenium grid on docker

1 篇文章 0 订阅
1 篇文章 0 订阅

In this artical we are going to cover these 2 scenarios:

1. Run test cases on selenium-hub-nodes with/without debug mode inside of docker, and hub will assign test cases automaticlly.

2. Run test cases manually on multi selenium-standalone containers with/without debug inside of docker, you will need to assign test cases to different selenium-standalone containers.

 

Prerequisite:

  • I'm on Windows 10 Enterprise version, which support Docker.
  • Use docker-compose commands to launch docker images, base on yml file. 

To launch docker images, just run the following command in powsershell, it will read the config from the "docker-compose.yml" file from the same folder path you from the command at. 

docker-compose up -d

To terminate docker images, just run the following command in powershell:

docker-compose down
  • User VNC: need to download VNC binary and put it in a folder you want, then add the folder path to your OS environment path.

If I rename the vnc binary file to vnc.exe, just run the following command in powsershell to open a vnc window that connected to a container (Given all ports and containers are available).

vnc localhost:5902

Scenario 1:

In this scenario, we will lanuch 1 selenium hub and 2 selenium nodes(both chrome nodes).

In the test code, we just use the URL of hub as RemoteWebDriver,  and the hub will assign test cases automaticlly.

This is the docker-compose.yml file: use "docker-compose up -d" to read this yml file and launch containser.

# To execute this docker-compose yml file use `docker-compose -f <file_name> up`
# Add the `-d` flag at the end for detached execution
version: "3"
services:
  hub:
    image: selenium/hub:3.141.59
    container_name: hub
    ports:
      - "4444:4444"
    healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost:4444"]
        interval: 2s
        timeout: 10s
        retries: 5
  chrome1:
    image: selenium/node-chrome:3.141.59
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      - HUB_HOST=hub
      - VNC_NO_PASSWORD=1
    ports:
      - 4445:4444
  chrome2:
    image: selenium/node-chrome:3.141.59
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      - HUB_HOST=hub
      - VNC_NO_PASSWORD=1
    ports:
      - 4446:4444

This is a simple test cases shows you which remote url to use:

    class Test
    {
        [Test]
        public void Test1()
        {
            var dc = new ChromeOptions();
            var driver = new RemoteWebDriver(new Uri(" http://localhost:4444/wd/hub"), dc);

            driver.Navigate().GoToUrl("http://www.google.com");

            Thread.Sleep(TimeSpan.FromSeconds(10));

            driver.Quit();
        }
    }

 

Scenario 2:

In this scenario, we will lanuch 3 selenium standalone containers, you can manually assign test cases to any of the 3.

This is the docker-compose.yml file: use "docker-compose up -d" to read this yml file and launch containser.

In this yml file, we use standalone-chrome-debug image so that we can use vnc to connect to the container and see what's going on there. Since the VNC default port is 5900 and we map it out to 5901, 5901 and 5903 port for 3 different containers, we just need to run "vnc localhost 5901" to open a vnc viewer window to see what's going on inside of containers.

# To execute this docker-compose yml file use `docker-compose -f <file_name> up`
# Add the `-d` flag at the end for detached execution
version: "3"
services:
  chrome1:
    image: selenium/standalone-chrome-debug:3.141.59
    volumes:
      - /dev/shm:/dev/shm
    environment:
      - VNC_NO_PASSWORD=1
    ports:
      - 4445:4444
      - 5901:5900
  chrome2:
    image: selenium/standalone-chrome-debug:3.141.59
    volumes:
      - /dev/shm:/dev/shm
    environment:
      - VNC_NO_PASSWORD=1
    ports:
      - 4446:4444
      - 5902:5900
  chrome3:
    image: selenium/standalone-chrome-debug:3.141.59
    volumes:
      - /dev/shm:/dev/shm
    environment:
      - VNC_NO_PASSWORD=1
    ports:
      - 4447:4444
      - 5903:5900

After executing above, if you run "docker ps" command, you will see 3 containers are launched:

 

This is a simple test cases shows you run 3 different test cases on 3 different selenium containers.

We can see that 3 different test cases are running on 4445, 4446 and 4447 3 different port, which stands for 3 different containers.

Now these 3 test cases are running one by one, but we can refactor the driver init later to make them running in parallel. 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值