Selenium UI Test Execution On Remote Selenium Grid Running In Kubernetes Environment
Selenium UI test execution using Kubernetes infrastructure. Selenium UI test execution on remote selenium grid running in the Kubernetes environment.
Join the DZone community and get the full member experience.
Join For FreeSelenium tests require local web driver support to run on regular desktop machines and even the same can be run using docker selenium hub support on Linux machines.
But do you know, we can even run selenium tests on headless browser supported by remote selenium hub service running inside Kubernetes environment?
Let's See Step By Step How This Can Be Achieved
1. Selenium grid setup using k8s by running selenium hub as service.
Run below command using kubectl utility to bring up selenium hub:
kubectl run selenium-hub --image selenium/hub:3.10.0 --port 4444
2. Bring up any browser type pod on which you would like to run selenium tests. Here will show an example of chrome browser deployment on k8s cluster.
kubectl run selenium-node-chrome --image selenium/node-chrome:3.10.0 --env="HUB_PORT_4444_TCP_ADDR=selenium-hub" --env="HUB_PORT_4444_TCP_PORT=4444"
Note: Similarly you can bring up Firefox or any other browser deployment similar to chrome, as shown above using respective selenium firefox node images.
3. Check whether both above pods are running using kubectl command:
kubectl get pods | grep selen*
The pods should be in running state.
selenium-hub-d9d5df799-z66dc 1/1 Running 0 112s
selenium-node-chrome-8496b566c7-xbgvv 1/1 Running 0 54s
4. Check for the service details of selenium-hub using kubectl command:
kubectl get services| grep sele*
selenium-hub NodePort 10.XXX.XX.XX9 <none> 4444:30986/TCP 24s
It should show details on which port, the selenium hub is running.
Here its 30986.
5. Now cross check whether we can see the details of hub browser in any Linux/Mac/Windows machine on which you want to run the tests.
Open up any browser and fetch url: http://XX.X.XX.XX:30986/grid/console
Where XX.. refers to the k8s server IP.
If you can see below information, then that means the hub is running fine and accessible from different machines like Linux/Mac/Windows.
6. Use remote web driver API for chrome as shown below to trigger your selenium tests on this remote grid running on k8s cluster.
driver = webdriver.Remote(command_executor='http://XX.X.XX.XX:30986/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)
Now selenium tests triggered from any Linux/Mac/Windows machine under the same network can be executed using the remote selenium hub running in k8s environment.
Opinions expressed by DZone contributors are their own.
Trending
-
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
-
Microservices With Apache Camel and Quarkus
-
Effective Java Collection Framework: Best Practices and Tips
-
Writing a Vector Database in a Week in Rust
Comments