Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:scripting_state_model [2020/07/17 21:03]
admin [Assert and track requirements]
tutorial:scripting_state_model [2021/01/05 03:00] (current)
Line 37: Line 37:
  
  
-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]] for more details.+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]] for more details.
  
 ===== Model triggers ===== ===== Model triggers =====
Line 112: Line 112:
    $SYS.log('Random phone#: ' + $RANDOM.randPhone('999-999-9999') );    $SYS.log('Random phone#: ' + $RANDOM.randPhone('999-999-9999') );
        
 +==== Web App Automation====
 +For test automation, for example web application you would activate //Selenium// plugin.  Once you have the plugin activated, you will be able to use //$SELENIUM// to interact with your web application through //Selenium/WebDriver//
 +
 +For example:
 +
 +   $SELENIUM.getWebDriver().findElement(org.openqa.selenium.By.id('DrinkWater').click();
 +
 +=== Page Object===   
 +You could also use //PAGES// tab to define page object:
 +   //PAGES Script
 +   import org.openqa.selenium.By;
 +   mainPage = $SYS.addPage('MainPage')
 +   elem = mainPage.addElement('DrinkWater', By.id('Water'))
 +   elem.addAction('click', { elem, params ->
 +      $SELENIUM.getWebDriver().findElement(elem.locator).click();
 +   })
 +   
 +Then in //TRIGGERS// tab, you can do this:
 +   $SYS.page('MainPage').element('DrinkWater').perform('click');
 +   
 +The advantage of using page objects is that all element locators are organized and managed in one central place for easy maintenance.
 +
 +=== Find Element Locator ===
 +Web element locator can be xpath, css or by id, etc. as supported by //Selenium//.
 +
 +There are many browser add-on/extension tools that can help you find locators for web element very easily.  Check out [[../externalsources | External Sources]] for a list of such tools.
 + 
 ===== User variables ===== ===== User variables =====
  
Line 147: Line 174:
 where 'tag' is the requirement tag/id, 'condition' is a boolean script expression and 'fail msg' is the failure description if the 'condition' is not evaluated to the true (for assertTrue()) / false (for assertFalse()).  Optionally you may include 'assertID' which is the unique id assigned to this defect. where 'tag' is the requirement tag/id, 'condition' is a boolean script expression and 'fail msg' is the failure description if the 'condition' is not evaluated to the true (for assertTrue()) / false (for assertFalse()).  Optionally you may include 'assertID' which is the unique id assigned to this defect.
  
 +As example, the following script will assert random number is greater than 5:
  
 +   $SYS.assertTrue ('GE5', $RANDOM.randNum(0,10) >= 5, 'failed to generate a random number with value at least 5');
  
 +You may also perform check with if/else and then raise the defect explicitly, for example:
 +    
 +   if ($RANDOM.randNum(0,10) >= 5) {
 +      $SYS.addReqPassed ('GE5', 'Successfully generated a random number with value at least 5');
 +   }
 +   else {
 +      $SYS.addReqFailed ('GE5', 'failed to generate a random number with value at least 5');
 +   }
  
 +The requirement 'GE5' will be automatically tracked for the model and the coverage information is available in [[../ide_result | RESULT]] tab.
 +
 +Add your own script to perform assertion and requirement tracking to the model TRIGGERS, re-run the model, and check [[../ide_result | RESULT]] tab.
  
  
 ===== 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 //Environment Variable// via //$SYS.getEnvVar(...)// However a better option is to set a user variable for which the initial value can be set dynamically before the model execution starts.   //Initialization scripts// accomplishes just that.
 +
 +//Initialization scripts// can be entered in {{wiki:idescreen:ide_execsettings.png?linkonly | Model Execution Settings}}.
 +
 +
 +