0
votes

I've got an issue with the Loop controller in Jmeter when using a CSV reader which hopefully someone can shed some light on for me.

So I have a CSV file which contains a bunch of currency codes and their respective names (See below), I'm then using the CSV values in a subsequent HTTP Request.

            ALL,Albanian Lek
            DZD,Algerian Dinar
            ARS,Argentine Peso
            AMD,Armenian Dram
            AUD,Australian Dollar
            AZN,Azerbaijan New Manat
            BSD,Bahamian Dollar
            BHD,Bahraini Dinar
            BDT,Bangladeshi Taka
            BZD,Belize Dollar
            BOB,Bolivian Boliviano
            BRL,Brazilian Real
            GBP,British Pound
            BND,Brunei Dollar
            XOF,CFA Franc BCEAO
            XAF,CFA Franc BEAC
            XPF,CFP Franc
            KHR,Cambodian Riel
            CAD,Canadian Dollar
            CLP,Chilean Peso
            CNY,Chinese Yuan Renminbi
            COP,Colombian Peso
            KMF,Comoros Franc
            CRC,Costa Rican Colon
            HRK,Croatian Kuna
            CZK,Czech Koruna
            DKK,Danish Krone
            DJF,Djibouti Franc
            DOP,Dominican R. Peso
            XCD,East Caribbean Dollar
            EGP,Egyptian Pound
            EEK,Estonian Kroon
            EUR,Euro
            FJD,Fiji Dollar
            HNL,Honduran Lempira
            HKD,Hong Kong Dollar
            HUF,Hungarian Forint
            ISK,Iceland Krona
            INR,Indian Rupee
            IDR,Indonesian Rupiah
            ILS,Israeli New Shekel
            JPY,Japanese Yen
            JOD,Jordanian Dinar
            KZT,Kazakhstan Tenge
            KES,Kenyan Shilling
            KWD,Kuwaiti Dinar
            KGS,Kyrgyzstanian Som
            LAK,Lao Kip
            LVL,Latvian Lats
            LBP,Lebanese Pound
            LTL,Lithuanian Litas
            MYR,Malaysian Ringgit
            MRO,Mauritanian Ouguiya
            MUR,Mauritius Rupee
            MXN,Mexican Peso
            MNT,Mongolian Tugrik
            MAD,Moroccan Dirham
            NAD,Namibia Dollar
            NPR,Nepalese Rupee
            NZD,New Zealand Dollar
            NIO,Nicaraguan Cordoba Oro
            NOK,Norwegian Kroner
            OMR,Omani Rial
            PKR,Pakistan Rupee
            PGK,Papua New Guinea Kina
            PYG,Paraguay Guarani
            PEN,Peruvian Nuevo Sol
            PHP,Philippine Peso
            PLN,Polish Zloty
            QAR,Qatari Rial
            RON,Romanian New Lei
            RUB,Russian Rouble
            RWF,Rwandan Franc
            WST,Samoan Tala
            SAR,Saudi Riyal
            SGD,Singapore Dollar
            SOS,Somali Shilling
            ZAR,South African Rand
            KRW,South-Korean Won
            LKR,Sri Lanka Rupee
            SZL,Swaziland Lilangeni
            SEK,Swedish Krona
            CHF,Swiss Franc
            TWD,Taiwan Dollar
            TZS,Tanzanian Shilling
            THB,Thai Baht
            TND,Tunisian Dinar
            TRY,Turkish Lira
            USD,US Dollar
            UGX,Uganda Shilling
            UAH,Ukraine Hryvnia
            UYU,Uruguayan Peso
            AED,Utd. Arab Emir. Dirham
            VUV,Vanuatu Vatu
            VEF,Venezuelan Bolivar
            VND,Vietnamese Dong
            ZMK,Zambian Kwacha

In my While Loop I have a the following conditional check: ${__javaScript("EOF" != "${currencyCode}")}

note I have stackoverflow doesnt seem to display the angle brackets but there are there in my JMeter

So what I'm seeing is that the loop is going through the CSV and the required HTTP Request is being sent. However once the last value in the CSV value ("ZMK" in this case) is reached a extra Request is being made with a value of

So it looks like the Whileis doing one more loop than it should be.

I've checked the CSV file in VIM and every other editor I could think of and there are no blank lines or tabs at the end of the CSV file.

If I make my Loop condition ${__javaScript("ZMK" != "${currencyCode}")} everything works fine. But the CSV could grow so I dont want to hardcode anything.

Just to give you a better picture of my test here is the overall picture

           + Thread Group
           ++ Simple Controller
           +++ While Loop with condition ${__javaScript("<EOF>" != "${currencyCode}")}
           ++++ CSV Reader (Recycle on EOF = FALSE, STOP THREAD ON EOF = FALSE, SHARING = Current Thread)
           ++++ HTTP Request using value from CSV file

Also my

4

4 Answers

0
votes

Try putting your CSV reader all the way at the top of the testplan. It is below your While controller now which is causing this issue.

0
votes

Try totally removing your While Controllerand providing a reasonable number of Loops in Thread group (or alternatively replace it with Loop Controller)

Also, you should make your CSV Data Set Config a child of HTTP Request. See Using CSV DATA SET CONFIG guide for more details on how to implement CSV reading logic in JMeter.

Another option is using Beanshell to retrieve all currency codes and local names and store them to JMeter variables.

Following Beanshell code will obtain all currencies available in Java and store them to JMeter Variables

    Set<Currency> currencies = Currency.getAvailableCurrencies();       
    for (Currency currency : currencies) {

        vars.put(currency.getCurrencyCode(), currency.getDisplayName());            

    } 
0
votes

${__javaScript("${currencyCode}" != "EOF",)} Worked with me.

0
votes

Put your CSV reader at the top of the testplan as a child of a while controller with the following condition(function or variable): ${__javaScript(“${currencyCode}” != “<EOF>”,)}. Then you have to increase the number of threads of your thread group to the number of rows in your CSV file, this way it will loop over each line in the csv file with each thread.