Debugging with Java

Pre requirements

In this example we will create a new Android Java project from MomentumSuite.com and then we will run tests on our computer with your own device.

 

1-Integrate your account with your GitHub account

2- Create a new Android project on momentumsuite.com .

Add a section, case and a step with a dummy code and Save it.

Thread.sleep(10000);

3- Check your new GitHub project

After a few minutes, you will see a new Github project on your Github account.

 

4-Check your code on Github

Switch to Java branch and check your code in the right place

5-Checkout your Git repository on your computer and download the latest code from GitHub

6-Open your Java project with your favorite IDE (IntelliJ / Eclipse / VS Code) .

Build your project and make sure your project’s built was successful.

We recommend that you to use VSCode with Momentumsuite extension. It’s better to manage updating or adding new cases/steps / sections.

7-Open application.properties file

Open application properties file under resources and change with your appium host, appium port, APK path on your computer or URL. AutomationName must be “UiAutomator2” for Android projects.

8- Enable Developer mode on your Android device

Enable Developer mode on your Android device and enable USB debugging. After that, you plug your device into your computer with a USB cable. Allow and trust connections on popup messages between your mobile device and computer.

9- Connect device and get UDID number

Open a new terminal window/command prompt on your computer. Run “adb devices“ command to check connected devices to a computer. Copy the UDID number of your Android device from the terminal window and paste it on your application.properties file as device Udid value.

10- Set and load environment variables

Type “source ~/.bash_profile“ on terminal window and press ENTER. (only for MacOS) to load your environment variables on terminal window like JAVA_HOME etc.

11- Type “Appium &“ on terminal window and press ENTER. That will start appium server

Appium server is used for running tests locally on your computer.

If you want to debug your tests and use the Recorder locally, you can start with appium client with the next step instead of this step.

12- Run your Java TestNG testcases on your favorites IDE and check the appium console logs.

 

(OPTIONAL) Change screenshot folder on your computer:

Open “MomentumDriver.java” file on utils package. Find “saveScreenshot” function and change your “savePath“ location to store screenshots before and after the test/steps.

 

(OPTIONAL) Add new capabilities:

Open “DriverManager.java” file on utils package. Find “SetCapabilities” function and change or add your extra capabilities. There is a relationship between DriverManager.java and application.properties file. Define the new capability from DriverManager.java and set it from application.properties file, that’s all.

 

(OPTIONAL) Appium Client usage:

First of all terminate your appium server if it’s currently running on your terminal window.

Press command+space and search for “Appium“ and open it.

Click Edit configurations and Set your ANDROID_HOME , JAVA_HOME path. Save and restart.

Click Start Server. In this state, you can only run your tests from your favorite IDE. If you need to record scenarios or debug screens click “Start Inspector Session“

Set your capabilities for your device like application.properties file.

Example Capability set

{ "platformName": "Android", "bundleId": "io.selendroid.testapp", "no-reset": "true", "full-reset": "false", "app": "/Users/ozgur.kaya/Documents/selendroid-test-app-0.17.0.apk", "automationName": "Appium", "autoGrantPermissions": "True" }

 

Click Start Session and start to debug your app. You can add breakpoints on your code and record scripts wth different languages. Copy the scripts that generated from Appium and paste into your Automation project, that’s all..