简体   繁体   English

如何在不关闭表单的情况下按按钮更改QTP中使用DotNetFactory制成的表单的textField中的文本?

[英]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. 我有一个在Quick Test Professional(QTP)中运行的测试,在运行前将被某些用户输入修改。 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 . 为此,我使用了QTP提供的DotNetFactory来创建一个表单,该表单具有我需要的各种字段/按钮,并遵循本示例中概述的策略。

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. 我得到的表单设计包括一个按钮,该按钮会将表单中的各个textField重置为其默认值。 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. 我当前的感觉是,我可以使用form.show()而不是使用form.showDialog()命令,并在等待按钮按下时尝试连续循环。 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. 是的,那篇文章很好地展示了带有QTP的DotNetFactory的功能。 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. 我宁愿使用Visual Studio创建表单,因为使用丰富的IDE来创建和维护表单要容易得多,而大多数情况下都是通过点击来实现的。 It would only take about 5 minutes to create something like below. 创建下面的内容大约只需5分钟。 (If you don't have Visual Studio license, you can use SharpDevelop or Visual Studio Express). (如果您没有Visual Studio许可证,则可以使用SharpDevelop或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. 下面的示例是在VB.Net中完成的,一个人可以轻松使用C#或他们更喜欢的任何其他.net语言。 (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) (对不起,我想添加表格的Visual Studio屏幕截图以使其更清楚,但由于我是stackoverflow的新用户并且没有足够的声誉而无法这样做)

VB.Net Form Code Snippet: VB.Net表单代码段:

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: 我还没有详细解释如何使用Visual Studio(我敢肯定网上有很多资源),但是基本上来说,为用户输入输入创建QTP解决方案所需遵循的步骤从一个很好的寻找,是:

  1. Design a form and corresponding code in Visual Studio. 在Visual Studio中设计一个表单和相应的代码。 (Note, choose a class library project rather than WinForms project, as you want to compile this into a dll afterwards) (请注意,选择一个类库项目而不是WinForms项目,因为之后您要将其编译为dll)
  2. Load the library using DotNetFactory in QTP. 使用QTP中的DotNetFactory加载库。
  3. Invoke the form in QTP using .ShowDialog(). 使用.ShowDialog()在QTP中调用表单。
  4. Use the properties values captured by the form. 使用表单捕获的属性值。

Corresponding QTP Code: 相应的QTP代码:

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. 让我知道您是否需要有关任何步骤的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不关闭应用程序的情况下关闭登录表单并显示主表单? - How can I close a login form and show the main form without my application closing? 如何在不关闭form2的情况下使用来自form2的值更新form1中的富文本框的内容? - How to update contents of rich text box in form1 with values coming from form2 without closing form2? 如何通过单击按钮使表单标题动态更改? - How do you make a form title dynamically change with a button click? 关闭表单后启用按钮 - Enable a button after closing a form 当我在组合框中选择一种语言时,如何更改所有表单的文本? - How can I change all the form's text when I choose a language in combobox? 如何使表单的Text属性始终等于文本框的Text属性? - How can I make it so that a form's Text property will always equal a textbox's? 如何使Windows窗体的关闭按钮不关闭窗体但使其不可见? - How do I make the close button of a Windows Form not close the form but make it invisible? 单击按钮如何更改表单图标? - How do I change my icon of the form on the click of a button? 如何在不关闭子表单的情况下关闭主表单? - How to close main form without closing child forms? 关闭表格时如何获取单元格值的变化? - How to get cell value change when closing form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM