Programming for Automation through Eg. Pick up a language then learning the ins and outs of a tool.
By: Cerosh Jacob
Tags: Programming, Automation Testing, Selenium Test Automation, Test Automation, Robot Framework

To outshine in test automation profession trusting on education a single testing tool is not the recommended tactic. Irrespective of the tool you must acquire how to code. Pick up a programming language then learning the ins and outs of an automation tool can give the advantage. In this post compares two scripts that are for performing the same action using the same libraries. The screenshot captured below depicts the functionality. Robot Framework is the tool used for the example but similar features are available regardless of the tool.

Script 1 :

***Settings***

Library String

Library SeleniumLibrary

Library Collections

Robot Framework testing capabilities are extending for this script using String, SeleniumLibrary and Collections library.

***Variables***

${PIN_LOCATOR1} id=PageConfiguration.PIN1

${PIN_LOCATOR2} id=PageConfiguration.PIN2

${PIN_LOCATOR3} id=PageConfiguration.PIN3

${PIN_LOCATOR4} id=PageConfiguration.PIN4

${CONFIRM_PIN_LOCATOR1} id=PageConfiguration.CONFIRM_PIN1

${CONFIRM_PIN_LOCATOR2} id=PageConfiguration.CONFIRM_PIN2

${CONFIRM_PIN_LOCATOR3} id=PageConfiguration.CONFIRM_PIN3

${CONFIRM_PIN_LOCATOR4} id=PageConfiguration.CONFIRM_PIN4

@{PIN_NUMBER} null

Scalar variables are used to store the locators so that the variable name is replaced with its string value as-is. A list variable is also created and initialized to null. Robot Framework stores its variables in one internal storage and allows using them as scalars or lists. Using a variable as a list requires its value to be a list and does not allow strings as lists, but other iterating objects are accepted.

***Keywords***

Generate Enter And Confirm A Random PIN

${PIN_NUMBER} Generate A Random Personal Identification Number

Enter The Personal Identification Number ${PIN_NUMBER}

Confirm The Personal Identification Number ${PIN_NUMBER}

This high-level keyword collaborates generating, entering and confirming the personal identification number. Generates a random four-digit personal identification number and stores it in list variable. Fetches the personal identification from the list variable and enters the value in respective text boxes. Enters values fetched again from the list into respective text boxes to confirm the personal identification number.

Generate A Random Personal Identification Number

${number1} Generate Random String length=1 chars=123456789

Append To List ${PIN_NUMBER} ${number1}

${number2} Generate Random String length=1 chars=123456789

Append To List ${PIN_NUMBER} ${number2}

${number3} Generate Random String length=1 chars=123456789

Append To List ${PIN_NUMBER} ${number3}

${number4} Generate Random String length=1 chars=123456789

Append To List ${PIN_NUMBER} ${number4}

[Return] ${PIN_NUMBER}

This low-level keyword generates the random personal identification number and returns the value as a list. The keyword ‘Generate Random String’ creates individual PIN character and the keyword is extending from String library. The length and characters to consider for generating the random string are through argument definition. Each new character generated is appended at the bottom of the list and the keyword is extending from the Collections library.

Enter The Personal Identification Number

[Arguments] ${PIN_NUMBER}

Input Text ${PIN_LOCATOR1} ${PIN_NUMBER[0]}

Input Text ${PIN_LOCATOR2} ${PIN_NUMBER[1]}

Input Text ${PIN_LOCATOR3} ${PIN_NUMBER[2]}

Input Text ${PIN_LOCATOR4} ${PIN_NUMBER[3]}

This low-level keyword enters the PIN and the keyword is extending from SeleniumLibrary. The locator stored in the scalar variables is the elements identification strategy. Since the PIN is stored in the list variable, the index of the list variable is used to access data to enter.

Confirm The Personal Identification Number

[Arguments] ${PIN_NUMBER}

Input Text ${CONFIRM_PIN_LOCATOR1} ${PIN_NUMBER[0]}

Input Text ${CONFIRM_PIN_LOCATOR2} ${PIN_NUMBER[1]}

Input Text ${CONFIRM_PIN_LOCATOR3} ${PIN_NUMBER[2]}

Input Text ${CONFIRM_PIN_LOCATOR4} ${PIN_NUMBER[3]}

This low-level keyword enters the PIN again to confirm the new value. This keyword behaves the same as the predecessor and the only difference is the scalar variable.