VBScript Procedures and VBScript Error Handling – An Excellent Guide for VBScript Tutorial 3 & 4

VBScript Procedures VBScript Sub Procedure 1 300x118 1

VBScript Tutorial – Table of Content

VBScript Tutorial #1: Overview of VBScript Variables 

VBScript Tutorial #2: VBScript Conditional Statements and Loops

VBScript Tutorial #3: VBScript Procedures

VBScript Tutorial #4: VBScript Error Handling and Execute VBScript

VBScript Tutorial #5: VBScript String Functions

VBScript Tutorial #6: VBScript Date Functions

VBScript Tutorial #7: VBScript Time Functions

VBScript Tutorial #8: VBScript Array Functions

In this VBScript Tutorial, we are going to learn about VBScript Procedures, including VBScript Functions and VBScript Sub Procedures. Also, we are going to learn about VBScript Error Handling and approaches to Execute VBScript through this tutorial.

VBScript Tutorial #3: VBScript Procedures

VBScript Procedures:

VBScript procedures are the block of statements enclosed by special keywords to perform specific actions. VBScript procedures have the ability to accept input values and return the output value. Here, the input values are represented as the arguments. 

VBScript procedures are mainly used to organize the codes in a professional way for code reusability and better maintenance. Let’s assume a big program or codes have some basic arithmetic operation is performed repetitively. So, if there is a change in that operation, we need to change in every place where it’s used. Instead of doing the same, if we write one VBScript procedure for the same operation and use the reference of that in all the places, then we need to change the code in one place. In this way, we can reduce script maintenance efforts.

VBScript procedures can be referred to by using the keyword “Call”. Also, VBScript allows calling any procedure without using this keyword.

The Advantages of VBScript Procedures:

· Code reusability.

· Reduce script maintenance efforts.

· Better readability of codes.

· Better organization of codes.

Types of VBScript Procedures:

The VBScript procedures are accepting inputs, process it and perform some operation based on the types of procedure. Broadly, VBScript procedures are classified into two types which ate specified below – 

· VBScript Sub procedure

· VBScript Function procedure

VBScript Sub Procedures:

The VBScript sub procedures group multiple statements without returning any output values. It can accept the inputs as arguments. This type of procedures is to start and end with Sub and End Sub keywords, respectively. VBScript Sub procedures can accept arguments but do not return any output values. 

Example – Here we will write a small vbscript sub procedure which accept an argument as alert messages and display it in a popup message box.

‘Call the vbscript sub procedure
Call displayAlert(“This is an example of vbscript sub procedure”) 
Sub displayAlert(alertMessage)
\tMsgbox alertMessage
End Sub
VBScript Procedures - VBScript Sub Procedure
VBScript Procedures – VBScript Sub Procedure

VBScript Function:

If we want to execute a block of statements with returning any output values, we need to use VBScript functions. At the beginning of the VBScript functions, we need to use “Function” keyword to define the function name and at the end the “End Function” keyword is used. VBScript Functions can accept arguments as well as return values. To return value from a function, the value has to be assigned to the function name before closing the function.

Example – In this example, we will calculate the circle area using a vbscript function. Here, the radius will be passed as an argument to the VBScript function and return the area as output.

Dim calcArea 
'Call the vbscript function
calcArea = calcCircleArea(7)
msgbox "The area of the circle is " & calcArea 
Function calcCircleArea(radius)
\tdim pi, a
\tpi = 22/7
\ta = pi*radius*radius
\tcalcCircleArea = a
End Function
Output(Message Box): The area of the circle is 154

ByRef and ByVal Arguments in VBScript Procedures:

ByRef Argument – To keep the changes made in the argument even after the VBScript procedure is called, then we have to send the argument by reference(ByRef). If there is nothing is specified when passing arguments into the VBScript procedures, by default it’s treated as passed by reference. The keyword ByRef is used to pass the argument by reference.

Example of ByRef – Refer below code, here argument Counter has been passed by reference into the procedure. Initially, it’s defined with value four, and in the procedure, it’s incremented by 1. As the argument has been passed by reference, the value of the argument will be five after the function call.

Function incrementCounter(ByRef Counter)
   Counter = Counter +1
   incrementCounter = Counter
End Function
Dim x
myCounter=4
call incrementCounter(myCounter)
msgbox myCounter

Output => 5

ByVal Argument – When an argument is passed by value(ByVal), any modification, done on the argument’s value in the VBScript functions, will not persist after the function call. The keyword ByVal is used to pass the argument by value.

Example of ByVal – Refer below code, here argument Counter has been passed by value into the procedure. Initially, it’s defined with value four, and in the procedure, it’s incremented by 1. As the argument has been passed by value, the value of the argument will remain four after the function call.

Function incrementCounter(ByVal Counter)
   Counter = Counter +1
   incrementCounter = Counter
End Function
Dim x
myCounter=4
call incrementCounter(myCounter)
msgbox myCounter

Output => 4

VBScript Tutorial #4: VBScript Error Handling & Execute VBScript

VBScript Errors:

VBScript errors are nothing but unhandled events which is not handled through the code. In vb scripting, if any events are encountered which are not handled through the codes, they are treated as VBScript errors.

Types of VBScript Errors: 

The different types of VBScript errors are mentioned below – 

Syntax Errors – The primary reasons for this type of VBScript errors are the incorrect structure of the script, typographical errors, incorrect spelling of keywords, syntactical errors. If the syntax errors exist, the script will not be executed at all. It appears during the compilation time of the script. 

Logical Errors – This type of VBScript errors are appeared due to some unexpected events such as number, or date conversion failed due to inappropriate data. It appears while the test scripts are getting executed.

VBScript Errors
VBScript Errors

VBScript Error Handling:

It is not possible to handle all the unexpected VBScript errors through coding. So, it’s the first priority to handle VBScript errors. Primarily, there is one approach to handle the VBScript error in the scripts. This approach is the combination of using “On Error Resume Next” statements and Err Object’s property.

On Error Resume Next statements: 

It was using the On-Error- Resume-Next statements; the exception can be handled partially. In this approach, the test script block should be started with “On Error Resume Next” statements. It signifies that in case of any error, execution will be skipped the current step and proceed with next step. After that, by checking the Error, we can handle the exceptions. Important keywords are –

· On Error Resume Next – In case of Error, VBScript will not raise an error message; instead of that, execution will move to the next step.

· On Error Goto 0 – It will work in reverse procedure with comparison to the above keyword. So, after execution of this step, VBScript will throw errors in case of any exceptions.

· Error.Description – It stores the error description.

· Error.Number – It holds the error number. For success, the value is zero.

· Error.Clear – It reset the Error object.

 On Error Resume Next
\t'Vbscript statement 1
\t'Vbscript statement 1
\t. . . . .
\tIf error.number <> 0 then 'Checking for error
\t\t'..Handle the error
\tElse 'Success condition no need to handle anything
\t\tError.Clear
\tEnd If
On Error Goto 0

Approach to Execute VBScript:

There are different ways that are available to execute VBScripts. The most used approaches are –

  • Execute VBScript through .vbs file
  • Execute VBScript as a part of HTML web development

Execute VBScript through .vbs file: The steps to execute vbscript through .vbs file are –

  1. Write VBScript codes in a simple flat file. Any editor such as, note pad, Note Pad++, Edit Plus, etc can be used to create the file.
  2. Save the file with .vbs extension.
  3. Execute the file by double-clicking on it.
  4. Same file can be executed through the command prompt using the full file path. Command to execute vbs file is WScript “<file_name_with_path>”.

Through out this vbscript tutorial, we are using this approach to run all the demo vbscripts.

Execute VBScript as a part of the web page: In this approach, we need to write the VBScript codes with in tag <script> in the web page. The syntax will be looks like below –

<script type="text/vbscript">
-\tVbscript statements …
</script>

This approach is used while developing web pages using the classic ASP. Also same can be used in other technologies like PHP, JSP etc.

Tools Uses VBScript:  The major tools which supports vbscripts are – UFT,  Excel Macro, Visual Basic, Classic ASP (client side scripting)

Conclusion:

In this VBScript article, we have learned about the learn about VBScript Procedures and VBScript Error Handling through this tutorial. We hope this tutorial has helped a lot to brush up on your basics of VB Scripting. To get more information on VBScripting, please click here.

 

Perfecto Tutorial – An Excellent Perfecto Selenium Integration Tutorial Part 2

Perfecto Selenium Integration Access Perfecto Cloud 300x143 1

The scope of software testing is leading the IT industries now to ensure the quality of the product. Apart from regular web application testing, the scope for mobile testing is also rapidly increasing. The mobile devices can be tested either manually or through the mobile automation tools. Many mobile test automation tools are available in the market which provides mobile labs and the automation capabilities as well. The well known tools are Perfecto, SeeTest, Mobile Lab, etc. 

Perfecto Tutorial – Table of Content

Perfecto Tutorial 1# Install Selenium Setup for Web Automation

Perfecto Tutorial 2# Perfecto Selenium Integration for Mobile Automation

Perfecto Tutorial 3# Import Sample Project for Perfecto Automation

Through this, “Selenium for Perfecto” article, we will provides a complete and detailed overview of Perfecto Selenium Integration using Selenium WebDriver (Java). Also, we will execute a sample project for Perfecto automation with the help of Perfecto mobile lab and automation capabilities.

Perfecto Selenium Integration for Mobile Automation

In this section, we will explain the step by step approach to execute selenium webdriver test cases using the Perfecto mobile lab and automation capabilities. The pre-requisites assumptions to start with this article, are mentioned below –

  • Basic knowledge in Selenium WebDriver.
  • Developed a Selenium test case which will be used here.
  • New to the Perfecto.

Configuration details for Perfecto Automation:

Here we will update the pom.xml file with the necessary Perfecto dependencies and edit the codes from Step 1 to add them in the security data, the Perfecto cloud name, driver details, smart test data update.

The modified code is called PerfectoSelenium.java. The below process walks the users through the configuration.

  • Copy the dependencies
  • Supply the security token
  • Select a device
  • Supply the URL to connect to the Perfecto cloud
  • Create an instance of the reporting client
  • Execute the test

Step1# Accessing Perfecto Cloud: 

  • Register for the first time user for two weeks of the free trial from the perfecto trial license web.
  • Log in with the Perfecto cloud using the above free trial user.

Step2# Capture Security Token from Perfecto Cloud:

The security token is an encrypted version of long string which will be used later to connect the Perfecto mobile lab from third-party tools like Selenium WebDriver. Steps to capture the security token are mentioned below –

First, click on user name which is displayed in the right top corner and click on “My Security Token” link from user menu to open “My Security Token” popup.

Here, we need to click on “GENERATE SECURITY TOKEN” button and copy the generated security token.

Perfecto Selenium Integration - Perfecto Security Token
Perfecto Selenium Integration – Perfecto Security Token

Step3# Select a Device and get the Capabilities:

Capabilities are used to define the mobile devices which will be accessed from the Perfecto cloud. The structure for defining the capabilities are look like below –

DesiredCapabilities capabilitiesSample = new DesiredCapabilities(webBrowserName, “”, Platform.ANY);

capabilitiesSample.setCapability(“testPlatformName”, “Android”);

Here, “platformName” capability is used to define the platform of the mobile OS. To find the source code for the desire capabilities of the mobile android devices, we need to open the Perfecto Cloud UI with Manual Testing view. The source code of capabilities, can be copied to our selenium test case. The steps to follow for capturing the desire capabilities through the perfecto mobile cloud are mentioned below –

  • Click on Open Device option which is available under the Manual Testing section. This section is located in Perfecto Landing page.
  • On the Manual Testing view, select a device to proceed next.
  • Now click to open the Capabilities tab which is available in the details pane. The details pan will be available after selection of the device only.
  • All the capabilities will be displayed here. We can copy either all or selected capabilities based on the requirement.
Perfecto Selenium Integration - Perfecto Mobile Capabilities
Perfecto Selenium Integration – Perfecto Mobile Capabilities

Step4# URL to Connect Perfecto as Appium Server:

The structure of the URL for perfecto cloud will be looks like below – 

https://<<Cloud Name>>.perfectomobile.com/nexperience/perfectomobile/wd/hub

If the URL to access the Perfecto cloud manually is “https://testingcloud.app.perfectomobile.com/lab/devices” then the cloud name will be testingcloud.

Step5# Reporting Client Instance Creation:

The best way to run our test in Perfecto, the first step is to crate an instance with the reference of ReportingClient class i.e., the smart reporting client. It will help us to analyze the report after the test execution. The reporting client is used to collect the basic information of the test. Later, this information will be send to the Smart Reporting system. 

In the sample project(Utils.java), we have shown about the usage of the ReportiumClientFactoryclass’ createPerfectoReportiumClient() method. The instance of PerfectoExecutionContext class provides the link to the factory class.

withWebDriver() – With the help of this method, the link for the driver instance are supplied.

build() – This method is used to create the instance of the context object which will be supplied to the createPerfectoReportiumClient() method for ReportiumClient instance creation.

The main purpose of this reporting is to analyze the test result from the Perfecto Cloud.

Perfecto Selenium Integration - Reporting Client Instance
Perfecto Selenium Integration – Reporting Client Instance

Sample Project to Demonstrate the Perfecto Automation Approach in Mobile Devices

Manual Test Scenario:

  1. Login to the perfecto mobile cloud with valid user credential.
  2. Select any available device.
  3. Open the setting app.
  4. Click on sub-menu contains text as “data usage”.
  5. Verify that “Data Saver” submenu will be displayed.

Basic Information Collected: As pert of test automation, we have collected the Information such as cloud name, security token, capabilities, app package/activity name, captures the object’s property, etc.

Download codes for a sample project: Please click here to download codes for Sample Project. In this sample project, the basic codes are available for Local Appium, Local Selenium, Perfecto Appium and Perfecto Selenium. In this article, we will execute the java test code for Perfecto Appium.

Steps to Prepare the Test for Execution:

Step 1# Import the Sample Project into Eclipse Workspace, which was downloaded previously. This project can be imported through navigation “File->Open Projects from File System” available in Eclipse IDE.

Step 2# After importing the sample project, we need to update the file PerfectoAppium.java to modify basic details such as cloud name, security token, capabilities, app package/activity name, object’s property, etc. which are captured previously.

Step 3# Once the selenium test is ready for execution; we need to the right click on “PerfectoAppium.java” class to run the test as “Run As-> TestNG Test”.

Step 4# After successful execution, the test result can be viewed from Eclipse and Perfect Analyze tab as well.

Perfecto Selenium Integration - Sample Project
Perfecto Selenium Integration – Sample Project
Perfecto Selenium Integration - Execution Log Eclipse
Perfecto Selenium Integration – Execution Log Eclipse
Perfecto Selenium Integration - Execution Result Perfecto
Perfecto Selenium Integration – Execution Result Perfecto

Sample Project to Demonstrate the Perfecto Automation Approach in Web Application:

At the starting point, LocalSelenium.java, a small Javascript with Maven dependencies can be configured to understand the basics on test automation using Selenium build tool Maven. The pom.xml file is institutional here as it contains all configurations setup and dependencies.

Note: Intentionally, the simple script has been written for better understanding. The purpose of the script to show the approach to connect Perfecto from Selenium. After connecting the Perfecto website, the script will check the title.

To start: 

  1. Copy by cloning the sample project which is available in GitHub. The clone URL is – https://github.com/PerfectoMobileSA/PerfectoSampleProject
  2. Launch the IDE and check out the project from GitHub or Import in Eclipse.
  3. Need to download the appropriate Chrome driver as per the Chrome version which is installed in the device.
  4. Execute the LocalSelenium.java project as TestNG Test.

Conclusion:

Through this, “Selenium for Perfecto” article, we have discussed about complete and detailed overview of Perfecto Selenium Integration using Selenium WebDriver (Java). Also, we have learned to execute a sample project for Perfecto automation with the help of Perfecto mobile lab and automation capabilities. To learn more on Perfecto Automation, please click here.

Selenium For Perfecto Automation:Perfecto Selenium Integration

Selenium for Perfecto Eclipse Workspace 300x137 1

Testing is now the most important part of the software development life cycle to ensure the quality of the product. Also, without testing, we can’t ensure the fulfilment of all the requirements. With the usage of mobile apps, the mobile testing opportunities are getting increased proportionally. There are several mobile testing tools, and labs are available in the market, such as Perfecto, SeeTest etc. 

Perfecto Tutorial – Table of Content

Perfecto Tutorial 1# Install Selenium Setup for Web Automation

Perfecto Tutorial 2# Perfecto Selenium Integration for Mobile Automation

Perfecto Tutorial 3# Import Sample Project for Perfecto Automation

This Selenium for Perfecto Tutorial by Lambda Geeks is written to provide a complete and exhaustive overview of Installation of Selenium Perfecto using WebDriver (Java) framework and basic coding for web automation.

Perfecto Automation: Perfecto Selenium Integration

Overview of Perfecto Tutorial:

The Perfecto Automation tool is an entirely web-based SaaS i.e. Software as a Service platform which provides mobile labs with mobile automation capabilities. that allows mobile application designers and QA professionals both work with services The Perfecto can be used by mobile application developers or the QA testers as it allows the services such as manage apps, monitoring, testing services, etc.

The devices available in Perfecto mobile lab, can be accessible by multiple users irrespective of geographical locations for development, testing or monitoring purposes.

The perfecto allows the test automation activities through a web based interface which is designed for automation purposes. This interface enables to design simple test cases with out implementing the complex logics. For complex logical test cases, we can integrate the perfecto with Selenium tool.

The commands i.e. the keywords to perform the different actions for mobile test automation, are available in the Perfecto cloud as widgets. Perfecto only allows the test developer to create test cases, add the keywords with definition of different properties in the user interface as it follows keyword-based scripting approach. The Perfecto as a testing tool is compatible with text and image recognition.

The Perfecto Mobile cloud is compatible with third party tools like Selenium, UFT, TOSCA, etc. So, by integration with those tools, it will be very easy to identify objects (using the object Finder/scan mechanism of the third party tools) and develop the complex test cases. Through out this Perfecto Tutorial, we are going to learn on perfecto selenium integration.

Prerequisites for Perfecto Automation with Selenium:

Here we will discuss the process to execute the Selenium scripts with Java using Eclipse IDE; We consider that the readers 

  • Are hands-on Selenium
  • Have existing scripts for work

There is some mandatory setup need to complete before you get started, make sure you have installed the following:

Java Development Kit – It is required to create the java environment which is required for Perfecto Selenium Integration.

Selenium WebDriver – It’s required to enable the selenium. Click here to download the corresponding jar files.

Chrome Driver – The corresponding Crome Driver has to be downloaded from here, as per the version of chrome installed in mobile device.

IDE – An IDE is required to develop the test cases. The available IDEs are Eclipse or IntelliJ IDEA etc. To work with Eclipse, which a popular IDE, TestNG and Maven plugins are also required.

Selenium for Perfecto Automation

Selenium is free(Open source) test automation tool which is primarily used for automation testing of the web application. But, with the help of third party mobile testing tools, it has the capability to test mobile apps as well. Selenium is supporting programming languages such as Java, C#, Python, etc. Different selenium frameworks available in the market are,

· Selenium IDE

· Selenium RC

· Selenium WebDriver

In this particular selenium for the perfecto tutorial, we will work with Selenium WebDriver framework with Java language. Also, we are going to use Eclipse IDE for managing the selenium for the Perfecto project.

Step1# Download and install Selenium: 

  1. Install Java: The Selenium WebDriver runs in the Java environment. So, the first step is to install the appropriate JDK from the internet. We can download the JDK from here. After the installation, the system restart is required.
  2. Install Eclipse IDE: This IDE is required to create workspace and develop the test cases with the help of Selenium. To download the Eclipse IDE, please click here. It should be downloaded based on the operating system’s version. It’s required to write, compile and run the selenium program.
  3. Download Selenium Java Client Driver: Java Client for Selenium WebDriver can be downloaded from here.
Selenium for Perfecto - Download Selenium
Selenium for Perfecto Automation – Download Selenium

Step2# Configure Eclipse IDE with Selenium: 

  1. Launch the eclipse.exe from the Eclipse folder to open the IDE.
  2. Select the workspace for the Selenium IDE to start with and click OK.
Selenium for Perfecto - Eclipse Workspace
Selenium for Perfecto Automation – Eclipse Workspace
  1. Now create a Java project from the menu navigation ”File->New->Project” and then select “Java Project” option. We need provide the project related information after clicking on “Next” button. The required details are –
    • Project Name  – It refers the name of the project. An project folder will be created in the workspace based on the name.
    • Use default location – Either we can accept the default location in workspace or save the project in different place.
    • Select an execution JRE – If multiple JREs are available, we need to select the correct version.
    • Project Layout – We can define the project layout (folder structure) based on this option.

Click on Finish button to create a new project as name “androidProject”.  

Selenium for Perfecto - Create New Project in Eclipse
Selenium for Perfecto Automation – Create New Project in Eclipse

4. Now we need to create a new package as an android package and a new class as an android class within the newly created package. The packages can be created by right-clicking on the root folder for the newly created project.

5. Now we need to refer the external selenium Jar files within the project. It can be done by following the navigation – “Right-Click on Project Folder -> Properties -> Java Build Root -> Libraries -> Click on Add External JARs -> Select the selenium Jar Files”. Here we need to select all the jar files available in the “selenium-xxxxx” folder and “selenium-xxxxx\\libs” folders.

Once all the external jar files are selected, we need to click on the Apply button and then OK to close the window.

Selenium for Perfecto - Add External JARs for Selenium
Selenium for Perfecto Automation – Add External JARs for Selenium

6. Download and install compatible ChromeDriver version from the web. This is required from mobile web testing using Perfecto.

Step3# Configure testNG in Selenium: 

  1. Install testNG from eclipse marketplace(Help->Eclipse Marketplace->search testNG and install).
Selenium for Perfecto - Install TestNG
Selenium for Perfecto – Install TestNG
  1. Add the External library for TestNG. It can be done by following the navigation – “Right-Click on Project Folder -> Properties -> Java Build Root -> Libraries -> Click on Add Library -> Select TestNG option and proceed next to add this library”.
Selenium for Perfecto Add TestNG Library

Step4# Create TestNG Class: 

Creat TestNG class is a very simple, easy process to perform. We need to follow the below steps to create TestNG class – 

  1. Convert Java project as TestNG Project – Right-click on the src folder under the project root and click on option Convert to TestNG from the navigation “TestNG->Convert to TestNG”. After deletion of “Convert to TestNG” option, a new window will be appeared where we need to lick on “Finish” button to complete the conversion.
Selenium for Perfecto - TestNG Project
Selenium for Perfecto – TestNG Project
  1. Create TestNG Class – Right-click on the src folder under the project root and click on option Create TestNG Class from the navigation “TestNG->Create TestNG Class”. A new window will appear. Here, we need to provide basic details such as Source Folder, PackageName, Class Name and Annotations as per below diagram to create TestNG Class. Now, click on FINISH button to create the class.
Selenium for Perfecto - Add TestNG Class
Selenium for Perfecto – Add TestNG Class

Step5# First Selenium Test Case using TestNG: 

Test Scenario: We will write a basic test case to open google in a chrome session. To automate this scenario, we need to copy the below sample programme into androidTestNGClass.java file. 

package androidPackage;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
 
public class androidTestNGClass {  \t
  WebDriver driverChrome;  \t
  @Test
  public void f() {
  \t //set the chrome driver and location where we store the chromedriver.exe
         System.setProperty("webdriver.chrome.driver", "C:\\\\Drivers\\\\chromedriver.exe");
  \t 
  \t  //Uppdare driverChrome with chrome driver
  \t  driverChrome = new ChromeDriver();
  \t  String url = "https://www.google.com";
  \t  driverChrome.get(url);
  \t  //Capturing the title
  \t  String expectedTitle = "Google";
  \t  String actualTitle = driverChrome.getTitle();
\t  //Validate the title
  \t  Assert.assertEquals(actualTitle, expectedTitle);
    }
  @BeforeMethod
  public void beforeMethod() {
  \t  System.out.println("Starting the browser session");
  } 
  @AfterMethod
  public void afterMethod() {
  \t  System.out.println("Closing the browser session");
  \t  driverChrome.quit();
  }
}

We can execute the above test case by clicking on option – “Right-Click on project-> Run As -> TestNG Test”. During the execution, the google website will open in a chrome browser, and the test will verify the title of the web page. At the end of execution, execution log is available in Eclipse Console section.

Step6# Install Maven in Eclipse IDE: 

Install Maven plugin from eclipse marketplace(Help->Eclipse Marketplace-> search m2e connector for maven dependency plugin and install). Maven plugin is required while the selenium project is created using Maven Build Tool.

Selenium for Perfecto - Install MAVEN
Selenium for Perfecto – Install MAVEN

Conclusion:

Till now, we have covered the detailed installation of Selenium for perfecto web automation through Webdriver framework (Java) and basic coding for web automation. In the next topic, I will write about Perfecto Selenium Integration for Mobile Automation.

VBScript Tutorial 2:Conditional Statements,Loop

VB Scripting in UFT If Else Conditional Statements in UFT

VBScript Tutorial – Table of Content

VBScript Tutorial #1: Overview of VBScript Variables 

VBScript Tutorial #2: VBScript Conditional Statements and Loops

VBScript Tutorial #3: VBScript Procedures

VBScript Tutorial #4: VBScript Error Handling and Execute VBScript

VBScript Tutorial #5: VBScript String Functions

VBScript Tutorial #6: VBScript Date Functions

VBScript Tutorial #7: VBScript Time Functions

VBScript Tutorial #8: VBScript Array Functions

In this VBScript Tutorial, we are going to learn about different kinds of VBScript Conditional Statements (vbscript if else statement & vbscript  select case statement) and VBScript Loop Statements (for loop, do while loop & while loop).

VBScript Tutorial #1: VBScript Conditional Statements and VBScript Loop

VBScript Conditional Statements:

Conditions are nothing but some criteria or comparison, based on which we can perform a certain task. VBScript conditional statements are the most important features in VBScript as a programming language. VBScript conditional statements perform different computations or actions based on certain ones or comparisons or conditions. Through the VBScript conditional statements, we can develop functional logic.

In this section, we are going to learn about different VBScript conditional statements, which are frequently used during programming. The frequently used conditional statements are – 

· VBScript If Statement

· VBScript Case Statement

VBScript If Statement:

The VBScript If the statement is used to validate one or more conditions through the program. Multiple conditions can be added using logical boolean operators such as AND, OR, NOT, etc. Here, the conditions are the expressions that compare one value or variable with another with the help of comparison operators like equal(=), not equal(!=), Not (!), etc. Based on the verification result, we can perform a specific task.

The conditions should be kept between “If” and “Then” keywords. If there is any task need to be performed based on the false condition, the task has to be performed after the “Else” statement. At the end of the if statement block, we need to close the VBScript if statement by using the keyword “End If.” Structure of VBScript If Statement – 

If <Condition1> AND <Condition2> AND .. <Condition3> Then

  • actions for success case

Else

  • actions for failure case

End If

VBScript ElseIf Statement:

Through the VBScript ElseIf Statement, we can add multiple VBScript If statements based on the result of the previous conditional result. Nested VBScript ElseIf statements are used while different actions or tasks need to be performed based on each of the conditions. Structure of VBScript If Statement –

If <Condition1> Then

  • actions for condition 1

ElseIF<Condition2> Then

  • actions for condition 2

ElseIF<Condition3> Then

  • actions for condition 3

Else

  • actions for else condition

End If

Example: Identify Saturday, Sunday, and Business Working Days using VBScript IF statement and VBScript ElseIf statement. Here, we will use more than one ElseIf statements to fulfill our requirements. Also, we can put multiple conditions along with the If statement with the help of ‘AND’ or ‘OR’ operators.

VBScript If Statement
VBScript If Statement

VBScript Select Case Statement:

A VBScript Select Case Statement is an alternative approach to using multiple VBScript IfElse statements. VBScript Select Case statements are used while we have different logics/statements based on the different values against any variable. It’s also known as a switch-case statement. It helps us to write code more efficiently and readable.

A VBScript Select Case statement works with a single test expression that is executed once, at the beginning. The result of the expression will be compared in each case statement. For the match, the block of statements associated with that case will be executed. VBScript Select Case block always should end with the keyword “End Select.” Structure of VBScript Select Case Statement –

Select <Expression> // This Expression can have any value between 1-3

Case 1

  • actions for expression value 1

Case 2

  • actions for expression value 2

Case 3

  • actions for expression value 3

Case Else

  • actions else condition

End Select

For example: Identify Saturday, Sunday, and Business Working Days using if conditions.

VB Scripting in UFT - Select - Case Conditional Statements in UFT
VB Scripting in UFT – Select – Case Conditional Statements in UFT

VBScript Loop:

When similar kinds of statements need to be executed repeatedly, it’s advisable to write looping statements to make the code more readable and efficient. The VBScript loop works repeatedly based on conditions or the iteration counter. Every VBScript loop has three parts –

·        Loop Iterations – It’s basically the loop counter based on these statements that are getting executed.

·        Loop Condition – Based on this loop will be executed, and once the condition meets, loop iteration will be completed.

·        Loop Statements – it’s basically the repeated activities that are executed based on the condition.

Below VBScript Looping statements are frequently used during the coding – 

  • VBScript For Loop
  • VBScript While Loop
  • VBScript Do While Loop

VBScript For Loop:

VBScript For Loop statements is used to execute repeated statements based on the predefined iteration counter. In this structure, the loop will continue until the iteration is reached to the predefined counter value as a condition. The VBScript For Loop should always start with the “For” keyword and end with the keyword “Next.”

While defining the counter in the after “For” keyword, we can specify the increment or decrement of the counter using the keyword “Step.” By default, if we do not use this keyword, VBScript For loop defined the increment by 1. Also, we can use the VBScript Exit For the statement to exit from the loop, which can be placed within any VBScript conditional statements within this looping structure. Structure for “VBScript For Loop” – 

For nIteration = <start> to <end> Step <incremet/decrement by>

— Repeatative Statement 1

— Repeatative Statement 2

If  <Condition> Then

            Exit For

End If

Next

Example – here loop will be executed until the counter value has been reached to 10,

For nIteration = 1 to 10 Step 1

Msgbox “Current Iteration – “ & nIteration

Next

VBScript While Loop:

VBScript While Loop statements are used to execute repeated statements based on one or more conditions. In this structure, conditions are checked at the beginning of the loop. So, if the conditions are not met, the loop will not be executed. The keyword “While” is used to check the condition. We can use the “Exit While” statement to exit from VBScript while loop, which can be used in an IF statement within this looping structure. Structure for “VBScript While Loop” – 

While <Loop Condition>

— Repeatative Statement 1

— Repeatative Statement 2

If  <Exit Condition> Then

            Exit While

End If

Wend

Example – here loop will be executed until the counter value has been reached to 10,

VB Scripting in UFT -Looping Statements in UFT (While-Wend)
VBScript Loop – VBScript While Loop Statement

VBScript Do While Loop:

VBScript Do While Loop statements are used to execute repeated statements based on one or more conditions. This loop will be ontinued untill the loop conditions return False. VBScript Do While Loop structure, conditions are checked at the end of the loop. So, irrespective of the conditions are meet or not; the loop statements are always executed for the first iteration. We can use the “Exit Do” statement to exit from this loop, which can be placed in any conditional statement within this looping structure.

The keyword “While” is used to check the condition. The main difference between VBScript Do While Loop and VBScript While Loop statement is the position of the conditional statement. Structure for VBScript “Do While Loop” –

Do

— Repeatative Statement 1

— Repeatative Statement 2

If  <Exit Condition> Then

            Exit Do

End If

Loop While <Loop Condition>

Example – here loop will be executed until the counter value has been reached to 10,

VB Scripting in UFT - Looping Statements in UFT (Do-Loop)
VBScript Loop – VBScript Do While Loop

Conclusion:

In this VBScript article, we have learned about the VBScript Conditional Statements (vbscript if else statement & vbscript  select case statement) and VBScript Loop Statements (for loop, do while loop & while loop).. We hope this tutorial has helped a lot to brush up on your basics of VB Scripting. If you want to learn more about VBScript, please click here.

VBScript Variables – An Excellent Introduction Guide for VBScript Tutorial 1

vbscript tutorial Web Browser 300x87 1

VBScript Tutorial – Table of Content

VBScript Tutorial #1: Overview of VBScript Variables 

VBScript Tutorial #2: VBScript Conditional Statements and Loops

VBScript Tutorial #3: VBScript Procedures

VBScript Tutorial #4: VBScript Error Handling and Execute VBScript

VBScript Tutorial #5: VBScript String Functions

VBScript Tutorial #6: VBScript Date Functions

VBScript Tutorial #7: VBScript Time Functions

VBScript Tutorial #8: VBScript Array Functions

In this VBScript Tutorial, we are going to learn VBScript Variables, VBScript Array, VBScript Constants, and Dictionary Object in VBScript.

VBScript Tutorial #1: VBScript Variables

VBScript is the shorter form of Visual Basic Scripting which follows the Visual Basic language. The VBScripting was introduced by Microsoft. It’s a very simple languages to learn which allows to develop server-side as well as client-side scriptings.

VBScript Features:

· It is a simple scripting language.

· It is case insensitive and easy to learn for any entry-level programmer.

· It is an object-based programming language and does not follow the OOPS concept.

· It supports the COM which is a shorter form of Component Object Model (COM) structure. It allows to manage the elements from the environment where it is getting executed.

· The VBScripting which executed in server side, is compatible with hosting platform such as Internet Explorer web browser, Internet Information Services (IIS) as web server and Windows Scripting Host (WSH).

· It can be used to develop both server-side(Classic ASP) and client-side scripting.

· Tools like Excel macro, UFT (Unified Functional Testing) follow the VB Scripting.

VBScript as a client-side scripting:

vbscript tutorial - Web Browser
vbscript tutorial – Web Browser
vbscript tutorial - window scripting
vbscript tutorial – window scripting

· VB Scripts are supported in internet explorer only. The web browsers which are well known in market like Mozila Firefox, google Chrome etc., are not compatible with VBScript.

· It is platform-dependent i.e., only supported by windows environment.

· The debugging of VBScript is challenging as there is non availability of proper development area.

 VBScript Comment:

The purpose of the VBScript comment is to educate the compiler to skip the particular line or lines of code from the execution. Basically, VBScript comments are used to document or write the descriptions/objectives during the scripting. It will help to increase the readability of the code block by writing the description, change the log using the commenting. Two types of VBScript comments are available –

Single line VBScript comment: It’s done by using the single quote ( ‘ ) at the beginning of each line. Example of single-line comment in VBScript –

‘ Single line comment example

Multiple lines VBScript comment: Multiple lines VBScript comment is used to comment on more than one line. This type of VBScript comment can be achieved by putting more lines between “/*” and “*/” symbols. Example of multiple lines VBScript comment –

/*

VB Statement 1

VB Statement 2

….. and so on

*/

VBScript Variables:

The VBScript variables are one kind of placeholders which refer memory locations to store data. During the execution, VBScript allows to modify the variables. The declared name of VBScript variables are used to access the variables for reading or writing purposes. The variables have the ability to interact with any data types such as string, char, number, date, etc. As per the data types, the vbscript variables are changed accordingly. For an example – if we assign a number within double quote, it will be treated as string value.

We can declare VBScript variables in three ways which are explained below –

  • VBScript dim
  • VBScript public
  • VBScript private

VBScript Dim:

Dim stands for declare immediate. It means, VBScript dim allows to declare a variable immediately for any kinds of data types. We can declare multiple variables which are separated by comma, with a single VBScript dim statement. The scope of which are declared using VBScript dim statement, are restricted with in the code block such as functions, sub-procedures, local scripts etc., where it was declared. Below examples has shown the syntax of VBScript dim statement for variable declaration – ,

Dim var1

Dim var1, var2, var3

Using the keyword dim, we can declare the variables immediately with specifying the logical name of the variables. It is mandatory to declare the each of the variables if we specifying the statement “Option Explicit” at the starting of the script. So, if the statement does not specified, the variable declaration is an optional step. In this case, the variables are auto declared while defining the variables.

VBScript Public:

When variables are declared with the keyword public, the variables are accessible from through out the entire script. Basically, public keyword is used to define a variable as global variable.

VBScript Private:

When variables are declared with the keyword private, the scope of the variables are restricted to with in the code block.

Assigning Values to VBScript Variables:

In the below example, we will declare (using VBScript dim satement) assign values such as number and string to the variables with the help of equal(=) symbol,

'''''declare variables using VBScript dim statement
dim numVar
dim strVar
'''''define the variables - number and string
numbVar = 12345667788
strVar = "This is sample variable"

While assigning values to the variable, we need to keep the variable name in the left side of equal symbol and value has to be kept in the right side. For strings or characters, we need to keep the value with in double quote.

Scalar Variables – Defining a variable with single value, is known as scalar variable.

Array Variables – Conceptually an array represents a list of values. In VBScript, when a variable is assigned with multiple same type of values, is know as an array. Array can be declared with parenthesis after the variable name. It can be declared in same way how we declare a variable. The structure to declare an array is shown below –

Dim myArrayName(max index)

Here the index is used to refer the each elements of an array which start from zero. So, the max index denotes the length of array minus one. Values can be assigned to the each array element using the array indexes. In the below example, we will define an array which holds 3 student names –

' Declare an array with VBScript dim statement
Dim arrStudentName(2) 
' Assigning the student names using the index
arrStudentName(0) = "Tom"
arrStudentName(1) = "Jack"
arrStudentName(2) = "Jerry"

VBScript Variables – Naming Convention:

Syntactically, there is no specific naming conventions are available. But it advisable to follow the below guidelines for better readability of scripts,

· The starting character of a variable should be alphabetic.

· Any embedded period should not be kept.

The name of the variable should be logical as per the usage.

Length should not cross the limit of 255 characters.

VBScript Constants:

The value of VBScript constant variable can not be modified after definition. So, the constant variable is basically a read-only variable. It has to defined during the declaration. The VBScript provides default constant variable which can be used during scripts. The example of default constants are – vbOK, vbCancel, vbTrue, vbFalse, etc. The Const keyord is used to declare a constant in VBScripting. Below example, we will see how to define constant variables for number and strings –

Const strConstant= “This is my string.”

Const numConstant = 123

VBScript Array:

Conceptually an array represents a list of values. In VBScript, when a variable is assigned with multiple same type of values such as string, integer, etc., is know as an array. The VBScripts allows to keep the list of same type values in the same memory location(VBScript array). The each array elements can be accessed using the reference numbers which is known as array index. The index is always starts from zero.

Structure wise, VBScript Array has two sections – the logical name of array name and the array subscript that denotes the highest index value. The array subscript is equals to the length of array minus one.

The VBScript array has to be declared first, otherwise it will throw errors. Similar to the variable declaration, we can declare the VBScript array using the dim statement. By considering usage or scope, VBScript two type of arrays –

·     Local VBScript Array – The scope of this type arrays are restricted to the code block (functions or sub procedures) where it was declared.

·     Global VBScript Array – We can use this type of arrays throughout the scripts. This type of arrays should be declare at the beginning of the script.

Static and Dynamic Arrays:

Also, we can declare the VBScript array as static or dynamic while creating the scripts.

A static VBScript array – It has a fixed number of array elements which can not be altered during the script execution.

A dynamic VBScript array – The number of array element can be changed at anytime. When the number of elements are not fixed or pre-defined, we can use this array.

Working with VBScript Arrays:

Syntax for array declaration – Dim myArray(subscript value)

In the below example, we will create an VBScript array of marks of 3 students and store the calculated average marks into a variable –

'Declaration of array and value assignment for three students
dim arrMarks(2)
arrMarks(0) = 10
arrMarks(1) = 15
arrMarks(2) = 20
'Calculate the average and store it in a variable
Dim avgMarks
avgMarks = (arrMarks(0)+arrMarks(1)+arrMarks(2))/3

Dictionary Object in VBScript:

The dictionary object in VBScripts, has the similarity with the VBScript array. Which means, it’s also allowing to store a list of values. But the primary differences of dictionary object in VBScript, are that it can holds different types of data and a key has to be assigned for each data instead of indexes.

The dictionary object in VBScript can be declared for usages with the reference of “Scripting.Dictionary” class. 

Advantages of Dictionary Object in VBScript:

· Different types of data can be stored in a single variable.

· With the help of key, we can access the corresponding elements easily.

· This concept is very flexibles as there is predefined methods are available to manipulate the dictionary object in vbscript.

Example – Dictionary Object in vbscript: 

In the below example, we will see the codes for different operations on dictionary objects –

' **** Create a Dictionary Object in VBScript ****
'Create a variable.
Dim dict
Set dict = CreateObject("Scripting.Dictionary")
'Adding keys and items.
dict.Add "Name", "VBScript"
dict.Add "Id", "1"
dict.Add "Trainer", "K Mondal"
'**** Checking the availability of a Key from the dictionary object in VBScript ****
If dict.Exists("Name") Then
   msg = "The name key exists"
Else
   msg = "The name key does not exists"
End If
'Read an item
dim sName 
sName = dict.Item("Name")
'get the count of element
dim nCount
nCount = dict.count
'Delete single item
dict.Remove("Name")
'Delete All item
dict.RemoveAll

Conclusion:

In this VBScript article, we have learned about the Overview of VBScript Variables, VBscript Array, VBScript Constantsand Dictionary Object in VBScript. For more details on VBScript, please click here.

API Testing in TOSCA – An Excellent Guide for Tosca 13.x

API Testing in Tosca Overview

Tosca Tutorial – Table of Content

Tosca is now become one of the leading test automation tool which follows the script less methodology. Through out the entire Tosca tutorial, we have already learned about the different Tosca components and test automation approach. Now we are going to explain the concepts of API Testing in TOSCA.

Tosca Tutorial #1: Tosca Overview

Tosca Tutorial #2: Tricentis Tosca Setup – Install, Uninstall and License Configuration

Tosca Tutorial #3: Tosca Workspace Creation

Tosca Tutorial #4: Understanding of TOSCA Commander and Tosca User Management

Tosca Tutorial #5: Tosca Scanning – An Introduction to Modules

Tosca Tutorial #6: Tosca Test Case Creation

Tosca Tutorial #7: Tosca Parameters and Library– Buffer, Business Parameter, TCP

Tosca Tutorial #8:Tosca Test Execution, Reports, and Bug management

Tosca Tutorial #9: Test Case Design – An approach to test data management 

Tosca Tutorial #10: Tosca Test Data Management.

Tosca Tutorial #11: API Testing in Tosca

Tosca Tutorial #12: Tosca Interview Questions and Answers

In this “API Testing in TOSCA” article, we will explain the overview of API and the detailed steps of automated API Testing in TOSCA.

API Testing in Tosca

What is API?

API is the shorter form of Application Program Interface. It’s working as an interface which allows two applications to communicate with each other through common message formats such as, XML, JSON, etc. Let’s consider the below figure to understand more on API–

Assume, we have four different applications – SAP App, Mobile Apps, Web Portal and Billing System, which are integrated by common interface as API. Here API is working as an interpreter. Each of the system interacting with each other by sending an API request and receiving the API response. Basically, each system is communicating with API and based on the request, API routes the messages to the target system.

API Testing in Tosca - Overview
API Testing in Tosca – Overview

Purposes of API:

  • Communicate between different applications.
  • It’s platform-independent.
  • Development of one system is not dependant with another.
  • Fast and secure communication.
  • Easy to integrate many applications.

Different Types of API:

REST API (Representational State Transfer): It’s a web service API which is now an essential part of modern web-based applications such as, Facebook, Netflix, etc. REST API should comply with below standards –

  • Stateless – It does not allow to store the data they received from a requestor.
  • Client-Server Architecture – Client and Server’s REST APIs should be independent with each other.
  • Cache – The cache is storing the browsing data for a specific period of time.
  • Uniform Interface – Communication should be HTTP requests using URL, CRUD(Create, Read, Update, Delete) and JSON.
  • Layered System – REST APIs should use different architecture layers which contributes towards a clear hierarchy.
  • Code on demand – It’s an optional rule to transmit code within the application through the API.

RPC API (Remote Procedure Call): These are the simplest API which is used from old days. The aim of RPC is to execute code on the server system. It was easier for application developers to develop applications involving more programs or services in the RPC API.

There are two types of RPC APIs – XML-RPC and JSON-RPC.

SOAP API (Simple Object Access Protocol): It is also one kind of web API. SOAP is the first to define the process about the applications to use a network connection to manage services. It’s a special protocol which is defined by the World Wide Web Consortium (W3C).

API Testing in TOSCA:

Before understanding the API Testing in TOSCA, first, we need to understand the “What is API Testing?”.

What is API Testing? 

The API Testing is an approach to test the API components of any software product in efficient way. To perform API testing, we need to validate the API response received based on the API request. The main moto of API testing is to test the core functionality, reliability, performance and security through the API. API Testing is ideal for testing the core functionality of the application when the all the application is partially developed. So, it allows us to start the testing before the integration of the software components.

For more information on API Testing, please click here.

API Testing in TOSCA:

The goal of API testing is to ensure that the core functionalities of the application work as expected without interacting in the UI layer. To perform the API Testing, always, we need to take help from any third party tools like Postman, UFT, TOSCA, etc.

Here, TOSCA is one of the best automation tools for API Testing.

Benefits API Testing in TOSCA:

  • API testing can be used to validate the core functionalities even when the UI hasn’t been developed/modified. Hence testing can be initiated much before actual functional testing (UI based) is done.
  • Frequent application changes can be tested quickly. 
  • It is easy to maintain test cases in TOSCA.
  • The API testing in TOSCA can be done much faster.
  • Standalone Tosca API Scanning Wizard is available to scan the API in the easiest way.
  • Easy to create Tosca test scenarios.

Supported Standards for API Testing in TOSCA:

Web Service StandardsSOAP 1.1, SOAP 1.2, REST
Transport LayerHTTP 1.1, IPv4, IPv6
Message FormatXML, JSON
Message Description LanguageOData 4.0, SWAGGER, WSDL 1.1, WADL, XSD, JSON Schema
AuthenticationBasic Authentication, Kerberos/SPNEGO, NTLM

Process flow for API Testing in TOSCA:

API Services – Identify the API details and functional flow for automation.

API Scan – Scan the API and create Tosca modules.

Create Test Case – Generate test cases and perform cleanup with parameterization.

Run – Execute the test cases and share the reports to stack holders.

API Testing in Tosca - Process Flow
API Testing in Tosca – Process Flow

Step by Step Guide to Perform Automation of API Testing in Tosca:

Step1# Collect API Details – We need to collect below API Information of the sample application,

Step2# Identify Scenarios and data formats for the API Request.

Test Scenario – After logging into the sample swagger application, need to add a new coffee brand and verify.

Data Format – Data need to be passed through JSON format.

Step3# Manually Verify the scenario using tools like Postman (Optional). Please go through the article on Postman to understand the process to test the API.

Step4# Scan the API with the endpoint reference. Scanning steps are mentioned below –

1) Open the API Scan wizard from “API Testing” tab available in TOSCA Header section.

2) Click on URI button and enter the endpoint address. Now click on OK to start scanning.

API Testing in Tosca - Scan API
API Testing in Tosca – Scan API

3) After a few moments, API scan will be completed, and scanned API modules are displayed in the API Scan Wizard.

API Testing in Tosca - Scanned Components
API Testing in Tosca – Scanned Components

Step5# Create modules and test cases – Selecting the root folder, i.e. “Swagger Demo CoffeeShop V2”, click on “API Test Case” to generate modules and test cases in the TOSCA. For every transaction, there are two parts – one for request and another for the response.

API Testing in Tosca - Generated Modules
API Testing in Tosca – Generated Modules

Step6# Cleanup scenarios: Auto-generated test cases can be used as a base suite which needs to be cleaned by removing the unwanted folders, create module attributes to parametrize the response values such as, authentication token which will be required to perform any transaction.

Post Coffee (Modules for API Request) –

API Testing in Tosca - Modules after Cleanup
API Testing in Tosca – Modules after Cleanup

After assigning the parameters, the API Test Case will look like below,

API Testing in Tosca - Test Case
API Testing in Tosca – Test Case

Step7# Execute API Test Case in TOSCA – First of all, we need to add the newly created test case into the execution list. Now, the execution can be initiated by clicking on “Run” button. As it’s an API Testing, no application UI will be visible through out the execution. After completion of execution, Report will look like below, 

API Testing in Tosca - Execution Log
API Testing in Tosca – Execution Log

Conclusion:

In this “API Testing in TOSCA” article, we have learned about API and API Testing in TOSCA. To know more on API testing in Tosca from Tricenties support portal, please click here.

UFT Tutorial: Recording With Checkpoints & Dictionary Object

Recording in UFT Types

Testing is now an essential phase of the software development life cycle to secure the product’s quality. Also, without having testing, we can’t ensure the fulfillment of all the requirements. Here automation is playing an essential role in the testing cycle to reduce the efforts and time. In the market, there are multiple testing tools available to automate the testing process. The most used automation testing tool is UFT.  

In this UFT Tutorial, we are going to learn the below topics –

  • Recording in UFT
  • Checkpoints in UFT
  • Dictionary Objects in UFT
  • Test Execution in UFT

UFT Tutorial – Table of Content

UFT Tutorial #1: UFT Overview

UFT Tutorial #2: UFT Setup – Download, Install, License Configuration and ALM Connection

UFT Tutorial #3: UFT Object Repository

UFT Tutorial #4: UFT Actions & Function Library 

UFT Tutorial #5: UFT Parameterization 

UFT Tutorial #6: VB Scripting in UFT

UFT Tutorial #7: Step by Step Guide to Create Test Case in UFT

UFT Tutorial #8: Exception Handling in UFT

UFT Tutorial #9: Recording in UFT with Checkpoints & Dictionary Object 

UFT Tutorial #10: UFT Interview Questions and Answers 

UFT Tutorial #8: Recording, Checkpoints & Dictionary Object in UFT

Recording in UFT:

Automation recording in uft is an option to record the manual navigation in the test application through the UFT tool to generate the linear test scripts. All the data in the recoded scripts are hardcoded. The record and play approach is ideal for one-time execution. But for the longer run, we need to modify the recoded test cases to implement data parameters, reusables proper test framework, etc. Recording in UFT can be initiated by pressing the F6 key or Record button under the Record tab.

Limitations of recording in UFT:

· All the data are hardcoded.

· Recorded scripts are not stable and difficult to use for the longer run.

· Required high maintenance efforts.

· Redandant duplicate object hierarchy can be created.

Different options for recording in UFT:

·        Normal mode/ UI Automation Recording – It’s also known as Contextual, which is the default recording behavior that uses the full features of the UFT object recognization approach. It’s used to record UFT compatible applications.

·        Low-level recording mode – If the application is not compatible with UFT, i.e., the entire screen is identified as a single Win Object. In this case, the low-level recording mode can be used to record the steps based on the application co-ordinates.

·        Analog Recording – It’s used to record mouse movements and keyboard operation.

·        Insight Recording – Insight objects can be inserted on any AUT. Once we press the Record button, Insight Recording appears under the Record menu and recording toolbar.

Different recording options can be chosen by selecting the recording mode from the recording wizard.

Recording in UFT - Types
Recording in UFT – Types

Step by step Guide for Recording in UFT:

Recording Scenario: Search the keywords “Automation Testing” on google.

Step1# Open internet explorer and navigate to www.google.com.

Step2# Start the recording by pressing the “F6” button or selecting the menu “Recording-> Record F6”.

Recording in UFT - Step2
Recording in UFT – Step2

Step3# For the first time below “Record and Run Settings” wizard appears to configure the recording settings such as URL, Record, and run on any open browser, etc. Same configurations are also available for mobile or Windows Applications. Here, we will select the “Record and run on any open browser” option and proceed.

Recording in UFT - Step3
Recording in UFT – Step3

Step4# Now the recording wizard appears, and we can manually navigate the scenario in the web browser. UFT will capture the steps which are performed manually and store in the test case.

Step5# After completion of manual navigation, click on the stop button to end the recording.  The recorded script will look like below.

Recording in UFT - Step5
Recording in UFT – Step5

Checkpoints in UFT:

Checkpoints in UFT are used to verify the specified properties of objects between actual values and expected values. These verification points are performed at the run time. If the expected values are matched with actual, UFT will generate PASS statue; else, it will be FAIL status. Checkpoints are used based on functional specifications.

Types of Checkpoints in UFT:

There are different types of checkpoints available in UFT. Those are – 

·       Standard checkpoints in UFT: It validates the expected values of the object, which are captured during recording with the actual values of the object during the execution time.

·       Page Checkpoints in UFT: When a standard checkpoint is created for a web page is called a page checkpoint. Page checkpoints in UFT are used to validate the different types of object count, such as links, images, etc. Also, it can be used to check the time taken to load the web page.

·       Bitmap Checkpoints in UFT: It is used to check the bitmap of an image or the entire webpage. It performs a pixel to pixel comparison of the test image.

·       Image Checkpoints in UFT: It helps us to check properties like the source file of the image. We can not use it to check the bitmap or pixel of the images.

·       Text Checkpoints in UFT: It checks the text available in a webpage or application. This text can be available in a small portion or section of the application.

·       Accessibility Checkpoints in UFT: It verifies standards as per W3C instructions and guidelines for Web-based technology and information systems. 

·       Database Checkpoints in UFT: It’s used to verify the database. It creates a query to store database values as expected values during recording time. During the execution, the same query is used to capture current values from the database, which will be compared with expected values. 

·       Table Checkpoints in UFT: In Table Checkpoint, we can check the contents of the table during the run time. Initially, these checkpoints store the contents of a table as an expected value, which will be verified with the actual table value during execution.

·       XML Checkpoints in UFT: It’s used to verify XML files.

Step by Step Guide to Create Checkpoints in UFT:

Now, we will learn how to create standard checkpoints in UFT based on the below example. By following the same guide, we can create different types of checkpoints.

Checkpoint Scenario: Create standard checkpoints in UFT during the recording in the web-browser.

Step1# Open internet explorer and navigate to www.google.com.

Step2# Start the recording by pressing the “F6” button or selecting the menu “Recording-> Record F6”.

Step3# Search the keywords “Automation Testing” on google to record the corresponding automated scripts.

Step4# Now select Standard checkpoint from the menu navigation “Design->Checkpoint->Standard Checkpoint F12” or pressing the “F12” key.

Checkpoints in UFT - Step4
Checkpoints in UFT – Step4

Step5# Select the desired object in the application for which a standard checkpoint needs to be created. Here, we are selecting the web element to verify the text “Test Automation Software.”

Checkpoints in UFT - Step5
Checkpoints in UFT – Step5

Step6# Review the Checkpoint properties and click OK to add the checkpoint step into the test case.

Checkpoints in UFT - Step6
Checkpoints in UFT – Step6

Step7# Checkpoint step is now added in the script. Also, the same is available in the object repository as well. In this scenario, the inner text property of the test object will be validated during the execution.

Checkpoints in UFT Step7
Checkpoints in UFT – Step7

Step8# Checkpoint verification status can be seen in the UFT execution report.

Checkpoints in UFT - Step8
Checkpoints in UFT – Step8

Dictionary Object in UFT:

The dictionary object in UFT is similar to the array. But the primary difference with the array is that there is a key associated with each element in the dictionary object.

The dictionary object in UFT can be defined by referring to the Scripting.Dictionary class. 

Advantages of Dictionary Object in UFT:

· It stores items in an organized way.

· Easy to access any items using the key string.

· It is more flexible to handle with pre-defined methods.

Example of Dictionary Object in UFT: 

Create a Dictionary Object:

Dim dict’ Create a variable.

Set dict = CreateObject(“Scripting.Dictionary”)

dict.Add “Company”, “Microfocus” ‘Adding keys and items.

dict.Add “Tool”, “UFT”

dict.Add “Trainer”, “LambdaGeeks”

Checking the Existence of Specific Keys:

If dict.Exists(“Company”) Then

     msg = “Key exists”

Else

     msg = “key doesn’t exist”

End If

Read Any Item:  dict.Item(“Company”)

Get The Count: dict.count

Delete Any Item: dict.Remove(“Company”)

Delete All Item: dict.RemoveAll

Test Execution in UFT:

Steps for Test Execution in UFT are shown below – 

Step1# Open the test case in UFT.

Step2# Click on the Run button or press the “F5” key to initiate test execution in UFT.

Step3# Now, we need to select the Result Location. If there are any ALM test sets are available or need to execute from a specific folder, we need to select the first option, i.e., “New run result folder.” For any temporary run to check the script, we need to select the second option. Once the selection is done, please click on the Run button to start the execution.

Test Execution in UFT - Run Setting
Test Execution in UFT – Run Setting

Step4# After completion of the execution, we can view the default UFT result from the menu navigation “View->Last Run Result.”

Test Debugging options in UFT:

The different debugging options are mentioned below – 

Debug Point: By pressing on the “F9” key, the debug point can be added to the selected line of code. It’s required to pause the execution pointer at this particular line. Using the same key, we can also remove the selected breakpoint.

Run From Step: By pressing on the “Ctrl+F5” keys, execution can be started from the selected step.

Step Over (F10): If we want to perform line-by-line debugging, we need to keep on clicking on the “F10” key.

Step Into (F11): If we want to perform line by line execution, including child components as well, we need to keep on pressing the key “F11”.

Clear All Breakpoints: We need to press on keys “Ctrl+Shify+F9”.

Conclusion:

In this “Advance UFT Features” article, we have learned about important advanced UFT concepts such as Recording, Checkpoint, Dictionary Object, Test Execution in UFT, etc. Click here to understand more from the Microfocus support

portal. Also, if you want to prepare for UFT Interview Questions, please click here.

Exception Handling in UFT & Synchronization (HandOn Guide!)

Recovery Scenario in UFT Step2 1024x474 1

In this Exception Handling in UFT and Synchronization article, we are going to learn the below topics –

· Exception Handling in UFT

· Recovery Scenario in UFT

· Synchronization in UFT

UFT Tutorial – Table of Content

Exception Handling And Synchronization in UFT

Exceptions in UFT:

An exception is nothing but an undefined event or error. In automation testing, if any errors or events are encountered which are not handled through the automated steps, they are treated as exceptions. Exceptions can be occurred due to any of the below scenarios – 

Bug – 

Any new bugs or issues in the application which are not handled properly can be the reason for an exception.

Environment Error – 

Environment outage or network latency can create exceptions as the expected screens/pages are not available.

Test data – 

Due to the correctness or invalid test data, an exception can occur during the test execution.

Technical issue – 

If the test case is not designed properly, an exception can occur during the test run.

Undefined popup – 

Any undefined popups such as Security, timeout, Information, Warning also can be the sources of exception.

The impacts of exceptions are – 

  • Test execution failure.
  • Need more effort to perform debugging/ re-execution.
  • Increase the cost and maintenance efforts.
  • Automation goal, i.e., ROI, can not be achieved.

Exception Handling in UFT: 

It is not possible to handle all the unexpected errors through automation. But if we use exception handling during the scripting, the chances of unexpected error can be minimized. The tool provides some mechanism for exception handling in UFT. The approaches for exception handling in UFT are – 

  • Recovery Scenario in UFT
  • Scripting and Test Setting
  • On-Error-Resume-Next statements for VBS
  • Using Test Settings
  • Using Exit Statement

Recovery Scenario in UFT:

A recovery scenario in UFT is an approach to handle unexpected events/ errors during the execution. The “Recovery Scenario Manager” wizard helps to manage the recovery scenarios. We can open the “Recovery Scenario Manager” by using the navigation “Resources → Recovery Scenario Manager.” While creating the recovery scenario, we need to perform three configuration steps in UFT based on the requirements. Those are Triggering Event, Recovery operations, and Post-Recovery Test Run Options.

Triggering Event: 

It defines the unexpected events, which will call the Recovery Scenario. The different options/ events available during the creation of recovery scenario in UFT are specified below – 

  • Unexpected pop-up windows.
  • Errors which may appear due to Object State.
  • Errors during the Run time.
  • Application Crash.

The main usage of recovery scenario to handle different types of unexpected errors and perform some predefined steps against each types of error.

Recovery operations: 

Based on this configuration, UFT will perform a set of actions for recovery purposes.

Post-Recovery Test Run Options: 

After the recovery, we need to configure these options to execute some predefined steps which may be required.

Step by Step guide to create a Recovery Scenario in UFT:

Now, we will learn how to create the recovery scenario in UFT based on an example.

Example – An error popup (missing mandatory fields) is appearing while trying to save the records intermittently. In this particular situation, we need to click on the OK button to close the error popup and re-execute the current step as a post-recovery action.

  • Step1#  We need to open the “Recovery Scenario Manager” from the navigation menu “Resources → Recovery Scenario Manager.”
  • Step2# Click on the “New Scenario” icon to open the wizard to create a recovery scenario in UFT and click on the Next button to select the triggering event.
Recovery Scenario in UFT - Step2
Recovery Scenario in UFT – Step2
  • Step3# We need to select the “popup window” radio option as the Trigger Event of the recovery scenario and click on the Next button.
Recovery Scenario in UFT - Step3
Recovery Scenario in UFT – Step3
  • Step4# Now, we need to click on the pointing hand icon and identify the error popup window using the mouse. UFT tries to identify the popup based on the window title and text. So, after the identification, we can use a regular expression to make it robust.
Recovery Scenario in UFT - Step4
Recovery Scenario in UFT – Step4
  • Step5# Initially, recovery operations are not set. To define the recovery operation, we need to click Next.
Recovery Scenario in UFT - Step5
Recovery Scenario in UFT – Step5
  • Step6# Now, based on our requirement, selecting “Keyboard or mouse operation.” On the next screen, select the “Click button with label” option using the pointer hand option and click on the Next button.
Recovery Scenario in UFT - Step6
Recovery Scenario in UFT – Step6
  • Step7# Recovery operation is defined now. Here, after unchecking the option “Add another recovery operation”, we need to click on “Next” button to proceed.
Recovery Scenario in UFT - Step7
Recovery Scenario in UFT – Step7
  • Step8#  We will select the option “Restart current test run” in the Post-Recovery section and provide the scenario name on the next screen. After entering the name, we need to click on “Next” button to proceed to the final screen.
Recovery Scenario in UFT - Step8
Recovery Scenario in UFT – Step8
  • Step9# Based on the requirement, we can add this scenario to the current test or to the default test settings. Now, to close the “Recovery Scenario” wizard in UFT, we need to click on the “Finish” button.
Recovery Scenario in UFT - Step9
Recovery Scenario in UFT – Step9
  • Step10# Now, we need to save the recovery scenario in an external file and close.

Scripting and Test Setting Approach:

On-Error-Resume-Next statements: 

It was using the On-Error- Resume-Next statements; the exception can be handled partially. In this approach, the test script block should be started with “On Error Resume Next” statements. It defines that in case of any error, execution will will skip the present step and continue with next step. After that, by checking the error, we can handle the exceptions. Important keywords are –

On Error Resume Next – 

In case of error, UFT will not raise an error message; instead of that, execution will move to the next step.

On Error Goto 0 – 

It will work in reverse procedure with comparison to the above keyword i.e., in case of any unhandled error, an UFT error popup will be thrown with three options – retry, skip and stop.

Error.Description – 

It stores the error description.

Error.Number – 

It holds the error number. For success, the value is zero.

Error.Clear – 

It reset the Error object.

Exception Handling in UFT - On Error Resume Next Statement
Exception Handling in UFT – On Error Resume Next Statement

Using Exit Statements: 

UFT provides some predefined methods which will allow us to handle the exceptions through the scripts. The frequently used methods are –   

ExitActionIteration – 

Use to exit the current iteration of the action. ExitAction – Exits the current action.  

ExitTest – 

UFT will exit from the test execution.

ExitTestIteration –  

Skip the current test iteration and the execution will be continued with the next test iteration.

Using Test Settings:

We can configure the recovery steps by selecting any of the below options from the UFT Test Setting wizards (Run Tab).

Pop up message box 

In case of any error, UFT shows a popup message with error details.

Proceed to next action iteration –

UFT will execute the next action iteration when an exception has occurred.

Stop run –

Execution will be stopped.

Proceed to next step – 

Execution will be resumed from the next step.

Proceed to next test iteration – 

UFT will execute the next test iteration for any error.

Exception Handling in UFT - Test Setting
Exception Handling in UFT – Test Setting

Synchronization in UFT:

Synchronization in UFT is an approach to define the time interface between the tool and the application under test. If the application behavior is slower than the expectation of UFT, the test will be failed. So, synchronization in UFT is another important topic for test automation.

Chances of synchronization errors can be minimized by using either of the below approaches –

Wait:  

The default Wait(timeout) statement is a static method to handle the synchronization errors. Here, timeout denotes the hardcoded wait time in seconds. During the execution, the script will wait for specific time at this point. We need to define the value of timeout based on the application responses.

WaitProperty in UFT:

To use the method WaitProperty in UFT, we need to specify the property name, the expected value of the property and the maximum wait time in mili-seconds. This is a dynamic way to handle the synchronization. Here, the execution will wait till the the property value satisfies with the expected value in the application. If the property value does not match, after the spefied maximum timeout, the script will proceed with the next step. Example –

Window(“<windiow name>”).WinListView(“<view name>”).WaitProperty “visible”,true,20000

  • Loop:

This is an indirect way to handle the synchronization dynamically. We can use a loop with a condition to check the the object’s property value does not satisfied with expected value. In the loop statement, we can provide a small time out value using the Wait(timeout) statement. So, the checking will be done after each timeout and loop will be continued until the object is visible.

  • Test Setting:

 We can define the synchronization timeout in the Test Setting wizard (Run tab and web tab for web navigation timeout). Based on this configuration, UFT will wait for the test objects.

Conclusion:

In this “Exception Handling in UFT ..” article, we have learned about exception handling in UFT along with recovery scenarios and synchronization in UFT. Please click here to get more information on “Exception Handling” from the Microfocus support portal.

UFT Tutorial:Create Test Case–Step By Step Guide For UFT 14.x

Create Test Case in UFT Folder Structure 300x100 1

Software testing is become the most important phase in software development life cycle which ensures the quality of end product. So, with out the successful testing phase, it will be extremely risky to deploy the software product in the production. In today’s busy life, market demands a faster releases of software product with high quality. Here, is come into the picture to reduce the testing cycle with expected quality. There is lots of automation tools are available in the market, but Unified Functional testing (UFT) tool is playing as the key player in software testing domain.

In this Create Test Case in UFT article, we are going to learn about the step by step guidance to create the test case in UFT along with the test framework.

UFT Tutorial – Table of Content

UFT Tutorial #1: UFT Overview

UFT Tutorial #2: UFT Setup – Download, Install, License Configuration and ALM Connection

UFT Tutorial #3: UFT Object Repository

UFT Tutorial #4: UFT Actions & Function Library 

UFT Tutorial #5: UFT Parameterization 

UFT Tutorial #6: VB Scripting in UFT

UFT Tutorial #7: Step by Step Guide to Create Test Case in UFT

UFT Tutorial #8: Exception Handling in UFT

UFT Tutorial #9: Recording in UFT with Checkpoints & Dictionary Object 

UFT Tutorial #10: UFT Interview Questions and Answers 

Step by Step Guide to Create Test Case in UFT

UFT is the short form of Unified Functional Testing, which is previously known as Quick Test Professional (QTP). With the help of VB Scripting, test cases build to automate any functional testing scenario.  Here, we are automating a sample application using the tool UFT. We are trying to explain each of the steps to automate the test scenario. First, we will understand the functional scenario which will be automated later in this article –

Functional Test Scenario:

Test Case Summary: Book flights through sample Flights Application.

Step#DescriptionExpected Result
1Open the Flights App (FlightsGUI.exe)The login screen should appear.
2Login with a valid credential (Username- John, Password- HP)Book Flight Screen Should appear.
3Enter below criteria and click on Find Details –  Source: Frankfurt  Destination: Portland  Travel Date: Today + 2 days  Class: Business  Tickets: 1A list of flights available should be displayed.
4Select the first available option and click on the button, “SELECT FLIGHT.”Flight Details screen should appear.
5Enter passenger name and click on “Order” button.A confirmation message with the Order Number should appear.
6Close the application.The application should disappear.

Test Automation Approach:

After analyzing the scenario, we can assume that the application having one major flow, i.e., flight booking, and this flow is applicable for different sets of test data. So, we will follow the below test automation approach to automate this particular scenario.

Framework Identification: Hybrid Framework which will be a combination of data-driven and modular automation test frameworks.

Environment variables: We need to store the configuration information such as application details, user credentials, framework path, etc., in external environment variables.

Test data: In a data-driven approach, we will store the data in the external excel sheet, which will be imported in the test case.

Object Repository: Create a central repository of test objects (i.e. shared object repository) so that multiple test cases can refer it to increase the reusability.

Reusables/Modules: We will create functions as modules to break the scenario into small parts.

Create Testcase in UFT – Step by Step Guide:

Step1 – Folder Structure: 

Below folder structure need to be created to set up the data driven automation test frameworks. The required folders are – 

Scripts  – UFT test cases will be stored here.

DataTable – It’s used to store the test Datasheets.

EnvirnmentFile – External Environment variable(xml) files are kept here.

ObjectRepository – The shared object repository (.tsr file) will be kept here.

The result – Result related files can be stored here.

Library – Function libraries will be stored here.

Create Test Case in UFT - Folder Structure
Create Test Case in UFT – Folder Structure

Step2 – Create XML for External Environment Variables: 

All the configuration or user-related data that are applicable for the entire automation suite need to be kept in an external environment file(XML) so that same can apply to the entire suite. Which needs to be stored in the EnvironmentFile folder. Here below parameters are created – 

ProjectName – It will be used for reporting purposes.

AppPath – The application exe path is stored here.

UserId/UserPwd – Refer to the application credential.

FrameworkPath – Refer to the root path of the test framework’s folder structure.

Create Test Case in UFT - External Environment Variable
Create Test Case in UFT – External Environment Variable

Step3 – Create External Data Sheet:

All the required test data will be store in an external excel file (FlightbookingData.xlsx), which needs to be stored in the DataTable folder. In this excel, column A, i.e., “TestCaseID,” will be used to map the data row with the current test case. 

Create Test Case in UFT - Shared Object Repository
Shared Object Repository (Create Test Case in UFT )

Step4 – Create/Modify Shared Object repository:

· Open the UFT component “Object Repository Manager” to create shared repository..

· Navigate Each of the application screens, as shown below images.

· Add the required test objects into this newly created shared object repository.

· The object repository is created now. Now we need to save the shared object repository in the ObjectRepository folder with the “TSR” extension.

Create Test Case in UFT - Application Overview
Create Test Case in UFT – Application Overview
Create Test Case in UFT - Shared Object Repository
Create Test Case in UFT – Shared Object Repository

Step5 – Create reusables:

Below functions need to be created in a function library which will store in Library folder with qfl extension,

ImportSheetAndSelectRow – Import Datasheet and Select Desire Data Row

OpenApp – Open Application

LoginToApp – Login to the Application

EnterDetailsToFindFlight – Enter details to find flights.

SelectFlight – Select a row to book the flight.

EnterPassengerNameAndOrder – Book the flight and verify the success message.

CloseApp – Close the application.

Create Test Case in UFT - Function Library 1
Create Test Case in UFT – Function Library 1
Create Test Case in UFT - Function Library 2
Create Test Case in UFT – Function Library 2

Step6 – Create Testcase in UFT:

Now we need to create the empty test case in uft and link the external resources. It should be created in the Scripts folder. After the creation of the test case, the external environment XML shared object repository and function library has to be attached with the test case.

Create Test Case in UFT - Associates with External Components
Create Test Case in UFT – Associates with External Components

Step7 – Call the modules:

Now we need to call the reusable modules, stored in the function library, in the local action(based on the test functionality) to complete the development. After this step, the test case will be complete from the automation point of view.

Create Test Case in UFT - Automated Test Case
Create Test Case in UFT – Automated Test Case

Step8 – Perform dry run and check the reports:

No need to execute the test case once to check if the scripts are working as expected. We can perform this check by reviewing the below reports. 

Create Test Case in UFT - Dry Run Result
Create Test Case in UFT – Dry Run Result

Here, based on the logs displayed in the report, we can assume that the test case has been developed correctly.

Conclusion:

In this Create Test Case in UFT article, we have learned about step by step approach to develop the test framework and create a test case in UFT. Please click here to get more information on this topic from the Microfocus support portal.

VB Scripting in UFT–An Excellent Guide for Beginners

VB Scripting in UFT If Else Conditional Statements in UFT 300x124 1

Testing is now the most essential phase in software development process to ensure the quality of the product. Also, without having testing, it will be very risky to release the software to use. The test automation process has changed the testing dimension with respect to effort savings and lightning fast regression cycle. There is many test automation tools are used in the testing industry. But, the most used automation testing tool is UFT.  

In this VB Scripting in UFT article, below topics will be explained with examples –

· Variables in UFT

· Constants in UFT

· Array in UFT

· Conditional Statements in UFT

· Looping Statements in UFT

· Sub and Function Procedures in UFT

UFT Tutorial – Table of Content

UFT Tutorial #1: UFT Overview

UFT Tutorial #2: UFT Setup – Download, Install, License Configuration and ALM Connection

UFT Tutorial #3: UFT Object Repository

UFT Tutorial #4: UFT Actions & Function Library 

UFT Tutorial #5: UFT Parameterization 

UFT Tutorial #6: VB Scripting in UFT

UFT Tutorial #7: Step by Step Guide to Create Test Case in UFT

UFT Tutorial #8: Exception Handling in UFT

UFT Tutorial #9: Recording in UFT with Checkpoints & Dictionary Object 

UFT Tutorial #10: UFT Interview Questions and Answers 

UFT Tutorial #4: VB Scripting in UFT

VB Scripting in UFT:

UFT supports VB Scripting as the programming language to write the code for any test cases. VB Script is derived from Visual Basic 4.0 language, which was developed by Microsoft. VB Scripting in UFT is very easy to learn, and it can be used to develop both server-side and client-side scripting.

Variables in UFT:

Variables in UFT are the placeholder that denotes a memory location that stores program information. It can be changed during run time. A variable has been represented by its name to read/write the stored value. Only one type of variant is available in VB Scripting, which can interact with numbers, strings, or dates. Based on the data, the variable is acted accordingly.

If we store any number with the double quotation, then it’s acted as a string type variable. VBScript in UFT allows us to declare the variables with the help of below three statements –

  • Dim
  • Public
  • Private

Dim Statement – Dim is used to declare any variable immediately irrespective of the datatype. One dim statements allows to declare multiple variables which are separated by comma. The scope of this type of variable is within the code block( in the Case of UFT, scope is restricted to the corresponding actions or function or sub).

Dim myVariable

 Dim myVariable1, myVariable2, myVariable3

We can declare any variable immediately by using its name in the code. So, in this case, an additional declaration statement is not required. But, if we keep the statement “Option Explicit” at the beginning of our scripting area, we have to write the variable declaration statement. Otherwise, UFT will throw an error message.

Public statement – If we declare variables as public, the variables are available throughout all the scripts in the suite.

Private statement – If we declare variables as private, variables are available within the script itself.

Assigning Values to Variables:

Using the below structure, we can assign values to the variables using the equal symbole – 

variableNameString = “My Value” //Assign string

variableNameNumber = 1234 //Assign number

Here variable name should be kept on the left side of the equal symbol, where the value should be kept on the right side. For String, the value should be kept within double quote marks.

Scalar Variables – When we store a single value to the variable, it’s represented as Scalar Variable.

Array Variables – When string more than one value in a single variable, it is known an array. We declare an Array Variable with a parenthesis. In the below example, a single-dimension array containing six elements is declared:

Dim myArrayStudents(5)

Here index starts from 0 to 5, so the records will always be one more than the number shown in parenthesis. Value assignments are done in the below way –

myArrayStudents(0) = “Vikram”

myArrayStudents(1) = “Tom”

.

.

myArrayStudents(5) = “Jerry”

Naming Convention:

The standards rule for the naming convention are mentioned below – 

  • It should begin with an alphabetic character.
  • It should not contain an embedded period.
  • Name should be self explanatory.
  • The maximum length should not be exceeds 255 chars.

Constants in UFT:

We can consider a constant as a variable of a number or String whose value will never change. i.e., after defining a constant, it will be acted as a read-only place holder. The VBScript already provides many in build constants variables like , vbOK, vbTrue, vbFalse, vbCancel, and so on. A constant has to be declared and defined using the keyword “CONST” like the below example –

Const MyString = “This is my string.”

Const MyAge = 49

 Within modules, constants are always private, and visibility can not be changed.

Array in UFT:

Array in UFT is a variable that stores a collection of values having the same data type such as number, String, etc. A set of same type elements can be stored in the same memory location where each of the element can be accessed by their reference number which are known as array index. The index of the first element always start from zero value.

While declaring an array we need to define two parts – the logical name of the array and the array subscripts which indicates the highest value of array index. Array indexes are the unique numbers which represent the each element of that array. This index always starts from zero.

It should be declared before use. We can declare an array by the dim statement. Two types of arrays are available in UFT –

·        Local Array – The scope of local array is restricted to the current function or procedure block where it was declared.

·        Global Array – If the array is declared globally or at the start of script, the values of the array (i.e. scope) can be accessed from all the functions or procedures which are defined with in the same vbscript.

Static and Dynamic Arrays:

VBScript allows us to declare static or dynamic array in UFT.

A static array can not be modified during the uft regression. It means, the static array keeps defined number of elements through out the execution.

A dynamic array can be enhanced at any point of time during the test execution.

Declare and assign Values to Arrays:

Declaration statements – Dim myArray(subscriptvalue)

Example: Declaring an array which stores four students name and assigns the value in it.

Dim arrStudents(3)

arrStudents(0) = “Tom”

 arrStudents (1) = “Henry”

arrStudents (2) = “Tina”

arrStudents (3) = “Vicky”

Conditional Statements in UFT:

The conditional statements are most important features of scripting to make it flexible and robust. The mostly used conditional statement in UFT will be explained through out this section.

If-Else Statement:

The If – Else statement is used build the conditional log in the UFT script. The purpose of this statement is to check one or multiple conditions and perform certain activities based on the checking. For an example – Here we will identify the current week day using the if-then-else statement.

If-Else Conditional Statements in UFT
If-Else Conditional Statements in UFT

The multiple elseif statements can be used to check multiple conditions. Also, we can write multiple conditions in the first line of “if statement” which should be separated by logical operators such as OR, NOT, AND, etc.

Select Case Statement / Switch Case Statement:

It is an alternative approach of instead of using multiple if conditions for a single variable. 

The Select-case statement is very helpful for the scenario where based on the different values of a single variable, we need to perform different activities. It’s also know is switch-case-statement. The use of case statement, we can write our script in a organized way. The select case statement execute the conditional expression at the beginning and the result of the conditional expression, will matched with different static conditions in case statement. Here, only the associated steps will be executed for the match case.

For an example – Here we will identify the current week day using the select case statement.

Select - Case Conditional Statements in UFT
Select – Case Conditional Statements in UFT (VB Scripting)

Looping Statements in UFT:

In a situation, where similar codes are executed again and again based on some conditions, it is advisable to use looping statements for better readability and efficiency . In this section, we will discuss about the different kinds of loops with the examples, which are very helpful in UFT scripting. The loops work on conditions or maximum iteration counters. The frequently used looping statements in UFT are explained below –

· Do Loop Statement

· While Loop Satement

· For Loop Statement

Do Loop:

When we need to execute few steps repeatedly based on one or multiple conditions, we need to use the Do Loop statements as it allows to continue the looping based on conditions. The loop will be continued till the conditions are getting satisfied. Here, the conditions are checked at the end of the looping statement. That means, the first iteration is always executed irrespective of the condition checking result. To exit from the middle of the loop for another specific if condition, the “Exit Do” statement can be used. At end of the loop, “while” statement is used for conditional checking. Example – In this example, the loop will be continued, until the counter value reached to 10,

VB Scripting in UFT - Looping Statements in UFT (Do-Loop)
VB Scripting in UFT – Looping Statements in UFT (Do-Loop)

It’s similar to Do-Loop structure. When we need to execute few steps repeatedly based on one or multiple conditions, we can use the While Loop statements as it allows to continue the looping based on conditions. The loop will be continued till the conditions are getting satisfied. Here, the conditions are placed at the beginning of the loop with the help of while keyword. That means, none of the iteration will be executed if the checking of the conditions are failed. To exit from the middle of the loop for another specific if condition, the “Exit While” statement can be used. At beginning of the loop, “while” statement is used for conditional checking. The primary difference between Do-Loop and While-Wend statement is the place of condition checking.

Example – In this example of VB Scripting, the loop will be continued, until the counter value reached to 10,

VB Scripting in UFT -Looping Statements in UFT (While-Wend)
While-Wend Looping Statements in UFT (VB Scripting in UFT)

For Loop:

For– Next statements are defined predefined iteration counter. The loop will be continued till the counter reached the highest value which is specified with “for” keyword. To exit from the middle of the loop for another specific if condition, the “Exit For” statement can be used. At end of the loop, “while” statement is used for conditional checking.

Example – In this example, the loop will be continued for ten iterations,

VB Scripting in UFT - Looping Statements in UFT (For-Next)
VB Scripting in UFT – Looping Statements in UFT (For-Next)

Sub Procedure in UFT:

A sub procedure in UFT is a group of statements which are bounded by the keyword “Sub” and “End Sub” to perform a specific task. It does not return any value. We can pass values to sub procedure as arguments. An empty parenthesis() represents that there is not input arguments. In UFT, the sub is used to create a unit of the functional block for modularization. 

For example, the below code shows that a sub is used to calculate and display the interest value based on the input interest rate, years, and principal amount.

VB Scripting in UFT - Sub Procedure in UFT
VB Scripting in UFT – Sub Procedure in UFT

Function Procedure in UFT:

A function procedure in UFT is a group of statements which are bounded by the keyword “Function” and “End Function” to perform specific activity and return the output. A function procedure in UFT is a block of statements enclosed by Function and End Function statements to perform specific actions. It has the data return capabilities, which is the primary difference with a sub. We can pass values to function procedure as arguments. We need to include an empty parenthesis() when no argument is required. In UFT, Function is used to create a unit of the functional block for modularization. 

For example, the below code shows that a Function is used to calculate and display the interest value based on the input interest rate, years, and principal amount.

VB Scripting in UFT - Function Procedure in UFT
VB Scripting in UFT – Function Procedure in UFT

Conclusion:

In this VB Scripting in UFT article (UFT Tutorial), we have learned about different variables, constants, arrays, conditional and looping statements. Click here to learn more on VB Scripting. Also, if you want to prepare for UFT Interview Questions, please click here.