Android: set package name depending on device running on - android

I have functional autotests for some SDK (as aar-libs) and TeamCity CI server with several Android devices and emulators connected on.
If I use gradle to run my tests (./gradlew connectedDebugAndroidTest), all tests will run on each device, but each next results will overwrite previous ones and TeamCity will show only the last results.
I have to distinct these results and should know which results from what device/emulator.
Any ideas?

Decided to create additional build configuration on Team City, which will parse all connected devices from adb devices and trigger all other configurations passing device name as parameter

Related

Android instrumentation does not start on a second device

Since some time, when I run an instrumentation test on a device (emulator) and try to start another test on a second device in parallel, I get the following exception:
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:connectedDebugAndroidTest'.
java.nio.file.FileSystemException: D:\Android\MyApp\app\build\outputs\androidTest-results\connected\name_of_the_first_device\logcat-MyApp.TestClassName-TestName.txt:
The process cannot access the file because it is being used by another process
The problem seems to be, that the build process tries to access a file from the first test device, which is already blocked. But I'm using a different device and try to run a different test.
The reason why I do that is because some of the tests are very large and therefore I try to spread them to several devices, so I get my results faster. The machine I run the tests on, has a hell of performance, so it can't be a problem of the resources ;-).
When I did the described actions some months ago, it worked properly, so I guess it's due to some updates (probably in Gradle or whatever). But I installed several updates since then, so it can't just be a problem of the current version.
Update - Two more inputs:
I recently switcht to using hilt and therefore created my own TestRunner, because an Application annotated with #HiltApplication cannot be used for tests, so I had to create a custom one for testing which needs to be run in a custom TestRunner as described here.
When I run the same tests on multiple devices using "Select Multiple Devices" dropdown in Android Studio it works properly.
The error message indicates a conflict over a build-and-run output file on your development computer, not on the Android test device. That is, it's trying to do another build-and-run in the same build output directory that the running test is using for purposes like the test's logcat output.
My first thought is to try duplicating androidTest to another build target. Same contents, different target name, different output directory. That workaround seems likely to get past this limitation (but with new limitations) and to help debug the problem. But the name_of_the_first_device subdirectory suggests that it can keep a logcat output file per test device, so the real question is how to get the test runner to use a separate subdirectory per test device.
Second thought is to point you to the the docs, Run Tests with Multiple Devices and Shard Tests.
With a custom TestRunner, see Write a Sharded IRemoteTest Test Runner (and other pages in the "Tradefed" section) on making it a "shardable" test runner which enables the test infrastructure to distribute the full test execution over several devices.

How to make local mobile device visible for CI tool

I am building automation project and want to run tests automatically on local mobile device, that connected to my machine. For that I uploaded my project to GitLab, created .yml file with commands in CI/CD and created schedule.
The next chalenge:
to run tests automatically, on mobile device connected to my machine.
Is any options to make local device visible for GitLab CI/CD?
On your local machine, install the gitlab-runner and register it to your GitLab project. In order to use the device, you'll need to use the shell executor. Be sure to specify at least one unique tag for the runner (say, android for example)
In your yaml, add the tag you used for your runner in the tags: key. For example:
myjob:
tags:
- android
script:
# ...
This will make sure that only your runner will pick up the job.

WARNING: No target specified, deploying to device '' even though --target is specified

I know this question has been asked a thousand times but I find myself in a situation I cannot quite explain.
I get No target specified, deploying to device '0123456789ABCDEF' even though I specified the target with the switch --target with the below command.
ionic cordova run android --target:0123456789ABCDEF
But I get the following:
No target specified, deploying to device '0123456789ABCDEF'
I even tried to add the --device:0123456789ABCDEF switch as well but all the same.
How can I actually make it deploy correctly?
In addition, if I have 2 android devices deployed, it mostly deploys to the other device instead. To work around this, I usually unplug the second device, then plug it again when deployment is done.
According to the CLI docs example you need to use = to give the value and not :.
Use:
ionic cordova run android --target=0123456789ABCDEF

Rebooting android using monkeyrunner

I have this application which I'm testing. I use a script which automatically installs the app but I also want to restart the device. This is important as after the installation I run a monkey-test on the device and all kind of quirks and bugs may arise. To get rid of these I want to restart the phone to get it into some kind of "known state". (These bugs are not only in the app as the phone has been known to suddenly shutdown during the tests)
My installation script is run with jython and I know of the device.reboot() command but this takes almost no time at all (which makes me suspicious) and doesn't work very well. I know there's three arguments: "bootloader", "recovery" and "None" but I can't find the impact these would have on the device.
So my question is, is device.reboot() the right command to use? If yes, what happens when I don't use any arguments with the device.reboot() command and what is the effects of the arguments.
It may be worth mentioning that I run the jython script from a batch command prompt in jenkins. So any batch commands using adb or similar would work just as fine.
device.reboot("None") works on my device

Android: Deploy Test Project

I've created a Test project in eclipse to run some tests for one of my android library. I can run it without problems in eclipse on my device. Is it possible to run these tests on other devices without having them connected to eclipse? I want to send the test project apk to other people so they can run the tests on their device.
I think I'd need something like a test runner app that runs the test and displays the result on the device itself. Does anyone know such an app?
Thanks
Is it possible to run these tests on other devices
without having them connected to eclipse?
yes it is!!
just send the tested .apk file to their mobile, install and use app.
no need any test runner app for this, i have checked it.

Categories

Resources