Running Espresso test on a specific Android application from outside that application - android

I would like to write an Espresso test that I can run on an application from outside that application. I don't have much experience with Android, but, as I understand it, a UI test is generally written and executed from inside the project of the application that it is supposed to test. For instance, according to the file explorer in Android Studio, the java files for a test application I was developing are stored in com.package.example.name, and the java files for the UI test are stored in com.package.example.name (androidTest).
I want to develop a UI test for an application (Application A) for which I do not have the project files. As I do not have the project for Application A, I cannot develop the test for Application A from inside that same project like I normally would. Thus, I have to somehow create and run it from outside.
My initial thought was to create a test application (Application B) from scratch and add a button to it that, when pressed, will open Application A. I would develop an Espresso test from inside Application B, have it press that button to launch Application A, and then have it follow other Espresso instructions I would develop by viewing the R.ids of Application A's UI elements through uiautomatorviewer.bat, included in the Android SDK tools.
At least to me, this seemed like it would work just fine in theory, so I went forward with the plan. However, when the button inside Application B is pressed by the UI test and Application A launches, the test cannot find an activity to continue testing on. No error is explicitly thrown; Logcat prints messages like "W/RootViewPicker﹕ No activity currently resumed - waiting: 2000ms for one to appear," repeatedly, where 2000ms increases as time goes on.
Historically, I have not had any problems when running Espresso tests across activity changes. I assume this issue has something to do with the fact that the activity being launched exists outside of the project where the Espresso test is based.
If anyone knows of a way to get an Espresso test to run successfully on an application when based in a project located outside of that application, I'd appreciate any advice you may be able to offer. I think I'm on the right track, but I don't know for sure. Thanks!

Related

How to run the same Specflow test for iOS and Android using Appium?

I had existing UI tests using Xamarin UI Test and NUnit. In my test class I was able to decorate the class with
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
I could in turn use this in my test setup and execution to handle different thing per platform and the test runner in VS would show things like "LoginTest - iOS", "LoginTest - Android".
I have switched to Appium and I am trying to use Specflow, but I can't figure out how to make a single Scenario target both platforms automatically. I don't want to have to change a config file to run iOS vs Android, when I run the tests I want to run both, or ideally have the test runner display different distinct tests for each platform but derived from the same feature/step code.
How do I parameterize the entire Scenario per platform?
**UPDATE
Ok, so I have sort of stumbled on how to accomplish this but I am still not sure whether this is the optimal way.
In my feature file I have this for example:
Scenario Outline: Successful login
Given the user is on login page
And the user entered valid credentials
When the user presses sign in button
Then the user ends on dashboard page
Scenarios:
|platform|
|IOS|
|Android|
Adding the Scenarios table with no variable specified adds the table to the scenarioContext.ScenarioInfo.Arguments["platform"]. It also adds an entry per platform to the test runner in VS.
The only real problem I see in this way is that you have to enter the Scenarios table of platforms for each Scenario Outline. This seems like it could become a nightmare later with tons of tests and say you want to add another platform. It would be great to be able to specify the table in an external file that was included or referenced some way by each feature file since I would likely use it for all my tests.
Ok, so I stumbled upon the Nuget SpecFlow.Contrib.Variants.
This does exactly what I want and I was able to switch from my OOB workaround to the package without much issue.
With the Variants package you can decorate a feature or scenario with something like
#Platform:Android
#Platform:IOS
Then in test runner you get this much cleaner view like:
This allowed me to remove all my repeated:
Scenarios:
|platform|
|IOS|
|Android|
Very little setup, works great, I wish I found it first.
https://github.com/totaltest/SpecFlow.Contrib.Variants

How do you write an Androidx Instrumentation that runs multiple Instrumentations?

I want to write an Androidx test that starts an Application, waits for it to crash, and then starts it again.
As I understand it, by default, AndroidX tests run on a instrumentation, and when one test crashes, the entire instrumentation is brought down with it.To prevent one test from crashing the whole test suite, AndroidX includes an AndroidTestOrchestrator. This allows each test to run in its own instrumentation, so one test crashing only brings down the instrumentation it is in.
Given what I am trying to do, it looks like I will need to create my own AndroidTestOrchestrator to run a test with two instrumentations, one to run the Application crash, and then another to see that it is recovered from correctly.
How feasible is this?

Is it possible to do automated testing with detox outside of the target application?

I have built a react-native application and am trying to build a few specific end-to-end tests on the android side. For this, I have setup detox. Unfortunately, to test properly, I need to see how the application responds when the user is performing actions outside of the target application.
e.g. I need to automate click A within target application A, click android home button, swipe right on screen and then open application B. Application A should then open itself and the test can confirm if it has opened to the right screen.
Is something like this possible within Detox? If not, are there any frameworks that would allow me to test this?
What you are wanting to do is use something called 'Appium' instead of 'Detox'. This is due to Appium interfacing with the androids uiAutomator API which allows automation and testing outside of a single application, Detox is more for testing the behaviour within the application itself rather than outside of it.

Create Android APK Test Application

I have an app to be tested, called app A.
I also have a test project for automated testing of this app.
I want to have a second app which includes these test cases, so that I can run all test cases for app A by starting another, app B.
I don't want to start tests in Eclipse, I want to start them directly from the phone where the app should be tested
Someone knows a solution?
BR
I guess you want to run the tests from your code, in such case this post, presenting a solution to run instrumentation from code, will be of help.
Maybe i didnt' understand... You want to start an activity from MainActivity but the 2nd activity has to be hidden from launcher?

how to figure out the flow of an android project using debug

I'm new to android development.
I download a toy project and want to figure out the flow of this project.
Can I use debugging to figure out it and how?
Let me explain it more detail. Every android project starts from an "main" activity. I guess I find the "main" activity for the project and set a breakpoint at the onCreate method of this "main" activity. I expect to run this project from that breakpoint one step by step to figure out the flow. However it doesn't work since the debugging stop after finishing the onCreate method.
Start with AndroidManifest.xml file. Open it and look for an Activity with LAUNCHER category. Then open that Activity and go to onCreate(...) method. This is where your app starts. Inside the method, there is a call to setContentView(R.layout.some_layout). some_layout.xml in res/layout folder is UI for this Activity.
Each window you see in Android app is an Activity and each Activity has a layout file.
The "flow" of an android application is more like an asynchronous model than a sequential flow of action. There is a main application loop that processes external events (such as clicks on button) and callbacks related to the activity lifecycle (such as your onCreate method), and lot of other stuff.
Every event is put into the queue and processed asynchronously, so it's not easy to follow it. It's better to think about actions and reactions. In any case you can dig into the android source code and see what's running behind the scenes. Some hints about the model of android apps can be found here but any google search for "android ui thread queue" would lead to relevant info.
If you want to learn the flow of a typical android application, I would recommend you download the samples if you haven't already and add your own log statements. You could use the debugger too. Then start making small changes here and there to force different 'flows' of control, as you make guesses about what should happen and observe your logging statements and the app behavior to see what's going on.
The sample projects can be downloaded from the adt plugin in eclipse and come as ready-made projects. They are also a good way to learn because they are generally the 'best-practice' way of doing things.
Hope that helps! Good luck :)

Categories

Resources