1. Prepare your environment
  2. Install Kantu Selenium IDE
  3. Record a script using Kantu
  4. Test the script in Kantu
  5. Troubleshoot script issues using Kantu
  6. Revise the script as necessary
  7. Copy the script to APM
  8. Test the script in APM
  9. Declare variables
  10. Use variables in the script
  11. Specify milestones
  12. Save the workflow
  13. Run the script on a monitoring point
  14. Maintenance
  15. Commonly used Selenium commands
  16. Additional resources
  17. Examples
    1. Login to APM example
    2. Wikipedia example

Use the Selenium scripting language to create scripts used for Experience monitoring. The “Selenese” commands can be entered manually or generated automatically using a 3rd-party script recorder such as Kantu for Chrome (Selenium IDE Lite). Kantu’s Selenium IDE Lite is a Chrome extension that creates Selenium scripts by recording your mouse clicks and key strokes as you interact with a web application - just like recording a macro. At a high level, the steps are: start the recorder, interact with your app, stop the recorder, then test the script created and revise it if necessary.
As recording a script is just a starting point, it is likely that, once recorded, you will need to revise it. In particular, you may need to manually add waits, assertions, or tests. For example, adding a command that waits for something to load, or checks that a certain label exists, or checks that something is visible. Once you are happy with the script, copy it from the recorder to the appropriate web app group workflow in APM and preview the script execution on a monitoring point.
The following steps describe how to use Kantu (V2.3.0) to record your scripts. The steps are similar with other script recorders. Scripts can also be created manually within APM at Experience > Web App Groups > Configure > Workflows….

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.

Install Kantu Selenium IDE

Use the Kantu Selenium IDE Chrome extension to create and test Selenium scripts. This step only needs to be done once.

To install the Kantu Selenium IDE:

  1. Open the Chrome browser.
  2. Go to the Kantu Selenium IDE homepage.
  3. Follow the Kantu Selenium IDE download link.
  4. Click Add to Chrome.
    • The extension is loaded into Chrome.

Record a script using Kantu

Before recording, take some time to plan your steps through the app, and the results you expect to see from it. Start out small. Record a few lines and verify that they play back successfully before moving on.

To record a script using Kantu:

  1. Open the Chrome browser.
  2. Navigate to the target URL (the URL of the web app you are creating the script for).
  3. Click the Kantu Browser Automation icon on the top right of the Chrome browser.
  4. Click + Test Case.
    • A blank “Untitled” test case is created.
  5. Click Record to start recording.
  6. Execute the planned workflow at the target URL.
    • Confirm that your actions are being recorded in Kantu.
    • If an action can’t be recorded, move on and deal with it in the troubleshooting phase.
  7. Click Stop Record to stop recording.
  8. Click Save.. to save the recording.

Test the script in Kantu

Once the script is recorded, play it back to make sure there are no errors.

To play the script in Kantu:

  1. Click Play Macro.
    • You will see the script executing the recorded commands in the Chrome browser.
    • The Logs tab shows the commands being executed.

Troubleshoot script issues using Kantu

Use the Logs tab at the bottom of Kantu to review any error messages. Update the script accordingly and play it back again until there are no errors.

Common errors include:

  • Using a link that opens in a separate tab.
    • Use AppNeta-specific Selenium command “selectActiveWindow” to switch script execution to the new tab.
  • A target element is not found.
    • Confirm that you have not used a dynamically generated id or name attribute to identify an element.
    • Things to try:
      • Right-click the problem element in the Chrome browser and select Inspect to determine how best to identify the element. There are a number of ways to identify an element:

Contact AppNeta Customer Support if you are having difficulties.

Revise the script as necessary

If you need to add commands to pause script execution or to test for things like the visibility or existence of various page elements, this is done by manually entering commands in the script.

To add a command to the script:

  1. Right-click the command above the one you want to insert and click Insert new line.
  2. In the Command field, select the command you want to add.
  3. In the Target field, enter the locator that identifies the target element the command is to act on.
  4. In the Value field, enter a value required by the command (if applicable).
  5. Click Save.

Continue to revise the script and testing it as necessary to confirm that it behaves as expected.

Copy the script to APM

In order to run the script from your monitoring points, you need to copy it to the workflow of a web app group in APM.

To copy the script to APM:

  1. In Kantu, right-click the script you recorded and select Export as HTML (old).
  2. Click the exported HTML file.
    • In your browser you will see a table with the commands on separate rows.
  3. Right-click the page and select View Page Source.
    • The HTML source appears.
  4. Copy all the HTML source on the page.
  5. Log in to APM.
  6. Change organization to the one you want to use.
  7. Navigate to Experience > Web App Groups.
  8. Click Configure for the web app group you are creating the script for (create a web app group if necessary).
  9. In the Workflows… pane, click the edit icon next to the workflow are creating the script for.
    • The Edit Workflow page opens.
  10. In the Script section, select Selenium Script.
  11. Click the Source tab.
  12. Remove any existing code and paste in the script you recorded.
  13. Click OK.
  14. Click Save.
    • The script is now loaded in APM.

Test the script in APM

Before leaving the script to run, you should test that it is working properly from a monitoring point as scripts that work in Kantu may not work in APM.

To test the script in APM:

  1. Navigate to Experience > Web App Groups.
  2. Click Configure for the web app group containing the web path you are testing.
  3. In the Workflows… pane, click the edit icon next to the workflow you want to edit.
    • The Edit Workflow page opens.
  4. In the Preview section, select a monitoring point and a target.
  5. 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.
    • Any Selenium commands not supported by APM are flagged.

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}”.

Specify milestones

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 script is copied to APM, milestones are 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.

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.
    • The script source appears in a separate tab.
  2. Copy the script source.
  3. Follow the steps above from Copy the script to APM using the script you’ve copied (rather than the one from Kantu) and the other information included in the example.

Login to APM example

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

Wikipedia example

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