I'm unable to get the detailed description of installation of an apk. I have tried adb install "filename.apk" it showing only success. Is there any way to get full log file while installing or executing ?
When running a UI test on the emulator or device the gradle builds two apk files, one for the app, and one for the testing code. Let’s build both the app and the testing app and install them.
First connect a device or an emulator, and type in the command line in the project folder:
./gradlew clean installDebug installDebugAndroidTest
This command will:
clean the build folder
compile and install the app on the device
compile and install testing app on the device
Now for the fun part. Run the tests from command line:
adb shell am instrument -w -r -e debug false -e class com.your.app.ExampleInstrumentedTest#checkButton com.your.app.test/android.support.test.runner.AndroidJUnitRunner
Let’s explain the above command first:
“adb shell am instrument -w” runs all the UI tests
“-e debug false” is because we don’t want to debug the testing
“-e class com.your.app.ExampleInstrumentedTest#checkButton com.your.app.test/android.support.test.runner.AndroidJUnitRunner” this tells our app to run a specific test
Related
Hello there are tests written on Java + cucumber
The structure is as follows:
https://i.imgur.com/moLVY6L.png
The main question is how to run this tests not from the IDE, say from the console or even wrap it all in jar file
The problems encountered are that you need the main class to create a jar,
It seems as there is a certain java cucumber.api.cli.Main - but how to use it I do not understand. Either way, there's probably a way to run this just from the command line. Please tell us how to do it?
You can download Maven with following terminal script :
$brew install maven
After brew installation, you need to go to the project directory which includes pom.xml file in terminal :
$cd /path/of/your/project
And finally you can run following command to run your tests :
$mvn clean test
You can try the below on command prompt.
java -cp "E:\Workspace\CucumberProj\Jars*;E:\Workspace\CucumberProj\bin" cucumber.api.cli.Main --glue stepDefination E:\Workspace\CucumberProj\Feature\Login_Test.feature
While I create a new project, I change the package name to that of the third party apk package name (com.apowersoft.mirror) and select the Empty script and save.
I create a new (small) test script within the package then connect my android device and run the test.
The error message below is displayed:
//Testing started at 11:01 ...
// 10/24 11:01:50: Launching ExampleTest...
//$ adb push C:\Users\LOCAL.ADMIN\Android Studio Test
//Files\Practice\app\build\outputs\apk\debug\app-debug.apk
The app-debug apk is the apk that is automatically built upon running the script (I do not need this apk so I deleted it and tried to replace it with the third party apk (ApowerMirror app) but that did not work. The apk just appeared in the folder again after I re-ran the script.)
///data/local/tmp/com.apowersoft.mirror
//$ adb shell pm install -t -r
//"/data/local/tmp/com.apowersoft.mirror"
//pkg: /data/local/tmp/com.apowersoft.mirror
//Success
//$ adb push C:\Users\LOCAL.ADMIN\Android Studio Test
//Files\Practice\app\build\outputs\apk\androidTest\debug\app-debug-
//androidTest.apk /data/local/tmp/com.apowersoft.mirror
//$ adb shell pm install -t -r
//"/data/local/tmp/com.apowersoft.mirror.test"
//pkg: /data/local/tmp/com.apowersoft.mirror.test
//Success
//Running tests
//$ adb shell am instrument -w -r -e debug false -e class
//'com.apowersoft.mirror.ExampleTest'
//com.apowersoft.mirror.test/android.support.test.runner.AndroidJUnitRunner
//Client not ready yet..
//Started running tests
Immediately after this, my first test fails. see below (in bold)
//android.support.test.uiautomator.UiObjectNotFoundException:
UiSelector[TEXT=Register]
In which folder should I put the third party apk file (ApowerMirror app) that I want to test?
Please note: When I have the apk already installed on my device and I run the test script, I receive the error message below (Failure [INSTALL_FAILED_VERSION_DOWNGRADE]) and when I uninstall it and try again, the error message above is displayed:
//Testing started at 12:47 ...
//10/25 12:47:29: Launching ExampleTest
//$ adb push C:\Users\LOCAL.ADMIN\Android Studio Test
//Files\MyApplication\myapp\build\outputs\apk\debug\myapp-debug.apk
///data/local/tmp/com.smartvg.tcr.aevi
//$ adb shell pm install -t -r "/data/local/tmp/com.smartvg.tcr.aevi"
//pkg: /data/local/tmp/com.smartvg.tcr.aevi
//Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
I'm using an Android 7.1.1 x86_64 emulator and the test passes when run in UI mode but fails when it is run in headless mode. Can anyone please help me?
This is the command I used to create avd
avdmanager create avd -n test -k "system-images;android-25;default;x86_64"
command to run emulator in headless mode
emulator -avd test -skin 540x960 -no-window -no-audio -no-snapshot
command to run test
gradlew connectedDebugAndroidTest --stacktrace
And this is the error i get
Tests on test(AVD) - 7.1.1 failed: Instrumentation run failed due to 'Process crashed.'
I inherited Android Java-code in my company, without Gradle-files etc, and I want to be able to compile this on my dev-server (I program from a ChromeOS machine, hence a CLI SSH connection to a server where I do dev stuff). Now I found some Docker images like this one (which doesn't even have a working command line example) but I haven't managed to create an APK yet. What am I missing and how would you do this?
You have three steps to do:
Migrate your project to gradle.
It isn't too difficult since there are plenty of gradle project out there and you can try to follow them or just read "Migrating to Gradle" article.
Build project with gradle on local machine.
If you migrated properly you can build your project in terminal like:
./gradlew assembleDebug
but it might be also assembleDevDebug or assembleProdRelease which depends on your buildType and flavor in gradle. Check which assembles are available by running:
./gradlew tasks
Build project using Docker.
Based on image you linked:
docker run -t -i ksoichiro/android -v /path/to/project:/workspace -w workspace /bin/sh -c "./gradlew assembleDebug"
How can I run Android emulator from Jenkins to run my tests?
When I write in Execiute Windows bath comand, command to run emulator:
emulator -avd Tester
and run my tests I have this errors:
..>emulator -avd Tester 'emulator' is not recognized as an internal
or external command, operable program or batch file.
..>exit 9009 Build step 'Execute Windows batch command' marked build
as failure
I set path for Android_SDK, java in Windows path and it works from cmd.
What should I do to run emulator?
You can automate the process with the Android Emulator Plugin for Jenkins.
You just need to find where the file "emulator.exe" is located, and then run the command in that location. For example, the most probably is that it is located in C:...android-sdk\tools
so, go to the command promt, type cd C:\android-sdk\tools. Then type the command, and it will work just fine. I hope this is the answer even though it´s late. So, accept the answer.