Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Advance Usages

Stan Lo edited this page May 24, 2020 · 1 revision

Advance Usages

Tapping methods like tap_on! are designed for simple use cases. They're actually short for

device = TappingDevice.new { # tapping action }
device.tap_on!(object)

And if you want to do some more configurations like stopping them manually or setting stop condition, you must have a TappingDevie instance. You can either get them like the above code or save the return value of tap_*! method calls.

Stop tapping

Once you have a TappingDevice instance in hand, you will be able to stop the tapping by

  1. Manually calling device.stop!
  2. Setting stop condition with device.stop_when, like
device.stop_when do |payload|
  device.calls.count >= 10 # stop after gathering 10 calls’ data
end

Device states & Managing Devices

Each TappingDevice instance can have 3 states:

  • Initial - means the instance is initialized but hasn't tapped on anything.
  • Enabled - means the instance is tapping on something (has called tap_* methods).
  • Disabled - means the instance has been disabled. It will no longer receive any call info.

When debugging, we may create many device instances and tap objects in several places. Then it'll be quite annoying to manage their states. So TappingDevice has several class methods that allows you to manage all TappingDevice instances:

  • TappingDevice.devices - Lists all registered devices with initial or enabled state. Note that any instance that's been stopped will be removed from the list.
  • TappingDevice.stop_all! - Stops all registered devices and remove them from the devices list.
  • TappingDevice.suspend_new! - Suspends any device instance from changing their state from initial to enabled. Which means any tap_* calls after it will no longer work.
  • TappingDevice.reset! - Cancels suspend_new (if called) and stops/removes all created devices. Useful to reset the environment between test cases.
Clone this wiki locally