<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: archagy</title>
    <description>The latest articles on DEV Community by archagy (@archagy).</description>
    <link>https://dev.to/archagy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F150041%2Fc21362f1-3e31-40b0-86cc-3809a0a282d9.png</url>
      <title>DEV Community: archagy</title>
      <link>https://dev.to/archagy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/archagy"/>
    <language>en</language>
    <item>
      <title>How to run webdriverio on WSL windows Ubuntu</title>
      <dc:creator>archagy</dc:creator>
      <pubDate>Mon, 07 Oct 2019 18:06:42 +0000</pubDate>
      <link>https://dev.to/archagy/how-to-run-webdriverio-on-wsl-windows-ubuntu-1fi5</link>
      <guid>https://dev.to/archagy/how-to-run-webdriverio-on-wsl-windows-ubuntu-1fi5</guid>
      <description>&lt;p&gt;This is a hacky way to run webdriverio and maybe other kind of node frameworks like protractor on WSL (windows Subsystem for Linux).&lt;/p&gt;

&lt;h4&gt;Before to start &lt;/h4&gt;

&lt;p&gt;I would like to mention this still uses the npm for windows but only to install the wdio client; We have to install it because we need the chromedriver version for windows.&lt;/p&gt;

&lt;h2&gt;What's WSL?&lt;/h2&gt;

&lt;p&gt;Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10 and Windows Server 2019. &lt;a href="https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux" rel="noopener noreferrer"&gt;wikipedia &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So basically you can run Ubuntu or other many distros on Windows, of course there are some incompatibilities but for now I prefer to use WSL instead of git bash, MSYS or powershell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;git bash sometimes froze or didn't show some logs and it's the same for MSYS (git bash use MSYS), I know there are other alternatives like cygwin or MINGW but kinda the same problems.&lt;/p&gt;

&lt;p&gt;Node it could be a nightmare on windows, it depends on what are you doing. For example I lost many hours trying to make node-gyp work on windows.&lt;/p&gt;

&lt;p&gt;I know I can use a virtual machine or docker etc.. there are many ways to have linux environment for develop software but I like to share this one, maybe it could be helpful for someone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Start
&lt;/h2&gt;

&lt;p&gt;Install WSL on windows - &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" rel="noopener noreferrer"&gt; (official windows guide) &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step it's to enable the WSL on your machine you can do that running this command on powershell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From windows store you can search for the linux distro you like to install. I choose ubuntu.&lt;/p&gt;

&lt;p&gt;After the installation finish, you have to restart your machine and now you can type your distro on the windows start menu and open your terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flbiddhbqc23649ofm9db.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flbiddhbqc23649ofm9db.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: it looks like this because I already installed tmux and some plugins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can't access to my external drives.
&lt;/h2&gt;

&lt;p&gt;Your local files it's on /mnt/c or /mnt/f it depends of how your partitions were made. &lt;/p&gt;

&lt;p&gt;My only problem was the rights permission on the partition, it can only be modified by the root and the command to change the user seems to work but the access folder it was still only by root.&lt;/p&gt;

&lt;p&gt;If you have the same problem, close the Ubuntu terminal and from powershell run the next command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Restart-Service -Name "LxssManager"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will restart WSL service and if you open your terminal again you would be able to modify your files without problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  I can modify my files from windows on WSL and vice versa?
&lt;/h2&gt;

&lt;p&gt;There are many comments from the WSL version 1 where they recommend to don't modify your files from the WSL on windows. Since the version 2. I readed there are no problem now. However I would recommend to modify only your files from the C or external drives and don't play around directly on the WSL directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's install node.
&lt;/h2&gt;

&lt;p&gt;On windows I really like this node manager &lt;a href="https://github.com/coreybutler/nvm-windows" rel="noopener noreferrer"&gt; nvm-windows &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to the release tab and download the installer it's very easy to install and use. With nvm you can install any node version and change from version to version easily.&lt;/p&gt;

&lt;p&gt;You can do the same on your ubuntu terminal&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt; nvm for ubuntu&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  start the webdriver config and install
&lt;/h2&gt;

&lt;p&gt;From ubuntu you can create a symbolic links so create one from your home to your external drive. I have a external ssd and I can access from home easily thanks for the symbolic link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6hiyo9khzn9fkv0jgy9c.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6hiyo9khzn9fkv0jgy9c.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is important to install your projects on C or your external drives, it would be more easy to access and edit from Windows or Ubuntu.&lt;/p&gt;

&lt;p&gt;Run the following commands to start a new webdriverio project example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir webdriverio-test &amp;amp;&amp;amp; cd webdriverio-test
npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;expected output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wrote to /mnt/f/projects/personal/webdriverio-test/package.json:

{
  "name": "webdriverio-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, from powershell let's install webdriver.io.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhpu33jkwwf2o361h0235.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhpu33jkwwf2o361h0235.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can install any other dependency on ubuntu we only need webdriver cli for windows.&lt;/p&gt;

&lt;p&gt;Run the next command to generate the config  file for webdriverio&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#you have to be on your root project still on windows
./node_modules/.bin/wdio config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;select the local options.&lt;/p&gt;

&lt;p&gt;and select your browser driver that you like. I choose chromedriver.&lt;/p&gt;

&lt;h2&gt;
  
  
  On WSL/Ubuntu.
&lt;/h2&gt;

&lt;p&gt;let's create our first test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p ./test/specs
touch ./test/specs/basic.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;use your any editor and add paste this code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require('assert')

describe('webdriver.io page', () =&amp;gt; {
    it('should have the right title', () =&amp;gt; {
        browser.url('https://webdriver.io')
        const title = browser.getTitle()
        assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js')
    })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's edit our package.json to add the wdio script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "webdriverio-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "./node_modules/.bin/wdio wdio.conf.js"   #edit this
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@wdio/cli": "^5.14.4",
    "@wdio/jasmine-framework": "^5.14.4",
    "@wdio/local-runner": "^5.14.4",
    "@wdio/spec-reporter": "^5.14.4",
    "chromedriver": "^77.0.0",
    "wdio-chromedriver-service": "^5.0.2"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can run your test like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cmd.exe /c "npm run test"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3y5wnx0vg3hoyznqrej4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3y5wnx0vg3hoyznqrej4.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can save the previous command on a bash alias.&lt;/p&gt;

&lt;p&gt;thanks for reading any suggestion or recommendation would be appreciated. &lt;/p&gt;

</description>
      <category>testing</category>
      <category>automation</category>
      <category>wsl</category>
      <category>webdriverio</category>
    </item>
  </channel>
</rss>
