Table of Contents

IDE Script Editor

Script Editor allows you to create and edit MScript (groovy script). Plugins may be activated for the model to add specialized functions to interact with AUT or automate processes.


Editor Overview

Script Editor is a source code editor with:

The tool pallet on the upper-right corner of the editor gives you quick access to common editor features.

The info mini-button i gives more detailed information on these editor features.

Click P to open a dialog to activate Plugins for the model.


Code Assist

Code assist is supported on system functions and plugin functions, which includes your own custom plugins.

Code assist can be opened with Ctrl-Space in one of the following:


Plugins

Plugins extends the capability of TestOptimal to perform specialized operation. They are java class that implements a set of functions to be exposed to Script editor.


MScript Types

There are 4 types of MScript:

Except User Script, all scripts are automatically created when the model is created. All scripts can be left blank.

All scripts are executed as model executes.


TRIGGER Script

TRIGGER Script is a collection of TRIGGER to be executed when a state or transition is traversed during model execution.

A TRIGGER is an annotated groovy function. It must be declared with the annotation as show below:

 @TRIGGER('U1062')
 def 'state name' () { 
 
 }

where U1062 is the unique id assigned to the state or transition.

Types of TRIGGER

Besides TRIGGER for state and transition, there are system defined TRIGGER to help with initialization and error handling. These TRIGGER types are:

Create TRIGGER

To create a TRIGGER, press Ctrl-I on a blank line and select the desired TRIGGER type or a state / transition. The TRIGGER script is inserted into the editor.

The groovy function name for TRIGGER is populated with the state name and transition name. You may change the groovy function name if you desire. But do not change the UID field in the annotation line.

When the state and transition names are changed after TRIGGER is created, you must manually edit the groovy function names to match if desired.

Trigger List

Listing of states and transitions that have TRIGGER script created. Click on the state and transition to quickly scroll to the script.


PAGES Script

PAGES Object is a technique commonly used in UI automation.

PAGES Script is the place to declare page objects. A page consists of elements and functions that can be performed on the page.

Add appropriate import statements at the top of the script:

 import org.openqa.selenium.By;

Create Page Objects

Use the following script to create a new page object:

 page1 = $PAGE.addPage('MainPage')

Add Page Actions

Pages may contain one or many page actions. Page actions are groovy functions and must be declared with one parameter page.

Use the following script to add a page action to a page:

 page1.addAction('getPageSource', { page ->
    $EXEC.log('Getting page source for: ' + page.getName());
    $VAR.webdriver.findElement(By.tagName('body')).getText();
 })

assuming that $VAR.webdriver has been assigned to WebDriver object that you have created.

Add Page Elements

Pages may contain one or many page elements.

Use the following script to add a page element to a page:

 loginElem = page1.addElement('loginID');

Add Element Actions

Elements may contain one or many element actions. Element actions are groovy functions and must be declared with two parameters: elem and params, where params is an optional array of objects you would pass in when you call the action from TRIGGER Script.

Use the following script to add an element action to an element:

 loginElem1.addAction('click', { elem, params ->
   $EXEC.log('Clicking on element ' + elem.getName() + ' on element locator: ' + elem.getLocator());
   $VAR.webdriver.findElement(elem.getLocator()).click();
 })

Usages / Examples

Pages, elements, actions can be called from TRIGGER Script. Below are a few examples:

 @TRIGGER('U1062')
 def 'Start' () {
    $EXEC.log('Page Source is: ' + $SYS.page('MainPage').perform('getPageSource'));
    $PAGE.page('MainPage').element('loginID').perform('click');
 }

STEPS Script

STEP Script enables Behavior Driven Development (BDD) scripting like Cucumber using natural language.

 @TRIGGER('U1062')
 def 'Start' () {
    >> Open Firefox browser
    >> Goto URL http://google.com
    >> Login with user id admin and password admin 
 }
 
 

Create Steps

Steps are annotated groovy functions as follows:

 @STEP('Goto URL {url}')
 def gotoURL (String url) {
    $VAR.webdriver.get(url);
 }
 
 @STEP('Login with user id {userid} and password {password}')
 def loginAs (String userid, String password) {
    $VAR.webdriver.findElement(By.id('loginid')).sendKeys(userid);
    $VAR.webdriver.findElement(By.id('password')).sendKeys(password);
 }
 
 

MCASES Script

MCASE Script is where MCase are defined.

Often times you may have a set of specific test scenarios you want to make sure are covered to complement the system generated test cases. You can achieve just that with MCase - a custom test case / workflow that you defined explicitly for the system to generate a sequence path from the model to achieve specific scenario.

Consider your model as a map to GPS, MCase is just a set of way points you want to visit. When you execute MCase, a sequence path (trip/route) is auto-generated from your model.

 $MCASE.addMCase('MCase 1').navigateToState('V75Cents').executeTransition('add50', { state -> $SYS.log('MCase 1')});
 $MCASE.addMCase('MCase 3').navigateToState('V50Cents').executeTransition('add25', { state -> $SYS.log('MCase 3')}).skipToState('End');

In additional to follow through path and execute the automation script (TRIGGER) along the path, you have the option to add additional automation/process script to be executed as illustrated in above example.


User Script

Besides TRIGGER Script, PAGES Sript, STEPS Script and MCASE Script, you may also add additional scripts.

To create a user script, click on “+”. You can rename the script by clicking on the pencil mini-button.

 //MyScript 
 def add (p1, p2) {
    return p1 + p2;
 }
 
 def multiply (p1, p2) {
    return p1 * p2;
 }

Calling User Script Functions

 
 @TRIGGER('U1062')
 def 'Start' () {
    $EXEC.log('adding 10 and 20: ' + $MyScript.add(10, 20));
    $EXEC.log('multiplying 10 and 20: ' + $MyScript.multiply(10, 20));
 }

Include File

You may include script file into your TRIGGER script. Just add the @INCLUDE_FILE below:

 @INCLUDE_FILE 'absolute file path to include file'

The above script will literally inject the content of the included file into current script before TRIGGER script is executed.

The side effect of using this INCLUDE_FILE is that the injected scripts will mess up the script line # reported on errors.


ShortCut Keys

Shortcut keys allow you to perform basic editor functions with a keyboard. Below is the list of the shortcut keys (Windows key in bold / Mac key in italic):

Except for Ctrl-R / Ctrl-I for windows and Cmd-R / Cmd-I for Mac, check out CodeMirror Commands for additional key mappings and details of mapped commands.