How o do test with Selendroid ?

Answer

 

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: 

  1. Launch the application
  2. Enter a text "Guru99 Test" to the text field
  3. Press "Show Text" button

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

  • selendroid-client-0.10.0.jar : Selendroid java client library
  • selendroid-standalone-0.11.0-with-dependencies :Selendroid standalone server library
  • selenium-java-2.40.0.jar : Selenium Web Driver library

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

  • Button Show Text ID : "btnShow"
  • Text Field ID: "edtText"
  • Label Text ID: "txtView"

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

  1. Enter the text "Hello Guru""
  2. Click Show Text Button
  3. Wait a while
  4. Verify that the app display the text as user enter to text field (Ex. Display the text "Hello Guru")

 

         

All mobile testing Questions

Ask your interview questions on mobile-testing

Write Your comment or Questions if you want the answers on mobile-testing from mobile-testing Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---