Device farm interactive testing done programmatically - android

AWS has a 'remote-desktopy' feature (https://aws.amazon.com/blogs/aws/aws-device-farm-update-remote-access-to-devices-for-interactive-testing/) as part of its device farm, but it is far too slow to use in browser. Does anyone know if there is a programmatic/CLI way to interact with that system?
I would like to test the functionality of a third party app on a cloud based mobile testing platform such as Firebase Test Lab, or AWS device farm. I have no way to instrument this app.
The testing requires I download two apps on the device (one is the app to be tested, the second has a supporting function). At the start of the test I have to launch the support app, and then switch over to the app I am testing. I imagine the only way to do this is via the device's 'home' button. The actual testing is just a set of basic UI interactions.
Does the Firebase Test lab or other platform have a feature that I could use to do this?
If there was a way to extract events from the AWS remote-desktop, I could see an approach using a selenium/other webdriver. But I am not sure this a real option.
Any thoughts on this are appreciated.
Thanks!

"The UI Automator APIs allow you to write robust tests without needing to know about the implementation details of the app that you are targeting. You can use these APIs to capture and manipulate UI components across multiple apps" (documentation)
To tap the Home button you can use UiDevice.pressHome().

Related

How to use Android UI Automator without access to source code

so I am trying to learn test automation on an Android, Basically I want to learn how to use Google's UI Automator, however, it seems like all tutorial that I could find requires me to have access to the source code of the app under test.
I found this repo AndroidTestWithoutSource it uses espresso but requires me to re-sign the APK.
My target environment basically is a production test environment I mean like install the app under test on an android device then connect the device to my PC through ADB, for learning purposes I like to test youtube or even the native settings app.
Is my goal even possible with UI Automator? like being able to test apps installed in the device like appium does?
I would really appreciate a sample to that launch youtube app just to get me started.
Thank you!
Yes you can for instance use UI Automator viewer to get the resource ids (textview ids, edittext ids, etc) you want to click or act on.
After that you can write a UI Automator test that starts the app you're going to test (having the package name) and acts on the resource ids you previously collected.
Hope this helps.

How to restrict/disable print service(s) in Android?

I am trying to achieve a use case where on installing an app, all print services barring one would get disabled on the Android device.
To achieve this, I looked into Android's Device Administration API capabilities but that doesn't fulfill the use case. I also looked into Google's Android for Work framework and arrived at the following observations / possible solutions -
By setting up managed profiles (work profile): This was introduced from Android 5.0 but can only manage the listed/enterprise controlled and has no control over other apps as mentioned in the below links -
https://developers.google.com/android/work/build-dpc
https://developer.android.com/work/managed-profiles.html
By writing a Device Policy Controller (DPC) app: To achieve the specific use-case the DPC would have to run as the device owner in which case the provisioning needs to be done via NFC and is not straightforward. Also, this scenario is generally meant for corporate owned, single use (COSU) devices.
So my questions/doubts here are -
Is there any straightforward way in which this use case can be achieved?
Is this even achievable as it violates the Android Security model?
You should write your custom DPC. Right now you can do provisioning using several methods. If you have devices which use Android 7 and above you can use QR code provisioning which is quite convenient. For this purpose you can upload your dpc apk to a remote server and write information about the server, application DeviceAdminReceiver and apk checksum to QR code (you can take this QR code as example).
You can check to google awesome project TestDPC which will give your deep understanding of what is DPC and how can you use it.
You can read more about provisioning methods in android documentation. Also if you can contact the manufacturer of devices you can ask him to preinstall your custom dpc.
It is achievable and doesn't violate Android Security model because during provisioning your dpc app it get Device Owner (root). So you can do anything without any restrictions. Here you can check device owner API and possibilities. Also take a look at TestDPC source code and you will understand that nothing is impossible with Device owner mode :)

Android black-box testing (no access to app code). Is Google's Espresso a good choice?

I have recently been looking in to Espresso, which looks for me very promising.
I am recently working in an Android test project, and we are recently using Espresso as we see some benefits with that. Unfortunately the setup in the company I work for is such that I do not have access to the entire code for the Application we are testing.
So how I can create a test using android studio?
You can use UIAutomator to get the ids of various views.
See here
With view ids you can perform assertions/click and other actions on them
An example
onView(withId(R.id.play_search_container)).perform(click());
Hence you can go through the whole UI flow by clicking on various elements.
if you want to write a test outside of application's code, I mean: pure black-boxing, Espresso would be a pretty hard to implement as it needs a bit of application architecture (the same thing is with Robotium or `UiAutomator): names of Activities, views texts, contentDescriptions or idies.
You can use instead of Espresso:
UI/Application Exerciser Monkey
The Monkey is a program that runs on your emulator or device and
generates pseudo-random streams of user events such as clicks,
touches, or gestures, as well as a number of system-level events. You
can use the Monkey to stress-test applications that you are
developing, in a random yet repeatable manner.
monkeyrunner(requires Python language programming basics)
The monkeyrunner tool provides an API for writing programs that
control an Android device or emulator from outside of Android code.
With monkeyrunner, you can write a Python program that installs an
Android application or test package, runs it, sends keystrokes to it,
takes screenshots of its user interface, and stores screenshots on the
workstation.
The monkeyrunner tool is primarily designed to test
applications and devices at the functional/framework level and for
running unit test suites, but you are free to use it for other
purposes.
Calabash
Calabash is a framework that enables Automated UI Acceptance Tests
written in Cucumber to be run on iOS and Android applications.
Calabash works by enabling automatic UI interactions within an
application such as pressing buttons, entering text, validating
responses, etc.
From: Introduction to
Calabash
Hope it will help

Calabash Automated Testing with Paypal

I'm using Calabash framework for test automation and there's a need to automate the sign up scenario of an Android/IOS application.
Just so happens that is that one of the sign up steps is to link to a Paypal account.
At least for Android, I can confirm that the Paypal/Braintree SDK opens the default external browser for the user to complete the linking process, when this happens Calabash framework cannot interact with the browser and the test hangs.
Can I force Paypal SDK to use an embedded webview for the linking process?
If not, does anyone picture another way of automating this scenario?
Although this is a common scenario (i.e. facebook sign in, Google sign in etc...) unfortunately neither calabash framework currently provide a documented way to interact with 3rd party applications. The limitation lies in security features of both operating systems which disallow automation to jump outside of its process (and mobile browsers are separate processes).
However, as I mentioned this is a common scenario so there is a solution: we generally advise people to use something called "backdoor methods", which are methods inside of your application that you can trigger directly from calabash. Documentation is available for iOS and Android from Xamarin's official docs pages.
The idea is that you'd create a backdoor method in your application that simulates the user having successfully logged in/done whatever via Paypal/facebook/whatever. When you get to the part in your test where the user would normally go to that third party app, you instead invoke the backdoor.
Consider also philosophically: what happens if Paypal/facebook/whatever is down? What if the user isn't able to log in due to factors outside of your application's control? It doesn't make sense for your app's test to fail in this case, because the failure is unrelated to your application. In other words, backdoors allow you to test your app, not Paypal.
Hope this is helpful, please let me know if you'd like more info.

how to do cross app automation testing for android

lots of apps now need to interact with other apps. i'll give some examples:
take picture by calling system camera
open url like http://www.shihuangzhilu.com in a browser
android instruments can only test one app per time. can we do automation testing here?
You can't explicit definitely not using the current testing framework of android.
What you can do is use robotium, and then check if you have gotten the values back, and that you are no longer within your application/activity, that's the only way i can think of.
Yes, you can test across applications, see monkeyrunner:
http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html
(not to be confused with Monkey, another android tool)

Categories

Resources