Erin Li, Author at Perficient Blogs https://blogs.perficient.com/author/erinli/ Expert Digital Insights Mon, 14 May 2018 16:16:27 +0000 en-US hourly 1 https://blogs.perficient.com/files/favicon-194x194-1-150x150.png Erin Li, Author at Perficient Blogs https://blogs.perficient.com/author/erinli/ 32 32 30508587 How to Do Android Automation Testing with Espresso & UIAutomator https://blogs.perficient.com/2017/07/05/how-to-do-android-automation-test-with-espresso-and-uiautomator/ https://blogs.perficient.com/2017/07/05/how-to-do-android-automation-test-with-espresso-and-uiautomator/#comments Thu, 06 Jul 2017 04:54:27 +0000 http://blogs.perficient.com/delivery/?p=8480

About Espresso and UIAutomator

Espresso is a powerful, efficient Android Automation Test Framework, it contains three parts: ViewMatchers, ViewActions and ViewAssertions. Compared with other frameworks, it is simpler and easier for us to learn, but there is a limitation: you can only do operations in your tested app. So, if you want to deal with notifications or interact with other applications, you will need to combine it with UIAutomator. UIAutomator is a UI testing framework suitable for cross-app functional UI testing and since UIAutomator is now also based on Android Instrumentation, we can easily use it with Espresso in one test suite.

Begin with code

1.configure your project

Open your app’s build.gradle file and add the following lines inside dependencies:

 

How to Do Android Automation Testing with Espresso & UIAutomator

Add to the same build.gradle file the following line in android.defaultConfig:How to Do Android Automation Testing with Espresso & UIAutomator

2.basic sample

How to Do Android Automation Testing with Espresso & UIAutomator

3.permissions

When we launch an App for the first time, if your Android version is above 5, it will ask for permissions. But it is not a context inside our tested App, so we need to use UIAutomator as in the following lines:How to Do Android Automation Testing with Espresso & UIAutomator

 

4.DrawerActions and NavigationViewActions

If you used NavigationView to do the sidebar, you can test it with DrawerActions and NavigationViewActions.How to Do Android Automation Testing with Espresso & UIAutomator

 

5.RecyclerView

We always use RecyclerView in our App in order to interact with RecyclerView using Espresso. The espresso-contrib package has a collection of RecyclerViewActions that can be used to scroll to positions or to perform actions on items.

How to Do Android Automation Testing with Espresso & UIAutomatorHow to Do Android Automation Testing with Espresso & UIAutomator

 

6.Espresso Intents

When you try to test results from an Intent, you can do it as follows:How to Do Android Automation Testing with Espresso & UIAutomator

 

7.Notification

I was blocked when I tried to get element in a notification, then I found a useful tool. UIAutomatorViewer is helpful for us to analyze UI components, and you can find it in your Android->sdk->tools folder.How to Do Android Automation Testing with Espresso & UIAutomator

 

Then I finished testing notifications as follows:

How to Do Android Automation Testing with Espresso & UIAutomator

8.Alert dialog and Toast

Sometimes we will use alert dialog and toast in our application, and if we want to interact with it, we can check it as following lines:How to Do Android Automation Testing with Espresso & UIAutomatorHow to Do Android Automation Testing with Espresso & UIAutomator

This blog is just a glimpse of an Android Automation Test, there are still many things left to be researched. I hope we can make greater progress together.

]]>
https://blogs.perficient.com/2017/07/05/how-to-do-android-automation-test-with-espresso-and-uiautomator/feed/ 3 210930
How To Get Your Fitness Data From Google Fit? https://blogs.perficient.com/2017/06/14/how-to-get-your-fitness-data-from-google-fit/ https://blogs.perficient.com/2017/06/14/how-to-get-your-fitness-data-from-google-fit/#respond Thu, 15 Jun 2017 02:28:41 +0000 http://blogs.perficient.com/delivery/?p=8185

About Google Fit

“Google Fit is an open ecosystem that allows developers to upload fitness data to a central repository where users can access their data from different devices and apps in one location “. That means you can use your apps (not only Google Fit) or devices such as Apple Watch to upload your fitness data to the Google Fitness Store. You can also get your fitness data that you uploaded from the Store so you can do something else when you need it.

Before we can invoke methods from the Google Fit APIs, we have to connect to the appropriate fitness service, which are part of the Google Play services. The following APIs are available to us:                                                                       How To Get Your Fitness Data From Google Fit

What we always use are SensorsApi, RecordingApi and HistoryApi.

Sample overview

I did a sample project of getting fitness data from Google Fit, and show it in a line chart. As following, I get steps and weight in seven days from today. And these data were almost uploaded by Google Fit app, also I try to use my own app to upload steps data in sensor.                                                                                                                                                                   How To Get Your Fitness Data From Google Fit

Preparation

First, of course, you need a Google Account. Google Fit is available on Android devices with Google Play services 7.0 or higher. You should install the Google Play Service in your device, and then install the latest client library for Google Play services on your development host. Finally, get an OAuth 2.0 client ID for your Android applications.

How to begin with code

1.configure your project                            

 How To Get Your Fitness Data From Google Fit

2.uses-permission

if you want to use your own app to upload fitness data, you need to open your location service for sensor to collect data.

How To Get Your Fitness Data From Google Fit

3.ConnectionCallbacks      

4.OnConnectionFailedListener

How To Get Your Fitness Data From Google Fit

5.Create a GoogleApiClient

This client is used to subscribe steps data to Google Fit Store.

How To Get Your Fitness Data From Google Fit

You can change the Api and Scope attributes to do different things. For example, to get your weight data from the Store:

How To Get Your Fitness Data From Google Fit

6.Subscribe data

How To Get Your Fitness Data From Google Fit

7.Get your steps data from Google FitHow To Get Your Fitness Data From Google Fit

Then you can get your fitness data from the DataReadResult. If you want to show it in charts, you can get a third-party library to help you.

It’s not difficult to build a sample project if you refer to official documents, but we need to try harder to better understand it.

That’s all, hope you can give me your advice.

]]>
https://blogs.perficient.com/2017/06/14/how-to-get-your-fitness-data-from-google-fit/feed/ 0 210916
How to use Fingerprint and PIN Code? https://blogs.perficient.com/2017/06/06/how-to-use-fingerprint-and-pin-code/ https://blogs.perficient.com/2017/06/06/how-to-use-fingerprint-and-pin-code/#respond Wed, 07 Jun 2017 03:09:47 +0000 http://blogs.perficient.com/delivery/?p=8057

About Fingerprint

Nowadays, almost every smart phone has Fingerprint Identification, as you know, it’s safer and more convenient to use fingerprint to unlock your phone.

We usually use fingerprint to unlock screen, login App, and payment authentication. And Google Pixel use fingerprint swipe to access notifications. There is also an App called “Fingerprint Gestures” can allow you to use fingerprint sensor to customize more actions such as play song, toggle ringer mode, and screen scroll down. Indeed, we can see that fingerprint is a useful function and it has great possibility in the future.

Fingerprint

I use fingerprint to do the quick login in this App. You need to login first to turn on your “Touch Login”.

And then you can use it when you login next time. In fact, I think when I have “Remember” function, it’s not very important to use fingerprint especially I don’t have any privacy info in it. But this is just a demo, so never mind.

How to begin with code?

  1. add uses-permission in Manifest.xml
  2. check if device support fingerprint                       
  3. check if turn passcode on                                               
  4. check if enrolled fingerprint                                             
  5. start to authenticatePlease attention, don’t set CryptoObject “null”, because it can be used to prevent hostile attack from third-party.
  6. AuthenticationCallback

    We need to override these callbacks as following:

About PIN Code

I learnt two kinds of PIN Code of Android. One is used to protect SIM card, if you input wrong code three times, it will lock you SIM card and you need to use PUK Code to unlock it. And another is 4 digital number we used to unlock screen. What I need is a 4-digit number to do the quick login. And you need to create your PIN Code before you use it.

PIN Code

I used a third-party library,” LolliPin” (you can get it from GitHub) to do the PIN Code. It also contains fingerprint function, but I finish fingerprint before so I didn’t try it. Also, first, turn on “PIN” option in the settings. And after you enable your PIN, you can change PIN Code with new number.

I use 4 digital number as PIN Code, you can change length in code if you want.   

How to begin with code?

1.Prepare dependency

Download source code from GitHub, and then import it as a module. Add repository as following in your project’s gradle file, and don’t forget to compile it in your app’s gradle file.

2.enable PIN

3.change PIN

4.unlock PIN

That’s all, I’m a freshman of Android development, so if you find any problems, please kindly give me your advice.

]]>
https://blogs.perficient.com/2017/06/06/how-to-use-fingerprint-and-pin-code/feed/ 0 210909