Forum Discussion

NLESM5's avatar
NLESM5
New Contributor
2 months ago

If... Then... Else

HI,

Is it possible to build in if then else functions in LoadNinja? Looking for a way to deal with different flows based on input in the same script instead of having two nearly identical scripts.

Emiel

5 Replies

  • Humashankar's avatar
    Humashankar
    Champion Level 2

    Hi NLESM5 

    LoadNinja currently lacks explicit if-then-else logic within a single script, but there are creative options to achieve similar functionality and manage diverse flows based on input.

    One approach is to divide your script into smaller, reusable scenario calls.

    The main script can dynamically call these sub-scenarios based on conditions, leveraging variables or data from previous steps to determine which sub-scenario to execute, effectively simulating if-then-else logic.

    Hope this helps - Happy to help further!!
    Thank you very much and have a great one!
    Warm regards

    • BGomes's avatar
      BGomes
      New Contributor

      Hi Humashankar ,

      I'm new to using the tool, is it possible to have an example with images? because I'm struggling to understand how we can call other scripts based on variables or data from previous steps.

      Thank you

  • Humashankar's avatar
    Humashankar
    Champion Level 2

    Hi BGomes 

    Please make use of the below help article to get the better handle with the tool:

    https://loadninja.com/articles/how-to-use-databanks-in-loadninja/

    https://support.smartbear.com/loadninja/docs/api-tests/variables.html

    Regards

    • BGomes's avatar
      BGomes
      New Contributor

      Hi Humashankar ,

      Thank you for the response. 
      Variables are only applicable to API tests, at least from my understanding.
      For UI tests how can we create a main script that uses data from previous steps to determine which sub-scenario to execute?

      Kind regards,

  • Humashankar's avatar
    Humashankar
    Champion Level 2

    Hi BGomes 

    While LoadNinja currently lacks direct if-then-else functionality and strong variable handling in UI tests, modeling challenges for dynamic test flows, you can also try other options as stated below,

    Leverage CSV or Excel files to store input values and expected outcomes, iterating through data sets to execute test steps based on current row data and it is all part of Data-Driven Testing.

    Extract dynamic UI values using JavaScript and store them in variables, then implement conditional logic within code blocks to control subsequent test steps with the help of JavaScript Code Blocks

    Regards