Create a VBScript Component

If you are not familiar with the process of creating scripted components in useMango™, you can learn more about it here.

Create a new VBScript scripted component

  1. Create a new scripted component in useMango™.

  2. After successfully creating the component, select VBScript(CScript) from the Engine dropdown.

  1. Select VBS-Infrastructure from the Resource Group dropdown.

Let’s start by writing a VBScript to find length of a given string:

  1. We will use the same component that we created previously. Change the component’s name to “Length of String.”

  2. Let’s include some parameters that will be passed to our newly created component.

If you are not familiar with the process of using parameters in scripted components in useMango™, you can learn more about it here.

  1. Create a Input parameters of type Text and name it string , respectively. Add an Output parameter of type Text and name it output.

Here’s a sample code snippet that divides 2 numbers:

Public Function ExecuteComponent(framework)
    Dim data,str_len

    On Error Resume Next
        data = framework.Data.GetArgument("P1", "").Value

        str_len = len(data)
        framework.log.info("The length of given string is " & str_len)
        framework.Data.SetOutputParameter "P2", str_len

        If Err.Number <> 0 Then
            Err.Raise 1234, "Source_of_error", "This is a custom error message."
            framework.StepFail Err.Description
        End If
    framework.StepPass "PASSED"
End Function
  • The name of the component function should be execute_component. We are passing a framework parameter that can be used to show information / debug the component.

  • To log information, we can use the framework.log.info() method, for example,

    framework.log.info ("This is informing")
    

  • To debug, use the framework.log.debug() method, for example,

    framework.log.debug ("This is debugging")
    

  • It also accepts a variable number of input arguments, which are identified by their parameter Ids, in this case P1 and P2.

  • To pass a component, we need to return a StepPass object whose constructor is of the form:

    framework.step_pass(message)
    

  • The message parameter, which specifies the success message, is of type string.

  • The outputs parameter, which specifies the component outputs, is a variable number of keyword arguments that can be specified in the format framework.data.set_output_parameter(‘ID’, value). In our case, the output is saved in a variable with the Id P2.

  • To indicate that a component has failed, we must return a StepFail object whose constructor is of the form:

    framework.StepFail(message)
    

  1. Copy the above sample code in the file component.vbs and save the changes.

That’s it! You’ve created your first ruby component, which you can use in any of your tests!