Background Script Rule

The Background Script rule is one of the rules you can apply when you generate a web virtual user (VU) script from a recording in Eggplant Performance Studio using the Generation Rules wizard. On the Background Script Rule page in this wizard you can specify the parameters of the background script that is started or stopped instead of the requests that form the background script's web traffic. Background Script Rule Page below provides detailed information about this page. For information about background scripts, see Background Scripts.

How the Background Script Rule Works

The following diagram illustrates how the Background Scripts rule works:

Background Script rule diagram in the Rules Generation wizard

Example Script Code Changes (Java)

The following example code shows the effect of applying a Background Script rule:

Url url1 = new Url(protocol1, server1, "/ajax/Timer");

try (Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1))

{

request1.setHeader("Dnt", "1");

....

 

try (Response response1 = request1.send())

{

....

}

}

 

Url url2 = new Url(protocol1, server1, "/ajax/Timer");

try (Request request2 = getWebBrowser().createRequest(HttpMethod.POST, url2))

{

request2.setHeader("X-Requested-With", "XMLHttpRequest");

....

 

try (Response response2 = request2.send())

{

....

}

}

Changes to the following:

Url url1 = new Url(protocol1, server1, "/ajax/Timer");

try (Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1))

{

request1.setHeader("Dnt", "1");

....

 

try (Response response1 = request1.send())

{

....

}

}

 

createBackgroundScript(

"TriggerTimer",

"com.testplant.testing.backgroundScriptJava",

AutomaticStopCriteria.StopImmediatelyAtEndOfIteration,

EnumSet.of(ExecutionFlags.Loop, ExecutionFlags.LongRunningScript),

Duration.ofMillis(16032),

Duration.ofMillis(2004));

Rules

The code example above uses the following Background Script Rule options:

Fully qualified script class name: "com.testplant.testing.backgroundScriptJava"

Script Id: "TriggerTimer"

Execution Parameters: Execute script repeatedly in a loop with Pause between script loops: 00:00:16:032

Stop criteria: Stop background script automatically: "Stop Immediately At End Of Iteration"

Advanced options: Overwrite VU group's automatic stop timeout: Custom: 00:00:02:004

Filter

Filter by: Request header: Header name: "X-Requested-With" and Header value: "XMLHttpRequest"

The code removed from the main script, highlighted in red above, is placed into a background script. For this example, the following code is placed into the backgroundScriptJava background script:

void Action1()

{

Url url2 = new Url(protocol1, server1, "/ajax/Timer");

try (Request request2 = getWebBrowser().createRequest(HttpMethod.POST, url2))

{

request2.setHeader("X-Requested-With", "XMLHttpRequest");

....

try (Response response2 = request2.send())

{

....

}

}

}

After the call to the backgroundScriptJava script occurs, the script starts and runs in the background. It runs in parallel with the main script.

For information about these options see Background Script Rule page below.

Generation Rules Wizard Pages

The pages you see in the Generation Rules Wizard vary depending on the type of rule you select and whether you are creating a new rule or editing an existing one. Following are the pages you see when you create or edit a Background Script rule.

Select the Rule Type Page

The first page you see when you create any new rule in the Rules Generation Wizard, is the Select the rule type page shown below.

Select a Rule Type page with the Background Script rule selected in the Rules Generation Wizard

Select Background Script from under Miscellaneous Rules in the Rule Types pane on the left. The diagram on the right changes to display an explanation of how the Background Script rule works. The same diagram is shown at the top of this page.

Background Script Rule Page

The second page you see when you create a Background Script rule in the Rules Generation Wizard is the Select a background script page shown below.

The Background Script Rule page in the Rules Generation wizard

Provide the following information in the Select a background script page:

Insert a call to create and start this background script when the first request belonging to this rule filter is made (the filter is described on the next page): This option is enabled by default. You can deselect it to prevent a background script being started at all, only the requests will be removed.

Fully Qualified Script Class Name: Specify the name of the background script class, preceded by the package/namespace, for example, com.testplant.testing.MyBackgroundScript.

If this script doesn't exist within the project, it will be created with the appropriate package/namespace. For example, entering com.example.myScript will create a script called myScript in the package/namespace com.example when the main script is generated.

Script ID: The ID that can be used to refer to the background script within any scripts in the virtual user's (VU's) workflow.

Execution Parameters: Specify whether you want to call the background script's script() method once or repeatedly in a loop, and for loops whether to pause in between.

Stop criteria: Specify one of the following options:

  • Insert a call to stop this background script after the last request belonging to this rule filter is made (the filter is described on the next page): This option inserts StopBackgroundScriptImmediately(ID) at the point where the last request would have been sent.
  • Stop background script automatically: This option specifies to pass the AutomaticStopCriteria to the CreateBackgroundScript method.

Advanced Options

Create the background script but do not start it automatically: This option inserts the ExecutionFlags.JustCreate flag, so you must add a call to the startBackgroundScript(ID) method.

Override VU group's automatic stop timeout: This option only affects the background script that is started by this rule. If the background script is still running when it is supposed to stop, then this value can be used as a timeout. It is a temporary override for the value on the runtime settings on the Group Specifications tab.

Create Request Filter Page

The third page you see when you create a Background Script rule in the Rules Generation Wizard is the common Create Request Filter page.

Specify which requests to exclude from the main script on the Create Request Filter page. These requests are not automatically included the background script, you must write that yourself. See the Create Request Filter for more information.

Rule Name Page

The fourth page you see when you create a Background Script rule in the Rules Generation Wizard is the common Rule Name and Summary page.

Enter a name in the Rule name box, and a summary in the Summary box if you want. See the Rule Name and Summary page for more information about naming your rule and finishing the wizard.

 

This topic was last updated on January 13, 2022, at 02:42:23 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant