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

Last updated: Oct 05, 2020 12:52

This article explains how you can pass dynamic data from a .csv file to Quantum.

To pass dynamic data:

  1. Create a .csv file containing the data you want to pass to Quantum. The following example shows a .csv file source that contains two pairs of contact names with contact phones.

    contactName,phoneNumber
    Perfecto Quantum,1234
    Quantum Perfecto,4567
  2. Place the file in the following folder: src/main/resources/data/
  3. Create a feature file that takes the .csv columns as input and points to the data file, as shown in the following example.

    @dynamicData
    Feature: Add Contact
    
      Scenario Outline: Dynamic Data
        Given I launch Contacts application
        Then I Add Contact with name "<contactName>" and number  "<phoneNumber>"
      Examples: {'datafile' : 'src/main/resources/data/contactNames.csv'}
  4. Add an implementation for the step that uses the .csv data, as shown in the following example.

        @When("I Add Contact with name \"([^\"]*)\" and number  \"([^\"]*)\"$")
        public void I_add_contact_with_name(String contactName, String phoneNumber) throws Throwable {
            DeviceUtils.switchToContext("NATIVE");
    
            if (!isAndroid()) {
                System.out.println("this is an iOS");
                getDriver().findElement("contacts.page").click();
            }
    
            //Add contact
            click("add.contact.btn");
            // in some Android devices, after clicking on add contact, a popup appears asking which account to save the contact under
            //we will look for this and if it appears select the device option
            if (isAndroid()) {
    
                if(isText("Save contacts to",20)) {
                    getDriver().findElement("save.phone").click();
                }
    
            }
            DeviceUtils.waitForPresentTextVisual("Phone", 20);
            //Insert name and number
            getDriver().findElement("add.name").sendKeys(contactName);
            Thread.sleep(2000);
            getDriver().findElement("phone.field").click();
            Thread.sleep(2000);
            getDriver().findElement("add.phone").sendKeys(phoneNumber);
            DeviceUtils.waitForPresentTextVisual(phoneNumber, 20);
            //Save contact
    
            getDriver().findElement("save.contact").click();
    
            if (isAndroid()) {
                DeviceUtils.waitForPresentTextVisual("connected via", 20);
                //return to main screen
                getDriver().findElement("back").click();
                DeviceUtils.waitForPresentTextVisual("contacts groups more", 20);
            }
    
    
        }
  5. Run the test by adding the scenario's tag to your TestNG.xml configuration file.