This section is a step by step guide to create your first test script using Selendroid
Suppose we have an Android application under test name Guru99App. The application include a text field and a button name "Show Text".
We need execute following test case using Selendroid.
Test Cases |
Condition |
Expected output: |
|
The binary of the application under test is available Device is connected to PC |
The text "Text Show here" is change to the text which user enter in text field |
Step 1) Create a Java project in Eclipse
Step 2) Add selenium and Selendroid jar file in eclipse environments
Right click Guru99Test Project -> Build Path -> Add External Archives
Navigate to the folder which stored the jar files
There're 3 jar files should be added
Select all -> Choose Open to add jar file to the project
Step 3) after adding the above library, those libraries will be added to the Reference Libraries of the test project. Tester can use the APIs of those library to develop the test program
Create package "com.guru.test"and add java file "Guru99Test.java" like below
Right Click Guru99Test -> New -> Package
Type com.guru.test to the Name field on New Java Package dialog à Finish
The Eclipse will create a list folders and sub folders like this in the source code structure
Step 4) Install TestNG for Eclipse
In Eclipse, Help -> Install New Software, in the Install Dialog, click Add and enter the following
Press OK -> Next to install the TestNG
Step 5) Copy the Guru99App.apk to the folder of Test App
Step 6) Get the ID of application under test.
Suppose we have an APK file name Guru99App.apk. Follow the step which is described in previous section, execute the command on terminal
Step 7) Open the file Guru99Test.java (in sample code) and change as following
To create a new test session with Selendroid, you have to provide the app id in the format: com.guru99app:1.0. This app Id can is identified in step 6. If you don't set the app Id matching the Android device, the test session will throw error and will not start.
After initializing the found device, Selendroid creates a customized selendroid-server and installs the Selendroid server on it
Selendroid also installs the application under test and starts the selendroid-server on device
After initzalizing the test session succesfully, the test command is started executing on device. (Such as enter text, press button…). If the test app ends the test session, the emulator will stop automatically
Step 8) Start the new test session
Launch the Selendroid server using following command on terminal like step 6
After the Selendroid Server started, open the sample test project Guru99test on Eclipse, set a breakpoint at line 77 on file Guru99Test.
Start a test session by right Click to Guru99Test project -> Debug As -> TestNg Test.
tep 9) Get the Id of GUI element of application under test
After this step, you can get the ID of each above UI element
Those IDs will be used in next step
Step 10) Enter the test program like below
A test program using Selendroid includes 3 sections
Setup Test:
Following is the code for setup test, it will set up the condition for a test session.In case of an error, the Selendroid will throw the exception and the test app will stop.
Execute Test
Below is the code to execute a test. The code includes the commments
Here are the test steps again