13. Useful Statements, Functions and Expressions

Function: Math.round() Type: JavaScript

Advanced View SLL Snippet:

SET VARIABLE number VALUE STATIC "20.49" HALT ON ERROR
SET VARIABLE round VALUE EXPRESSION "Math.round(@number)" HALT ON ERROR

Execution Result:

Expression: \..* Type: Regular Expression (Regex)

Advanced View SLL Snippet:

WEB GOTO_URL "https://reference.subject-7.com" HALT ON ERROR
WEB VALUE_GET RESULT_VARIABLE links SOURCE ELEMENT XPATH "count(//a)" XML_TYPE "{http://www.w3.org/1999/XSL/Transform}NUMBER" ATTRIBUTE "TEXT" EXCLUDECHARS "\..*" HALT ON ERROR

Execution Result:

 

Expression: ^(.*[\\\/]) Type: Regular Expression (Regex)

Advanced View SLL Snippet:

  • Value is coming from Web Page

WEB VALUE_GET RESULT_VARIABLE last_value SOURCE ELEMENT XPATH "//sample_XPath" XML_TYPE "{http://www.w3.org/1999/XSL/Transform}NODE" ATTRIBUTE "TEXT" EXCLUDECHARS "^(.*[\\\/])" HALT ON ERROR

Execution Result:

  1. Backslash:

2. Forward slash:

 

Function: str.split Type: JavaScript

Advanced View SLL Snippet:

SET VARIABLE var VALUE STATIC "This is an automated test" HALT ON ERROR
WEB VALUE_GET RESULT_VARIABLE var_without_spaces SOURCE JAVA_SCRIPT "var str = '@var';\n\nvar replaced = str.split(' ').join('_');\n\nreturn replaced" HALT ON ERROR

Execution Result:

Function: -[^-]+$ Type: Regular Expression (Regex) / in addition to JavaScript

Advanced View SLL Snippet:

SET VARIABLE var VALUE STATIC "This-is-an-automated-test" HALT ON ERROR
WEB VALUE_GET RESULT_VARIABLE var_excluding_anything_after_last_hyphen SOURCE JAVA_SCRIPT "const regEx = /-[^-]+$/;\n\nconst value = '@var';\n\nconst finalValue = value.replace(regEx, '');\n\nreturn finalValue" HALT ON ERROR

Execution Result:

Â