Documentation

Looking for something in particular?

Switch API

A Switch statement selects one of several alternatives based on the value of an integer, a character, or a string variable. Once a match is found, only the steps in that case will be executed.

  • The switch expression is evaluated once.
  • The value of the expression is compared with the values of each case.
  • If there is a match, the associated block of code is executed.
  • The break and default keywords are optional.

This Example will use Switch API to create an Account or Case based on user action.

  1. Click on drop-down a “Set Value” from a Test Palette into your test case and Update the following parameter: Value: The value to switch on the case (In our scenario, it will be “Account” or “Case”).
  2. Select a Switch API from the Test Palette and set the Value as {$Action}. This Value is a variable which we set in just the above step. So it will fetch that Action Value to Switch.
  3. Add Case Clause and Default from right-click on the Switch Step and add.
  4. In the first Case Clause add the object name you want to make. And In the second add the second object name you want to make. In this case, it is Account and Case.
  5. Drag the Account API from the Metadata section under the first Case Clause and set it as a Create Object Step.

    Fill up the details to create an object. Similarly, do this with Other Objects with respective to case clauses.

  6. Add a Break API from the Test Palette right down Create Object Step. Also, do this for other clauses as well.

When Provar execution reaches a break keyword, it breaks out of the switch block. This will stop the execution of case testing inside the block. When a match is found, and the job is done, it’s time for a break. There is no need for further execution inside the block.

  1. Drag a set value under a Default, and add your desired message in that field.The default keyword specifies steps to run if there is no case match. Save the test case and run it.

Note:  If the break statement is not applied in the matching clause then default will execute(If there is a match also). Example: When the break is not applied.

After Successfully Running the test case.


Feedback

Was this article helpful for you?
Documentation library

Trying to raise a case with our support team?

We use cookies to better understand how our website is used so we can tailor content for you. For more information about the different cookies we use please take a look at our Privacy Policy.

Scroll to Top