Back to Blog
Automation Testing

How to Dockerize Your Automated Tests Using Docker Containers

Avanish Pandey

November 7, 2022

How to Dockerize Your Automated Tests Using Docker Containers

What are Automated Tests?

How to Dockerize Your Automated Tests In programming testing, test computerization is the utilization of programming separate from the product being tried to control the execution of tests and the examination of genuine results with anticipated outcomes. Test robotization can mechanize some redundant yet important assignments in a formalized testing process as of now set up, or play out extra testing that would be hard to do physically. Test robotization is basic for consistent conveyance and persistent testing.

There are numerous ways to deal with test mechanization, anyway beneath are the general methodologies utilized broadly:

Graphical UI testing. A testing system that produces UI occasions, for example, keystrokes and mouse clicks, and watches the progressions that bring about the UI, to approve that the recognizable conduct of the program is right.

Programming interface-driven testing. A testing structure that utilizes a programming interface to the application to approve the conduct under test. Commonly API driven testing sidesteps application UI out and out. It can likewise be trying open (typically) interfaces to classes, modules or libraries are tried with an assortment of info contentions to approve that the outcomes that are returned are right.

How to Dockerize Your Automated Tests Using Docker Containers

Making and running E2E tests is regularly viewed as a flaky and complex procedure. It requires a ton of set up that can in any case effectively bomb when running on various machines or in a CI (constant mix) condition. Introducing and keeping up various programs and WebDrivers both for nearby tests and CI tests requires some serious energy. What’s more, in any event, when done, it can at present fall flat due to straightforward issues, for example, if the screen goals on engineer’s nearby machines, or in CI, is extraordinary.

The standard points of interest of Docker likewise apply: not managing OS similarity or having dependencies introduced. To run the Selenium Server you would require Java introduced (or if nothing else be begun/halted expressly). To run Express you would require Node.js, and for Chrome, you’d need Chrome itself just as ChromeDriver.

When utilizing Docker these dependencies are dispensed with. You just utilize various compartments that as of now contain these, which will work exactly the equivalent regardless of on which machine they are run. At the point when you at that point think that it is so natural to incorporate Docker with your CI, Dockerizing your test procedure turns into an undeniable decision. we can see that we will utilize two Docker holders. They should know about one another and have the option to impart. One will contain our application and tests, and one a Selenium Server, GeckoDriver, and Firefox, with the goal that we needn’t bother with Firefox, introduced on our nearby machine.

How to Dockerize Your Automated Tests

Docker Compose is a device for "characterizing and running multi-holder Docker applications." It begins Docker compartments with the order docker-create up and stops them with docker-make down. On the off chance that a client characterized Dockerfile is being utilized, – fabricate is utilized to manufacture it, either the first run through docker-create up is run, or if changes have been made to the Dockerfile. docker-compose.yml is the record that characterizes what the up order will do.

Our subsequent stage is to make this docker-compose.yml. It is vigorously dependant on space.

For our Selenium Server, drivers, and program, we utilize a pre-characterized picture accessible from the open Docker Hub called selenium/independent firefox. We indicate which adaptation we need, 3.12.0-americium. On the off chance that we didn’t indicate this the most recent picture would be utilized as a matter of course (which is anything but an awful thing). As prompted, we arrange it to share the host’s memory to forestall the program being run from smashing and uncover port 4444, the default Selenium port. We likewise map this to port 4444 on our nearby machine, permitting us to visit localhost:4444/wd/center point/static/asset/hub.html in our program.

For our application holder, we are not simply utilizing a picture worked by another person, however, we are composing a Dockerfile to indicate how our application is assembled. Similarly, as the selenium-firefox holder, we uncover a port, 3000 for this situation, as that is the place Express runs as a matter of course. By planning this utilizing 3000:3000 we can visit localhost:3000 while the application is being run in Docker to see it in our nearby program.

Our Dockerfile utilizes the open node: carbon picture as a base, sets the working registry, duplicates a few documents from our neighborhood machine to the holder, runs npm introduce so the compartment has every single required reliance, and afterward runs the npm start order we indicated.

# Defaults – we can pass which variant of ruby we need to introduce in rvm # Install RVM – as the name proposes, this area introduces rvm

# Install ruby form – we introduce the Ruby form in rvm and bundler diamond

# Copy test contents – we will make/tests catalog, duplicate over our tests from the nearby machine to the holder and run group introduce (Advantage of running pack introduces is that it will be executed uniquely during the hour of making the Docker picture and we don’t have to execute it again every time we make the compartment to execute tests. This will spare a lot of time in the holder run stage. Likewise, we expect that Gemfile.lock is forward-thinking as of now, the client will check its vault and afterward execute tests situated in that archive)

# Set working catalog and finish assessments that you need to execute – as the name recommends, we are setting the working registry in the compartment to be/tests and we execute tests from that area (tests have just been duplicated over to this index in the past advance). Something essential to note is the TESTS_TO_RUN variable which ought to be populated when we run the holder. Here, we can finish which accurate assessments we need to execute (so we are not restricted to execution of complete suite as it were). This works similarly that

the separation of tests works in RSpec. We can give * to execute everything, substring or complete name of the content to execute some portion of the test suite or one explicit test content

How to Dockerize Your Automated Tests


For our situation, utilizing docker-form ended up being a great decision. Running everything with one order makes your life significantly simpler and brought together design makes this a somewhat simple answer to keep up. Despite the fact that the arrangement of joining the Owl detailing instrument to organize is somewhat simple, it is an immense advance forward with regards to finishing the procedure of everyday test execution.

With just two "docker-make up’s", you have a test domain running alongside tests and an announcing apparatus where consequences of the tests will be continued. Subsequent to perusing these two articles, we truly trust you see the advantages of this methodology and that it can help you in your day by day test condition arrangement too.

I trust this short prologue to the containerized world with regards to test computerization will assist you with realizing all the advantages this methodology can give you. Utilizing holders in programming advancement is getting increasingly more of a standard methodology and tests are no special case either. The advantages of containerized miniaturized scale administrations can without much of a stretch been found in the arrangement of testing work processes. Here is a portion of the issues we unravelled with this methodology:

We can without much of a stretch offer our tests and test condition between one another with negligible or zero arrangement that should be done before running tests (considerably more, we can breeze through assessments to designers when they need to execute them against their neighborhood improvement situations).

We don’t need to stress over similarity issues between different Selenium and program drivers variants. It is anything but difficult to change the variants and test them out. Already, it was very tedious to introduce programs, program drivers, and relating Selenium web driver diamonds and ensure every one of them cooperate.

Avanish Pandey

November 7, 2022


Subscribe to our Newsletter

Sign up to receive and connect to our newsletter

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Latest Article