<?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: GEORGIOS ROMANAS</title>
    <description>The latest articles on DEV Community by GEORGIOS ROMANAS (@gromanas).</description>
    <link>https://dev.to/gromanas</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%2F379177%2F8987b861-0e08-473b-b194-9a9a74a1c6f8.jpeg</url>
      <title>DEV Community: GEORGIOS ROMANAS</title>
      <link>https://dev.to/gromanas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gromanas"/>
    <language>en</language>
    <item>
      <title>How to Automate Biometrics (Android edition)</title>
      <dc:creator>GEORGIOS ROMANAS</dc:creator>
      <pubDate>Tue, 12 May 2020 09:57:52 +0000</pubDate>
      <link>https://dev.to/gromanas/how-to-automate-biometrics-android-edition-2c7c</link>
      <guid>https://dev.to/gromanas/how-to-automate-biometrics-android-edition-2c7c</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5uar75urhzadb5lqsk21.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5uar75urhzadb5lqsk21.gif" alt="Image description" width="395" height="835"&gt;&lt;/a&gt;Some sprints ago, me and my team, during the sprint planning event, we were discussing the implementation of touchID on login in our React Native App. &lt;/p&gt;

&lt;p&gt;I have started the POC of Biometrics (as I have never done it in the past), so I could have a clear view if would be possible to automate on Android platform using an Android 9.0 emulator.&lt;/p&gt;

&lt;p&gt;After a bit of research, I saw all solutions that I have found on the web (i don't know if I've missed any, sorry for that) are instructed how to add a fingerprint manually and then using an &lt;code&gt;adb&lt;/code&gt; command to pass it in the biometric alert and make the valid login. &lt;/p&gt;

&lt;p&gt;Then I have checked if there are any &lt;code&gt;adb&lt;/code&gt; commands that will make my life easier and &lt;strong&gt;BOOM&lt;/strong&gt;....&lt;/p&gt;

&lt;p&gt;&lt;em&gt;With the power of Appium and WebdriverIO!!!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8vs7g9z5fzufuvxl9kgb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8vs7g9z5fzufuvxl9kgb.jpg" alt="With the power of Appium and WebdriverIO" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I came to the following solution:&lt;/p&gt;

&lt;p&gt;First of all, I took notes on how those actions can be done manually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to Android &lt;code&gt;Settings&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Tap on &lt;code&gt;Security &amp;amp; Location&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;Screen Lock&lt;/code&gt;, there are several types such as &lt;code&gt;Pin&lt;/code&gt;, &lt;code&gt;Pattern&lt;/code&gt;, &lt;code&gt;Swipe&lt;/code&gt;, &lt;code&gt;Password&lt;/code&gt; (I chose &lt;code&gt;Pin&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;You have to follow the wizard of your choice. &lt;/li&gt;
&lt;li&gt;Then you tap on &lt;code&gt;Fingerprint&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;There is again a wizard to follow&lt;/li&gt;
&lt;li&gt;Then I should open my app&lt;/li&gt;
&lt;li&gt;Go to Login screen and provide the fingerprint on Biometrics Alert&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it! Now let's automate!&lt;/p&gt;

&lt;p&gt;I have configured Appium with &lt;code&gt;--relaxed-security&lt;/code&gt; flag in &lt;code&gt;wdio.conf.js&lt;/code&gt;, so Appium can accept &lt;code&gt;adb&lt;/code&gt; commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;appium&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--relaxed-security&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
              &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;appium&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, the real fun starts!&lt;/p&gt;

&lt;p&gt;The first 4 manual steps I found out that could be done like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mobile: shell&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;am start -a android.settings.SECURITY_SETTINGS &amp;amp;&amp;amp; locksettings set-pin 1234&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, as I am still in Android &lt;code&gt;Security Settings&lt;/code&gt; I need to tap on &lt;code&gt;Fingerprint&lt;/code&gt; using Appium desktop I found the selector and click on it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;android=new UiSelector().text("Fingerprint")&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Fingerprint wizard is open and there is a &lt;code&gt;Next&lt;/code&gt; button, using the same approach as above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;android=new UiSelector().resourceId("com.android.settings:id/fingerprint_next_button")&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;     
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I need to provide the pin I have setup on &lt;code&gt;Screen Lock&lt;/code&gt; and tap keyboard's &lt;code&gt;Done&lt;/code&gt; button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mobile: shell&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input text 1234 &amp;amp;&amp;amp; input keyevent 66&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the wizard prompts the user to touch the sensor (this should be done 3 times), here Appium provides us the &lt;code&gt;.fingerPrint(fingerprintId)&lt;/code&gt; method, that actually executes an &lt;code&gt;adb&lt;/code&gt; command &lt;code&gt;adb -e emu finger touch fingerprintId&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pause&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fingerPrint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final step of the wizard is to tap on &lt;code&gt;Done&lt;/code&gt; button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;android=new UiSelector().resourceId("com.android.settings:id/next_button")&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we should start our App. This is again provided by Appium using &lt;code&gt;.startActivity("com.example", "ActivityName");&lt;/code&gt; method. In my example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;com.reactnativesampleapp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;com.reactnativesampleapp.MainActivity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What remains is to actually login into the app using biometrics:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9aisqlrbvayghtsrlzvc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9aisqlrbvayghtsrlzvc.gif" alt="Image description" width="395" height="835"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more info you can check here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/gromanas/ReactNativeSampleApp/blob/master/README.md" rel="noopener noreferrer"&gt;https://github.com/gromanas/ReactNativeSampleApp/blob/master/README.md&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdriverio</category>
      <category>appium</category>
      <category>testing</category>
      <category>biometrics</category>
    </item>
  </channel>
</rss>
