TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Docker

    Run Selenium Test on Docker Container

    Overview

    In this tutorial, we will learn the steps involved to run a Selenium Test on a Docker container. A Docker container image is a lightweight, standalone package of software that includes everything needed to run an application. Docker Image becomes Docker Container on the runtime when run on the Docker Engine.

    Docker Containers

    Docker Hub

    Open a web browser and Navigate to the Docker Hub.

    https://hub.docker.com/

    We can find Docker images on the Docker Hub. Docker Hub is an image library. It’s like a repository of the Docker images.

    Search Docker Hub for Selenium image. There would be several images in the search results. Each one is used for a specific purpose. Choose selenium/standalone-chrome Docker image to run a test on Google Chrome Browser.

     

    Docker Hub Standalone Chrome

     

    Alternatively, to run a test on the Mozilla Firefox browser, choose the image: selenium/standalone-firefox. In this tutorial, we will use Chrome image. We will run a simple Selenium test on the Google Chrome browser

    Pull the Docker Image

    $ docker pull selenium/standalone-chrome

     

    docker pull command

    We can use the Docker images command to check the images on the local repository.

    $ docker images

    Docker Local Repository

    Start Docker Container

    Run the following command:

    $ docker run -d -P selenium/standalone-chrome

    Check the container details with docker ps list container utility.

    $ docker ps

     

    docker ps command

    Sample Selenium Test

    The sample test will launch Mantis bug tracker URL and just print the Title of the login page on the console. Use a RemoteWebDriver instance to test against the Grid on the docker container. Since the test and the container runs on the same machine, we have used

    http://localhost:49153/wd/hub

    Listening port might vary. 49153 is the listening port on my machine. The docker ps command output would have the details to verify.

    We will use the Chrome browser in Selenium Test. Instantiate ChromeOptions object and pass it to the RemoteWebDriver instance. ChromeOptions is used to set capabilities and customization of Chrome browser in Selenium.

    ChromeOptions options = new ChromeOptions();

    URL remote = new URL(“http://localhost:49153/wd/hub”);

    WebDriver driver = new RemoteWebDriver(remote, options);

     

    Selenium Test On Docker

    Code Snippet

    import org.testng.annotations.Test;
    import java.net.URL;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.RemoteWebDriver;
    
    public class SeleniumOnDockerTest {
    
     @Test
     public void MantisTestOnDocker() throws Exception {
     ChromeOptions options = new ChromeOptions();
     URL remoteURL = new URL("http://localhost:49153/wd/hub");
     WebDriver driver = new RemoteWebDriver(remoteURL, options);
     driver.get("https://www.TestingDocs.com/mantis");
     System.out.println(driver.getTitle() + 
    " \nwww.TestingDocs.com -Selenium Tutorials");
     System.out.println("Test was run on Docker container. 
    Check the Docker Logs!");
     }
    }

    Sample Output

    Selenium Test on Docker Container

     

    Check the Grid logs in the container. Any errors can be debugged using the logs.

    Docker Logs

    This step might vary on the Docker setup. On Windows, the easiest way is to launch the Docker Desktop application, select the container and click on LOGS tab to views the container logs.

     

    Docker Logs TestingDocs

     

    That’s it. We have successfully run a selenium Test on Docker.

    Related

    In this tutorial, we have run a test using a single Container. We can scale this to distributed testing using Selenium Grid using multiple containers.  To learn more:

    Selenium Grid with Docker

    https://www.testingdocs.com/selenium-grid-setup-with-docker-containers/

    —

    Selenium Tutorials

    Selenium WebDriver Tutorials on this website can be found at:

    https://www.testingdocs.com/selenium-webdriver-tutorial

    For more details on the Selenium, visit the official website at:

    https://www.selenium.dev/

    Related Posts

    Container Technology

    Docker /

    Advantages of Containerization Technology

    Connection Refused Error

    Docker /

    Fix Connection refused Error Selenium Tests On Docker

    Docker Compose YAML File

    Docker /

    Docker Compose Tool

    Docker Install Check

    Docker /

    Docker Install on Ubuntu

    Download and Install Docker Desktop

    Docker /

    Download and Install Docker Desktop

    › Getting Started with Docker

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com