Runtime Entities

Variables

A variable is a named area of memory in meta-language. The data kept in the variable, are called the value of this variable.

The main points that you need to know about variables in the meta-language:

  1. Variables serve to store any data, and use this data in different blocks and contexts
  2. You can write sting literal value directly to the variable, also you can populate variable with value of the register or other variable
  3. Variables are used as substitution data with various commands, including commands for populating the register
  4. Variables exist in all contexts and context-independent

Below are examples of using variables:

              # USING VARIABLES `term` AND `page` FOR WALKING TO SPECIFIC PAGE
- walk:
    to: 'http://www.somesite.com/?q=<%term%>&page=<%page%>'
    do:

# USING VARIABLES `term` AND `page` IN THE COMMAND FOR ADDING LINK TO THE POOL
- link_add:
    pool: results
    url: 'http://www.somesite.com/?q=<%term%>&page=<%page%>'

# USING VARIABLE `date` IN THE COMMAND FOR FINDING ELEMENTS WITH CSS-PATH
- find:
    path: '.vetrina > tbody > tr:has(td:nth-of-type(4):matches(<%date%>))'
    do:
              
              # USING VARIABLES IN POST REQUEST
- walk:
    repeat: <%repeat%>
    to:
        post: https://www.someonlinestore.com/shop/AjaxCategoryCustomResultsView
        data:
            storeId: 31150
            catalogId: <%catid%>
            langId: -1
            categoryId: <%categoryid%>
            frgPageName: CategoryPage
            beginIndex: <%ind%>
            currentPageNumber: <%cpn%>
            pageView: grid
            currentScrollNumber: <%cpn%>
            env_maxEditorialScroll: 0
        headers: 
            x-requested-with: XMLHttpRequest
    do:

# USING VARIABLE `age` IN THE FORM
- find:
    form: main
    do:
    - fields_set:
        age: <%age%>
    - submit
              
                # USING VARIABLE `age` WHEN POPULATING THE REGISTER
- register_set: Jane is <%age%> years old

# USING VARIABLES `fieldname` AND `age` HEN INITIALIZING VARIABLE WITH SPECIFIC VALUE
- variable_set:
    field: <%fieldname%>
    value: Jane is <%age%> years old
                
              # USING VARIABLE `total` WHEN EXECUTING JS SNIPPET
- eval:
    routine: js
    body: '(function() {
              var t = <%total%>;
              var offset = [];
              for (var i = 1; (i-1)*26 < t; i++) {
                offset.push(i);
              }
              return offset.join(",");
            })();'
              

As you see, we can use variables for substitution very widely.