Appium-W3C Action(W3C动作)


Perform a chain or multiple chains of keyboard and pointer (touch, mouse, stylus) actions //执行一个或多个键盘和指针(触摸、鼠标、手写笔)操作链

Example Usage
JavaWebElement source = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID");
WebElement target = (MobileElement) driver.findElementsByAccessibilityId("SomeOtherAccessibilityID");

Point source = dragMe.getCenter();
Point target = driver.findElementByAccessibilityId("dropzone").getCenter();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence dragNDrop = new Sequence(finger, 1);
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(0),
PointerInput.Origin.viewport(), source.x, source.y));
dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(700),
PointerInput.Origin.viewport(),target.x, target.y));
dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(dragNDrop));
Pythonelement = driver.find_element_by_accessibility_id("elId")
actions = ActionChains(driver)
actions.move_to_element(element)
actions.click(hidden_submenu)
actions.perform()
Javascript// webdriver.io example
// Example: expressing a 1-second pinch-and-zoom
// with a 500ms wait after the fingers first touch:
driver.performActions([{
"type": "pointer",
"id": "finger1",
"parameters": {"pointerType": "touch"},
"actions": [
{"type": "pointerMove", "duration": 0, "x": 100, "y": 100},
{"type": "pointerDown", "button": 0},
{"type": "pause", "duration": 500},
{"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": -50, "y": 0},
{"type": "pointerUp", "button": 0}
]
}, {
"type": "pointer",
"id": "finger2",
"parameters": {"pointerType": "touch"},
"actions": [
{"type": "pointerMove", "duration": 0, "x": 100, "y": 100},
{"type": "pointerDown", "button": 0},
{"type": "pause", "duration": 500},
{"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": 50, "y": 0},
{"type": "pointerUp", "button": 0}
]
}]);

// release an action
driver.releaseActions();

// wd example
// Performs a 'pinch-and-zoom’
var actions = new wd.W3CActions(driver);
var touchInput = actions.addTouchInput();
touchInput.pointerMove({duration: 0, x: 100, y: 100});
touchInput.pointerDown({button: 0});
touchInput.pause({duration: 500});
touchInput.pointerMove({duration: 1000, origin: 'pointer', x: -50, y: 100});
touchInput.pointerUp({button: 0});
var secondTouchInput = actions.addTouchInput();
secondTouchInput.pointerMove({duration: 0, x: 200, y: 200});
secondTouchInput.pointerDown({button: 0});
secondTouchInput.pause({duration: 300});
secondTouchInput.pointerMove({duration: 1000, origin: 'pointer', x: 50, y: 100});
secondTouchInput.pointerUp({button: 0});
await actions.perform();

// Releases any previously run actions (e.g.: if a key is ‘down’ because of /actions, releases it using key up)
await driver.releaseW3CActions();
Ruby# ruby_lib example
# Send keys to an element
# Build Single action chain
action_builder = action
keyboard = action_builder.key_inputs
el = find_element(id: "some_id")
action.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys(‘keys’).perform

# Build multiple action chains
# Example: expressing a 1-second pinch-and-zoom
# with a 500ms wait after the fingers first touch:
f1 = action.add_pointer_input(:touch, 'finger1')
f1.create_pointer_move(duration: 1, x: 200, y: 500, origin:
::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f1.create_pointer_down(:left)
f1.create_pause(0.5)
f1.create_pointer_move(duration: 1, x: 200, y: 200, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f1.create_pointer_up(:left)

f2 = action.add_pointer_input(:touch, 'finger2')
f2.create_pointer_move(duration: 1, x: 200, y: 500, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f2.create_pointer_down(:left)
f2.create_pause(0.5)
f2.create_pointer_move(duration: 1, x: 200, y: 800, origin: ::Selenium::Web@Driver::Interactions::PointerMove::VIEWPORT)
f2.create_pointer_up(:left)

perform_actions [f1, f2]

# ruby_lib_core example
# Send keys to an element
# Build Single action chain
action_builder = @driver.action
keyboard = action_builder.key_inputs
el = @driver.find_element(id: "some_id")
@driver.action.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys').perform

# Build multiple action chains
# Example: expressing a 1-second pinch-and-zoom
# with a 500ms wait after the fingers first touch:
f1 = @driver.action.add_pointer_input(:touch, 'finger1')
f1.create_pointer_move(duration: 1, x: 200, y: 500, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f1.create_pointer_down(:left)
f1.create_pause(0.5)
f1.create_pointer_move(duration: 1, x: 200, y: 200, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f1.create_pointer_up(:left)

f2 = @driver.action.add_pointer_input(:touch, 'finger2')
f2.create_pointer_move(duration: 1, x: 200, y: 500, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f2.create_pointer_down(:left)
f2.create_pause(0.5)
f2.create_pointer_move(duration: 1, x: 200, y: 800, origin: ::Selenium::Web@Driver::Interactions::PointerMove::VIEWPORT)
f2.create_pointer_up(:left)

@driver.perform_actions [f1, f2]
C#var inputDevice = new PointerInputDevice(PointerKind.Touch);
var actionSequence = new ActionSequence(inputDevice, 0);

actionSequence.AddAction(inputDevice.CreatePointerMove(element));
actionSequence.AddAction(inputDevice.CreatePointerDown(PointerButton.TouchContact));
actionSequence.AddAction(inputDevice.CreatePause(TimeSpan.FromSeconds(1)));
actionSequence.AddAction(inputDevice.CreatePointerUp(PointerButton.TouchContact));

driver.PerformActions(new List {actionSequence});
PHP// TODO
Description
  • input source: Represents an input device (pointer or key) that a series of actions are dispatched to. The input source has a unique ID.
    /* 输入源:表示一系列操作被分派到的输入设备(指针或键)。输入源具有唯一的ID */
  • action: An action that is dispatched to an input source. For a keyboard source, this can be ‘keyDown’ or ‘keyUp’. For a pointer event this can be ‘pointerMove’, ‘pointerDown’, or ‘pointerUp’. ‘pause’ events can also be sent to the device.
    /* 动作:分派到输入源的动作。对于键盘源,可以是“keyDown”或“keyUp”。对于指针事件,可以是“pointerMove”、“pointerDown”或“pointerUp”“暂停”事件也可以发送到设备 /
    The Actions API takes a list of input sources and executes each ‘tick’. A ‘tick’ is a slice of an action chain, so if you have two input sources, the first ‘tick’ is the 0-indexed action, the second ‘tick’ is the 1-indexed action, etc… All of the actions per tick are executed concurrently.
    /
    Actions API获取输入源列表并执行每个“勾选”。“tick”是动作链的一部分,因此如果有两个输入源,第一个“tick”是0索引动作,第二个“tick”是1索引动作,等等。。。。每个勾号的所有操作都同时执行 */
Support
Appium Server
PlatformDriverPlatform VersionsAppium VersionDriver Version
iOSXCUITest9.3+1.6.0+All
UIAutomationNoneNoneNone
AndroidEspresso?+1.9.0+All
UiAutomator2?+1.6.0+All
UiAutomatorNoneNoneNone
MacMac?+1.6.4+All
WindowsWindows10+1.6.0+All
Appium Clients
LanguageSupportDocumentation
JavaAllseleniumhq.github.io
PythonAllselenium-python.readthedocs.io
Javascript (WebdriverIO)All
Javascript (WD)All
RubyAllwww.rubydoc.info
PHPAllgithub.com
C#Allgithub.com
HTTP API Specifications
Endpoint

POST /session/:sessionId/actions

URL Parameters
namedescription
session_idID of the session to route the command to
JSON Parameters
nametypedescription
actionsarray<array>An array of input sources
actions[$INDEX]objectAn object that represents an input source
actions[$INDEX].typestringThe type of input source. Can be ‘pointer’, ‘key’ or ‘null’
actions[$INDEX].idstringUnique identifier of the input device which is used for current and future actions
actions[$INDEX].parametersobject(optional) Set parameters for the input source. Required for ‘pointer’ inputs
actions[$INDEX].parameters.pointerTypestringType of pointer. Can be ‘touch’, ‘mouse’ or ‘pen’
actions[$INDEX].actionsarray<object>A list of actions to perform on the input source
actions[$INDEX].actionsarray<object>A list of actions to perform on the input source
actions[$INDEX].actions[$INDEX]objectThe action to perform on the input source
actions[$INDEX].actions[$INDEX].typestringThe type of action. For any input source it can be ‘pause’. For ‘pointer’ input source ‘pointerMove’, ‘pointerUp’ or ‘pointerDown’. For ‘key’ it can be ‘keyDown’ or ‘keyUp’
actions[$INDEX].actions[$INDEX].valuestringFor a ‘keyUp’ or ‘keyDown’ action thevalue to send to the keyboard. Should be a one-character string (“s”, “\uE009”)
actions[$INDEX].actions[$INDEX].durationnumberHow long to perform the action in ‘ms’. Only applicable to ‘pause’ and ‘pointerMove’.
actions[$INDEX].actions[$INDEX].originstring``|``objectFor ‘pointerMove’, this tells the input source what x,y are relative to. Can be ‘viewport’, ‘pointer’ or {‘element-6066-11e4-a52e-4f735466cecf’: ‘’}
actions[$INDEX].actions[$INDEX].xnumberX coordinate of pointer move event
actions[$INDEX].actions[$INDEX].ynumberY coordinate of pointer move event
Response

null

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aniona

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值