We will be experimenting, in this blog post, with installing Docker, deploying Selenium HQ's various Chrome and Firefox Docker images, regular versions, and using them with their Docker image of Selenium Hub.
Later on, we will tie this in with my BasicWebDriverFramework_Gradle, including into the project our work with PageFactories, and adding RemoteWebDriver and DesiredCapabilities functionality. In the post after this, we will build on this information, using Docker Compose to scale Selenium Grid.
Docker: https://www.docker.com/
SeleniumHQ Images: https://hub.docker.com/u/selenium/
Docker-Compose: https://docs.docker.com/compose/
- Want to tinker a bit with setting up a virtual environment with VirtualBox, Vagrant, and Docker first?
- Want a practice exercise setting up Docker?
- Unfamiliar with the command line? Want a practice exercise setting up Selenium Grid?
Normally, to set up Grid, you would:
- Download Selenium-StandAlone-Server
- Start up the Selenium Hub: java -jar selenium-server-standalone-2.53.0.jar -role hub
- Start up various nodes: java -jar selenium-server-standalone-2.53.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox,maxInstances=2 -browser browserName=chrome,maxInstances=2
... Then the Selenium Grid would be ready to use at http://localhost:4444.
With Docker, it is still that same three step process... except we can bundle all of those three steps into one with Docker Compose. That is for later blog posts. First, though, let's talk about Docker...
1. Install Docker
Docker is similar to a virtual machine, but more lightweight. With a virtual machine, the operating system also needs to be included. With Docker, the Docker Engine is separate from the Docker images you can pull from Docker Hub https://hub.docker.com/ running the images on your system. System errors? You can blow away the Docker image on your system and pull in a fresh image.
1.1. Download and Install Docker Toolbox
Install Docker Toolbox: https://www.docker.com/products/docker-toolbox. To run Docker commands, you need to run the Docker Quickstart Terminal. Check and install everything. We will need Docker Compose later, and VirtualBox needs to be installed inside Docker. Oracle's VirtualBox is bundled with the Toolbox. Note: Quickstart is NOT quick the first time around.
- Docker's GitHub site: https://github.com/docker/docker
- Need more info? See the Guide to setting up Docker Toolbox
Once it (finally) installed, you should see this:
Note that Docker is configured to use your default machine with the IP Address: 192.168.99.100.
1.2. Verify Docker is Working
Type in the Terminal window:
- docker version
Want to see other Docker Commands? Go to https://docs.docker.com/engine/reference/commandline/cli/
2. Install SeleniumHQ Docker Images
2.1. Review the Images from Docker Hub
The Docker images we will be installing are at SeleniumHQ: https://hub.docker.com/u/selenium/ ... you can click on these individual images to see how you can interact with them.
For a description of what these images do, we can go to the Selenium HQ Selenium Docker GitHub site at https://github.com/SeleniumHQ/docker-selenium:
- selenium/hub: Image for running a Selenium Grid Hub
- selenium/node-chrome: Selenium node with Chrome installed, needs to be connected to a Selenium Grid Hub
- selenium/node-firefox: Selenium node with Firefox installed, needs to be connected to a Selenium Grid Hub
- selenium/standalone-chrome: Selenium standalone with Chrome installed
- selenium/standalone-firefox: Selenium standalone with Firefox installed
- selenium/standalone-chrome-debug: Selenium standalone with Chrome installed and runs a VNC server
- selenium/standalone-firefox-debug: Selenium standalone with Firefox installed and runs a VNC server
- selenium/node-chrome-debug: Selenium node with Chrome installed and runs a VNC server, needs to be connected to a Selenium Grid Hub
- selenium/node-firefox-debug: Selenium node with Firefox installed and runs a VNC server, needs to be connected to a Selenium Grid Hub
You can build your own Docker images using the base images, run one standalone browser at a time on port 4444 with the standalone versions, use the headless versions of the browser to run the tests, or use the debug versions to see exactly what the test is doing on your screen.
2.2. Run the Selenium/ Hub
2.2.1. Go to Docker Hub and select the Selenium/ Hub Docker image for instructions.
Go to Selenium HQ's Selenium repository on the Docker Hub at https://hub.docker.com/r/selenium/ and select the Docker image called "Selenium/ Hub". All Docker Images list instructions on how the image is run. More thorough information is on https://github.com/SeleniumHQ/docker-selenium.
2.2.2. Launch a container from the Docker image.
To run the selenium/hub Docker image, https://hub.docker.com/r/selenium/hub/ enter the following into the Docker Terminal:
docker run -d -p 4444:4444 --name selenium-hub selenium/hub:2.53.0
- Run a Container based on a Docker Image. If the image cannot be found, pull it down from the Docker Hub: docker run
- Start the container in detached mode, as opposed to foreground mode, so the console won't become attached to input, output, and standard error streams: -d
- Map the Host Port to the Container Port. Remember, the IP address is 192.168.99.100. Let's use HOSTPORT 4444 and CONTAINERPORT 4444: -p 4444:4444
- Set the name of the container as selenium-hub (much easier than the UUID Long and Short Identifier): --name selenium-hub
- Run the image called "selenium/hub" but specify a version of the image with the tag "2.53.0": selenium/hub:2.53.0
... Need more information?
- Examine the Dockerfile for this image at https://hub.docker.com/r/selenium/hub/~/dockerfile/ to see the default environment values set up for the Jetty server setting up the Selenium Grid.
- See the Docker Run Reference at https://docs.docker.com/engine/reference/run
2.2.3 Verify the images have been installed
Type into the Docker Terminal:
- docker images
2.2.4. Verify that the Selenium Grid is running.
Selenium Grid will be running on your local host. Go to it and make sure you are using the version of selenium-standalone-server that you designated, 2.53.0: http://192.168.99.100:4444/
"You are using grid 2.53.0Select "console". Notice that there are no nodes yet running.
"Find help on the official selenium wiki : more help here"default monitoring page : console"
2.3. Setup Chrome and Firefox Nodes
We are going to set up the Docker images for Chrome and Firefox, and add them to the already running Selenium Hub.
2.3.1. Run from the Docker Engine node-chrome and node-firefox.
For Chrome:
docker run -d --link selenium-hub:hub selenium/node-chrome:2.53.0
For Firefox:
docker run -d --link selenium-hub:hub selenium/node-firefox:2.53.0
2.3.2. Verify that nodes are now set up in the Selenium Grid.
Go to the Selenium Grid console, at http://192.168.99.100:4444/grid/console
Congratulations, it's a Grid Console! |
Ignore the "Remote Control" instance of each browser. That is used in Selenium RC.
Hover your cursor over the browser instances in your "WebDriver" sections. You can see what you can set up in RemoteWebDriver for Desired Capabilities:
- browserName: "chrome" or "firefox".
- maximum numbers of instances that can run: 1
- platform: LINUX.
You can easily scale up or down the number of instances. Don't scale up to more than you think you might need... each instance of a browser running on your machine chews up a lot of memory!
WARNING! These Docker images are not meant to be like virtual machines, always running in the background.
"Note: Since a Docker container is not meant to preserve state and spawning a new one takes less than 3 seconds you will likely want to remove containers after each end-to-end test with --rm command. You need to think of your Docker containers as single processes, not as running virtual machines." -Docker-Selenium, GitHub
2.4. Future plans.
2.4.1. Scaling Selenium Grid
Next blog post, we will look at using Docker Compose at https://docs.docker.com/compose/overview/ to set up a YAML (*.yml) file, so we can easily bring up all hubs and nodes, spin up more nodes, or stop all services, all with one command line... and a lengthy configuration file.
2.4.2. RemoteWebDriver and DesiredCapabilities
Following that, we will be finally adding RemoteWebDriver and DesiredCapabilities to finally, after all the work we have done to prepare for Docker-Selenium, hook up our browser tests up with the Selenium Grid.
Rough Test to Demonstrate Docker-Selenium Hookups:
@Test public void test_FirefoxDockerGridNavigatesToLoginPage() throws Exception { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setBrowserName("firefox"); capabilities.setPlatform(Platform.LINUX); driver = new RemoteWebDriver(new URL("http://192.168.99.100:4444/wd/hub"), capabilities); driver.get("http://the-internet.herokuapp.com/login"); assertThat(driver.getTitle(), is(equalTo("The Internet"))); }
... If you run this individual test, it takes the DesiredCapabilities, and attempts to find a node at whatever URL you give it to run the test. Here, we have listed the Linux version of Firefox, what we have listed as a property of our WebDriver instance of Firefox.
2.5. Docker Commands
See Docker images: Want to see what Docker images you have on your system?
docker images
See Running Containers: Show us only Docker containers that are currently running:
docker ps
See ALL containers: Show us ALL of the Docker containers, even those not running.
docker ps -a
Logs: Want to see the log files of selenium-hub? (Reference: logs)
docker logs -f selenium-hub
... Make sure to CTRL-C out of the logfile.
Stop an individual container, like selenium-hub, from running (Reference: stop):
docker stop selenium-hub
Stop ALL containers from running:
docker stop $(docker ps -a -q)
Get help:
docker help
Get help on a command, such as "ps":
docker help --ps
Remove the Docker image, selenium-hub, after stopping the container from running (Reference: rmi):
docker rmi selenium-hub
Coming Up...
Future blog posts will cover:- RemoteWebDriver: Taking our DesiredCapabilities we touched upon, and expand it.
- Docker Compose: https://docs.docker.com/compose/: Bundle together scaling up or down Selenium Grid browser nodes, downloading Selenium Grid, starting up a Hub, and starting up various nodes.
- MicrosoftWebDriver: ( Link ): How to incorporate Microsoft Edge into your tests.
- Microsoft Virtual Images: https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ add IE8, IE9, IE10, IE11 on Windows 7 or IE 11 and Microsoft Edge to Windows 10 nodes to your Selenium Hub! Just use VirtualBox, Vagrant, HyperV (Windows), VMWare, or Parallels (Mac). Take a snapshot of the images because the originals are only good for 90 days.
- Selenium Grid Extras: https://github.com/groupon/Selenium-Grid-Extras
Until the next time I find four spare hours to research and write up more documentation... Happy Testing!
-T.J. Maher
Sr. QA Engineer,
Fitbit-Boston
// BSCS, MSE, and QA Engineer since Aug. 1996
// Automation developer for [ 1.5 ] years and still counting!
// Check out Adventures in Automation and Like us on Facebook!
16 comments:
Thanks for sharing the valuable information. Keep on sharing.
Docker and Kubernetes Training
Docker and Kubernetes Training in Hyderabad
Kubernetes Online Training
Docker Online Training
39 years old Video Producer Kristopher from La Prairie, has
hobbies and interests for example model railways,
and scrabble. that covered going to Tyre.오피사이트
I want to remark on some things on your blog, the site style is perfect and the articles are really excellent. Good job, cheers. See this
windows 10 activator txt
ben shapiros sister
lunk alarm planet fitness
green glass door
I'd want to comment on a few points on your blog; the layout is wonderful, and the content is excellent. Congratulations for a job well done. Look at this.
thoptv for pc
oreo tv for pc
Kissanime
Download alexa app for windows 10 pc
As a result, these people use marijuana in large amounts for longer periods of time than what they intend to. Snuffle Mat
Pyramid cafe in Shimlawith Italian Music played at a very decent volume, which makes it a good Place for Relaxed and comfortable sitting.
rooftop bar in Shimla | cafe and bar near me
Thanks for sharing beautiful content. I got information from your blog. Keep sharing
stump removal gold coast
tree stump removal gold coast
This is new knowledge for me, I am excited about it. thanks
digital marketing services gold coast
This is a very good post. Just wonderful.
bird control gold coast
I am intrigued by this new information for me. thanks
Cheyenne Garage Door
Garage Door Repair Cheyenne
This is a very good post. Just wonderful.
Middleton garage doors
Middleton garage door repair
Your article is extremely attractive and interesting
organic seo company
organic seo solutions
This is a very good post. Just wonderful.
Garage doors repair Longmont co
Garage doors openers Longmont
Excellent weblog, many thanks a lot for your awesome posts! leer mas
our web site sclinbio,com
Excellent weblog, many thanks a lot for your awesome posts! leer mas
our web site https:/sclinbio,com/
This is a comprehensive guide for setting up Selenium Grid with Docker, complete with step-by-step instructions and useful links. Docker's flexibility and lightweight nature make it an ideal choice for Selenium Grid deployment. Looking forward to the future posts on Docker Compose integration.
How to Divorce in New York City
How to File an Uncontested Divorce in New York
Post a Comment