X Auto Testing Tools

本文介绍了XTest扩展在Linux下的应用,特别是如何通过XTestFakeKeyEvent和XTestFakeButtonEvent等函数来模拟键盘和鼠标事件,为Xdriver测试提供了一种自动化解决方案。此外还探讨了一些较少使用的函数如XTestSetGContextOfGC。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

xAutoClick
http://xautoclick.sourceforge.net/documentation.html

Linux下类似按键精灵的东东。
可以改进一下用于X driver的测试。


XTest Extention是关键,尝试Auto Testing工具的开发,积累.
libXtst包含的函数有:
       XTestQueryExtension, XTestCompareCursorWithWindow, XTestCompareCurrentCursorWithWindow, XTestFakeKeyEvent,
       XTestFakeButtonEvent, XTestFakeMotionEvent, XTestFakeRelativeMotionEvent, XTestGrabControl, XTestSetGContextOfGC,
       XTestSetVisualIDOfVisual, XTestDiscard - XTest extension functions

键盘的按键操作函数:
int XTestFakeKeyEvent(display, keycode, is_press, delay);

 Display *display;
 unsigned int keycode;
 Bool is_press;
 unsigned long delay;


鼠标的按键操作函数:
 int XTestFakeButtonEvent(display, button, is_press, delay);

 Display *display;
 unsigned int button;
  Bool is_press;
  unsigned long delay;


还有判断鼠标移动位置等函数,总体来说是“Keep It Simple”的设计。

使用这个扩展进行X窗口等测试,需要考虑延展性。先实现几个最简单的操作小程序:鼠标单击左键、双击左键、鼠标位置移动、键盘输入等。再编写shell脚本调用‘Little tool’去进行综合测试。

熟悉了XTestFakeKeyEvent, XTestFakeButtonEvent, XTestFakeMotionEvent, XTestFakeRelativeMotionEvent, XTestGrabControl等使用方法。
但是如下两个函数并不熟悉:

XTestSetGContextOfGC
       sets the GContext within the opaque datatype referenced by gc to be that specified by gid.

XTestSetVisualIDOfVisual
       sets the VisualID within the opaque datatype referenced by visual to be that specified by
       visualid.


PS: XTestFakeKeyEvent类似Windows下SendMessage(hwnd, KEY_PRESS,0 ,128)的功能
### JavaScript 中 `new` 关键字的作用 在 JavaScript 中,`new` 是一种用于创建对象的关键字。它通过调用构造函数来初始化一个新的对象实例[^4]。以下是其具体作用: 1. **创建新对象** 当使用 `new` 调用某个构造函数时,会先创建一个全新的空对象。 2. **链接原型链** 新创建的对象会被设置为指向该构造函数的 `prototype` 属性,从而继承构造函数中的方法和属性。 3. **执行构造函数** 构造函数会被自动调用,并将新建的对象作为上下文 (`this`) 提供给构造函数使用。如果构造函数返回了一个非原始类型的值,则忽略默认返回的新对象并采用显式的返回值;否则,默认返回的是这个新对象。 #### 示例代码 以下是一个简单的例子展示如何利用 `new` 实例化对象: ```javascript function Animal(name, sound) { this.name = name; this.sound = sound; } var dog = new Animal('Dog', 'Woof!'); console.log(dog); // 输出 {name: "Dog", sound: "Woof!"} ``` 对于特定于 `AutoTesting` 对象的情况,假设存在如下定义: ```javascript function AutoTesting(config) { this.config = config || {}; this.runTests = function () { console.log("Running tests with configuration:", this.config); }; } // 使用 new 创建实例 const testingInstance = new AutoTesting({ mode: "strict" }); testingInstance.runTests(); // 输出 Running tests with configuration: {mode: "strict"} ``` 上述代码展示了当实例化 `AutoTesting` 类型时,`new` 的工作流程以及最终生成的对象结构。 ### 注意事项 尽管现代开发中箭头函数和其他形式逐渐流行起来,但在某些场景下仍需依赖传统的基于类或者构造器的方式完成复杂逻辑封装[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值