简体   繁体   中英

How Can I Make a Button Press Change the Text in textFields of a Form Made With DotNetFactory in QTP, Without Closing the Form?

I have a test running in Quick Test Professional(QTP) that is going to be modified by some user input before it runs. To accomplish this I have used the DotNetFactory that QTP offers to create a form with the various fields/buttons that I need, following the strategy outlined in this example .

The design for the form that I have been given includes a button that would reset the various textFields in the form to their default values. My problem is that I am not sure how to go about implementing this button as it seems any button presses will close the form. It does occur to me that I could close the form and reopen it with the default values but there are some fields that I do not wish to reset so this is not ideal. My current feeling is that instead of using the form.showDialog() command, I could use form.show() and attempt to loop continuously while waiting for a button press. That sounds good but does anyone know how to accomplish this in this scenario? Or is dynamically changing the form just not possible?

Thanks

Yes, that article is good to show the power of DotNetFactory with QTP. However it's not a solution I would use to create forms. Especially if you are intending to have more than a couple of fields on that form.

I would rather create the form using Visual Studio as it is much easier to create and maintain a form using a rich IDE, by mostly using point and click. It would only take about 5 minutes to create something like below. (If you don't have Visual Studio license, you can use SharpDevelop or Visual Studio Express).

The example below is done in VB.Net, one can just as easily use C# or any other .net language they are more comfortable with. (Sorry, I wanted to add Visual Studio screenshots of the form to make this clearer but not able to do so as I'm new user on stackoverflow and don't have enough reputation)

VB.Net Form Code Snippet:

Public Class EnvironmentDataForm
    Private strServerName As String
    Private strUsername As String
    Private strPassword As String
    Public Property DBServerName() As String
        Get
            DBServerName = strServerName
        End Get
        Set(ByVal value As String)
            strServerName = value
            TextBox_DBServer.Text = strServerName
        End Set
    End Property

    Public Property DBUsername() As String
        Get
            DBUsername = strUsername
        End Get
        Set(ByVal value As String)
            strUsername = value
            TextBox_DBUsername.Text = strUsername
        End Set
    End Property

    Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        strServerName = TextBox_DBServer.Text
        strUsername = TextBox_DBUsername.Text
        strPassword = TextBox_DBPassword.Text
        Me.Close()
    End Sub
End Class 

I haven't gone into detail of explaining how to use Visual Studio (I'm sure there are lot's of sources for this on the net), but basically the steps you need to follow to create a solution for QTP that takes in user input from a nice looking for, are:

  1. Design a form and corresponding code in Visual Studio. (Note, choose a class library project rather than WinForms project, as you want to compile this into a dll afterwards)
  2. Load the library using DotNetFactory in QTP.
  3. Invoke the form in QTP using .ShowDialog().
  4. Use the properties values captured by the form.

Corresponding QTP Code:

Set objEnvDataForm = DotNetFactory.CreateInstance(_
            "EnvironmentData.EnvironmentDataForm",_
            "C:\EnvironmentData.dll")

'This step will block QTP execution until the form is closed. 
'Also, make sure the form is designed to save the field data before closing: 
'    See Button1_Click() in the .Net code above
objEnvDataForm.Showdialog() 

strConnString = "DRIVER={Microsoft ODBC for Oracle};" &_
        "Server="& objEnvDataForm.DBServername  &_
        ";Uid="& objEnvDataForm.DBUsername  &_
        ";Pwd="& objEnvDataForm.DBPassword  

Set objCon = CreateObject("ADODB.Connection")   
objCon.Open strConnString

Hope that helps. Let me know if you need any more info on any of the steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM