{"id":796,"date":"2023-02-28T11:29:42","date_gmt":"2023-02-28T03:29:42","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=796"},"modified":"2023-04-05T17:43:42","modified_gmt":"2023-04-05T09:43:42","slug":"appium-automation-testing-appium-api-touchaction","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/28\/appium-automation-testing-appium-api-touchaction\/","title":{"rendered":"Appium\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0812\uff09\u2014\u2014 Appium API \u4e4b TouchAction \u64cd\u4f5c"},"content":{"rendered":"<p>Appium\u7684\u8f85\u52a9\u7c7b\uff0c\u4e3b\u8981\u9488\u5bf9\u624b\u52bf\u64cd\u4f5c\uff0c\u6bd4\u5982\u6ed1\u52a8\u3001\u957f\u6309\u3001\u62d6\u52a8\u7b49\u3002<\/p>\n<h2>\u6309\u538b\u63a7\u4ef6<\/h2>\n<p><!-- more --><\/p>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>press()<\/li>\n<\/ul>\n<p>\u5f00\u59cb\u6309\u538b\u4e00\u4e2a\u5143\u7d20\u6216\u5750\u6807\u70b9(x,y)\u3002\u901a\u8fc7\u624b\u6307\u6309\u538b\u624b\u673a\u5c4f\u5e55\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002<\/p>\n<pre><code class=\"language-java\">press(WebElement el, int x, int y)<\/code><\/pre>\n<p>press\u4e5f\u53ef\u4ee5\u63a5\u6536\u5c4f\u5e55\u7684\u5750\u6807(x,y)<\/p>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">TouchAction(driver).press(x=0, y=308).release().perform()<\/code><\/pre>\n<p>\u9664\u4e86press()\u65b9\u6cd5\u4e4b\u5916\uff0c\u672c\u4f8b\u4e2d\u8fd8\u7528\u5230\u4e86\u522b\u5916\u4e24\u4e2a\u65b0\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>release() \u7ed3\u675f\u7684\u884c\u52a8\u53d6\u6d88\u5c4f\u5e55\u4e0a\u7684\u6307\u9488<\/li>\n<li>perform() \u6267\u884c\u7684\u64cd\u4f5c\u53d1\u9001\u5230\u670d\u52a1\u5668\u7684\u547d\u4ee4\u64cd\u4f5c<\/li>\n<\/ul>\n<h2>\u957f\u6309\u63a7\u4ef6<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>longPress()<\/li>\n<\/ul>\n<p>\u5f00\u59cb\u6309\u538b\u4e00\u4e2a\u5143\u7d20\u6216\u5750\u6807\u70b9\uff08x,y\uff09\u3002 \u76f8\u6bd4press()\u65b9\u6cd5\uff0clongPress()\u591a\u4e86\u4e00\u4e2a\u5165\u53c2\uff0c\u65e2\u7136\u957f\u6309\uff0c\u5f97\u6709\u6309\u7684\u65f6\u95f4\u5427\u3002duration\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\u30021000\u8868\u793a\u6309\u4e00\u79d2\u949f\u3002\u5176\u7528\u6cd5\u4e0epress()\u65b9\u6cd5\u76f8\u540c\u3002<\/p>\n<pre><code class=\"language-java\">longPress(WebElement el, int x, int y, Duration duration)<\/code><\/pre>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">TouchAction action = new TouchAction(driver);\naction.longPress(names.get(1), 1000).perform().release();\naction.longPress(1, 302, 1000).perform().release();<\/code><\/pre>\n<h2>\u70b9\u51fb\u63a7\u4ef6<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>tap()<\/li>\n<\/ul>\n<p>\u5bf9\u4e00\u4e2a\u5143\u7d20\u6216\u63a7\u4ef6\u6267\u884c\u70b9\u51fb\u64cd\u4f5c\u3002\u7528\u6cd5\u53c2\u8003press()\u3002<\/p>\n<pre><code class=\"language-java\">tap(WebElement el, int x, int y)<\/code><\/pre>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">TouchAction action = new TouchAction(driver);\naction.tap(names.get(1)).perform().release();\naction.tap(1, 302).perform().release();<\/code><\/pre>\n<h2>\u79fb\u52a8<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>moveTo()<\/li>\n<\/ul>\n<p>\u5c06\u6307\u9488\uff08\u5149\u6807\uff09\u4ece\u8fc7\u53bb\u6307\u5411\u6307\u5b9a\u7684\u5143\u7d20\u6216\u70b9\u3002<\/p>\n<pre><code class=\"language-java\">movTo(WebElement el, int x, int y)<\/code><\/pre>\n<p>\u5176\u7528\u6cd5\u53c2\u8003press()\u65b9\u6cd5\u3002<\/p>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">TouchAction action = new TouchAction(driver);\naction.moveTo(names.get(1)).perform().release();\naction.moveTo(1, 302).perform().release();<\/code><\/pre>\n<h2>\u6682\u505c<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>wait()<\/li>\n<\/ul>\n<p>\u6682\u505c\u811a\u672c\u7684\u6267\u884c\uff0c\u5355\u4f4d\u4e3a\u6beb\u79d2\u3002<\/p>\n<pre><code class=\"language-java\">action.wait(1000);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Appium\u7684\u8f85\u52a9\u7c7b\uff0c\u4e3b\u8981\u9488\u5bf9\u624b\u52bf\u64cd\u4f5c\uff0c\u6bd4\u5982\u6ed1\u52a8\u3001\u957f\u6309\u3001\u62d6\u52a8\u7b49\u3002 \u6309\u538b\u63a7\u4ef6 \u65b9\u6cd5\uff1a press() \u5f00\u59cb\u6309\u538b\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[223],"tags":[],"class_list":["post-796","post","type-post","status-publish","format-standard","hentry","category-appium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=796"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/796\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}