[英]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解决方案所需遵循的步骤从一个很好的寻找,是:
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.