Skip to main content

SeeTestAutomation- Session 7 - Running Data Driven Tests

info

Please note that this tool is classified as a Legacy tool. We recommend transitioning to our updated solutions to maintain optimal performance and security in your workflows. For more information on this matter, please reach out to technical support .

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):

JUint

//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;
@Before
public void setUp(){
client = new Client(host, port, true);
client.setProjectBaseDirectory(projectBaseDirectory);
client.setReporter("xml", "reports", "Untitled");
}
@Test
public void testUntitled(){
client.setDevice("your_device");
client.launch("com.experitest.ExperiBank", true, true);
client.elementSendText("NATIVE", "text=Username", 0, "company");
client.elementSendText("NATIVE", "text=Password", 0, "company");
client.click("NATIVE", "text=Login", 0, 1);
client.verifyElementFound("NATIVE", "accessibilityLabel=Make Payment", 0);
}
@After
public void tearDown(){
// Generates a report of the test case.
// For more information - https://docs.digital.ai/bundle/TDB/page/seetestautomation-_report_of_executed_test.html
client.generateReport(false);
// Releases the client so that other clients can approach the agent in the near future.
client.releaseClient();
}
}

Step 4: Modifying the script:

  1. Add the following imports to the script:

    imports

    import com.experitest.client.*;
    import org.junit.*;
    import java.io.File;
    import java.io.FileNotFoundException;
    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). 

@Test

@Test
public void testUntitled() {
client.setDevice("your_device");
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

while(inputStream.hasNext())
{
String data = inputStream.nextLine(); // Read line
String[] values =data.split(","); // Split the line to an array
csvUserName=values[0];
csvPassword=values[1];
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"
client.click("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.
client.click("NATIVE", "text=Dismiss", 0, 1);
else
break;
}

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.