Automation Beyond

Testing and Test Automation for Software Quality Assurance. Above Requirements. Beyond Expectations. Methodologies and concepts. Framework Design. Programming and Scripting. Created by Albert Gareev.

DotNetFactory interface functions – create custom dialog

Posted by Albert Gareev on 2009/06/18

Parent page: Service Functions – DotNetFactory (QTP, VBScript)

Used resources

Service Functions – String (QTP, VBScript)

Implementing optional and default parameters

 Create TextBox along with the Prompt Label and place on the GUI Form.


 Public Function PlaceTextBox(ByRef objForm, ByVal objParameter)
    Dim sPrompt
    Dim intLeft, intTop
    Dim objTextBox, objLabel

  'Verify parameters
  If TypeName (objParameter) <>  "Dictionary" Then
   Set objParameter = CreateObject("Scripting.Dictionary")
  End If

  sPrompt = objParameter.Item("p.prompt")
  If sPrompt = "" Then sPrompt = "Input value"

  Set objTextBox = CreateTextBox(objParameter)

  intLeft = objTextBox.Left
  intTop = objTextBox.Top
  Set objLabel = CreateLabel(sPrompt, AssociateParameters("p.left = " & intLeft & " , p.top = " & intTop - 20))
  
  objForm.Controls.Add(objLabel)
  objForm.Controls.Add(objTextBox)

  Set PlaceTextBox = objTextBox
 End Function

Create ComboBox along with the Prompt Label and place on the GUI Form.


 Public Function PlaceComboBox(ByRef objForm, ByVal objItems, ByVal objParameter)
    Dim sPrompt
    Dim intLeft, intTop
    Dim objComboBox, objLabel

  'Verify parameters
  If TypeName (objParameter) <>  "Dictionary" Then
   Set objParameter = CreateObject("Scripting.Dictionary")
  End If

  sPrompt = objParameter.Item("p.prompt")
  If sPrompt = "" Then sPrompt = "Select value"

  Set objComboBox = CreateComboBox(objItems, objParameter)

  intLeft = objComboBox.Left
  intTop = objComboBox.Top
  Set objLabel = CreateLabel(sPrompt, AssociateParameters("p.left = " & intLeft & " , p.top = " & intTop - 20))
  
  objForm.Controls.Add(objLabel)
  objForm.Controls.Add(objComboBox)

  Set PlaceComboBox = objComboBox
 End Function

 Create Button, assign the event, and place on the GUI Form.


 Public Function PlaceButton(ByRef objForm, ByVal sText, ByVal objParameter)
    Dim objButton

  'Verify parameters
  If TypeName (objParameter) <>  "Dictionary" Then
   Set objParameter = CreateObject("Scripting.Dictionary")
  End If

  Set objButton = CreateButton(sText, objParameter)

  Select Case UCase(objParameter.Item("p.result"))
   Case "ABORT", "CANCEL", "NO"
    Set objForm.CancelButton = objButton
   Case "OK", "RETRY", "YES"
    Set objForm.AcceptButton = objButton
  End Select

  objForm.Controls.Add(objButton)

  Set PlaceButton = objButton
 End Function

Example.


Set objForm = CreateForm("Test Setup", AssociateParameters("p.startpos = CenterScreen, p.width = 400, p.height = 300, p.locksize = Yes, p.lockview = Yes"))

Set objSelectEnvironment = PlaceComboBox(objForm, AssociateParameters("1 = DEV1, 2 = DEV2, 3 = UAT"), AssociateParameters("p.prompt = Test Environment, p.left = 25, p.top = 50, p.item = DEV2"))
Set objInputUserID = PlaceTextBox(objForm, AssociateParameters("p.prompt = User ID, p.left = 25, p.top = 100"))
Set objInputPassword = PlaceTextBox(objForm, AssociateParameters("p.prompt = Password, p.left = 25, p.top = 150, p.masked = Yes"))

Set objOK = PlaceButton(objForm, "OK", AssociateParameters("p.left = 124, p.top = 200, p.width = 75, p.result = OK"))
Set objCancel = PlaceButton(objForm, "Cancel", AssociateParameters("p.left = 200, p.top = 200, p.width = 75, p.result = Cancel"))

objForm.Activate()
objForm.ShowDialog()

2 Responses to “DotNetFactory interface functions – create custom dialog”

  1. [...] For complex data input dialog you can create your own custom one using DotNetFactory interface [...]

  2. [...] DotNetFactory interface functions – create custom dialog  [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>