0

I am executing a script for a Salesforce page flow with Chrome Webdriver. The flows are written in Selenium JUnit code, exported and executed as JAR (JUnit Request Sampler) in JMeter 5.4.1. The page has a pop-up which has a textbox. which should read all values from a CSV file (currently kept within Selenium Project) one by one [eg. value1, value2...value n] (1 column,'n' rows) until all values are finished. Once one data is entered, "Next" button is clicked for next value to be captured from CSV. "Tube1Id" is the element name of the textbox. Currently the flow when run in JMeter executes till Textbox display in pop-up and stops, just on the step to read the CSV file. Can anyone please help?

public void jmeterTest() throws InterruptedException
{
    try
    {
        String CSVPath = "C:\\Users\\user\\Documents\\CAREDx\\SeleniumProject\\SeleniumProject\\CSVSamples\\samples.csv";   
        driver.get("https://baseurl/");
        
        /* code for pop up window open with Textbox*/
        
        WebElement Tube1Id = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='Tube1Id']")));   
                        
        CSVReader reader = null;
        reader = new CSVReader(new FileReader(CSVPath));
        String[] samples;
        while ((samples = reader.readNext()) != null) 
        {               
            String TubeId = samples[0];
            Tube1Id.sendKeys(TubeId);
            log.info(threadName + "::  Tube ID :: " + TubeId);
            
            /* code for Next button click */
        }
    }
}
  • Any errors? Does the CSVReader portion work on its own? – Curtis Jun 07 '21 at 15:55
  • I am directly running the JUnit code in JMeter, and the steps execute as per the code, opens browser, login, pop window opens with the textbox and the script stops. It stops and doesn't read anything. – Purbita Ghosh Jun 07 '21 at 16:06
  • include code for your "wait" object. (also initialization of webdriver... make sure you're not setting implicit wait as well.) – pcalkins Jun 07 '21 at 18:45
  • Hi, could you please explain a bit more..I am new to selenium and still learning webdriver scripting. I am using wait one for driver and 2 waits for pop window and textbox appearance. I have updated the question above for more clarity. – Purbita Ghosh Jun 08 '21 at 06:12
  • public void jmeterTest() throws InterruptedException { try { WebDriverWait wait = new WebDriverWait(driver, 30); String CSVPath = "\\SeleniumProject\\CSVSamples\\samples.csv"; driver.get("https://baseurl/"); – Purbita Ghosh Jun 08 '21 at 06:13
  • You need to debug and isolate the problem here. I'd suggest debugging a little to see where it's going wrong and then re-posting your question. For instance, what is the value of Tube1Id after the wait? Also try/catch that wait to see if Timeout is thrown. It sounds like all the exceptions you need are gobbled up and thrown as "interruptedException". It will also help if you include the HTML markup of the "popup". (More is better... use right-click inspect to get markup at that time.) – pcalkins Jun 08 '21 at 17:02

1 Answers1

1

I found another way to work this out since reading data from an external csv file location didn't work.

I added a CSV Dataset config element in JMeter under JUnit Request [Thread Group>JUnit Request>CSV Data set config], added csv location and variable name (samples). I added the values in CSV file as value 1@value 2@...@value n. In the selenium code I added :

String samples = junitSampler.getThreadContext().getVariables().get("samples");
String[] arrOfStr = samples.split("@");
/* in-between code */
for (String TubeID : arrOfStr)
{
    Tube1Id.clear();
    Tube1Id.sendKeys(TubeID);
/* remaining code for click Next */
}

It's working.