<?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 Kennedy Nwaorgu on Medium]]></title>
        <description><![CDATA[Stories by Kennedy Nwaorgu on Medium]]></description>
        <link>https://medium.com/@codejockie?source=rss-59617c1e2c0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Y-CxRygilB1E30WgMm95XA.jpeg</url>
            <title>Stories by Kennedy Nwaorgu on Medium</title>
            <link>https://medium.com/@codejockie?source=rss-59617c1e2c0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:18:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codejockie/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[Configure Build Variants in Xamarin.Android]]></title>
            <link>https://medium.com/@codejockie/configure-build-variants-in-xamarin-android-51e20c547ec1?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/51e20c547ec1</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[xamarin-android]]></category>
            <category><![CDATA[net-android]]></category>
            <category><![CDATA[android-build-variant]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Wed, 07 May 2025 01:04:09 GMT</pubDate>
            <atom:updated>2025-05-07T01:04:09.212Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous place of work, I maintained (mostly solely) a Xamarin.Android app that needed to be kept alive pending when it is replaced. One of the gripes we had was having to uninstall a release version of the app whenever we were working and testing locally. This can be quite frustrating, and it does not have to be that way. In this article, I will walkthrough a method for configuring build variants in Xamarin.Android apps.</p><h3>What are build variants?</h3><blockquote><strong>Build variants</strong> are a powerful feature that allows you to configure and manage multiple versions of an app within a single project. They are particularly useful for creating different versions of an app, such as free and paid, or for targeting different device configurations, such as API levels or screen sizes.</blockquote><p>In Android projects, this can easily be done by configuring build types in Gradle simply with an applicationIdSuffix .</p><pre>android {<br>    defaultConfig {<br>        applicationId = &quot;io.github.codejockie.app&quot;<br>    }<br>    buildTypes {<br>        getByName(&quot;release&quot;) {<br>            isMinifyEnabled = true<br>            proguardFiles(getDefaultProguardFile(&quot;proguard-android.txt&quot;), &quot;proguard-rules.pro&quot;)<br>        }<br><br>        getByName(&quot;debug&quot;) {<br>            applicationIdSuffix = &quot;.debug&quot;<br>            isDebuggable = true<br>        }<br>    }<br>}</pre><p>In newer .NET Android projects, a similar concept exists where you can provide an ApplicationIdSuffix in the project<strong> </strong>file (<strong>*.csproj</strong>). You can configure this conditionally as below.</p><pre>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;<br>  &lt;PropertyGroup&gt;<br>    ...<br>    &lt;ApplicationId&gt;io.github.codejockie.app&lt;/ApplicationId&gt;<br>    &lt;ApplicationIdSuffix Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Debug|AnyCPU&#39; &quot;&gt;.debug&lt;/ApplicationIdSuffix&gt;<br>  &lt;/PropertyGroup&gt;<br>&lt;/Project&gt;</pre><p>Doing something similar to the above methods in Xamarin.Android is quite involved as we will see shortly.</p><p>Below I have listed the two ways to do this:</p><p>1. Creating copies of the android manifest file for the different project configurations. This can become a problem quickly when you have to enable some settings, add/remove permissions etc., since you will have to do this for all the manifest files you made.</p><p>2. Using the project file to configure the aspects you want. This is my preferred option and the one I will walk through.</p><p>To get started, you will need to edit your project file i.e. the *.csproj file. Assuming you have both <strong>Debug</strong> and <strong>Release</strong> build configurations the following changes will be made.</p><p>Add the following to the *.csproj file if you do not already have it.</p><pre>&lt;PropertyGroup Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Debug|AnyCPU&#39; &quot;&gt;<br>&lt;/PropertyGroup&gt;<br>&lt;PropertyGroup Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Release|AnyCPU&#39; &quot;&gt;<br>&lt;/PropertyGroup&gt;</pre><p>The above adds a property group for the different types of build configurations in the app.</p><p>Now, for each of the newly added blocks add a new property to configure the package name when the set condition is true. For this we will use the <a href="https://learn.microsoft.com/en-us/dotnet/android/building-apps/build-properties#androidmanifestplaceholders">AndroidManifestPlaceholders</a> property of MSBuild which is a semicolon-separated list of key-value replacement pairs for <em>AndroidManifest.xml</em>, where each pair has the format key=value. In that example, it defines a ${key} placeholder that can then appear in <em>AndroidManifest.xml. </em>Make the following changes.</p><pre>&lt;PropertyGroup Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Debug|AnyCPU&#39; &quot;&gt;<br>+   &lt;AndroidManifestPlaceholders&gt;packageName=io.github.codejockie.app.debug&lt;/AndroidManifestPlaceholders&gt;<br>&lt;/PropertyGroup&gt;<br>&lt;PropertyGroup Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Release|AnyCPU&#39; &quot;&gt;<br>+   &lt;AndroidManifestPlaceholders&gt;packageName=io.github.codejockie.app&lt;/AndroidManifestPlaceholders&gt;<br>&lt;/PropertyGroup&gt;</pre><p>After doing that, open the <strong>AndroidManifest.xml</strong> file in the Properties directory, and set the `package` property as below.</p><pre>&lt;manifest<br>  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>  android:versionCode=&quot;1&quot;<br>  android:versionName=&quot;1.0.0&quot;<br>+  package=&quot;${packageName}&quot;<br>  android:installLocation=&quot;auto&quot;&gt;<br> &lt;uses-sdk android:minSdkVersion=&quot;23&quot; android:targetSdkVersion=&quot;31&quot; /&gt;<br> &lt;application android:allowBackup=&quot;true&quot; android:icon=&quot;@mipmap/icon&quot; android:label=&quot;FwdMbl - PCI Warehouse App&quot; android:supportsRtl=&quot;true&quot; android:theme=&quot;@style/AppTheme&quot;&gt;<br>  &lt;provider android:name=&quot;androidx.core.content.FileProvider&quot; android:authorities=&quot;com.example.app.provider&quot; android:exported=&quot;false&quot; android:grantUriPermissions=&quot;true&quot;&gt;<br>   &lt;meta-data android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot; android:resource=&quot;@xml/provider_paths&quot; /&gt;<br>  &lt;/provider&gt;<br> &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>That is all you need to get the issue fixed. It is worth mentioning that if you have a provider in your manifest and you already have a version of the app installed on your test device you might run into an error that is similar to below.</p><pre>Xamarin.Android.Common.Debugging.targets(613,5): Error ADB0010 : Mono.AndroidTools.InstallFailedException: Failure [INSTALL_FAILED_CONFLICTING_PROVIDER: Scanning Failed.: Can&#39;t install because provider name com.example.app.provider (in package x__AndroidPackageName_.x__AndroidPackageName_) is already used by com.example.app]<br>   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Internal/AdbOutputParsing.cs:line 353<br>   at System.Threading.Tasks.Task.Execute()</pre><p>This error occurs because a version of the app with the application ID `com.example.app` already uses said provider `com.example.app.provider`. In this case, we will have to update the provider in the manifest to reflect the set build configuration. Let’s make the following changes.</p><p><strong>.csproj file</strong></p><pre>&lt;PropertyGroup Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Debug|AnyCPU&#39; &quot;&gt;<br>-   &lt;AndroidManifestPlaceholders&gt;packageName=com.example.app.debug&lt;/AndroidManifestPlaceholders&gt;<br>+   &lt;AndroidManifestPlaceholders&gt;authorities=com.example.app.debug.provider;packageName=com.example.app.debug&lt;/AndroidManifestPlaceholders&gt;<br>&lt;/PropertyGroup&gt;<br>&lt;PropertyGroup Condition=&quot; &#39;$(Configuration)|$(Platform)&#39; == &#39;Release|AnyCPU&#39; &quot;&gt;<br>-   &lt;AndroidManifestPlaceholders&gt;packageName=com.example.app&lt;/AndroidManifestPlaceholders&gt;<br>+   &lt;AndroidManifestPlaceholders&gt;authorities=com.example.app.provider;packageName=com.example.app&lt;/AndroidManifestPlaceholders&gt;<br>&lt;/PropertyGroup&gt;</pre><p><strong>AndroidManifest.xml</strong></p><pre>&lt;manifest<br>  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>  android:versionCode=&quot;1&quot;<br>  android:versionName=&quot;1.0.0&quot;<br>  package=&quot;${packageName}&quot;<br>  android:installLocation=&quot;auto&quot;&gt;<br> &lt;uses-sdk android:minSdkVersion=&quot;23&quot; android:targetSdkVersion=&quot;31&quot; /&gt;<br> &lt;application android:allowBackup=&quot;true&quot; android:icon=&quot;@mipmap/icon&quot; android:label=&quot;FwdMbl - PCI Warehouse App&quot; android:supportsRtl=&quot;true&quot; android:theme=&quot;@style/AppTheme&quot;&gt;<br>-  &lt;provider android:name=&quot;androidx.core.content.FileProvider&quot; android:authorities=&quot;com.example.app.provider&quot; android:exported=&quot;false&quot; android:grantUriPermissions=&quot;true&quot;&gt;<br>+  &lt;provider android:name=&quot;androidx.core.content.FileProvider&quot; android:authorities=&quot;${authorities}&quot; android:exported=&quot;false&quot; android:grantUriPermissions=&quot;true&quot;&gt;<br>   &lt;meta-data android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot; android:resource=&quot;@xml/provider_paths&quot; /&gt;<br>  &lt;/provider&gt;<br> &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>You can configure the other bits of the manifest like the icon, label etc. in a similar way — add the key-value pair to the AndroidManifestPlaceholders property, then reference the key in the manifest. You can add more build configurations as needed and apply the aforementioned method.</p><p>And that is all you need to do get build variants set up in older Xamarin.Android projects. If you have enjoyed reading this and you learned something new, please like and follow <a href="https://medium.com/@codejockie">me</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51e20c547ec1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose: Type-safe Deep Link]]></title>
            <link>https://medium.com/@codejockie/jetpack-compose-type-safe-deep-link-1588672e722d?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1588672e722d</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose-navigation]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Wed, 07 May 2025 01:01:35 GMT</pubDate>
            <atom:updated>2025-05-07T01:01:35.240Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I explore type-safe deep linking in Jetpack Compose. In my <a href="https://play.google.com/store/apps/details?id=com.codejockie.wani.internal">app</a>, there is a Word of the Day widget that when clicked opens a screen showing details of the word. To get into the bits of it, I used Jetpack Glance for the widget and type-safe arguments for navigation. A view model handles the retrieval of the arguments via the SavedStateHandle.</p><p>To get started, I enabled deep link for the screen to be navigated to when the widget is clicked.</p><pre>@Serializable<br>data class Subject(val id: Int)<br><br>composable&lt;Subject&gt;(<br>  deepLinks = listOf(<br>    navDeepLinks&lt;Subject&gt;(basePath = &quot;$scheme://subject&quot;)<br>  )<br>) {<br>  SubjectScreen()<br>}</pre><p>The view model retrieves the id argument from SavedStateHandle as follows:</p><pre>@HiltViewModel<br>class SubjectViewModel @Inject constructor(<br>  savedStateHandle: SavedStateHandle<br>) {<br>  private val args = savedStateHandle.toRoute&lt;Subject&gt;()<br><br>  ...<br>}</pre><p>args will be the data passed to the route in this case the Subject data class.</p><p>Then in the manifest file, I set up an intent filter to handle the deep link as follows:</p><pre>&lt;activity<br>    android:name=&quot;.MainActivity&quot;<br>    android:exported=&quot;true&quot;<br>    android:launchMode=&quot;singleTop&quot;<br>    android:theme=&quot;@style/Theme.App&quot;&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;<br><br>        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;<br>    &lt;/intent-filter&gt;<br>    + &lt;intent-filter&gt;<br>    +    &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;<br>    +    &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;<br>    +    &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;<br><br>    +    &lt;data android:scheme=&quot;@string/app_scheme&quot; android:host=&quot;subject&quot; /&gt;<br>    +&lt;/intent-filter&gt;<br>&lt;/activity&gt;</pre><p>I used a string resource to define the scheme — this is to allow for flexibility as I have different build variants, and for simplicity I used the app’s name (lowercased).</p><p>&gt; The above step is required to have the deep link working as without it nothing happens.</p><p>Having completed the first two steps, I proceeded to the final step which — handle click in the (Glance) widget composable. For this, an intent is required which will trigger the launching of the app and navigating to the subject screen. This was done as follows:</p><pre>val intent = Intent(Intent.ACTION_VIEW).apply {<br>  data = &quot;$scheme://subject/$id&quot;.toUri()<br>  flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK<br>}</pre><p>The data has been setup to include the base path $scheme://subject plus the ID of the clicked word (subject) and converted to a URI. Flags have also been set to start a new task on the history stack.</p><p>With that out of the way, this intent is passed to the actionStartActivity() function as follows:</p><pre>Box(modifier = GlanceModifier.clickable(actionStartActivity(intent))) {<br>  ...<br>}</pre><p>That is all we need to get the deep link working. Now, when the widget is clicked, it opens the app on the specified screen.</p><p><strong>Conclusion</strong></p><p>Points to note:</p><ul><li>The scheme and host attributes defined in the intent filter’s data element must match that defined in the base path argument for the composable. Same goes for the data passed to the intent.</li><li>The existing (default) intent filter defined for the main activity should not be reused for enabling deep link — create a new one.</li></ul><p>Stay connected to get notified of new content by following <a href="https://medium.com/@codejockie">me</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1588672e722d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uCertify CIW JavaScript Course Review]]></title>
            <link>https://medium.com/@codejockie/ucertify-ciw-javascript-course-review-c497ca8a579?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c497ca8a579</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[certification]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Wed, 19 Jun 2019 11:44:02 GMT</pubDate>
            <atom:updated>2019-06-19T11:45:01.667Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*wIb2i8RRLa-JMUZ5q63wsQ.png" /></figure><p>JavaScript is among the most used programming language worldwide. It is very important to learn this programming language if you are working in this field or thinking about starting your career in this field. I am a Full Stack Developer and I use this programming language in my work daily. A few weeks back I got the opportunity to study the uCertify CIW: JavaScript Specialist v2.0 course (<a href="https://www.ucertify.com/exams/CIW/1D0-735.html)">https://www.ucertify.com/exams/CIW/1D0-735.html)</a>.</p><p>A JavaScript certification can help you in showcasing your skills and competency of this language. The CIW JavaScript specialist certification brings a lot of benefits for everyone involved as this is a prestigious credential that teaches a lot of great skills. The comprehensive cert guide provides complete knowledge and skills for working with this programming language. The chapters are so well-designed to provide you a complete understanding of all the aspects of JavaScript. The chapters contain knowledge checks and flashcards for testing the knowledge gained in the chapters. The live-lab provides hands-on learning of the exam objectives with the real-world scenarios. The course is strictly based on the CIW 1D0–735 exam objectives.</p><p>Some of the components added in the course are:</p><ul><li>15+ Lessons</li><li>134+ Quizzes</li><li>99+ Flashcards</li><li>2+ Full-length Tests</li><li>55+ Pre-assessments</li><li>55+ Post Assessments</li><li>66+ Live-labs (add-on component)</li></ul><p>I strongly recommend this course for the professionals looking forward to preparing for the CIW JavaScript specialist certification exam. The course will help you pass the exam with its learning resources.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c497ca8a579" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Switch Keyboard Language to Japanese]]></title>
            <link>https://medium.com/@codejockie/switch-keyboard-language-to-japanese-71198ba83b2e?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/71198ba83b2e</guid>
            <category><![CDATA[language]]></category>
            <category><![CDATA[japanese]]></category>
            <category><![CDATA[chinese]]></category>
            <category><![CDATA[english]]></category>
            <category><![CDATA[keyboard-shortcuts]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Sat, 23 Mar 2019 10:54:41 GMT</pubDate>
            <atom:updated>2019-03-23T10:54:41.061Z</atom:updated>
            <content:encoded><![CDATA[<h3>Switch Keyboard Language to English, Chinese and Japanese</h3><p>In this post I want to show you how you can quickly switch your keyboard input between three different languages in three steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/0*sQkTXK7XJ9QYC0PJ.jpg" /></figure><p>Secondly, open Karabiner, and navigate to the “Complex Modifications” tab. Click on “Add rule”, then click on the “Import more rules” button. This action will open a page in your default browser. On that page, use the search bar, and type “for Japanese” to narrow down the list.</p><p>Thirdly, Import the option that reads “switch English, Chinese, Japanese” and click on the Import button to the right hand side. This action switches back to Karabiner where you now have the option to enable the imported command. Click on Enable for the rule you just imported.</p><p>That’s it, you can switch quickly between English, Chinese, Japanese (Hiragana) and Japanese (Katakana) simply by holding the Option key and pressing 1 for English, 2 for Chinese, 3 for Japanese (Hiragana) and 4 for Japanese (Katakana).</p><p>Simple right?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71198ba83b2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common React Errors]]></title>
            <link>https://medium.com/@codejockie/common-react-errors-bb6b52a87c3e?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb6b52a87c3e</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Thu, 14 Feb 2019 12:02:38 GMT</pubDate>
            <atom:updated>2019-03-30T12:11:16.508Z</atom:updated>
            <content:encoded><![CDATA[<p>We all have been in that situation where we wrote some code and an error is the next “logical” thing. It can be a pain when we come across these scenarios and can be even more painful if we don’t have React setup properly for debugging.</p><p>Fixing these issues require understanding the problem, tracing the problematic line and fixing it. Sometimes it’s not that easy, as an error can be pointing to a line in one file while the actual error was from some other file. Another time these errors are cryptic, making it even more difficult to trace.</p><p>I want to point out some of the common errors we make when working with React and how to fix them. This is not an exhaustive list of errors but I am open to updating the list.</p><p>With that out of the way, let’s find those bugs. :)</p><ol><li>You made a stateless/functional component and did not return.</li></ol><pre>import React from &quot;react&quot;;</pre><pre>const Error = () =&gt; {<br>  &lt;div&gt;Error&lt;/div&gt;;<br>};</pre><pre>export default Error;</pre><p>You get the following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NmXRNO-MHRJM6w_sYF4YA.png" /></figure><p>The error message is quite intuitive, from the image above you can see that the error started from Line 19 which really isn’t the cause of the error but the point at which the error was caught. Fixing this is as simple adding a return into the said functional component.</p><pre>const Error = () =&gt; {<br>  return &lt;div&gt;Error&lt;/div&gt;;<br>};</pre><pre>// OR</pre><pre>const Error = () =&gt; &lt;div&gt;Error&lt;/div&gt;;</pre><p>2. Invoking an event handler method where a reference to the method is required.</p><pre>export default class Error extends React.Component {<br>  state = {<br>    text: &quot;&quot;<br>  };</pre><pre>  handleChange = ({ target: { value } }) =&gt; {<br>    this.setState({ text: value });<br>  };</pre><pre>  render() {<br>    return (<br>      &lt;&gt;<br>        &lt;input<br>          onChange={this.handleChange()} {/* Error: method invocation */}<br>        /&gt;<br>      &lt;/&gt;<br>    );<br>  }<br>}</pre><p>You get the error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajfmT_27StbwokTU-72GZA.png" /></figure><p>This can be fixed in two ways:</p><ul><li>Passing a reference instead of invoking the method like so: onChange={this.handleChange}</li><li>Use a fat arrow function: onChange={event =&gt; this.handleChange(event)}</li></ul><p>3. Importing a component that wasn’t exported and using same in render() . This can also occur as a result of mixing up default and named imports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a_WHT_qJlN7k09HlZ4ZHpw.png" /></figure><p>Fixing this is as simple as exporting the component and in the case of mixed up imports, ensure you import the component correctly.</p><p>4. You have a component that is connected to redux, and you call an action/function from the component’s props that you didn’t already pass to mapDispatchToProps() .</p><p>5. In React 16.8.0, Hooks were added. When you invoke a hook’s setter directly on an event handler like below:</p><pre>const Hooks = props =&gt; {<br>  const [value, setValue] = useState(&quot;Awesome&quot;);</pre><pre>return (<br>    &lt;div&gt;<br>      Hooks are here and they are great!! No I meant{&quot; &quot;}<br>      &lt;strong&gt;<br>        &lt;em&gt;{value}&lt;/em&gt;!<br>      &lt;/strong&gt;<br>      &lt;br /&gt;<br>      &lt;hr /&gt;<br>      &lt;button onClick={setValue(&quot;Fantastic&quot;)}&gt;Change Text&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><p>The following error ensues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVjwJzHp8IyPqEIT9JdFEg.png" /></figure><p>This can be fixed by changing onClick={setValue(“Fantastic”)} to onClick={() =&gt; setValue(“Fantastic”)} .</p><p>6. Sometimes an error can be tricky. Take for example the error below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*1nlMfQYZQd8doqnjeyBGHg.png" /></figure><p>There are various reasons for this kind of error, some already listed above. Aside from the causes already mentioned, it could be as a result of React version update, say a switch from v15 to v16 and not updating the deprecated lifecycle methods.</p><p>7. Another error is this:</p><pre>Warning: Functions are not valid as a React child. This may happen if you return a Component instead of &lt;Component /&gt; from render. Or maybe you meant to call this function rather than return it.</pre><p>A scenario for that error is this:</p><pre>&lt;select name=&quot;category&quot;&gt;<br>    value={category} <br>    onChange={this.handleChange}/&gt;<br>    &lt;option&gt;Select a category&lt;/option&gt;<br>    ...<br>&lt;/select&gt;</pre><p>From the code, you’d quickly notice that the select element was closed immediately after the the name attribute leaving the other attributes (value and onChange) hanging plus there is another self closing tag following the onChange attribute. Removing these fixes the error.</p><p>8. Another error could be this below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGt-SjSkojgG48q27SwGlg.png" /></figure><p>This code generated that error:</p><pre>return(<br>   &lt;ul onClick=&quot;this.handleToggle()&quot;&gt;<br>     ...<br>   &lt;/ul&gt;<br>);</pre><p>The cause of the error is pretty straightforward, the onClick expects a function but got a string type instead. A quick fix for this is taking out the surrounding quotes and replacing with {} like this: &lt;ul onClick={this.handleToggle()}&gt;</p><p>9. Take a look at the following code:</p><pre>function App() {</pre><pre>  function handleRefresh() {<br>    window.location.reload();<br>  }</pre><pre>return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Headlines&lt;/h1&gt;<br>      &lt;button onClick={handleRefresh()}&gt;Reload&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>On first look you’d think there’s nothing wrong with the code above but running it you’d be in an infinite re-rendering state. Why?</p><p>Well your button event handler invokes the handleRefresh() method directly which calls window.location.reload() . If you really must do this, then a slight modification to your onClick handler does the job. onClick={() =&gt; handleRefresh()} fixes it.</p><h3><strong>Conclusion</strong></h3><p>Errors are part of our development now and we see them even in code that works. What we do when they are found is what counts. I have a feeling you have at a point seen these errors or still have them at this moment in time. I hope this helps you fix those.</p><p>Feel free to suggest an addition to this.</p><p>I love the cool effects of the clap button, click to like, it is fun.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb6b52a87c3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[E2E Testing with Nightwatch: Part Three]]></title>
            <link>https://medium.com/@codejockie/e2e-testing-with-nightwatch-part-three-e7c3a8759917?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7c3a8759917</guid>
            <category><![CDATA[e2e-testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nightwatchjs]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Fri, 02 Mar 2018 19:12:32 GMT</pubDate>
            <atom:updated>2018-03-02T19:12:32.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*cg3WoO0m8yMnrgDQgALxiA.png" /></figure><p>It’d been quite some time since I promised to do a part three on Nightwatch.js pages. I want to thank Marissa who took the time out of her busy schedule to reach out to me about this part of the tutorial. I have had a lot on my table lately that I haven’t written in three months. I’m sorry about that. Moving on…</p><p>In this article, I would be talking about Page Objects. Without further ado, let’s begin.</p><blockquote>Note: Most of the things I write here are mostly what you would find in the Nightwatch.js documentation.</blockquote><h3><strong>What is a Page Object?</strong></h3><p>A page object allows a software client to do anything and see anything that a human can by abstracting away the underlying HTML actions needed to access and manipulate the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*idilmwefPf9xgx5_dY1Ojg.png" /></figure><p>A comprehensive introduction to Page Objects can be found in this <a href="https://martinfowler.com/bliki/PageObject.html">article</a>.</p><h3><strong>Configure Page Objects</strong></h3><p>In order to configure page objects in nightwatch, we need to add the page_objects_path property to our nightwatch.json file. If you take a look at it now, you’d see that we had done that already, if that’s not the case then go on and add it to your nightwatch.json config file. We assigned ”pages” to the page_objects_path property in our config, doing this we tell Nightwatch to read the page objects from the folder (or folders) specified in the page_objects_path configuration property.</p><p>You can also pass an array of folders to the page_objects_path property, allowing you to split page objects into smaller groups.</p><p>There are several properties exposed to use when we use page objects, we’ll look at them shortly.</p><h4><strong>The Url property</strong></h4><p>This property is optional as you can or do not have to provide it. When provided, it designates the page’s URL. Call the navigate method on the page object to navigate to the page.</p><p>The URL will usually be defined as a string:</p><pre>export default {<br>  url: &#39;<a href="http://google.com&/#39;">https://cjdocs.herokuapp.com&#39;</a>,<br>};</pre><p>You can also pass a function to it, in the case of a dynamic url. One use case would be when you want to support different test environments. You can create a function that gets called in the context of the page, thus allowing you to do:</p><pre>export default {<br>  url: function() { <br>    return this.api.launchUrl + ‘auth/signin’; <br>  },<br>};</pre><h4><strong>The Elements property</strong></h4><p>The elements property is used to define elements on your page that your tests will interact with through commands and assertions. This helps keep your code DRY especially in larger integration tests.</p><p>We don’t have to call useXpath or useCss in our tests to switch between locate strategies as this is done internally for us. By default, locateStrategy is set to CSS, but you can also specify XPath:</p><pre>export default {<br>  elements: {<br>    searchBar: { <br>      selector: ‘input[type=text]’ <br>    },<br>    submit: { <br>      selector: ‘//[<a href="http://twitter.com/name">@name</a>=”q”]’, <br>      locateStrategy: ‘xpath’ <br>    }<br>  }<br>};</pre><p>You can use the shorthand, if you’re creating elements with the same locate strategy as is default:</p><pre>export default {<br>  elements: {<br>    searchBar: ‘input[type=text]’<br>  }<br>};</pre><p>Using the elements property, we can refer to the element by prefixing &quot;@&quot; to its name, rather than selector, when calling element commands and assertions (e.g. click, etc).</p><p>Optionally, you can define an array of objects:</p><pre>var sharedElements = {<br>  mailLink: ‘a[href*=”mail.google.com”]’<br>};</pre><pre>export default {<br>  elements: [<br>    sharedElements,<br>    { searchBar: ‘input[type=text]’ }<br>  ]<br>};</pre><h4><strong>The Sections property</strong></h4><p>The sections property allows you to define sections of a page. It can be useful for two things:</p><ol><li><a href="http://nightwatchjs.org/guide#defining-sections">It provides a level of namespacing under the page</a></li><li><a href="http://nightwatchjs.org/guide#defining-sections">It provides element-level nesting so that any element defined within a section is a descendant of its parent section in the DOM</a></li></ol><p>Creating a section looks like this:</p><pre>export default {<br>  sections: {<br>    menu: {<br>      selector: ‘#gb’,<br>      elements: {<br>        mail: {<br>          selector: ‘a[href=”mail”]’<br>        },<br>        images: {<br>          selector: ‘a[href=”imghp”]’<br>        }<br>      }<br>    }<br>  }<br>};</pre><blockquote>Note that every command and assertion on a section (other than `expect` assertions) returns that section for chaining. If desired, you can nest sections under other sections for complex DOM structures.</blockquote><h4><strong>The Commands property</strong></h4><p>The commands property allows you to add commands to your page object. It is a useful way to encapsulate logic about the page that would otherwise live in a test, or multiple tests.</p><p>Nightwatch will call the command on the context of the page or section. You can call client commands like pause via this.api. When chaining, each function should return the page object or section.</p><p>The example below uses a command to encapsulate logic for clicking the submit button:</p><pre>const googleCommands = {<br>  submit: function() {<br>    this.api.pause(1000);<br>    return this.waitForElementVisible(‘<a href="http://twitter.com/submitButton">@submitButton</a>’, 1000)<br>      .click(‘<a href="http://twitter.com/submitButton">@submitButton</a>’)<br>      .waitForElementNotPresent(‘<a href="http://twitter.com/submitButton">@submitButton</a>’);<br>  }<br>};</pre><pre>export default {<br>  commands: [googleCommands],<br>  elements: {<br>    searchBar: {<br>      selector: ‘input[type=text]’<br>    },<br>    submitButton: {<br>      selector: ‘button[name=btnG]’<br>    }<br>  }<br>};</pre><p>Those are all the properties available to page objects. Now it’s time we see some of these properties in action. Yay!<br>I would be using my “still in the works” app <a href="https://cjdocs.herokuapp.com/">here</a>.</p><h4><strong>Write Tests</strong></h4><p>I’ll be testing the sign in page of the app. Let’s go ahead and do just that.<br>We will need to create a page file in the pages directory we created earlier. I called mine signinPage.js and added it to the pages directory.</p><p>signinPage.js:</p><pre>const signinCommands = {  <br>  signin(email, password) {<br>    return this<br>      .waitForElementVisible(&#39;<a href="http://twitter.com/emailInput">@emailInput</a>&#39;)<br>      .setValue(&#39;<a href="http://twitter.com/emailInput">@emailInput</a>&#39;, email)<br>      .setValue(&#39;<a href="http://twitter.com/passwordInput">@passwordInput</a>&#39;, password)<br>      .waitForElementVisible(&#39;<a href="http://twitter.com/signinButton">@signinButton</a>&#39;)<br>      .click(&#39;<a href="http://twitter.com/signinButton">@signinButton</a>&#39;)<br>  }<br>};</pre><pre>export default {  <br>  url: &#39;<a href="https://cjdocs.herokuapp.com/auth/signin&#39;">https://cjdocs.herokuapp.com/auth/signin&#39;</a>,<br>  commands: [signinCommands],<br>  elements: {<br>    emailInput: {<br>      selector: &#39;input[type=email]&#39;<br>    },<br>    passwordInput: {<br>      selector: &#39;input[name=password]&#39;<br>    },<br>    signinButton: {<br>      selector: &#39;button[type=submit]&#39;<br>    }<br>  }<br>};</pre><p>Next, we create another page object called instancesPage.js. This would be used to abstract away what we would search for when test passes the authentication phase.</p><p>instancesPage.js:</p><pre>export default {  <br>  elements: {<br>    homepageWelcomeTitle: {<br>      selector: &#39;//div/h1&#39;,<br>      locateStrategy: &#39;xpath&#39;<br>    }<br>  }<br>};</pre><p>Finally, we would create our test file, called signin.spec.js.<br>signin.spec.js:</p><pre>&#39;User can sign in&#39;(client) {<br>    const signinPage = client.page.signinPage();<br>    const instancesPage = client.page.instancesPage();</pre><pre>signinPage<br>      .navigate()<br>      .signin(process.env.EMAIL, process.env.PASSWORD);</pre><pre>instancesPage.expect.element(&#39;<a href="http://twitter.com/homepageWelcomeTitle">@homepageWelcomeTitle</a>&#39;).text.to.contain(&#39;Welcome to the CJDocs Home!&#39;);</pre><pre>client.end();<br>}</pre><p>After this, you can run your tests with the command npm test or yarn test.</p><p>That’s all there is to using page objects. Not so difficult I suppose?</p><h4><strong>Conclusion</strong></h4><p>Page objects really help make our code DRY, thereby abstracting some common functionalities into one place and just calling those defined methods/properties we can have a fully functional tests without repetitive code.</p><p>I hope you learned something new today. Hit the like button if you enjoyed it. Let me know in the comments if you have a question or if you want me to follow up on something.</p><p>What would you like me to write about? Have something in mind you’ve been wanting to learn for some time now, hit me up in the DM and I’d be sure to reply.</p><p>You can find me on Twitter <a href="http://twitter.com/codejockie">@codejockie</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7c3a8759917" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Short-Circuit Evaluation]]></title>
            <link>https://medium.com/@codejockie/javascript-short-circuit-evaluation-b81cb493d992?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b81cb493d992</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Thu, 01 Mar 2018 16:11:04 GMT</pubDate>
            <atom:updated>2018-03-01T21:41:22.823Z</atom:updated>
            <content:encoded><![CDATA[<p>Having been working with JavaScript for quite some time now I have seen various ways one can do something ultimately giving the same result. I would be discussing short-circuit evaluation in this post. This feature is available in various languages but the implementation might be different. For brevity, I would be dealing specifically with JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*FxS-Y-VoF6GhlI01KUTp5Q.png" /></figure><p>In short-circuit evaluation, the second argument is evaluated only if the first argument does (not) satisfy a given condition.</p><h3><strong>Logical AND (&amp;&amp;)</strong></h3><p><strong>Logical AND</strong> (&amp;&amp;): When a certain condition evaluates to false, the corresponding condition(s) is/are not evaluated when the &amp;&amp; operator is used.</p><p>Given the following code snippet:</p><pre>let username;</pre><pre>if (Meteor.user()) {<br> username = Meteor.user().username;<br>}</pre><p>We could use the &amp;&amp; operator to reduce the amount of lines we write as follows:</p><pre>const username = Meteor.user() &amp;&amp; Meteor.user().username;</pre><pre>// ES6 destructuring<br>const { username } = Meteor.user() &amp;&amp; Meteor.user();</pre><p>This is read as; if Meteor.user() is defined, assign the value of the username property from Meteor.user() to the username variable.<br>Looking at this code, we have significantly reduced the number of lines we type to get the same thing done.</p><h3><strong>Logical OR (||)</strong></h3><p><strong>Logical OR</strong> (||): When a certain condition evaluates to true, the corresponding condition(s) is/are not evaluated as they would be true when the || operator is used.</p><p>Given the following snippet:</p><pre>const name = null;<br>let language;</pre><pre>if (name) {<br> language = name;<br>} else {<br> language = “JavaScript”;<br>}</pre><p>In the snippet above, I am checking that name has a value, if it does I assign the value to thelanguage variable, otherwise I provide a default value JavaScript.</p><p>Using ||, we could significantly reduce that whole code to just one line as follows:</p><pre>const language = name || “JavaScript”;</pre><p>There’s not much difference in the the code above, except that it is shorter. It does same check for name, providing a default value if name is not defined.</p><h3><strong>Operator chaining</strong></h3><p>The operators (&amp;&amp; and ||) can be chained together to create a kind of if…else condition.<br>Using the first example above:</p><pre>const username = Meteor.user() &amp;&amp; Meteor.user().username || “code”;</pre><p>This translates to checking for the existence of Meteor.user(), if true assigns Meteor.user().username to username variable, otherwise assigns ”code” to username.</p><blockquote>NOTE: Using the short-circuit operator chaining is not advised as this can make your code less readable. Using operator chaining is disallowed in some JavaScript style guides.</blockquote><p>This brings us to the end of this post. I hope you learned something new. Have a comment/question? Kindly drop a comment/suggestion or question on the comment thread.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b81cb493d992" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[E2E Testing with Nightwatch: Part Two]]></title>
            <link>https://medium.com/cloudboost/e2e-testing-with-nightwatch-part-two-aaa25a4dc033?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/aaa25a4dc033</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[e2e-testing]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 12:27:06 GMT</pubDate>
            <atom:updated>2017-10-11T17:45:03.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_vl3SXp9doMFGCXhJwmrw.jpeg" /></figure><p>Welcome to the second part of the E2E Testing with Nightwatch tutorial. In this part, we’ll be writing actual tests for the <a href="http://todomvc.com/examples/react/#/">React TodoMVC App</a>. Read the first part <a href="https://medium.com/@codejockie/e2e-testing-with-nightwatch-part-one-309c221b7a98">here</a>.</p><p>This part borrows from the tests at <a href="https://g00glen00b.be/e2e-testing-nightwatch-js">g00glen00b</a>. The source code can be found <a href="https://github.com/codejockie/e2e-testing-nightwatch">here</a>.</p><h3><strong>Writing Our First Test</strong></h3><p>At the root of the project’s directory, create a new directory called tests. This folder name corresponds with the src_folders property value in the nightwatch.json file. In Nightwatch, all tests are Node.js modules.</p><p>For our first test, we’ll check that the main and footer section of the app don’t exist without any tasks. This is the default behaviour of the <a href="http://todomvc.com/examples/react/#/">TodoMVC App</a>.</p><pre>module.exports = {<br>  &#39;Does not show the task list if there are no tasks&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .expect.element(&#39;.main&#39;).to.not.be.present;<br>    client.end();<br>  },<br>  &#39;Does not show the footer if there are no tasks&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .expect.element(&#39;.footer&#39;).to.not.be.present;<br>    client.end();<br>  },<br>}</pre><p>First, let’s go to the application page and wait until view is visible by waiting for the header on that page, .header h1. When it’s loading, let’s test to see if the element with the class .main exists (which should not exist if there are no tasks). Let’s call the end() method and tell it to close the current browser.</p><p>If you forget to call the end() method, your test will still work. However, if you write multiple tests in the same file, the state will be preserved, which could lead to your tests failing because the data from earlier tests won’t be removed.</p><p>In Nightwatch you can decide to choose the chai assert or expect style of assertions. We’re not using the assert style here, so we don’t have to chain the end() method as the expect assertion doesn’t currently support method chaining. It is entirely up to you which assertion style you choose, the most important thing is that you’re consistent.</p><p>The second test is similar to the first. This time it’s testing if the element with the class .footer exists.</p><p>The next test will check if the input field is focused when the page is loaded. To do that we’ll use the :focus CSS selector, which returns only focused elements. Apply that to the .new-todo input field — your test will only succeed if that element is indeed focused:</p><pre>&#39;On page load, it sets focus on the input field&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .assert.elementPresent(&#39;.header .new-todo:focus&#39;)<br>      .end();<br>  },</pre><p>With elementPresent() we can check whether or not an element exists. It does not have to be visible.</p><p>For the next test, we’ll test that a new task is added when we enter a task in the input field and press the Enter key.</p><pre>&#39;When I add a task, it shows todo items&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .setValue(&#39;.new-todo&#39;, &#39;New task&#39;)<br>      .keys(client.Keys.ENTER)<br>      .assert.containsText(&#39;.todo-list li:first-child label&#39;, &#39;New task&#39;)<br>      .end();<br>  },</pre><p>The first few lines remain the same, but with setValue(), we set a value to the input field with class new-todo. After that, we submit it by pressing the Enter key using keys(client.Keys.ENTER) and verifying if the .todo-list has an item with a label with the same text as the value we entered earlier.</p><p>The next test goes even further, by not only adding a new task, but also by completing the task itself and verifying if it has been stricken through:</p><pre>&#39;Marks a todo item as completed by striking through it&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .setValue(&#39;.new-todo&#39;, &#39;New task&#39;)<br>      .keys(client.Keys.ENTER)<br>      .click(&#39;.todo-list li:first-child .toggle&#39;)<br>      .assert.cssClassPresent(&#39;.todo-list li:first-child&#39;, &#39;completed&#39;)<br>      .end();<br>  },</pre><p>We didn’t really verify if there’s a line through the text here, but we verified if the completed class is present. The CSS for this class provides the line through the text. To check an element, we used the click() API to click on the checkbox itself.</p><p>We’ve already verified that you can add and complete tasks. With the next test we’re going to see if the counter at the bottom of the application shows the correct number of tasks left.</p><p>To do that, we simply add tasks and complete them, and then verify if the number changes appropriately:</p><pre>&#39;Shows how many items there are left&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .setValue(&#39;.new-todo&#39;, &#39;New task&#39;)<br>      .keys(client.Keys.ENTER)<br>      .setValue(&#39;.new-todo&#39;, &#39;Another task&#39;)<br>      .keys(client.Keys.ENTER)<br>      .assert.containsText(&#39;.todo-count&#39;, &#39;2 items left&#39;)<br>      .click(&#39;.todo-list li:first-child .toggle&#39;)<br>      .assert.containsText(&#39;.todo-count&#39;, &#39;1 item left&#39;)<br>      .end();<br>  },</pre><p>Nothing new here. We added two elements, verified if the text matches ’2 items left’, then completed a task and verified if there is only ’1 item left’.</p><p>For the final test of the overview, we’re going to verify if we cannot add a task if we don’t enter a value in the text box or if we only enter spaces:</p><pre>&#39;Does not add empty or blank tasks&#39;(client) {<br>    client<br>      .url(https://medium.com/&#39;%3Ca%20href=%22/service/http://todomvc.com/examples/react/#/&#39;%22%3Ehttp://todomvc.com/examples/react/#/&#39;%3C/a%3E)<br>      .waitForElementVisible(&#39;.header h1&#39;)<br>      .setValue(&#39;.new-todo&#39;, &#39;New task&#39;)<br>      .keys(client.Keys.ENTER)<br>      .keys(client.Keys.ENTER)<br>      .setValue(&#39;.new-todo&#39;, &#39;  &#39;)<br>      .keys(client.Keys.ENTER)<br>      .assert.containsText(&#39;.todo-count&#39;, &#39;1 item left&#39;)<br>      .end();<br>  }</pre><p>What we did here is nothing new. We added a proper task, tried to submit the form without entering a new value, entered some spaces, and tried to submit again. In neither of these cases should a task be added. There should only be one item left — the first, and valid, task we added.</p><h3><strong>Global Configuration</strong></h3><p>Nightwatch commands like waitForElementVisible() or the assertions require the timeout parameter be passed to the element so that the test throws an error when that timeout limit is reached. Normally the waitForElementVisible() method looks like this:</p><p>waitForElementVisible(‘<a href="http://twitter.com/anElement">@anElement</a>’, 3000)</p><p>3000 is the number of milliseconds after which the test throws an element not visible exception. Fortunately, we can move that value outside the test so that the code is cleaner. In order to do that, create a globals.js file at the root of the project’s directory and paste this code:</p><pre>export default {  <br>  waitForConditionTimeout: 10000<br>};</pre><p>Afterwards, edit the nightwatch.json config file changing globals_path: “” to globals_path : “globals”.<br>Now all Nightwatch methods that require a timeout will have this global ten second timeout specified as the default. You can still define a special timeout for single calls if needed.</p><h3><strong>Running Tests</strong></h3><p>That’s it! All that’s left to do is run the test. In the terminal, navigate to your projects’ root directory and type this command:</p><p>npm test or yarn test</p><p>With everything set up correctly, you should see a console output similar to this one:</p><pre>Starting selenium server... started - PID:  30647</pre><pre>[Overview Spec] Test Suite<br>==============================</pre><pre>Running:  Does not show the task list if there are no tasks<br> ✔ Element &lt;.header h1&gt; was visible after 84 milliseconds.<br> ✔ Expected element &lt;.main&gt; to not be present - element was not found in 40ms.</pre><pre>OK. 2 assertions passed. (8.655s)</pre><pre>Running:  Does not show the footer if there are no tasks<br> ✔ Element &lt;.header h1&gt; was visible after 577 milliseconds.<br> ✔ Expected element &lt;.footer&gt; to not be present - element was not found in 25ms.</pre><pre>OK. 2 assertions passed. (3.731s)</pre><pre>Running:  On page load, it sets focus on the input field<br> ✔ Element &lt;.header h1&gt; was visible after 573 milliseconds.<br> ✔ Testing if element &lt;.header .new-todo:focus&gt; is present.</pre><pre>OK. 2 assertions passed. (4.36s)</pre><pre>Running:  When I add a task, it shows todo items<br> ✔ Element &lt;.header h1&gt; was visible after 563 milliseconds.<br> ✔ Testing if element &lt;.todo-list li:first-child label&gt; contains text: &quot;New task&quot;.</pre><pre>OK. 2 assertions passed. (4.812s)</pre><pre>Running:  Marks a todo item as completed by striking through it<br> ✔ Element &lt;.header h1&gt; was visible after 561 milliseconds.<br> ✔ Testing if element &lt;.todo-list li:first-child&gt; has css class: &quot;completed&quot;.</pre><pre>OK. 2 assertions passed. (4.808s)</pre><pre>Running:  Shows how many items there are left<br> ✔ Element &lt;.header h1&gt; was visible after 1599 milliseconds.<br> ✔ Testing if element &lt;.todo-count&gt; contains text: &quot;2 items left&quot;.<br> ✔ Testing if element &lt;.todo-count&gt; contains text: &quot;1 item left&quot;.</pre><pre>OK. 3 assertions passed. (6s)</pre><pre>Running:  Does not add empty or blank tasks<br> ✔ Element &lt;.header h1&gt; was visible after 562 milliseconds.<br> ✔ Testing if element &lt;.todo-count&gt; contains text: &quot;1 item left&quot;.</pre><pre>OK. 2 assertions passed. (4.858s)</pre><pre>OK. 15  total assertions passed. (37.525s)</pre><h3><strong>Summary</strong></h3><p>In this tutorial you’ve learned how to:</p><ul><li>create an end-to-end test and</li><li>use the globals.js file.</li></ul><p>Keep an eye out for the next part, where I would introduce Nightwatch pages!</p><p>Follow me on Twitter <a href="http://twitter.com/codejockie">@codejockie</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aaa25a4dc033" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/e2e-testing-with-nightwatch-part-two-aaa25a4dc033">E2E Testing with Nightwatch: Part Two</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[E2E Testing with Nightwatch: Part One]]></title>
            <link>https://medium.com/front-end-weekly/e2e-testing-with-nightwatch-part-one-309c221b7a98?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/309c221b7a98</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[selenium-webdriver]]></category>
            <category><![CDATA[e2e-testing]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 12:25:54 GMT</pubDate>
            <atom:updated>2018-02-26T10:05:36.956Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JwsB-WQwtvpTIB5p0fkAOg.png" /></figure><p><strong>So what is Nightwatch?</strong> <br><a href="http://nightwatchjs.org/">Nightwatch</a> is an automated testing framework for web applications and websites, written in Node.js and using the <a href="https://www.w3.org/TR/webdriver/">W3C WebDriver API</a> (formerly <a href="https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol">Selenium WebDriver</a>.</p><p>It is a complete browser (End-to-End) testing solution which aims to simplify the process of setting up Continuous Integration and writing automated tests. Nightwatch can also be used for writing Node.js unit tests.</p><p><strong>Why Nightwatch you ask</strong><br>- Clean syntax<br>Simple but powerful syntax which enables you to write tests very quickly, using only Javascript (Node.js) and CSS or Xpath selectors.<br>- Built-in test runner<br>Built-in command-line test runner which can run the tests either sequentially or in parallel, together, by group, tags or single. Grunt support is built-in.<br>- Selenium server<br>Controls the Selenium standalone server automatically in a separate child process; can be disabled if Selenium runs on another host.<br>- Cloud services support<br>Works with cloud testing providers, such as SauceLabs and BrowserStack.<br>- CSS &amp; Xpath support<br>Either CSS or Xpath selectors can be used to locate and verify elements on the page or execute commands.<br>- Continous Integration support<br>JUnit XML reporting is built-in so you can integrate your tests in your build process with systems such as Teamcity, Jenkins, Hudson etc.<br>- Easy to extend<br>Flexible command and assertion framework which makes it easy to extend to implement your application specific commands and assertions.</p><p><strong>Installation</strong><br>First things first, install <a href="http://nodejs.org/">Node.js</a> if you don’t yet have it. You can find the installation instructions on the Node.js project page. Once you have node installed, you can take advantage of node’s package manager called npm which happens to be the largest ecosystem of packages.</p><p>You would also be needing Java SDK if you do not already have it installed on your machine. You can download it from Oracle’s site at <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java SE Downloads</a>. After installing, you would want to ensure that Java is available in your environment path. You can test this by simply typing java -version in your terminal — this will print out the version of the installed Java on your machine.</p><p>Go to your terminal, create an empty directory and navigate to it. Next, type npm init -y or yarn init -y. The -y flag allows you to skip through the initialisation questions. A package.json file will be created at the root of the current directory.</p><p>Once you have a package.json file, while in the same directory, type npm install -g nightwatch or yarn global add nightwatch .The -g tells npm to install nightwatch globally, which will allow you to run it in any directory.</p><p>Next, in order to be able to run the tests, we need to download the Selenium standalone server. This can be done manually, downloading from their website. For this tutorial, we would be using npm to install it.</p><p>On your terminal, type npm install selenium-standalone --save-dev or yarn add -D selenium-standalone.<br>This command will install selenium-standalone and also save it to your package.json file created earlier.</p><p>Modify your package.json file by adding this ”e2e-setup”: “node_modules/selenium-standalone/bin/selenium-standalone install” to the scripts property. The package.json should look more or less like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/442cd615238b109641573e8e727d2aed/href">https://medium.com/media/442cd615238b109641573e8e727d2aed/href</a></iframe><p>Running npm run e2e-setup or yarn run e2e-setup on the terminal will download the latest version of selenium server, chromedriver, and geckodriver (this will be used for running tests in Chrome or Firefox browser).</p><p><strong>Configuration</strong><br>The test runner expects a configuration file to be passed, using a nightwatch.json file from the current directory by default, if present. A nightwatch.conf.js file will also be loaded by default, if found.<br>Nightwatch relies on nightwatch.json as the configuration file for the test runs. It should be placed in the project’s root directory because it specifies various configuration settings like test environments, test file paths, and selenium specific settings. This is what the configuration file looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f84928d891f3a11f5b7309d104774eff/href">https://medium.com/media/f84928d891f3a11f5b7309d104774eff/href</a></iframe><p>Using both configuration files is also possible, with nightwatch.conf.js always taking precedence if both are found.</p><p>Let’s walk through the important parts of the nightwatch.json configuration file. <br>- src_folders: An array of folders (excluding subfolders) where the tests are located.<br>- output_folder: The location where the JUnit XML report files (XML reports, selenium log and screenshots) will be saved.<br>- page_objects_path: Location(s) where page object files will be loaded from.<br>- globals_path: Location of an external globals module which will be loaded and made available to the test as a property globals on the main client instance. Globals can also be defined/overwritten inside a test_settings environment.<br>- selenium: An object containing Selenium Server related configuration options. In our case, it’s important to have the start_process set to true so that Selenium Server starts automatically. Also the server_path and webdriver.chrome.driver paths should have proper folder specified.<br>- test_settings: This object contains all the test related options. The important bit in the default environment is the desiredCapabilities object where we specify firefox as the browserName so that Nightwatch will run tests against it.</p><p><strong>Adding ES6 to Nightwatch</strong><br>In order to be able to write ES6 in Nightwatch, you need to install babel-preset-es2015 preset, babel-cli, and add-module-exports plugin, and add them to a .babelrc config file. <br>On the terminal, type npm i babel-plugin-add-module-exports babel-preset-es2015 -D or yarn add -D babel-plugin-add-module-exports babel-preset-es2015. <br>The .babelrc file looks like this:</p><pre>{<br>  “presets”: [“es2015”],<br>  “plugins”: [<br>    “add-module-exports”<br>  ]<br>}</pre><p>After doing that, you need to add a nightwatch.conf.js file to the root of your project. The file should contain these lines:</p><pre>require(‘babel-core/register’);<br>const fs = require(“fs”);</pre><pre>module.exports = ((settings) =&gt; {<br> const seleniumServerFileName =<br> fs.readdirSync(“node_modules/selenium-standalone/.selenium/selenium-server/”);<br> settings.selenium.server_path += seleniumServerFileName;<br> return settings;<br>})(require(“./nightwatch.json”));</pre><p>Nightwatch uses the additional code to get the selenium server executable dynamically. This would override the server_path specified in the nightwatch.json config file. <br>If you prefer to use the nightwatch.json config file to get the selenium server, remember to change this line:</p><p>”server_path” : “node_modules/selenium-standalone/.selenium/selenium-server/” in your nightwatch.json to this:</p><p>”server_path” : “node_modules/selenium-standalone/.selenium/selenium-server/x.x.x-server.jar”</p><p>where x.x.x is the version of selenium server installed. Your nightwatch.conf.js file should then look like this:</p><pre>module.exports = ((settings) =&gt; {<br> return settings;<br>})(require(“./nightwatch.json”));</pre><p><strong>Summary</strong><br>In this tutorial you’ve learned how to:</p><p>Install Nightwatch.js and its dependencies and configure the test environment.</p><p>In the second part of the tutorial, we’ll dive into writing actual tests. <a href="https://medium.com/@codejockie/e2e-testing-with-nightwatch-part-two-aaa25a4dc033">Part Two</a></p><p>You can find me on twitter <a href="https://twitter.com/codejockie">@codejockie</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=309c221b7a98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/e2e-testing-with-nightwatch-part-one-309c221b7a98">E2E Testing with Nightwatch: Part One</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[…the Good Path]]></title>
            <link>https://medium.com/@codejockie/the-journey-begins-dddd4ba24658?source=rss-59617c1e2c0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/dddd4ba24658</guid>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Kennedy Nwaorgu]]></dc:creator>
            <pubDate>Mon, 22 May 2017 06:50:55 GMT</pubDate>
            <atom:updated>2018-08-07T18:02:33.548Z</atom:updated>
            <content:encoded><![CDATA[<p>May 21st, 2017 — Sitting with my family in our living room, a call came in from a friend who wanted to know if I received a mail from the Andela Team. At the time I wasn’t aware as I already disconnected from the internet. I turned on my modem, told my friend I’d get back to him. I opened my Mail app and there laid a mail which had a subject that read ‘Welcome to Andela’ — you can’t begin to imagine how excited I was seeing that mail.</p><p>Let’s travel back in time to where it all began.</p><p>April 7th, 2017 — I had just concluded my national service to my nation. Prior to that I had applied to Andela a week before my passing out day. I got a lot of congratulatory messages from friends that day but one stood out — was a bit strange. A friend sent a message to me which read ‘Congrats bro… Andela calling’. One thing was clear no one knew about my application to Andela. Same day I received a mail instructing me to start my assessment as the proctor was ready.</p><p>I started the tests and finished the assessment — they were by no means easy, I got a mail on April 19th, 2017 inviting me to the interview.</p><p>April 26th, 2017 — I went for my interview with the team. I must say I was excited and nervous at same time. I was given a test paper that had three Python based questions. I felt pressured and as a result I couldn’t answer the third question correctly. The irony was I knew the solution but for one reason or the other I couldn’t write it correctly. I went home scared that I wouldn’t make it to the boot camp.</p><p>May 3rd, 2017 — I got a mail inviting me to the boot camp. I was excited as I thought I wasn’t going to make it to boot camp. I had already written about my experience and the first week at boot camp so I will be skipping that. Refer to my previous article(s) if you are interested.</p><p>May 13th, 2017 — Another mail came in that invited me to Week Two of boot camp. A lot of friends didn’t make it to week two. Week two kicked off with three topics we hadn’t been introduced to. After the training, projects were assigned to everyone — the goal was to finish the projects in four days. I was assigned a maintenance tracker app a full stack application.</p><p>The project on seeing the requirements involved I was completely overwhelmed and at that point I went blank all through that day, I couldn’t think of a solution to the challenge that was before me. That day was one of those days I want to forget as it was one of my bad days. I went home sad knowing I had just three days and few hours to come up with a working project. On getting home I thought to myself if this was the end of the journey for me. While at home I started to think and resolved to do my best and come out top. I put my laptop aside and worked without it. I drew the plans and designs of what a possible app could look like, at same time mapping out the user stories. By the time I was to go bed — 12am, I had figured out four of the eleven user stories and how to go about implementing them the following day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9wSjhkcxTUULv0w_gWByKA.jpeg" /><figcaption>That was me on Monday</figcaption></figure><p>Tuesday — I had set out goals for the day, one was to deploy my app to heroku and two was to implement the user stories I mapped out the previous day. I related with fellow boot campers seeking ideas in some areas I couldn’t figure out.</p><p>Wednesday through Thursday I kept on working on the other features I hadn’t implemented. By Thursday, all was done. During this period I was leaving the site late at night.</p><p>Friday — Presentation Day. It was my turn to present — being the 22nd person on the list. I was just about starting my presentation when I was told my app crashed. I was unhappy but was relaxed and calm, I restarted my app and started my presentation. My app kept crashing during my presentation and I kept at restarting it when it did. I concluded my presentation. At the end of the presentations, we were given a pep talk for the mail we were to receive few days from that day.</p><p>The present — May 21st, 2017. The mail that read ‘Welcome to Andela’ came in. I was so excited, and so were my family. I made it to Andela. Reading through the lines of the mail, I noted a part that said it was an invitation and challenge to work harder than I have ever done. If I learned anything at boot camp it would be you can’t stop working hard. I want to beat my previous best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*_JjA5Q_sYnDHUG45dC-f5g.png" /><figcaption>Me now</figcaption></figure><p>My journey to becoming a world class developer had just begun. I want to use this opportunity to thank my two awesome BFAs, couldn’t have asked for any other — always helpful. I also want to say a big thank you to the Boot camp Facilitators and the Andela Team for setting me on the path to greatness and excellence. The road ahead won’t be an easy one, I am resolved to getting better and becoming the best version of me everyday.</p><p>I won’t be dropping my pen here. I would write from time to time when I get the opportunity. Stay tuned and thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dddd4ba24658" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>