Preface

Selenium is one of the most robust and comprehensive solutions in browser automation. This thing has 2 main branches:

  • IDE
  • WebDriver

WebDriver (and formerly, RemoteControl) is used in conjunction with Selenium libraries to control either a clean browser instance directly or any browser instance through (remote) Selenium Server. Some scarce information about WebDriver can be found in APS documentation.

IDE is a Firefox-only addon (FF 30+ is recommended) that uses its own set of commands (although reminiscent of those of Selenium libs) to automate actions in the browser it's installed in.

This KBA will only discuss IDE.

What is a test?

A test, in the context of this article, is an action sequence that is created to achieve some goal. Unlike test in the general sense, our test may not check any functionality, it may simply automate several repetitive actions.

Actions in a test might include something like:

  • Click a link or a button
  • Type a text into text field
  • Check a check box

Why is this needed?

Tests may help automate repetitive tasks that have to be carried out many times. Such tasks may include:

  • Package deployment (PCP resource creation, RT creation or subscription provisioning)
  • CCP/MyCP UI testing
  • Package removal
  • Just about anything you can come up with!

Bottom line is that if you are doing something through the browser many times, you are better off automating it.

How do I start?

Download latest IDE addon from Selenium downloads page. As of this writing, 2.9.0 is the latest.

When you are done, an icon with letters Se will be shown either on your Firefox toolbar or in a hamburger menu (you may want to drag it onto the toolbar).

Pressing this button wil launch the IDE.

Note: Installing the IDE will most likely install Formatter addons as well. If you like to keep your browser clean, they are safe to remove and are not needed for APS testing:

Note: By default, IDE is pretty limited in terms of flow control (like branches or conditionals). I would recommend installing the extension for IDE which introduces commands like gotoif gotoLabel and label. You can download this extension user-extension.js. You need to place it somewhere locally and then set a path to it in Options > Options > General > Selenium Core extensions (user-extension.js) in IDE.

How do I create tests?

When first opening IDE you will be presented with an empty test case in an empty test suite.

Unlike WebDriver, IDE has a useful feature that allows it to record user's actions as they do it in their browser. Here is a quick IDE UI breakdown:

For a full description of elements on this UI, refer to Selenium IDE docs [1] at the end of the article.

When you press the record button, each action you make in any browser tab will be recorded and added to the current test case (they will appear in test case panel):

Note: Selenium tries to record every action you perform. However, it may sometimes make mistakes in its interpretation of your actions. Example: you may click a link because it says Instances (translated to command: clickAndWait("link=Instances")), Selenium may record this action as Press the 4th link on the page in a specific place (translated to command: clickAndWait("css=#somediv > a:nth-child(4)")). In these cases, you may manually select from a few available alternatives:

Note: When recording, Selenium inserts commands above the selected row in the test case panel. If you accidentally move the selection somewhere other than the bottom, you may get unexpected results (your actions will be added in the wrong place). Always keep an eye out for which row is selected in the test case panel.

In some cases, Selenium may not properly register the necessary action on its own (like what time to wait for availability of elements on the page). In this case, you will need to add the proper commands manually:

Adding commands manually requires basic understanding of Web Technologies (DOM events, page lifecycle and readiness events and frames/iframes). Sometimes, it is best to find a test which already performs the function you need instead of trying to search for the solution yourself. Examples of such tests may be found at the bottom of this page. In addition to that, KBAs with APS Applications product may include such tests in attachments.

In OSA, a general window with APS UI looks like this:

In this picture, there are 4 frames in total (with their respective DOM/JS names). Whenever you click a link in the leftFrame, mainFrame will refresh its contents (most of the time). aps2-ui frame is the one where APS custom JS UI resides. Notice how tabs on the picture are not part of the APS UI and instead are generated by OSA navigation engine. You can also see that the Screen ID shows the ID directly from package APP-META.xml when we are on the APS UI screen.

Billing follows the similar structure, but so far there are no APS frames there (so there are only 3 frames).

One of the biggest challenges of creating tests is to get IDE to wait for the page to be fully loaded before starting to execute actions (failing to do that will cause commands to fail as well because elements will not be present). Commands that may help in this:

  • waitForElementPresent
  • waitForVisible
  • clickAndWait

Information about what this commands do is accessible from within the IDE itself (as shown on the picture above: Reference tab)

The other challenge is to properly select the frame which holds the element you are trying to affect (click/edit, etc.). Sometimes browsers will preserve the current frame and therefore you may not be able to access the elements you expect (all locators are relative to currently selected frame). Relevant commands:

  • selectFrame
  • selectWindow

As you will get better at this task, you may want to spot and remove unused actions from your tests that are sometimes left after recording (Selenium will, for example, record 2 commands when interacting with a dropdown menu: one is select, which is correct, and the other is click, which is useless and can be omitted). It is a good practice to keep your tests as minimal as possible, because failing unused commands will cause test case to fail and stop.

How do I save tests?

To facilitate sharing and retention of tests, IDE comes with built-in save feature. In addition to saving singular test cases, you can also save a bunch of tests by saving a whole test suite. IDE stores tests in HTML format.

Note: You can rename tests through the test suite panel by right-clicking them and choosing Properties.

How do I run tests?

When you have opened a test case or a test suite, you can use one of the IDE controls to play either the whole suite one-after-another or a single test.

The test will start to execute on the current active browser tab. When it runs, it will mark successful steps with the green color and failed ones with the red.

Critical failures will cause the test to stop executing. After the test stops executing (through failure or success), its status will show up in the test stats section:

The log at the bottom of the window will be filled with messages as the test progresses:

In this log, you can find causes of errors, should they appear.

Related links:

Note: Use Save As browser command to save HTML files for opening in IDE instead of directly opening them in browser.

Internal content