<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Erwin Heitzman on Medium]]></title>
        <description><![CDATA[Stories by Erwin Heitzman on Medium]]></description>
        <link>https://medium.com/@erwin.heitzman?source=rss-66a7944ea2a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*fjGi_I-QSAx_FXpahtg_bA.jpeg</url>
            <title>Stories by Erwin Heitzman on Medium</title>
            <link>https://medium.com/@erwin.heitzman?source=rss-66a7944ea2a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 22:44:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erwin.heitzman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Lesson learned from writing a service for WebdriverIO]]></title>
            <link>https://medium.com/detesters/lesson-learned-from-writing-a-service-for-webdriverio-2111c0aa1533?source=rss-66a7944ea2a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2111c0aa1533</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[lessons-learned]]></category>
            <category><![CDATA[webdriverio]]></category>
            <category><![CDATA[async]]></category>
            <dc:creator><![CDATA[Erwin Heitzman]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 23:45:13 GMT</pubDate>
            <atom:updated>2020-01-10T16:10:14.369Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aZFBqCWMb6W2lV9HqsHJNw.png" /></figure><h4>Introduction</h4><p>At the end of 2019 I wrote my first service for a test framework called WebdriverIO and I must say that I have learned quite a lot when doing so. That&#39;s why I want to share my experience with you so that hopefully you learn something from it too.</p><p>The idea I had was to create a service that would download, start and stop a piece of software called WireMock. Now I am not going into details about what WireMock is or does but in short it is an application written in Java that allows you to mock/stub your internet traffic.</p><h4>Why?</h4><p>I was faced with WireMock during my job and realised that there&#39;s no service that does this. At the same time I thought to myself, how hard can it be?</p><p>Well, the challenges that I faced weren&#39;t really the type that I would normally face so it was a good thing that I started this little project of mine.</p><h4>Research</h4><p>I already had an idea of how to create a service locally that I could use but to create a npm package and use that is something different entirely.</p><p>To get a grasp of the things that would be required I started researching already existing services. For this I choose to use wdio-chromedriver-service and @wdio/selenium-standalone-service which helped me tremendously to understand how I could create a start.</p><p>For example I noticed that both services used the spawn function that is provided by the child_process module found in NodeJS. I tried to use spawnSynch function first because I had to wait for the process to start and I thought this was going to help me with that.</p><p>Instead of helping me it turned out that it would hang until this process was terminated, which is not what I needed. So I figured that I had to use the async version and deal with that issue in another way. After a while I actually got things working but what I didn&#39;t know yet was that while it seemed like everything was working in reality it wasn&#39;t working at all and I was just lucky.</p><h4>The code and the problem</h4><p>So what does the code actually look like? Let me show you what I had going.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be92eb0016ef3bbc64e184190ae9b053/href">https://medium.com/media/be92eb0016ef3bbc64e184190ae9b053/href</a></iframe><p>Here you see that the process is spawned and it is assigned to a property called process. This action was done async which means that my tests where started as soon as this action had been triggered (note: triggered yet maybe not completed). In this case the action went so fast that during testing this, it worked each time.</p><p>But as with all software it is good to be thorough when you write and test your code which is how I found out that I was just lucky for not running into issues during my testing phase.</p><h4>Approach when there is no obvious answer</h4><p>Even though I tried some solutions that might or might not work, I could not come up with a simple solution that would ensure that the service would be started though not be blocking the thread.</p><p>So after a while I stopped looking for solutions like promisify and decided to look at other software and I started with some already existing services. After some digging I found out that the wdio-selenium-standalone-service also faced the same challenge that I was facing and I quickly looked at the solution that was used there.</p><p>I could not believe my eyes when I saw the solution though, sometimes things are way easier than you think. You just have to simplify the problem and/or take a step back and approach it from a different angle!</p><h4>The solution</h4><p>If all that I did was start a program that runs on a specific port, then why not simply wait until that port is taken? Like i said, the solution might surprise you!<br>This goes to show that it’s good to sometimes take a step back, people sometimes say that going for a short walk is enough to clear their head and approach a problem from a different angle.</p><p>So what does the final code look like?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fc522d1ef896c49f73a1686412eefbb/href">https://medium.com/media/5fc522d1ef896c49f73a1686412eefbb/href</a></iframe><p>I installed a package called tcp-port-used and imported their waitUntilUsed method to wait until the port is taken (it waits for 10 seconds with an interval of 100ms). Easy right?</p><h4>Takeaway</h4><p>I hope you have learned that when you are stuck that the solution might be easier than you think. Taking a step back to approach it again later can be a good thing and I hope you now feel more comfortable in doing so!</p><p>Hopefully my story inspires you to create your own piece of software some day.</p><p>If this has been helpful to you, let me know in the comments below!</p><p>Cheers,</p><p>Erwin</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2111c0aa1533" width="1" height="1" alt=""><hr><p><a href="https://medium.com/detesters/lesson-learned-from-writing-a-service-for-webdriverio-2111c0aa1533">Lesson learned from writing a service for WebdriverIO</a> was originally published in <a href="https://medium.com/detesters">deTesters</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>