Testing 如何等待元素在Ranorex上可见?
在Ranorex中,我发现了如何等待元素的存在,但我没有发现如何等待元素可见 我想做同样的事情,但我想等到元素可见。不幸的是,我只看到Testing 如何等待元素在Ranorex上可见?,testing,end-to-end,web-testing,ranorex,Testing,End To End,Web Testing,Ranorex,在Ranorex中,我发现了如何等待元素的存在,但我没有发现如何等待元素可见 我想做同样的事情,但我想等到元素可见。不幸的是,我只看到Exist和notexist作为WaitFor语句的可能值。在我的例子中,测试是不可靠的,因为尽管元素存在,但有时会启动单击,但仍然不会显示 您知道如何执行此操作吗?对于Web元素,很难知道项目是否存在、是否可见等 通过将DOM页面位置和宽度与我的示例中的滑动菜单位置和宽度进行比较,我实现了可靠性,如下所示: Public Function IsMenu
Exist
和notexist
作为WaitFor
语句的可能值。在我的例子中,测试是不可靠的,因为尽管元素存在,但有时会启动单击,但仍然不会显示
您知道如何执行此操作吗?对于Web元素,很难知道项目是否存在、是否可见等 通过将DOM页面位置和宽度与我的示例中的滑动菜单位置和宽度进行比较,我实现了可靠性,如下所示:
Public Function IsMenuVisible() As Boolean
Dim menuVisible As Boolean
'Get page position and width
Dim pageXPosition As Integer = repo.WebPage.Self.Element.ScreenLocation.X
Dim pageWidth As Integer = repo.WebPage.Self.Element.ScreenRectangle.Width
'Get configuration menu position and width
Dim menuXPosition As Integer = repo.WebPage.Menu.Self.Element.ScreenLocation.X
Dim menuWidth As Integer = repo.WebPage.Menu.Self.Element.ScreenRectangle.Width
'If menu top right location is >= web page size (out of screen)
If menuXPosition + menuWidth > pageXPosition + pageWidth Then
Report.Info(String.Format("Configuration menu is hidden (menuXPositon = {0}, pageXPosition = {1}, pageWidth = {2}, menuWidth = {3}).", menuXPosition, pageXPosition, pageWidth, menuWidth))
menuVisible = False
Else
Report.Info("Configuration menu is currently visible.")
menuVisible = True
End If
Return menuVisible
End Function
Public Sub WaitForMenuToAppear()
Dim retries As Integer = WaitForMenuToAppearRetries
While Not IsMenuVisible() AndAlso retries > 0
retries -= 1
Report.Info(String.Format("Waiting for configuration menu to be visible ({0}).", retries))
Delay.Duration(1000)
End While
If Not IsMenuVisible() Then
Throw New RanorexException(String.Format("Menu did not appear within '{0}' seconds.", WaitForMenuToAppearRetries))
Else
Report.Info("Menu is visible.")
End If
End Sub
在我的示例中,菜单位于页面的右侧。请根据您的需要进行修改
然后,执行简单的用户代码循环多次,以等待菜单出现,如下所示:
Public Function IsMenuVisible() As Boolean
Dim menuVisible As Boolean
'Get page position and width
Dim pageXPosition As Integer = repo.WebPage.Self.Element.ScreenLocation.X
Dim pageWidth As Integer = repo.WebPage.Self.Element.ScreenRectangle.Width
'Get configuration menu position and width
Dim menuXPosition As Integer = repo.WebPage.Menu.Self.Element.ScreenLocation.X
Dim menuWidth As Integer = repo.WebPage.Menu.Self.Element.ScreenRectangle.Width
'If menu top right location is >= web page size (out of screen)
If menuXPosition + menuWidth > pageXPosition + pageWidth Then
Report.Info(String.Format("Configuration menu is hidden (menuXPositon = {0}, pageXPosition = {1}, pageWidth = {2}, menuWidth = {3}).", menuXPosition, pageXPosition, pageWidth, menuWidth))
menuVisible = False
Else
Report.Info("Configuration menu is currently visible.")
menuVisible = True
End If
Return menuVisible
End Function
Public Sub WaitForMenuToAppear()
Dim retries As Integer = WaitForMenuToAppearRetries
While Not IsMenuVisible() AndAlso retries > 0
retries -= 1
Report.Info(String.Format("Waiting for configuration menu to be visible ({0}).", retries))
Delay.Duration(1000)
End While
If Not IsMenuVisible() Then
Throw New RanorexException(String.Format("Menu did not appear within '{0}' seconds.", WaitForMenuToAppearRetries))
Else
Report.Info("Menu is visible.")
End If
End Sub
我必须这样做,因为滑动总是可见的。使用Ranorex Spy的突出显示功能,在网页的查看区域外绘制红色矩形
我让你来完成这个例子
希望这有帮助…您可以使用
Visible
属性等待元素:
DateTime start = DateTime.Now;
while (Repository.Element.Visible)
{
Delay.Seconds(1);
if(System.DateTime.Now.Subtract(start).TotalSeconds > MaxWaitTime)
{
Validate.Fail("");
}
}
您可以在回购路径中添加此元素
[@visible='true']
,并使用WaitForExists
:
repo.elementInfo.WaitForExists(SearchTimeOut)
似乎有太多的人要求这样做,Ranorex终于在直接集成它的过程中,正如您在本文中看到的