OpenClinica User Manual/SeleniumTasks

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Introduction[edit | edit source]

Sometimes you might need to perform an action in OpenClinica over and over again, and sometimes there isn't a built-in feature to help with that. Apart from being tedious, it can be a problem keeping track of where you are up to and avoid mistakes. At some point it is worth investing the time in automating the action.

Automation can be achieved by using a testing tool called Selenium. The Selenium IDE is available as a Firefox plugin. The examples discussed below also use the sideflow add-in, which allows flow control that would otherwise require use of a Selenium WebDriver. The IDE has the advantage of being able to record an action as a script (similar to the MS Office 'record macro' feature) which is helpful when getting started.

The following sections describe Selenium scripts (aka. test cases) which can be used with OpenClinica. The OpenClinica UI changes occasionally so if you are using a different version they may not work properly e.g. if the scripts don't correctly identify elements on the page any more.

As always, develop / test in a test instance before running a script in the live / production instance.

Remove Rules[edit | edit source]

OpenClinica rules can only be removed one at a time. The scripts discussed in this section facilitate bulk removal, using a single filter or many filters. Filters can be set using the Manage Rules table, which constructs a filter URL, which is what the scripts use.

So log in to OpenClinica, go to Manage Rules, put in the filter criteria for the rules you want to remove, apply the filter, and copy the URL. The URL needs to be html encoded (e.g. & -> & amp;), which Selenium will do for you if you paste it into the IDE, or you could encode manually, or use the XML Tools plugin for Notepad++, etc.

These scripts were written with OpenClinica 3.1.3.1. Before running them, log in to OpenClinica and change into the study you want to remove rules for.

Single Filter[edit | edit source]

This script is designed for removing rules meeting a single filter.

When getting the filter rule, make note of how many rules meet that filter criteria, as that number will be used to help stop the script. It would otherwise stop when it fails to activate the 'remove rule' button which would not be there if there are no rules left meeting the filter criteria.

  1. Insert target run number at line 31
  2. Insert filter URL at line 41

The test case will go to the filter address, delete the rule at the top, and repeat this however many times you set your target_run. Obviously this will hammer your server a bit so probably best to only do it when other users won't be using OpenClinica.

Once the test case has finished, the Selenium IDE will say 'Deleted x of y rules' in the log pane. If it otherwise ran out of rules because you set the target_run too high, the test case result should be 'fail'.

Many Filters[edit | edit source]

This script is designed for removing rules meeting a series of filters, which is an alternative to making a suite of many 'single filter' test cases.

In this case, only the relevant part of the filter URL is required, for example for a filter for the rule OID of 'RULE01', the important part of the URL is '&ruleAssignments_f_ruleOid=RULE01'. More than one of these can be done at once, separated by a comma (so, filter can't include commas). For example, to remove rules with a rule OID of 'RULE01', as well as rules that have both a rule OID of 'RULE02' and target the item 'I_ITEM01', you could use a filter string of:

&ruleAssignments_f_ruleOid=RULE01,&ruleAssignments_f_ruleOid=RULE02&ruleAssignments_f_targetValue=I_ITEM01

This script identifies the number of rules meeting each filter for you, so there is no target run number required. However you do need to specify the OpenClinica instance URL.

  1. Insert instance URL at line 26
  2. Insert filter(s) string at line 41

The number of rules deleted is echoed in the log once the test case is complete.

CRF Version Migration[edit | edit source]

OpenClinica CRFs can only be migrated to a new version one at a time (feature added in 3.1.3). This script facilitates bulk version migration, for a specified Event, CRF and target CRF version.

This script was written with OpenClinica 3.3. Before running the script, log in to OpenClinica and change into the study you want to migrate CRFs for.

  1. Insert name of Event containing the target CRF at line 29
  2. Insert target CRF name at line 34
  3. Insert CRF version to migrate to at line 39
  4. Insert instance URL at line 44
  5. (Optional) modify target CRF status(es) at line 306. The default is to migrate CRFs that have the status 'Initial Data Entry' or 'Data Entry Complete'.