1. Prepare your environment
  2. Create a script
  3. Test the script
  4. Declare variables
  5. Use variables in the script
  6. Edit milestone names
  7. Save the workflow
  8. Run the script on a monitoring point
  9. Maintenance
  10. Commonly used Selenium commands
  11. Additional resources
  12. Examples
    1. Wikipedia example
    2. Login to APM example

You can use the Selenium scripting language to create scripts for Experience monitoring. If you are new to scripting, an easy way to familiarize yourself with the workflow is to load one of the example scripts, test it in APM, let it run on a monitoring point, and then view the results. Once you have done this, try making changes to the script from within APM and test the changes. As you progress, check out Identifying Web Elements to help you specify web elements for use with Selenium commands. If you run into difficulties, check out Resolving Common Issues and Selenium Pop-up Handling. Once you start to create scripts from scratch, you can continue to use the APM script editor or, as an initial step, use a 3rd-party script recorder such as Kantu for Chrome (Selenium IDE Lite) to record your interactions and automatically generate a Selenium script. Keep in mind that it is typically necessary to modify the generated script to make it more robust.

The procedure for creating a Selenium script is as follows:

Prepare your environment

There are several points you should consider before you start scripting:

  1. Use Chrome for testing - Since the monitoring point uses Chrome to execute the script, it is best to use Chrome when creating the script.
  2. Script against the target URL - During script creation, make sure that you script against the same version of the site that the monitoring point will access when it runs the script.
  3. Script against an accessible target - Remember that the script you create will be run on a monitoring point and it needs to be able to access the target.
  4. Obtain the login credentials - We recommend that you set up a dedicated account for the script to log into the application being tested. Give it the minimal permissions required for your script to run.
  5. Use a clean browser - Remember that each time it runs, your script will be starting from a blank slate, so you’ll need to make sure the browser you are creating the script with is equally clean:
    1. Close all unnecessary tabs.
    2. Clear out your browser’s cache and cookies.
    3. Disable any plug-ins you don’t need or that could interfere with the script, particularly script blockers and ones that automatically enter text into fields, such as password managers.

The following additional points are recommended, but not compulsory:

  1. Plan ahead - As with any coding endeavor, it’s best to plan out what you’re trying to do ahead of time. Spend some time thinking about what you want to test, and what results you expect to see from it.
  2. Use two different browsers on two different monitors - Have the site you’re testing against open in Chrome on one monitor, and APM open in a different browser on another monitor. This ensures you don’t lose your work if the site you are testing against hangs or crashes Chrome. Also, you can restart Chrome and clear your cookies without affecting your APM session. While troubleshooting, perform an action on the Chrome monitor and observe the result. Then edit your code accordingly in APM on the other browser and monitor.
  3. IP address logging/alerting - If you log authentication requests, consider excluding alerts on attempts to authenticate from your testing workstation’s IP address and the public IP addresses of the monitoring points running the script. Not doing so can fill the log with unnecessary entries.

Create a script

To create a Selenium script you can use one of the example scripts provided, you can generate a script using a script recorder such as Kantu, or you can create a script manually.

Note: This step assumes that you have already created a web app group.

To create a Selenium script manually:

  1. Navigate to Experience > Web App Groups
  2. For the web app group you want to edit, click Configure.
  3. In the Workflows… pane, click to create a new workflow or click next to the workflow you want to edit.
  4. In the Name section, specify the workflow name.
  5. In the HTTP Authentication section, specify a valid Username and Password if required by the target web application.
  6. In the Script section, select Selenium Script.
  7. In the Script section, use the script editor to edit the script.
    • To edit a line of the script:
      1. In the Command field, select the command you want to use. See AppNeta-supported Selenium Commands for information on the supported commands.
      2. If required by the command, in the Target field, specify a command argument that defines what the command is acting on (for example, a URL, a filename, or a web element). See Identifying Web Elements for information on creating web element locators.
      3. If required by the command, in the Value field, specify a command argument that is not a target. Only a few commands require this (for example, type and assertText).
      4. A Milestone is automatically generated for each new page load.
    • To add a new line, click Add an action.
    • To delete a line, click the “X” icon to the right of the line you are deleting.
    • To move a line, drag the icon to the left of the line you are moving to where you want it moved.

Test the script

Once the script is created, you need to test it on a monitoring point.

To test the script:

  1. In the Preview section of the Edit Workflow page, select a monitoring point and a target.
    • The monitoring point should be one of those in the Monitor from… section of the web app group. The target should be one of those in the Monitor to… section of the web app group.
  2. Click Preview.
    • The script is sent to the monitoring point and queued for execution.
      • Be aware that, depending on monitoring point jobs currently queued and executing, the script may queued for several minutes before it is executed.
    • As the script executes, APM captures a screenshot approximately every second.
    • Confirm that the screen shots are what is expected and that the script completes properly with no errors.

Declare variables

If the script captured user credentials that have a password you do not want visible, you can declare a password variable to mask its value. Those variables declared as “password”, “passwd”, “pwd”, or “secret” have their values masked. All other variable names do not have masked values.

To declare a variable:

  1. In the Variables section of the Edit Workflow page, specify the variable name and value.

Use variables in the script

Once variables have been declared, they can be used in the script. For example, let’s assume a variable called “password” was created above.

To add a “password” variable to the script:

  1. In the Script section of the Edit Workflow page (with Selenium Script selected), click Table.
  2. Replace the actual password with “${password}”.

Edit milestone names

A milestone is automatically generated for each command that causes a page load. Having a milestone associated with each of these actions allows you to narrow down where a slowdown is occurring. Without timing data for each milestone, all you know is that the web app is slow.

A script can have up to 20 milestones.

When the milestone is generated it is automatically assigned to the appropriate commands. The milestone name is of the form “Milestone <number>: <description>” where the description is the command name, but this can be edited to provide a more meaningful name.

To edit the milestone name:

  1. In the Script section of the Edit Workflow page (with Selenium Script selected), click Table.
  2. In the Milestone column, edit the text as appropriate.
  3. Click OK.
  4. Click Save.
    • The changes are saved.

Save the workflow

If you have added variables or milestones you should use the Preview to retest and confirm there are no errors. Once this is done you can complete the process.

To complete the process, save the workflow:

  1. Click OK
  2. Click Save

Run the script on a monitoring point

Once the script is saved in APM, it is automatically downloaded to the monitoring point(s) associated with the web app group and is queued for execution. It takes some time (based on the test interval configured) to see test results.

To see the web path status:

  1. Navigate to Experience > Web App Groups.
  2. Select the web app group containing the script you created.
  3. The status is in the left column of the individual web paths in the web app group.
    • You can also click the web path for detailed test results.

Maintenance

For the script to continue to run without problems, the target environment must be stable. Some things to consider are:

  • Password expiry—Some web applications require new passwords periodically. Set a reminder to change passwords used in your scripts before they expire.
  • Web application changes—Changes to a web apps can cause your script to fail. Be sure to check that the script continues to run successfully when your web app changes.
  • Staging environment—Test against your staging environment as well as your production environment. This allows you to catch changes that affect script execution as well as to benchmark changes in application performance before it is run in production.

Commonly used Selenium commands

  • click/clickAndWait—Performs a click operation, and optionally waits for a new page to load.
  • open—Opens the specified URL.
  • type—Adds text to an input field, as though it was typed in.
  • verifyElementPresent—Verifies that the expected element is present on the page.
  • verifyTable—Verifies the contents of a table.
  • verifyText—Verifies that the expected text and its corresponding HTML tag are present on the page.
  • verifyTextPresent—Verifies that the expected text is somewhere on the page.
  • verifyTitle/assertTitle—Verifies the page title.
  • waitForElementPresent—Pauses execution until the expected element is present.
  • waitForPageToLoad—Pauses execution until the expected new page loads. Called automatically when clickAndWait is used.

See AppNeta-supported Selenium Commands for information on the supported commands.

Additional resources

Examples

The following examples can be used within APM.

To use the examples below:

  1. Click the Script link in the example you want to use.
  2. Right-click and select View Page Source.
    • You will see the HTML source for the script.
  3. Copy the script source.
  4. Follow the steps above (from Create a script) but, rather than entering the commands manually, click the Source tab in the Script section of the Edit Workflow page, remove any existing code, then paste the copied script. Use the other information included in the example (i.e., Target URL and Variables) as appropriate in the steps that follow.

Wikipedia example

Target URL: https://en.wikipedia.org
Script: Wikipedia example

Login to APM example

Target URL: https://login.appneta.com
Variables: username, password
Script: APM login example