{"id":2570,"date":"2018-05-23T05:46:52","date_gmt":"2018-05-23T05:46:52","guid":{"rendered":"http:\/\/www.ruthtech.com\/?p=2570"},"modified":"2018-05-23T07:23:00","modified_gmt":"2018-05-23T07:23:00","slug":"setting-up-rspec-with-zalenium-a-docker-solution","status":"publish","type":"post","link":"https:\/\/www.ruthtech.com\/?p=2570","title":{"rendered":"Setting up RSpec with Zalenium &#8211; a Selenium grid Docker solution"},"content":{"rendered":"<p><strong>The Problem?<\/strong><\/p>\n<ol>\n<li>If you are looking to run your test on multiple browsers and can&#8217;t justify why you should have third party solutions like Browserstack or Sauce Labs, or you want more flexibility with third-party solutions.<\/li>\n<li>Setting up and running selenium grid on your local machine connected to other computers as nodes can be very hectic to set up, computers connected to the grid can go to sleep or have<br \/>\nnetwork issues, which can fail tests if there is no check for the active node before running test, just to mention a few issues with the\u00a0current solution available. Adding all kinds of checks and writing extra code to manage grid makes the test suite too brittle to work with and diverts test engineers time from what is important, writing tests.<\/li>\n<\/ol>\n<p><strong>A Solution<\/strong><br \/>\nThe problem mentioned above is solved by integrating RSpec test framework with Zalenium.<\/p>\n<p><strong>What is Zalenium?\u00a0<\/strong><\/p>\n<p><!--more--><\/p>\n<p>Zalenium gets its name from the combination of Zalando and Selenium. It is a flexible and scalable container based Selenium Grid with video recording, live preview,<br \/>\nbasic auth &amp; dashboard built on docker-selenium to build a Selenium Grid in seconds, a grid that scales up and down dynamically with this solution based on docker-selenium<br \/>\nto run your tests in Firefox and Chrome.<\/p>\n<p><strong>Assumption<\/strong><br \/>\nThis tutorial assumes that you are somewhat familiar with Docker(Beginner level)<\/p>\n<ul>\n<li>Can write tests in RSpec<\/li>\n<li>Understands POM &#8211; Page Object Model<\/li>\n<\/ul>\n<p><strong>Getting started<\/strong><\/p>\n<p><em><strong>Download and start Docker<\/strong><\/em><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><a href=\"https:\/\/docs.docker.com\/docker-for-windows\/install\/\">Get docker for Windows<\/a><\/li>\n<li><a href=\"https:\/\/docs.docker.com\/docker-for-mac\/install\/\">Get docker for Mac<\/a><\/li>\n<li><a href=\"https:\/\/www.docker.com\/docker-ubuntu\">Get docker for Ubuntu<\/a><\/li>\n<li><a href=\"http:\/\/git clone git@github.com:femisimon\/zalenium-demo.git\">Clone the `Zalenium-demo` repo<\/a><code><\/code>\n<ul>\n<li><code>git clone git@github.com:femisimon\/zalenium-demo.git<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Run test without Docker compose<\/strong><\/p>\n<ul>\n<li><strong>On local Chrome:<\/strong>\n<ul>\n<li>run <code>bundle exec rake local<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>Zalenium solution:<\/strong>\n<ul>\n<li>Set up &#8211; on your terminal<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><code><br \/>\ndocker run --rm -ti --name zalenium -p 4444:4444 \/<br \/>\n-v \/var\/run\/docker.sock:\/var\/run\/docker.sock \/<br \/>\n-v \/tmp\/videos:\/home\/seluser\/videos \/<br \/>\n--privileged dosel\/zalenium start --desiredContainers 5 --maxTestSessions 5<\/code><\/p>\n<p>The set up above simply means docker will be running a new container named &#8211; <em>zalenium on port 4444:4444<\/em>, mapping the videos gotten to the directory on\u00a0<code>\/home\/seluser\/videos<\/code><\/p>\n<p>The most important part of this command is on the last line and as the saying &#8220;Save the best for last&#8221;, that is exactly what is done in the command above. Privilege is given to dosel\/zalenium which then enables it to start the number of desiredContainers as needed and also the maximum number of sessions that can be started simultaneously, the importance of having these sessions will be posted in the follow-up to this post, which will be on running tests parallel. The<code>desiredContainers<\/code> makes 5 containers available for us to run the test while <code>maxTestSessions- allows the number of sessions declared<\/code><\/p>\n<ul>\n<li>On the grid console, you can see 5 chrome and firefox browsers &#8211; <a href=\"http:\/\/localhost:4444\/grid\/console\">Selenium grid console<\/a><\/li>\n<li><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-2577\" src=\"http:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_3-300x126.png\" alt=\"\" width=\"300\" height=\"126\" srcset=\"https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_3-300x126.png 300w, https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_3-768x323.png 768w, https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_3-1024x430.png 1024w, https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_3.png 1757w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li>On Terminal &#8211; <code> bundle exec rake remote<\/code><\/li>\n<\/ul>\n<p><code><\/code><strong>Test Result<\/strong><\/p>\n<ul>\n<li>Rake local &#8211;\n<ul>\n<li>Finished in 41.82 seconds (files took 1.14 seconds to load)<br \/>\n8 examples, 0 failures<\/li>\n<li><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2581\" src=\"http:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_4.png\" alt=\"\" width=\"483\" height=\"469\" srcset=\"https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_4.png 483w, https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_4-300x291.png 300w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/li>\n<\/ul>\n<\/li>\n<li>Rake remote\n<ul>\n<li>Finished in 39.05 seconds (files took 0.76222 seconds to load)<br \/>\n8 examples, 0 failures<\/li>\n<li><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2582\" src=\"http:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_5.png\" alt=\"\" width=\"441\" height=\"456\" srcset=\"https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_5.png 441w, https:\/\/www.ruthtech.com\/wp-content\/uploads\/2018\/05\/Snip20180519_5-290x300.png 290w\" sizes=\"(max-width: 441px) 100vw, 441px\" \/><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Conclusion<\/strong><\/p>\n<p>As seen in the result above,\u00a0Zalenium\u00a0is more efficient and easy to set up when it comes to tests infrastructure. It is easy to scale depending on your organization&#8217;s needs. It has ready integrations for other third-party\u00a0solutions like Sauce labs and Browserstack&#8230;<\/p>\n<p>Happy Testing \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Problem? If you are looking to run your test on multiple browsers and can&#8217;t justify why you should have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2579,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130,139],"tags":[134,136,133,140,131,135,137,103,138,132],"_links":{"self":[{"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/posts\/2570"}],"collection":[{"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2570"}],"version-history":[{"count":12,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/posts\/2570\/revisions"}],"predecessor-version":[{"id":2599,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/posts\/2570\/revisions\/2599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=\/wp\/v2\/media\/2579"}],"wp:attachment":[{"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ruthtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}