TestStack.如何在WinForm应用程序中单击位于文档中的超链接
本文关键字:文档 超链接 于文档 单击 WinForm TestStack 应用程序 | 更新日期: 2023-09-27 18:01:54
我正在尝试使用TestStack在一个应用程序中做一些自动化测试。白色框架,我无法找到一个解决方案,如何点击位于一个文档的超链接。document.logstructure ():
AutomationId: linkTexts
ControlType: ControlType.Document
Name: Perform an action on event#LinkId=1
from devices/recording server/management server#LinkId=2
HelpText:
Bounding rectangle: 354,563,570,151
ClassName: WindowsForms10.RichEdit20W.app.0.ca490a_r12_ad1
IsOffScreen: False
FrameworkId: WinForm
ProcessId: 6816
System.Windows.Automation.ScrollPattern
System.Windows.Automation.TextPattern
UISpy:UISpy视图
和超链接的图片:app内超链接图片
经过几天的搜索,我能找到的最佳解决方案是:
{
...
//Get document container
var document = _modalWindow.Get(SearchCriteria.ByAutomationId(Config.DocumentRulesEvent));
// Get document's bounding Rectangle
string rightCorner = document.Bounds.Right.ToString();
string leftCorner = document.Bounds.Left.ToString();
string topCorner = document.Bounds.Top.ToString();
string bottomCorner = document.Bounds.Bottom.ToString();
// Hardcoded percent of x and y
int percentX = 22;
int percentY = 7;
GetCoordinatesFromBoundingRectangle(rightCorner, leftCorner, topCorner, bottomCorner, percentX, percentY);
}
public void GetCoordinatesFromBoundingRectangle(string rightCorner, string leftCorner, string topCorner, string bottomCorner, int percentX, int percentY)
{
// transform strings to integre
int a = Int32.Parse(rightCorner);
int b = Int32.Parse(leftCorner);
int c = Int32.Parse(topCorner);
int d = Int32.Parse(bottomCorner);
// Calculate X from AB segment
int x = (a - b) * percentX;
x = x / 100;
x = b + x;
//Calculate Y from CD segment
int y = (d - c) * percentY;
y = y / 100;
y = c + y;
ClickOnPoint(x, y);
}
// Method that moves mouse to x and y and click
public void ClickOnPoint(int x, int y)
{
var pointClick = new System.Windows.Point(x, y);
Mouse.Instance.Click(MouseButton.Left, pointClick);
}