Instrumentation test fails when run in headless emulator - java

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.'

Related

How to execute an APK (Test cases) through ADB command?

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

How to fix "FAILURE: Build failed with an exception.- Could not determine java version from '11.0.1'

I'm new in react-native and this is my first app. I followed the steps here.but once I run the command react-native run-android
this error appeared
Starting JS server... Building and installing the app on the device
(cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
What went wrong: Could not determine java version from '11.0.1'.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org Could not install the app on the device, read the error above for details. Make sure you have an
Android emulator running or a device connected and have set up your
Android development environment:
react docs
Here is my JAVA_HOME variable and my ANDRIOD_HOME variable
Click here please
Please note that I run the app on a device connected not on Android emulator
I'm using "windows OS", "android mobile" and my gradle version is 4.4
Also I went to my android dir and made a file names local.properties and put into it this path
sdk.dir=C:\Users\Eman Fateen\AppData\Local\Android\Sdk
Could you please help me how to solve this problem ?
You can't build with a version of Gradle that doesn't support JDK 11.0.1 itself. Either:
you can either edit the gradle/wrapper/gradle-wrapper.properties file to select a different distribution OR
use a Gradle >= 4.7 version to run the wrapper update task.
If neither of those work then you could try downgrading the JDK like this.

ReactNative, Android run error: Could not determine java version from '11.0.1'. Windows 10

Java version: 11.0.1
React Native version: 0.57.5
React Native CLI version: 2.0.1
Android device is connected and given access, tuned on debug via USB
When I run neact-native run android I get this following error:
Starting JS server... Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
Could not determine java version from '11.0.1'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
You seem to be using an older version of Gradle, from 4.8+ your project should build
The below directory gradle/ is in whichever directory gradlew or gradlew.bat is in.
Edit the file called gradle-wrapper.properties located in ./path-to-project-root/gradle/wrapper
Replace distributionUrl:... with the following
distributionUrl=http\://services.gradle.org/distributions/gradle-5.0-bin.zip
I was having the same issue. I update the gradle version to gradle-4.8-all.zip in the following file in disributionUrl:
[your-react-native-project]/android/gradle/wrapper/gradle-wrapper.properties
It solved the issue.

How to install a third party apk using Android Studio so that the tests, I have created, can run on the third party apk?

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]

Running Android emulator from Jenkins to run Junit test with Robotium

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.

Categories

Resources