在创建不同容器并将其连接到硒集线器的传统方法中,问题是如果需要创建新的容器节点,则需要返回并连接到集线器。 这是耗时的过程。 Zalenium来了,它能够在运行时创建节点容器,并在执行结束后销毁它。 Zalenium与Kubernetes一起使用,以获得自动缩放和自动修复功能。 因此Zalenium与Docker一起使用Kubernetes。 Zalenium将在需要时继续注册新节点。 我们不需要手动运行映像然后链接它。 我们也不需要任何固定数量的容器。 因此,基本上Zalenium会为我们做所有事情。 它将使我们的测试环境保持可扩展性。 它还可以在不同的云测试提供商(如Sauce Labs,BrowserStack,TestingBot,CrossBrowserTesting,LambdaTest等)上运行测试。 目前,Zalenium仅支持Firefox和Chrome浏览器。 Zalenium还将根据新版本自动更新我们的浏览器和驱动程序。 默认情况下,它将注册2个节点,并且每当您需要更多节点时,它将在运行时创建和销毁。
This is how to run this for the docker version.
# Pull docker-selenium
docker pull elgalu/selenium
# Pull Zalenium
docker pull dosel/zalenium
# Run it!
docker run --rm -ti --name zalenium -p 4444:4444 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/videos:/home/seluser/videos \
--privileged dosel/zalenium start
# Point your tests to http://localhost:4444/wd/hub and run them
# Stop
docker stop zalenium
After running the commands, you can check:
The grid console. http://localhost:4444/grid/console
The dashboard after running your first test. http://localhost:4444/dashboard
Live Preview of Execution. http://localhost:4444/grid/admin/live
In-case localhost does not work, check on what IP docker is running. In my case it is : 192.168.99.100
You can also interact with Live Previews with VNC.
Now, its time to execute Selenium tests. The Selenium project used for execution is available here: https://github.com/sonucogni/Zalenium
关于这个项目: 这是一个非常简单的Selenium项目。 它具有三个类,我们将导航到不同的网站并在这些类中捕获页面标题。 我们在TestNG文件中使用并行线程数为3。 因此,这三个课程将同时启动。 您无需在代码中指定驱动程序路径或任何其他详细信息,因为Zalenium会处理所有事情。
由于我想显示自动缩放功能,并且默认情况下它仅创建了两个容器,因此第三个将在运行时创建。 作为TestNG套件运行测试。
References:
https://opensource.zalando.com/zalenium/
https://github.com/zalando/zalenium