Appium-iOS-Low-Leavel Insights on iOS Input Events(ios输入事件的详解)

Low-Level Insights on iOS Input Events

          • What Are Input Events
          • Lets Simulate a Single Tap
          • How About More Complicated Actions
          • Further Reading

What Are Input Events
什么是输入事件

iOS uses events concept to handle signals received from different input devices. An event is an object, which is generated in response to a signal from an input device. These objects are then delivered to the corresponding kernel subsystem, which processes them and notifies all listening processes about taps, key presses, swipes, etc. This means that in order to emulate a signal generated by an external device, such as touch screen, it is necessary to just send event objects with the same properties and in the same sequence as they would be generated by a real device.

iOS使用事件概念去处理来自不同设备接受到的输入信号.
一个事件是一个对象,
引起响应的是一个来自一个输入设备的信号.
然后这些对象被床底到响应的内核子系统,
对他们进行处理并通知所有监听进程的关于taps.按键,swipes等.
这意味着为了去模拟一个通过设备产生的信号,
例如触摸屏幕,
它必须只发送事件对象的具有相同属性和顺序通过实体设备.
Lets Simulate a Single Tap
模拟一次tap

The events API itself is a part of Apple private API and is not open sourced and neither it is documented. XCTest framework also does not expose any public APIs for input events generation. Although, there is a possibility to perform events generation via XCTest private undocumented APIs. In particular, we are interested in XCPointerEventPath and XCSynthesizedEventRecord interfaces. These APIs allow to create chains of input events and supply them to the system kernel for execution.

事件的API本身是Apple private API的一部分并且不是开源的也没有文档.
XCTest框架也不公开任何用于生成事件的公共API关于输入事件产生的.
尽管如此,可以通过XCTest私有的未记录的API执行事件生成.
特别是,我们对`XCPointerEventPath` and `XCSynthesizedEventRecord`
接口是感兴趣的.
这些APIs允许去创建输入事件并提供给他们给系统内核执行.

In order to synthesize a single tap it is necessary to: - Create a new XCPointerEventPath instance and init it for touch at the starting point - Add a new liftUp event at 0.125s offset using liftUpAtOffset: method - Add the generated event path object to XCSynthesizedEventRecord instance using addPointerEventPath: method - Execute the events using synthesizeWithError: method of XCSynthesizedEventRecord instance and control the returned error

为了方便去综合一个单一的tap有必要去:
创建一个新的:`XCPointerEventPath`
为起点处的触摸实例并初始化它
添加新的`liftUp`事件在0.125s
补偿设置使用`liftUpAtOffset`:方法-添加产生事件路径对象添加到`XCSynthesizedEventRecord`
实例使用`addPointerEventPath`:方法-执行事件使用`synthesizeWithError`:
关于`XCSynthesizedEventRecord`实例化和控制返回错误的方法.

There are several limitations to these APIs: - Each XCPointerEventPath instance can only be executed for a single action. If one tries to add, for example, two taps to a single path, then these are effectively ignored - Each XCPointerEventPath instance can only be initialized for a particular pointer type: touch, mouse (since Xcode 10.2) or keyboard (since Xcode 10.2) - Events can only be added with increasing offset values to an existing XCPointerEventPath instance

这些APIs有些局限性:
每个`XCPointerEventPath`实例只可以为单个操作执行.
如果一个人想去添加,例如,
两个taps有一个路径,
他们实际都是被忽略的'XCPointerEventPath'
实例只可以对特定的指针类型初始化:
触屏,鼠标(自Xcode 10.2开始)或键盘(自Xcode 10.2开始)
时间只可以随着补偿值的增加而添加'XCPointerEventPath'实例.
How About More Complicated Actions
关于更多的比较操作

Unfortunately, the API is private and has zero documentation. That is why one can only figure out what it really can while playing with it and trying different input combinations. It is known that providing multiple XCPointerEventPath instances with overlapping timeouts will generate a multitouch action with the amount of fingers equal to the amount of the supplied event paths. So, in order to generate two-finger symmetric swipe we need to supply the following events:

不幸的是,API是私密的并且没有文档.
这就是为什么人们只可以弄清楚它实际上能做什么和尝试不同输入组合.
众所周知提供多个重叠超时的`XCPointerEventPath`实例
将生成一个多点触控动作带有等同于手指数量提供事件路径的数量事件.
因此,为了产生两个手指对称滑动我们需要提供以下事件:
  • Create a two XCPointerEventPath instances and init them for touch at the starting point
创建两个'XCPointerEventPath'事例并初始化他们以便在起点触摸.
  • Add a moveToPoint event at 0.525s offset using moveToPoint: method to each path
添加一个`moveToPoint`事件在`0.525s`补偿使用:每个路径的方式
  • Add a liftUp eventa at 0.525s offset using liftUpAtOffset: method to each path
添加一个`liftUp`事件在`0.525s`补偿使用`liftUpAtOffset`每个路径的方式
  • Add the generated event paths to XCSynthesizedEventRecord instance using addPointerEventPath: method
添加引发事件的路径`XCSynthesizedEventRecord`
事例使用addPointerEventPath:方式
  • Execute the events using synthesizeWithError: method of XCSynthesizedEventRecord instance and control the returned error
执行事件使用`synthesizeWithError`:
方式`XCSynthesizedEventRecord`实例化并控制返回的错误.
Further Reading

Unfortunately, there is no information on this topic at all (private API ¯\_(ツ)_/¯). Consider visiting the following resources:

不幸的是,根本没有信息这个主题的(私有API`¯\_()_/¯`).考虑访问以下资源
  • https://github.com/appium/WebDriverAgent/tree/master/PrivateHeaders/XCTest
  • https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentTests/IntegrationTests/FBW3CTouchActionsIntegrationTests.m
  • https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentTests/IntegrationTests/FBW3CMultiTouchActionsIntegrationTests.m
  • https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m

你可能感兴趣的:(Appium,java,python,ios,测试类型,设计模式)