0

In Web Application :

There is Single Page having Different Sections/Partitions Each section Retrieves the Data with the Help of Filter Query.

If there is no matching Result, Section will Send below Request only : Request 1: domain/search/jobs/csuser__search2_1413357426.1559

If the Query returns any matching Result, Section will Send below Two Requests: Request 1: domain/search/jobs/csuser__search2_1413357426.1559 Request 2: domain/search/jobs/csuser__search2_1413357426.1559/results_preview

How can I manage Request 2, which may or may not occur with each run.

Currently I am manually Recording entire Network calls, Removing unnecessary ones & running it for 'N' Loop Count. How can I make sure while test is runing if any section has matching results Request 2 Should also be taken care which I might not have benn recorded on my first execution.

Unnati Shukla
  • 342
  • 3
  • 15

2 Answers2

0

You can use combination of Beanshell PostProcessor and If Controller to work it around as follows:

  1. Add a Beanshell PostProcessor as a child of the Query request
  2. Put the following code into the PostProcessor's "Script" area:

    int length = prev.getSubResults().length;
    if (length > 1) {
        String path = prev.getSubResults()[length - 1].getURL().getPath();
        if (path.contains("results_preview")) {
            vars.put("resultPresent", "true");
        }
    } else {
        vars.put("resultPresent", "false");
    }
    
  3. Add an If Controller after the request

  4. Depending on your scenario put on of the following conditions to If Controller's "Condition" input
    • ${resultPresent}==true - children will be executed if the query returns results
    • ${resultPresent}==false - children will be executed if the query doesn't return anything matching

Beanshell code does the following:

  • check how many requests were executed
    • if there were more than 1 requests, path of the last request is extracted
      • if path contains "results_preview" variable resultPresent is being set with the value of "true"
    • if there was only 1 request then resultPresent variable is false

References:

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

As Dimitri said. The processor should run after (post) request 1. The if controller will then act on the results of the processor. Section two is only run when the condition is not "false".

CharlieS
  • 1,432
  • 1
  • 9
  • 10