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

In this session, we will demonstrate how to run a test that uses data from an external CSV file.

CSV file (Comma Separated Values) is a data file where all values are separated by a comma (",").

In this example, we will run a test from JUnit framework that will log into the "EriBank" app using the parameters "username" and "password" from a CSV file.

Step 1: Create a CSV file with the relevant data.

  1. Go into the folder where you want to save the file.
  2. Right click -> New -> Text Document -> Open the text file that was created.
  3. Write the values separated by a comma. In the first row, we can write titles for the values. In this case, the titles are "username" and "password", and the values are "company" for the username and "company" for the password:

  4. Click on File tab -> Save As
  5. In the "File name:" box, write the file name with the ending ".csv".
  6. In the "Save as type:" box, choose  "All Files".

  7. Click on "Save".

Step 2: Create the test on SeeTest Studio (as shown in previous sessions) with the following steps:

  1. SetDevice
  2. launch EriBank
  3. Send text to "UserName" field.
  4. Send text to "Password" field.
  5. Click on "Login" button.
  6. Verify "Make Payment" button.

Step 3: Export the test to JUnit framework (as shown in Session 3):

//package <set your test package>;
import com.experitest.client.*;
import org.junit.*;
public class Untitled {
    private String host = "localhost";
    private int port = 8889;
    private String projectBaseDirectory = "your_project_Base_Directory";
    protected Client client = null;
    public void setUp(){
        client = new Client(host, port, true);
        client.setReporter("xml", "reports", "Untitled");
    public void testUntitled(){
        client.launch("com.experitest.ExperiBank", true, true);
        client.elementSendText("NATIVE", "text=Username", 0, "company");
        client.elementSendText("NATIVE", "text=Password", 0, "company");"NATIVE", "text=Login", 0, 1);
        client.verifyElementFound("NATIVE", "accessibilityLabel=Make Payment", 0);
    public void tearDown(){
        // Generates a report of the test case.
        // For more information -
        // Releases the client so that other clients can approach the agent in the near future. 

Step 4: Modifying the script:

  1. Add the following imports to the script:

    import com.experitest.client.*;
    import org.junit.*;
    import java.util.Scanner;

      2. Change the test so the username and password will be used from the CSV file. In the following code, the test checks the username and password row by row from the CSV file (csvUserName and csvPassword hold the values from the CSV file)

public void testUntitled() {
    client.launch("com.experitest.ExperiBank", true, true);
    String csvUserName = null;
    String csvPassword = null;
    Scanner inputStream = new Scanner(new File("path/to/csv"));
    inputStream.nextLine(); //ignore the first line - Headlines 

	    		String data = inputStream.nextLine(); // Read line
	    		String[] values =data.split(","); // Split the line to an array
	            client.elementSendText("NATIVE", "accessibilityLabel=usernameTextField", 0, csvUserName); //send the text from the csv file to "user name"
	            client.elementSendText("NATIVE", "accessibilityLabel=passwordTextField", 0, csvPassword); //send the text from the csv file to "password"
	  "NATIVE", "text=Login", 0, 1);
	            if(client.isElementFound("NATIVE", "xpath=//*[@text='Invalid username or password!']", 0)) // check if user name or password are not correct. 
	    "NATIVE", "text=Dismiss", 0, 1);	 
    		client.isElementFound("NATIVE", "xpath=//*[@text='Make Payment']", 0); // check if the user is log in
    		inputStream.close(); //close the connection to the csv file


Now the text that sent to username and password fields is from the CSV file. 

  • No labels