Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
tutorial:scripting_state_model [2020/07/17 20:19] admin [Tutorial: Automation Scripting - State Model] |
tutorial:scripting_state_model [2020/11/24 22:00] admin [Activating plugins] |
||
---|---|---|---|
Line 9: | Line 9: | ||
* [[# | * [[# | ||
+ | This tutorial assumes that you are able to create a simple // | ||
===== Model scripting ===== | ===== Model scripting ===== | ||
Line 24: | Line 25: | ||
| | ||
def MBT_Start () { | def MBT_Start () { | ||
- | $SELENIUM.setBrowserChrome (); | ||
$SYS.log ('mbt started. '); | $SYS.log ('mbt started. '); | ||
| | ||
Line 30: | Line 30: | ||
| | ||
def ' | def ' | ||
- | $SYS.page('MainPage' | + | $SYS.log('State Start, transition addQuarter'); |
- | bal = $SYS.page(' | + | |
- | if (bal.equals(' | + | |
- | passMsg = " | + | |
- | $SYS.addReqPassed(" | + | |
- | } | + | |
- | else { | + | |
- | | + | |
- | | + | |
- | } | + | |
} | } | ||
- | You will need to following import to the beginning of the script for the trigger annotation keyword: | + | You will need to add following |
| | ||
- | The above examples uses // | ||
- | + | Besides triggers, scripts are also used for building UI Page Objects, Cucumber style test step definition and MCases, which are out of scope of this tutorial. Please refer to [[../ide_script | Script Editor]] | |
- | Besides triggers, scripts are also used for building UI Page Objects, Cucumber style test step definition and MCases. | + | |
===== Model triggers ===== | ===== Model triggers ===== | ||
Line 74: | Line 63: | ||
| | ||
def ' | def ' | ||
- | $SELENIUM.setBrowser ($SYS.getExecDir().getExecSetting().getOption(' | ||
$SYS.addTestOutput('< | $SYS.addTestOutput('< | ||
$SYS.addTestOutput('< | $SYS.addTestOutput('< | ||
Line 84: | Line 72: | ||
$SYS.addTestOutput('</ | $SYS.addTestOutput('</ | ||
$SYS.saveTestOutput(' | $SYS.saveTestOutput(' | ||
- | } | ||
- | |||
- | | ||
- | def ' | ||
- | // Failure detected | ||
- | $SELENIUM.snapScreen('' | ||
} | } | ||
| | ||
def ' | def ' | ||
+ | $SYS.log(' | ||
} | } | ||
| | ||
- | | + | def 'State_1' () { |
- | $SELENIUM.getWebDriver().get('http:// | + | $SYS.addTestOutput('< |
- | $SYS.page('MainPage' | + | $SYS.addTestOutput('< |
- | bal = $SYS.page(' | + | |
- | if (!bal.equals(' | + | |
- | | + | |
- | | + | |
- | } | + | |
} | } | ||
| | ||
- | def 'Start: add25'() { | + | def 'State_1: trans_A'() { |
- | $SYS.addTestOutput('< | + | $SYS.addTestOutput('< |
- | + | ||
- | $SYS.addTestOutput('< | + | |
- | $SYS.page(' | + | |
- | bal = $SYS.page(' | + | |
- | if (bal.equals(' | + | |
- | passMsg = " | + | |
- | $SYS.addReqPassed(" | + | |
- | } | + | |
- | else { | + | |
- | failMsg = " | + | |
- | $SYS.addReqFailed(" | + | |
- | } | + | |
} | } | ||
+ | |||
+ | Feel free to add any additional scripts you wish. | ||
+ | |||
+ | Once scripts are completed, run the model and inspect the output file " | ||
+ | |||
+ | |||
- | | ||
- | def ' | ||
- | $SYS.addTestOutput('< | ||
- | |||
- | $SYS.addTestOutput('< | ||
- | $SYS.page(' | ||
- | bal = $SYS.page(' | ||
- | if (bal.equals(' | ||
- | passMsg = " | ||
- | $SYS.addReqPassed(" | ||
- | } | ||
- | else { | ||
- | failMsg = " | ||
- | $SYS.addReqFailed(" | ||
- | } | ||
- | } | ||
===== Activating plugins ===== | ===== Activating plugins ===== | ||
Line 148: | Line 104: | ||
After the plugins are activated for the model, the plugin IDs are automatically added to the code-assist popup list (// | After the plugins are activated for the model, the plugin IDs are automatically added to the code-assist popup list (// | ||
- | {{wiki:idescreen:ide_script_ca.png? 100}} | + | {{wiki:overview:tut_state_model_scripting_plugin.png? 100}} |
+ | Go ahead and activate [[../ | ||
+ | For example: | ||
- | ===== User and environment | + | |
+ | |||
+ | For test automation, for example web application you would activate // | ||
+ | |||
+ | For example: | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | ===== User variables ===== | ||
- | ==== User Variables ==== | ||
The variables that you created/ | The variables that you created/ | ||
Line 174: | Line 140: | ||
} | } | ||
- | ==== Environment Variables ==== | ||
- | // | ||
- | // | ||
- | ENV.var1=value1 | + | ===== Assert and track requirements ===== |
- | ENV.var2=value2 | + | It's the responsibility of your scripts (TRIGGERS) to check and validate that AUT is behaving correctly. Your script does this by checking elements on AUT through //plugins// functions and assert that AUT elements have the expected values. |
- | They can be updated/set by script via //$SYS.setEnvVar(...)//, | + | For simplicity sake, we will just use a random number generator to simulate the values from your AUT and use that to demonstrate how to perform the assertion and tracking the requirements. |
- | $SYS.setEnvVar(' | + | The assert and tracking requirement are done with one of the two $SYS functions: |
- | The new value is saved back to // | + | |
- | | + | * $SYS.assertFalse (' |
- | // | + | |
- | $SYS.log("ENV variable var1=" + $SYS.getEnvVar('var1')); | + | where ' |
+ | |||
+ | As example, the following script will assert random number is greater than 5: | ||
+ | |||
+ | $SYS.assertTrue | ||
+ | |||
+ | You may also perform check with if/else and then raise the defect explicitly, for example: | ||
+ | |||
+ | if ($RANDOM.randNum(0, | ||
+ | | ||
+ | } | ||
+ | else { | ||
+ | $SYS.addReqFailed (' | ||
+ | } | ||
+ | |||
+ | The requirement ' | ||
+ | |||
+ | Add your own script to perform assertion and requirement tracking to the model TRIGGERS, re-run the model, and check [[../ | ||
- | |||
- | ===== Assert and track requirements ===== | ||
===== Initialization scripts ===== | ===== Initialization scripts ===== | ||
+ | Often times you may want to pass some configuration settings to your model scripts, for example, the AUT url which might change depending on if you are running your model against your development environment or QA environment or for this tutorial, maybe we want to change the threshold value of the random number the system must generate - which we have hard-coded to 5. | ||
+ | |||
+ | You could certainly accomplish this by setting // | ||
+ | |||
+ | // | ||
+ | |||
+ | |||
+ | |||