在 UIAutomation 中模拟绘图

发布于 2025-01-02 06:01:25 字数 66 浏览 5 评论 0原文

我有一个应用程序,允许用户使用绘图功能写入某个区域,然后保存图像。有没有办法用 UIAutomation 来模拟这个?

I have an application that allows the user to write into an area using a drawing function and then save the image. Is there a way to emulate this with UIAutomation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟到的我 2025-01-09 06:01:25

尝试使用内置函数dragFromToForDuration(from, to, timeout)。获取对象属性线origin.x和origin.y以及size.width和size.height,您将能够设置绘图的坐标。你甚至可以尝试画一些很棒的东西:)

这段代码将从绘图区域的左上角到右下角画一条线,持续 3 秒(至少我希望如此)。您可以更改超时参数以加快或减慢绘制速度。

var drawingAreaObject = ...mainWindow().<yourObject>;

var drawingAreaObjectRect = drawingAreaObject.rect();

var xBeginDrawPoint = drawingAreaObjectRect.origin.x + 1;
var yBeginDrawPoint = drawingAreaObjectRect.origin.y + 1;

var xEndDrawPoint = drawingAreaObjectRect.origin.x + drawingAreaObjectRect.size.width - 1;
var yEndDrawPoint = drawingAreaObjectRect.origin.y + drawingAreaObjectRect.size.height - 1;

UIATarget.localTarget().dragFromToForDuration({x:xBeginDrawPoint, y:yBeginDrawPoint}, {x:xEndDrawPoint, y:yEndDrawPoint}, 3);

您还可以尝试 flickInsideWithOptions (我不确定这个,但理论上是可能的)或 tapWithOptions() 来绘制一个点。
不幸的是,您只能使用此函数绘制线条。

Try to use build-in function dragFromToForDuration(from, to, timeout). Getting the object properties line origin.x and origin.y and size.width and size.height you will be able to set from and to coordinates for your drawing. You can even try to draw something awesome :)

This code will draw a line for 3 seconds from the top left corner to the bottom right corner of your drawing Area (at least I hope it will). You can change timeout parameter to draw faster or slower.

var drawingAreaObject = ...mainWindow().<yourObject>;

var drawingAreaObjectRect = drawingAreaObject.rect();

var xBeginDrawPoint = drawingAreaObjectRect.origin.x + 1;
var yBeginDrawPoint = drawingAreaObjectRect.origin.y + 1;

var xEndDrawPoint = drawingAreaObjectRect.origin.x + drawingAreaObjectRect.size.width - 1;
var yEndDrawPoint = drawingAreaObjectRect.origin.y + drawingAreaObjectRect.size.height - 1;

UIATarget.localTarget().dragFromToForDuration({x:xBeginDrawPoint, y:yBeginDrawPoint}, {x:xEndDrawPoint, y:yEndDrawPoint}, 3);

You can also try the flickInsideWithOptions (I'm not sure about this one but theoretically it is possible) or tapWithOptions() to draw a point.
Unfortunately you will be able to draw only lines using this functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文