The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Analytics

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

CircleCI

The demo present in this repository allows you to run automated Espresso tests (using Sauce Runner) in order to validate your Android Native Test Framework Environment, as well as your saucelabs.com account credentials

For Demonstration Purposes Only

The code in these scripts is provided on an "AS-IS" basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. These scripts are provided for educational and demonstration purposes only, and should not be used in production. Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by the Technical Services team at Sauce Labs.

Prerequisites

 Click here to expand the content
  1. Install homebrew: https://brew.sh/
  2. brew install node
  3. brew install watchman
  4. npm install -g react-native-cli
  5. Install JDK8
  6. Install and configure Android Studio
    • Choose a "Custom" setup when prompted to select an installation type. Make sure the boxes next to all of the following are checked:
      • Android SDK
      • Android SDK Platform
      • Performance (Intel ® HAXM)
      • Android Virtual Device
    • Open the SDK Manager (SDK Platforms section) and choose to install "Android 8.1 (Oreo)" - check the box that says "Show package details" and choose:
      • Android SDK platform 27
      • Google APIs Intel x86 Atom System Image
      • DO NOT CLICK 'APPLY' YET!
    • Also go to the SDK Manager's SDK Tools section - check the box that says "Show package details" and choose:
      • "27.0.3" under the Android SDK Build-Tools tree
      • Now click 'Apply' to pull down and install all the new dependencies
    • Add the following lines to your $HOME/.bash_profile config file:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
  1. Open ./sample-app-ios/android as a project in Android Studio
  2. Under the Tools menu, choose AVD Manager
  3. Click the Create Virtual Device button
  4. Choose a device definition (e.g. Pixel 2) and click Next
  5. Choose Oreo with API 27 and click Next

    you may need to select Download beside Oreo 27 to enable the Next button

  6. Click Finish to create the emulated device
  7. Launch the virtual device in the Android Emulator by clicking on the green triangle icon.
  8. Navigate to the root directory demo-react-native-espresso, open a shell and run: react-native run-android

WARNING: if you don't manually launch the emulator, run-android returns:

FAILURE: Build failed with an exception.
    
* What went wrong:
Execution failed for task ':app:installDebug'.
    > com.android.builder.testing.api.DeviceException: No connected devices!

* 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

BUILD FAILED in 3m 35s
45 actionable tasks: 24 executed, 21 up-to-date
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

Running the Demo via the Sauce Runner

All command line examples are in UNIX

  1. Clone this repository:
$ git clone https://github.com/saucelabs-training/demo-react-native-espresso.git
  1. Open Android Studio and import as a New Project with /android as the project directory.
  2. In the root directory (demo-react-native-espresso), run the following commands:
$ cd ../
$ npm install
  1. In Android Studio select Build > Make Project to build the application and install any dependencies.
  2. Export your Sauce Labs Credentials as Environment Variables.
  3. In the android directory, run the following commands to build the relevant .apk files:
$ cd android/
$ ./gradlew assembleRelease
$ ./gradlew assembleAndroidTest

Make sure you've set $JAVA_HOME correctly, and that you're using JDK 8. If you have multiple versions of Java, you may need to reset it with the following:

$ export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
  1. Navigate to the directory where you downloaded the Sauce Runner and create a runner.sh script:

We recommend copying the Sauce Runner directory into your project root directory (i.e. demo-react-native-espresso)

./sauce-runner-virtual-0.1.1-osx/bin/sauce-runner-virtual \
-u $SAUCE_USERNAME \
-k $SAUCE_ACCESS_KEY \
-f espresso \
-a ../android/app/build/outputs/apk/release/app-release.apk \
-t ../android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
-d 'deviceName=Samsung Galaxy S8 HD GoogleAPI Emulator,platformVersion=8.0' \
-d 'deviceName=Google Pixel GoogleAPI Emulator,platformVersion=8.1'
  1. If you're running this demo on OSX, run the following command:
$ ./runner.sh
  1. If you're running this demo on Linux or Windows, edit the following line in runner.sh:
./sauce-runner-virtual-0.1.1-<windows or linux>/bin/sauce-runner-virtual \
  1. The console output should read like so:
2019-07-03 11:14:33 - [INFO] Using sauce-runner v0.1.1
2019-07-03 11:14:33 - [INFO] Selected framework: espresso
2019-07-03 11:14:33 - [INFO] Using user: $SAUCE_USERNAME
2019-07-03 11:14:33 - [INFO] Using apikey: $SAUCE_ACCESS_KEY
2019-07-03 11:14:33 - [INFO] Using local App: ./release/app-release.apk
2019-07-03 11:14:33 - [INFO] Using local Test App: ./androidTest/debug/app-debug-androidTest.apk
2019-07-03 11:14:33 - [INFO] No include-tests filters specified
2019-07-03 11:14:33 - [INFO] No exclude-tests filters specified
2019-07-03 11:14:33 - [INFO] Set device: Samsung Galaxy S8 HD GoogleAPI Emulator - 8.0
2019-07-03 11:14:33 - [INFO] Set device: Google Pixel GoogleAPI Emulator - 8.1
2019-07-03 11:14:33 - [INFO] Trying to upload file ./release/app-release.apk to sauce-storage
2019-07-03 11:14:35 - [INFO] File uploaded: app-release.apk($SAUCE_STORAGE_ID) - Size:10915077
2019-07-03 11:14:35 - [INFO] Trying to upload file ./androidTest/debug/app-debug-androidTest.apk to sauce-storage
2019-07-03 11:14:36 - [INFO] File uploaded: app-debug-androidTest.apk($SAUCE_STORAGE_ID) - Size:3205179
2019-07-03 11:14:36 - [INFO] JUnit reports will be saved locally at the end of the tests
2019-07-03 11:14:36 - [INFO] Jobs created
2019-07-03 11:14:36 - [INFO] Jobs created
2019-07-03 11:14:41 - [INFO] Getting job status
2019-07-03 11:14:41 - [INFO] Job status: In progress
2019-07-03 11:14:41 - [INFO] Samsung Galaxy S8 HD GoogleAPI Emulator - 8.0 - Status: test queued
2019-07-03 11:14:41 - [INFO] Google Pixel GoogleAPI Emulator - 8.1 - Status: test queued
2019-07-03 11:14:56 - [INFO] Getting job status
2019-07-03 11:14:57 - [INFO] Job status: In progress
2019-07-03 11:14:57 - [INFO] Samsung Galaxy S8 HD GoogleAPI Emulator - 8.0 - Status: test queued
2019-07-03 11:14:57 - [INFO] Google Pixel GoogleAPI Emulator - 8.1 - Status: test queued
2019-07-03 11:15:12 - [INFO] Getting job status
2019-07-03 11:15:12 - [INFO] Job status: In progress
2019-07-03 11:15:12 - [INFO] Samsung Galaxy S8 HD GoogleAPI Emulator - 8.0 - Status: test session in progress
2019-07-03 11:15:12 - [INFO] https://saucelabs.com/beta/tests/$JOB_ID/watch
2019-07-03 11:15:12 - [INFO] Google Pixel GoogleAPI Emulator - 8.1 - Status: test session in progress
2019-07-03 11:15:12 - [INFO] https://saucelabs.com/beta/tests/$JOB_ID/watch
2019-07-03 11:15:27 - [INFO] Getting job status
2019-07-03 11:15:27 - [INFO] Job status: Complete
2019-07-03 11:15:27 - [INFO] Samsung Galaxy S8 HD GoogleAPI Emulator - 8.0 - Status: test complete
2019-07-03 11:15:27 - [INFO] Google Pixel GoogleAPI Emulator - 8.1 - Status: test complete
2019-07-03 11:15:42 - [INFO] Tests results for Samsung Galaxy S8 HD GoogleAPI Emulator - 8.0