{"id":797,"date":"2023-02-28T11:30:28","date_gmt":"2023-02-28T03:30:28","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=797"},"modified":"2023-04-05T17:43:30","modified_gmt":"2023-04-05T09:43:30","slug":"appium-automation-testing-appium-api-other-operations","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/28\/appium-automation-testing-appium-api-other-operations\/","title":{"rendered":"Appium\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0813\uff09\u2014\u2014 Appium API \u4e4b\u5176\u4ed6\u64cd\u4f5c"},"content":{"rendered":"<p>\u5176\u5b83\u64cd\u4f5c\u9488\u5bf9\u79fb\u52a8\u8bbe\u5907\u4e0a\u7279\u6709\u7684\u4e00\u4e9b\u64cd\u4f5c\u3002<\/p>\n<h2>\u7184\u5c4f<\/h2>\n<p><!-- more --><\/p>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>lockDevice()<\/li>\n<\/ul>\n<p>\u70b9\u51fb\u7535\u6e90\u952e\u7184\u706d\u5c4f\u5e55\u3002\u5728iOS\u8bbe\u5907\u53ef\u4ee5\u8bbe\u7f6e\u7184\u5c4f\u4e00\u6bb5\u65f6\u95f4\u3002Android\u4e0a\u9762\u4e0d\u5e26\u53c2\u6570\uff0c\u6240\u4ee5\u7184\u5c4f\u4e4b\u540e\u5c31\u4e0d\u4f1a\u518d\u70b9\u4eae\u5c4f\u5e55\u3002<\/p>\n<pre><code class=\"language-java\">driver.lockDevice(1000);  \/\/iOS\ndriver.lockDriice();  \/\/Android<\/code><\/pre>\n<h2>\u5f53\u524dActivity(Android only)<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>currentActivity()<\/li>\n<\/ul>\n<p>\u5f97\u5230\u5f53\u524d\u5e94\u7528\u7684activity\u3002\u53ea\u9002\u7528\u4e8eAndroid\uff0c\u4f8b(\u901a\u8baf\u5f55)\uff1a<\/p>\n<pre><code class=\"language-java\">String ca = driver.currentActivity();\nSystem.out.print(ca);\n-------------\u8f93\u51fa\u7ed3\u679c\u4e3a-------------\n.activities.PeopleActivity<\/code><\/pre>\n<h2>\u6536\u8d77\u952e\u76d8<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>hideKeyboard()<\/li>\n<\/ul>\n<p>\u6536\u8d77\u952e\u76d8\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5f88\u6709\u7528\uff0c\u5f53\u6211\u4eec\u5bf9\u4e00\u4e2a\u8f93\u5165\u6846\u8f93\u5165\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5c06\u952e\u76d8\u6536\u8d77\uff0c\u518d\u5207\u6362\u5230\u4e00\u4e0b\u8f93\u5165\u6846\u8fdb\u884c\u8f93\u5165\u3002<\/p>\n<pre><code class=\"language-java\">driver.hideKeyboard();  \/\/\u6536\u8d77\u952e\u76d8<\/code><\/pre>\n<h2>\u6ed1\u52a8<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>swipe()<\/li>\n<\/ul>\n<p>\u6a21\u62df\u7528\u6237\u6ed1\u52a8\u3002\u5c06\u63a7\u4ef6\u6216\u5143\u7d20\u4ece\u4e00\u4e2a\u4f4d\u7f6e(x,y)\u62d6\u52a8\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e(x,y)\u3002<\/p>\n<pre><code class=\"language-java\">swipe(int startx, int starty, int endx, int endy, int duration)<\/code><\/pre>\n<ul>\n<li>start_x\uff1a\u5f00\u59cb\u6ed1\u52a8\u7684x\u5750\u6807<\/li>\n<li>start_y\uff1a\u5f00\u59cb\u6ed1\u52a8\u7684y\u5750\u6807<\/li>\n<li>end_x\uff1a\u7ed3\u675f\u6ed1\u52a8\u7684x\u5750\u6807<\/li>\n<li>end_y\uff1a\u7ed3\u675f\u6ed1\u52a8\u7684y\u5750\u6807<\/li>\n<li>duration\uff1a\u6301\u7eed\u65f6\u95f4<\/li>\n<\/ul>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">driver.swipe(75, 500, 75, 0, 800);<\/code><\/pre>\n<h2>\u62c9\u51fa\u6587\u4ef6<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>pullFile()<\/li>\n<\/ul>\n<p>\u4ece\u8bbe\u5907\u4e2d\u62c9\u51fa\u6587\u4ef6\u3002<\/p>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">driver.pullFile(&#039;Library\/AddressBook\/AddressBook.sqlitedb&#039;)<\/code><\/pre>\n<h2>\u63a8\u9001\u6587\u4ef6<\/h2>\n<p>\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>pushFile()<\/li>\n<\/ul>\n<p>\u63a8\u9001\u6587\u4ef6\u5230\u8bbe\u5907\u4e2d\u53bb\u3002<\/p>\n<pre><code class=\"language-java\">pushFile(String remotePath, byte[] base64Data)<\/code><\/pre>\n<p>\u4f8b\uff1a<\/p>\n<pre><code class=\"language-java\">String content = &quot;some data for the file&quot;;\nbyte[] data = Base64.encodeBase64(content.getBytes());\ndriver.pushFile(&quot;sdcard\/test.txt&quot;, data);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5b83\u64cd\u4f5c\u9488\u5bf9\u79fb\u52a8\u8bbe\u5907\u4e0a\u7279\u6709\u7684\u4e00\u4e9b\u64cd\u4f5c\u3002 \u7184\u5c4f \u65b9\u6cd5\uff1a lockDevice() \u70b9\u51fb\u7535\u6e90\u952e\u7184\u706d\u5c4f\u5e55\u3002\u5728iOS\u8bbe [&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-797","post","type-post","status-publish","format-standard","hentry","category-appium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/797","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=797"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}