QTP中的Wait()函数
任何人都可以建议我一个可以在 QTP 中用于以下场景的函数...
因为有时页面导航需要时间,因此我们的脚本显示错误。为此,我们使用wait(time)
函数,但它是QTP控件等待的固定时间。我想使用一个函数(我听说过同步函数,但不知道如何使用它),以便QTP只等待时间,导航所花费的时间(不比它更多/更少)。
Can any body suggest me a function which I can use in QTP for following scenario...
As sometimes page navigation take times due to which our script shows an error. For that we use the wait(time)
function, but it is a fixed time for which the QTP control waits. I want to use a function (I have heard about the sync function, but don't know how to use it) so that QTP waits only for the time, time taken in navigation (not more/less then it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
处理这种情况的标准方法是使用 Page(或在某些情况下是 Browser)对象的 .Sync 方法。
我发现它非常不稳定,根据测试的应用程序,该功能可能会完美运行,而在其他情况下则不会等待足够长的时间。
该问题似乎主要与 Web 2.0 应用程序(基于 AJAX)有关。与服务器的网页连接通常比 java 脚本打开的异步连接更早关闭。
如果有一个视觉指南指示该页面仍在加载,您可以编写一个循环并检查该对象。一旦对象消失,您就可以恢复测试执行。
为了避免在需要同步的每个地方编写此代码,您可以使用以下代码用您自己的版本覆盖 QTP 本机方法:
谢谢,
马切伊
The standard way of dealing with this kind of scenarios is to use .Sync method of the Page (or in some cases Browser) objects.
I found it very temperamental and depending on the tested application this function might work perfectly and on the other occasion will not wait long enough.
The problem seems to be related mainly to Web 2.0 applications (AJAX based). Web page connection to the server is usually closed much earlier then asynchronous connection opened by java script.
If there is a visual guide indicating that that page is still loading you could write a loop and check for that object. Once the object disappear you could resume test execution.
To save yourself writing this code in every place where you need to sync you could overwrite QTP native method with your own version with following code:
Thanks,
Maciej
同步功能正是您想要的。您可以通过多种方式使用它,例如:
禁用。
结束。
想想 GUI 中发生了什么来指示您操作已完成。这个特定的对象和/或属性是您想要同步的对象和/或属性。
http://qtp.blogspot.com/2007/ 09/qtp-sync-wait-and-synchronization.html
其他选项包括使用
WaitProperty
和Exist
命令将脚本与应用程序同步。http://www.sqaforums.com/showflat.php?Number=555273
QTP 函数参考应该有助于使用这些函数并解释所使用的参数。如果您仍然遇到问题,请发布代码段,以便我们查看。
The sync functionality is what you want. You can use it in a variety of ways, such as:
disabled.
finish.
Think about what is happening in the GUI to indicate to you that the operation has completed. This particular object and/or property is what you want to sync on.
http://qtp.blogspot.com/2007/09/qtp-sync-wait-and-synchronization.html
Other options include using the
WaitProperty
andExist
commands to synchronize the script with the application.http://www.sqaforums.com/showflat.php?Number=555273
The QTP function reference should help with using these functions and explaining the parameters used. If you are still having issues, post a code segment so we can take a look.
WaitProperty 方法是这种情况的最佳解决方案。
等待指定的对象属性达到指定的值或超过指定的超时,然后再继续下一步。
返回值: 布尔值。如果属性达到该值,则返回 TRUE;如果在属性达到该值之前达到超时,则返回 FALSE。 FALSE 返回值并不表示步骤失败。
WaitProperty Method is best solution for this scenario.
Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.
Return Value: A Boolean value. Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value. A FALSE return value does not indicate a failed step.
最好的确定方法通常是对新页面中的对象使用
Exists(timeout)
。The best way to be sure is often to use
Exists(timeout)
on an object from the new page.'' 在您想要等待 obj 准备就绪的任何地方使用此函数
'' Use this function where ever you want to wait until the obj is ready
例如
Browser().page().link().click()
Browser().synchronize
这是一个很棒的函数,
享受一下
for example
Browser().page().link().click()
Browser().synchronize
it's a great function
enjoy
我使用如下所示的东西,基本上做一个循环来检查
如果页面上的元素存在,一旦它确实存在,您就可以退出循环并继续测试。
但是,如果该元素不存在,您不想陷入无限循环,因此我有
添加了另一个条件,在放弃之前检查一定次数。
如果达到最大重试尝试次数,或者找到该元素,则退出循环。
示例代码:
'
I use something as per below, basically do a loop which checks to see
if an element on the page exists, once it does exist you can exit the loop and continue with your test.
However, if the element does not exist, you do not want to be caught up in an endless loop, therefore I have
added another condition which checks a certain number of times before giving up.
If either the maximum number of retry attempts are reached, or if the element is found, then the loop is exited.
Example code:
'
你好,我希望这会有所帮助。这里首先检查对象( webelement )是否存在,然后检查它是否被禁用,然后调用同步,因此最好使用等待。谢谢
可用于各种网页控件。
Hi i hope this may help. Here first check the object ( webelement ) is present and then checks is it disabled and then it calls a sync so it will be better to use for wait. Thank you
can be used for all kinds of web controls.
将同步添加到预期的下一个页面对象。
例如,如果下一个浏览器和页面是“第 1 页”,那么该行将是:
或者,如果您不确定将出现哪个页面,只需使用
上面的行应该检查下一个浏览器和页面(假设只打开一个浏览器)当时)。
如果您想深入检查下一个元素的 Html 属性,您可以使用任何对象的 .Object 方法并检查其 HTML 属性,例如 css 等。
Add sync to the next Page Object expected.
For Example if the next Browser and Page are "Page 1", so line will be:
Or if you re not sure which Page will come just use
Above line should check any browser and page which comes next(assuming there is only one browser open at that time).
If you want to go deep and check next elements Html Properties you can use .Object method of any object and check its HTML properties like css etc.
当您确定单击某个按钮后应用程序中发生更改的对象后,例如单击“保存”后,应用程序返回一条消息,您可以将该对象放在 Exist(1) 语句中。
对象的参数“1”表示应检查元素的时间,低于该值将无法始终起作用(我是根据经验这么说的),而高于该值则不可取。
这是我经常使用的一个片段,并且效果很好,我认为它会满足您的需求。
如果对象没有 Exist 方法,请尝试 .Object.isDisabled 或 .Object。 (检查此处自动完成显示的内容)例如 Browser("Browser").Page("Page").WinElement("Message").Object.isDisabled 其中“Object”是尝试使用本机对象方法的方法。
请注意,UFT 用于自动化功能测试,需要一些时间来检查对象(一些毫秒)。
因此,对象出现,QTP 需要几毫秒或更长时间才能看到它存在或对象的属性更改了值。
After you identify the object that changes in your application after you click a certain button, as in after clicking Save, the application return a message, you can put the object with Exist(1) statement.
The Parameter "1" of the object represents time in which the element should be checked, lower than that will not work always (I say this from experience) and higher is not desirable.
This is a snippet I use very often and I have good results, and I think it will suit your needs.
If the object does not have the Exist method please try .Object.isDisabled or .Object. (check what autocomplete shows here) for example Browser("Browser").Page("Page").WinElement("Message").Object.isDisabled where "Object" is a method that tries to use native object methods.
Please note that UFT is used for automated functional testing and will take some time to check the object (some miliseconds).
So the object appears and it takes some miliseconds or more for QTP to see that it exists or that a property of the object changed value.
您可以使用以下 4 个属性:
例如 -
wait 0,500
例如 -
browser.page.sync()
或browser.page.sync(30)
例如 - 等待 25 秒:
browser.page.WaitProperty "text", "Simple Interest",25000
例如 -
browser.page.exist(30)
You can use from these 4 properties:
Ex -
wait 0,500
Ex -
browser.page.sync()
orbrowser.page.sync(30)
Ex - wait for 25 seconds:
browser.page.WaitProperty "text", "Simple Interest",25000
Ex -
browser.page.exist(30)
这是一种常见行为,应用程序需要一些时间才能导航到其他页面,而该页面的时间不固定。如果您使用 Wait(50) ..这将等待 50 秒,因为这是硬编码的等待...
如果您的脚本花费的时间少于 50 秒(假设为 20 秒),则脚本将强制 UFT 等待 30 秒以上,这会增加执行时间。
我根据我的应用程序行为使用了下面的
步骤:
代码如下:
1) browser().page.().webbutton("login").click
2) 将下一页对象存储在存储库中以进行验证
Browser("Browser姓名”)。 Page ("PageName").Webelement("Webelement name").waitproperty("Webbutton", "HomePage",30000)
这将给出布尔返回值。
this is a common behavior that application will take some time to navigate to other page which is not fixed time.If you are using Wait(50) ..this will wait 50 sec as this is hardcoded wait...
if your script is taking less than 50 sec suppose 20 sec then scripting is forcing UFT to wait for more 30 sec which increases execution time.
I used below based on my application behavior
Steps:
Code is as follows :
1) browser().page.().webbutton("login").click
2) Store the next page object in the repository for verification
Browser("Browser name"). Page ("PageName").Webelement("Webelement name").waitproperty("Webbutton", "HomePage",30000)
This will give Boolean return value .