The steps to implement a Silk Mobile data driven test are as follows:
• In Silk Mobile record a new test in which you perform the required interactions with the phone App (this will typically need to involve the entering of text e.g. perform a user search in twitter).• The interactions will be recorded as “click on default” commands within Silk Mobile, in which a click is performed on a particular element within the Silk Mobile repository.
• Select the “click on default” command which is responsible for keying of text into the search TextField - view the right hand of the screen select under “Properties”.
• Change the property from a “click element” to a “SendText” property, add a string value and save the changes (see Silk Mobile Help under “Add New Operation/Command” for further details).• Ensure that the script replays successfully, in that the correct search is performed and that the test returns to the correct base state at the end of the test.As Silk Mobile does not allow you to perform a data driven test within the GUI, export your test as a Silk4J or JUnit test (See SilkMobile Help under “Export code to Silk4J” for further details).
NB. Be sure to add the Silk Mobile client jar files to your JUnit project in Eclipse as detailed in the Silk Mobile Help.
Once you copied the code from Silk Mobile to Eclipse and verified that it runs successfully. You can then write your own Java functionality to pass a unique string to the sendText() command from a list of strings stored in an array. This will have the effect that the test becomes data driven in that the test method will be executed for each string within the array.
The sample Junit code below demonstrates how you can data drive using a basic static array, please be aware that other implementations are available such as reading data from an ODBC data source or from an Excel file and then iterating through all of the data using a "for" statement.
package org.silktest.mobile.test;
import com.experitest.client.Client;
import org.junit.*;
public class testAndroid {
private String host = "localhost";
private int port = 8888;
private String projectBaseDirectory = "C:\\Users\\johnly\\workspace\\DataDriven";
private String activeDevice = "adb:HT06PPL03347";
protected Client client = null;
//Create a list of names
public String[] myArrayList = {"John", "Andrea", "Corey", "Caiden", "Ann"};
int icounter; @Before
public void setUp(){ client = new Client(host, port); client.setProjectBaseDirectory( projectBaseDirectory); client.setReporter("xml", "reports"); }
@Test
//Created a method called "myDataDriven which will iterate through the list of //names in the array and pass a string to the test method "testJohnDataDriven"
public void myDataDriven(){
for(icounter=0;icounter<myArrayList.length;icounter++){ testJohnDataDriven(myArrayList[icounter]); System.out.println("Value of Array = "+ myArrayList[icounter]); } }
public void testJohnDataDriven(String myString){
client.setApplicationTitle(activeDevice); client.click("default", "element 31", 0, 1); client.click("default", "element 32", 0, 1); client.sendText(myString); client.click("default", "element 34", 0, 1); client.sendText("{F5}"); client.sendText("{ESC}"); client.sendText("{ESC}"); client.sendText("{ESC}"); }
@After
public void tearDown(){ client.generateReport(); }
}