{"id":12801,"date":"2020-05-11T05:20:12","date_gmt":"2020-05-11T09:20:12","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=12801"},"modified":"2021-04-22T04:43:20","modified_gmt":"2021-04-22T08:43:20","slug":"setup-linux-testing-environment-on-windows-using-wsl","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/setup-linux-testing-environment-on-windows-using-wsl\/","title":{"rendered":"Setup Linux testing environment on Windows using WSL1"},"content":{"rendered":"<p><strong>Update: This solution works on WSL1 only<\/strong><br \/>\n<\/p>\n<h4>Why this post?<\/h4>\n<p>If you are one of those testers that had been using a Windows machine and have had to setup a Linux system for running your Selenium automation test, this post is for you. I had to setup a Linux system for running the automation tests for one of our clients. The framework the client had been using, used a UNIX command to find the test files in the various subdirectories under the project root. This prevented us from running the tests on a Windows environment.<br \/>\nI am writing this post to share the steps I followed to setup a Linux environment on my Windows machine to run the Selenium tests. Hopefully, this will help other testers who face a similar issue.<\/p>\n<hr \/>\n<p><\/p>\n<h4>Windows Subsystem for Linux(WSL):<\/h4>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/wsl\/about\">WSL<\/a> is a cool feature on Windows 10 that allows you to run most of the GNU\/Linux commands and applications on Windows.<br \/>\nHere are the steps on how to setup WSL on Windows &#8211; <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/wsl\/install-win10\">https:\/\/docs.microsoft.com\/en-us\/windows\/wsl\/install-win10<\/a><br \/>\nYou can pick any distribution of Linux for WSL, I chose Ubuntu for my project. The steps I am about to suggest should work regardless of the Linux distribution you are planning to use.<\/p>\n<hr \/>\n<p><\/p>\n<h4>Access Windows files from WSL:<\/h4>\n<p>Now that you have WSL setup, you can start accessing Windows files from WSL. The Windows file system is mounted on the mount point &#8211; <code>\/mnt<\/code> on WSL. To see the contents of a file foo.txt in <code>C:<\/code> drive, you can use &#8211; <code>cat \/mnt\/c\/foo.txt<\/code> from WSL. The <code>.exe<\/code> files on Windows can be run from  WSL too. To  open Chrome browser on Windows run &#8211; <code>\/mnt\/c\/Program Files (x86)\/Google\/Chrome\/Application\/chrome.exe<\/code>.<\/p>\n<hr \/>\n<p><\/p>\n<h4>Link Windows&#8217;s Chrome and chromedriver to WSL:<\/h4>\n<p>To run a basic Selenium UI test on any environment you would need a browser and a driver to control the browser, in our case all we have to do is, make Windows&#8217;s Chrome browser and the chromedriver accessible from WSL, through <a href=\"https:\/\/en.wikipedia.org\/wiki\/Symbolic_link\">symlinks<\/a>.<br \/>\nRun the following commands on WSL to create symlinks:<\/p>\n<ol>\n<li><code>ln -s '\/mnt\/c\/Program Files (x86)\/Google\/Chrome\/Application\/chrome.exe' \/usr\/bin\/google-chrome<\/code>, this would create a file as google-chrome in <code>\/usr\/bin<\/code> and link it to the Chrome browser on Windows.<\/li>\n<li><code>ln -s \/mnt\/c\/Users\/username\/node_modules\/chromedriver\/lib\/chromedriver\/chromedriver.exe \/usr\/bin\/chromedriver<\/code>, this would create a file a chromedriver in <code>\/usr\/bin<\/code> and link it to the chromedriver on Windows.<\/li>\n<\/ol>\n<p><strong>Note:<\/strong> The location of Chrome browser and chromedriver will be different on your system. Check and substitute the right paths when using above commands. Also in some cases you may need to run as a root user for this to work.<\/p>\n<hr \/>\n<p><\/p>\n<h4>How it works:<\/h4>\n<p>When <code>driver = webdriver.Chrome()<\/code> is run from a script or Python interpreter on WSL, it searches for <code>chromedriver<\/code> binary in system path, it will locate the <code>chromedriver<\/code> we added with the above command and then will try to open <code>google-chrome<\/code> binary in the system path, again it will use <code>google-chrome<\/code> we added. WSL will start accessing the <code>chromedriver<\/code> and <code>google-chrome<\/code> from Windows as if they are present on its own filesystem and start running the test steps on the browser.<\/p>\n<hr \/>\n<p>There you go, you now have a Linux testing environment inside you Windows machine. Have fun testing!<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>Update: This solution works on WSL1 only Why this post? If you are one of those testers that had been using a Windows machine and have had to setup a Linux system for running your Selenium automation test, this post is for you. I had to setup a Linux system for running the automation tests for one of our clients. [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,136,30,92,1,195],"tags":[],"class_list":["post-12801","post","type-post","status-publish","format-standard","hentry","category-automation","category-chrome","category-selenium","category-ubuntu","category-uncategorized","category-windows"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=12801"}],"version-history":[{"count":27,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12801\/revisions"}],"predecessor-version":[{"id":15234,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12801\/revisions\/15234"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=12801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=12801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=12801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}