{"id":1580,"date":"2024-04-09T10:05:04","date_gmt":"2024-04-09T02:05:04","guid":{"rendered":"https:\/\/www.gyxwsjdxh.com\/?p=1580"},"modified":"2024-04-09T10:05:04","modified_gmt":"2024-04-09T02:05:04","slug":"2021%e5%b9%b4%e5%9b%9b%e5%a4%a7%e6%b5%81%e8%a1%8candroid%e6%89%8b%e6%9c%ba%e8%87%aa%e5%8a%a8%e5%8c%96%e6%b5%8b%e8%af%95%e5%b7%a5%e5%85%b7%ef%bc%8c%e5%85%a8%e5%9c%a8%e8%bf%99%e9%87%8c%e4%ba%86","status":"publish","type":"post","link":"https:\/\/www.gyxwsjdxh.com\/1580.html","title":{"rendered":"2021\u5e74\u56db\u5927\u6d41\u884cAndroid\u624b\u673a\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\uff0c\u5168\u5728\u8fd9\u91cc\u4e86"},"content":{"rendered":"\n

\n

Android \u81ea\u52a8\u5316\u6d4b\u8bd5\u7684\u5de5\u5177\u975e\u5e38\u591a\uff0c\u4f46\u662f\u76ee\u524d\u4e3b\u6d41\u4f7f\u7528\u7684\u5c31\u90a3\u51e0\u4e2a\uff0c\u6211\u4f1a\u8be6\u7ec6\u8bf4\u660e\u4ed6\u4eec\u5404\u81ea\u7684\u60c5\u51b5\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u51b3\u5b9a\u4f7f\u7528\u54ea\u6b3e\u5de5\u5177\u3002<\/span><\/span><\/p>\n

Appium<\/span><\/span><\/strong><\/span><\/p>\n

Appium \u662f\u76ee\u524d\u6700\u4e3b\u6d41\u7684\u79fb\u52a8\u6d4b\u8bd5\u81ea\u52a8\u5316\u6846\u67b6\uff0c<\/span>\u4e0d\u4ec5\u652f\u6301 Android \u5e94\u7528\uff0c\u800c\u4e14\u9002\u7528\u4e8e iOS\u3001\u6df7\u5408\u548c Web \u5e94\u7528\u7a0b\u5e8f<\/span><\/strong>\u3002<\/span><\/span><\/p>\n

\u5b83\u5e95\u5c42\u5b8c\u5168\u4f7f\u7528\u4e86 Selenium \u548c WebDriver \u7684 API\uff0c\u6240\u4ee5\u5982\u679c\u4f60\u4e4b\u524d\u6709\u7528\u8fc7 selenium, <\/span>\u51e0\u4e4e\u4e0d\u9700\u8981\u989d\u5916\u7684\u5b66\u4e60\u6210\u672c<\/span><\/strong>\u5c31\u53ef\u4ee5\u4f7f\u7528 appium\u3002<\/span><\/span><\/p>\n

appium \u901a\u8fc7 uiautomator\uff08API \u7ea7\u522b 16 \u6216\u66f4\u9ad8\uff09\u548c Seledroid\uff08API \u7ea7\u522b\u4f4e\u4e8e 16\uff09\u652f\u6301 Android\uff0c\u4f46\u662f\u4f60\u4e0d\u9700\u8981\u5177\u4f53\u61c2\u8fd9\u4e24\u4e2a\u6846\u67b6\u7684\u5177\u4f53\u7528\u6cd5\uff0cappium \u90fd\u5df2\u7ecf\u5e2e\u4f60\u5c01\u88c5\u6210\u4e86\u7edf\u4e00\u7684\u4f7f\u7528\u89c4\u5219\u3002<\/span><\/span><\/p>\n

Appium \u7684\u6700\u5927\u4f18\u52bf\u4e4b\u4e00\u662f<\/span>\u51e0\u4e4e\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00<\/span><\/strong>\uff08\u4f8b\u5982 Java\u3001Objective-C\u3001JavaScript\u3001PHP\u3001Ruby\u3001Python \u6216 C# \u7b49\uff09<\/span>\u7f16\u5199 Appium \u811a\u672c<\/span><\/strong>\u3002<\/span><\/span><\/p>\n

\u8fd9\u610f\u5473\u8fd9\u9009\u62e9\u6743\u5728\u4f60\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u81ea\u5df1\u6700\u64c5\u957f\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u5982\u679c\u4f60\u8fd8\u719f\u6089 Selenium\uff0c\u90a3\u4e48\u4e0d\u51fa\u610f\u5916\uff0c\u4f60\u53ef\u4ee5\u5728\u4e00\u5929\u4e4b\u5185\u4e0a\u624b\u4f7f\u7528\u3002<\/span><\/span><\/p>\n

\u53e6\u5916 webdriver \u662f\u4e00\u4e2a\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u5df2\u7ecf\u63d0\u4ea4\u7ed9\u4e86 w3c \u7ec4\u7ec7\uff0c\u4f60\u53ef\u4ee5\u57fa\u4e8e\u5b83\u7684\u534f\u8bae\u505a\u8fdb\u4e00\u6b65\u7684\u6269\u5c55\u3002\u770b\u770b\u7b80\u5355\u7684\u4ee3\u7801\uff1a<\/span><\/span><\/p>textFields<\/span> = driver.find_elements_by_tag_name(textField<\/span>)\n assertEqual(textFields[0<\/span>].get_attribute(“value”<\/span>), “Hello”<\/span>)\n

Airtest<\/span><\/span><\/strong><\/span><\/p>\n

\u7b2c\u4e8c\u4e2a\u6211\u8981\u63a8\u8350\u56fd\u4ea7\u4e4b\u5149 Airtest\u3002Airtest \u9879\u76ee\u662f\u7531\u7f51\u6613\u6e38\u620f\u63a8\u51fa\u7684\u4e00\u6b3e\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\uff0c\u9879\u76ee\u6709\u51e0\u5927\u7ec4\u4ef6\uff1a<\/span><\/span><\/p>Airtest<\/span>\uff1a\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u3001\u57fa\u4e8e\u56fe\u50cf\u8bc6\u522b\u7684 UI \u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u6e38\u620f\u548c App\uff0c\u652f\u6301\u5e73\u53f0\u6709 Windows\u3001Android \u548c iOS<\/span><\/span>Poco<\/span>\uff1a\u662f\u4e00\u6b3e\u57fa\u4e8e UI \u63a7\u4ef6\u8bc6\u522b\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\uff0c\u76ee\u524d\u652f\u6301 Android \u539f\u751f app\/iOS \u539f\u751f app\/\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u8fd8\u6709\u4e3b\u6d41\u7684\u6e38\u620f\u5f15\u64ce\uff0c\u4e5f\u53ef\u4ee5\u5728\u5176\u4ed6\u5f15\u64ce\u4e2d\u81ea\u884c\u63a5\u5165 poco-sdk \u6765\u4f7f\u7528<\/span><\/span>AirtestIDE<\/span>\uff1a\u8de8\u5e73\u53f0\u7684 UI \u81ea\u52a8\u5316\u6d4b\u8bd5\u7f16\u8f91\u5668\uff0c\u5185\u7f6e\u4e86 Airtest \u548c Poco \u7684\u76f8\u5173\u63d2\u4ef6\u529f\u80fd\uff0c\u80fd\u591f\u4f7f\u7528\u5b83\u5feb\u901f\u7b80\u5355\u5730\u7f16\u5199 Airtest \u548c Poco \u4ee3\u7801\uff0c\u751a\u81f3\u90fd\u53ef\u4ee5\u4e0d\u5199\u4ee3\u7801\u3002<\/span><\/span>AirLab<\/span>\uff1a\u771f\u673a\u81ea\u52a8\u5316\u4e91\u6d4b\u8bd5\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u975e\u5e38\u591a\u7684\u624b\u673a\u578b\u53f7\u548c\u517c\u5bb9\u6027\u6d4b\u8bd5\u3001\u6d77\u5916\u4e91\u771f\u673a\u517c\u5bb9\u6027\u6d4b\u8bd5\u7b49\u670d\u52a1<\/span><\/span>\u79c1\u6709\u5316\u624b\u673a\u96c6\u7fa4\u6280\u672f\u65b9\u6848<\/span>\uff1a\u4ece\u786c\u4ef6\u5230\u8f6f\u4ef6\uff0c\u63d0\u4f9b\u4f01\u4e1a\u5185\u90e8\u79c1\u6709\u5316\u624b\u673a\u96c6\u7fa4\u7684\u89e3\u51b3\u65b9\u6848<\/span><\/span>\n

\u4f7f\u7528 Airtest \u7684\u597d\u5904\u662f<\/span>\u4e2d\u6587\u6587\u6863\u5065\u5168<\/span><\/strong>\uff0c\u5bf9\u82f1\u6587\u4e0d\u597d\u7684\u540c\u5b66\u652f\u6301\u4f18\u5316\u3002\u5b98\u7f51\u4e5f\u8d34\u5fc3\u7684\u51c6\u5907\u4e86\u89c6\u9891\u6559\u5b66\u548c\u6f14\u793a\uff0c\u5e2e\u52a9\u4f60\u5feb\u901f\u4e0a\u624b\u3002<\/span><\/span><\/p>\n

\"2021\u5e74\u56db\u5927\u6d41\u884cAndroid\u624b\u673a\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\uff0c\u5168\u5728\u8fd9\u91cc\u4e86\u63d2\u56fe\"<\/div>\n

Detox<\/span><\/span><\/strong><\/span><\/p>\n

\u8fd9\u4e2a\u6846\u67b6\u975e\u5e38\u4f4e\u8c03\uff0c\u4f46\u662f\u4f60\u7528\u8fc7\u4e00\u5b9a\u4f1a\u7231\u4e0a\u5b83\u3002<\/span><\/span><\/p>\n

Detox \u4e00\u4e2a\u975e\u5e38\u5f3a\u7684 JavaScript \u79fb\u52a8\u6d4b\u8bd5\u6846\u67b6\uff0c\u5b83\u7684\u6d4b\u8bd5\u6267\u884c\u975e\u5e38\u5feb\u901f\u548c\u5065\u58ee\uff0c\u56e0\u4e3a\u5728\u6d4b\u8bd5\u6267\u884c\u671f\u95f4<\/span>\u4e0d\u9700\u8981\u5916\u90e8\u9644\u52a0\u5de5\u5177\u6765\u7f16\u6392\u548c\u540c\u6b65<\/span><\/strong>\u3002<\/span><\/span><\/p>\n

\u5982\u679c\u4f60\u4f18\u5148\u8003\u8651\u4ee5\u4e0b\u56e0\u7d20\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u9009\u7528 detox\uff1a<\/span><\/span><\/p>\u4f7f\u7528 JavaScript \u7f16\u7a0b\u8bed\u8a00<\/span><\/span>\u6bd4\u5176\u4ed6\u6d4b\u8bd5\u81ea\u52a8\u5316\u6846\u67b6\u66f4\u6613\u4e8e\u8c03\u8bd5<\/span><\/span>app \u662f React Native \u5f00\u53d1\u7684\uff0c\u53ef\u8fc5\u901f\u548c detox \u96c6\u6210<\/span><\/span>\u5728\u6d4b\u8bd5\u6267\u884c\u65b9\u9762\u6bd4 Appium \u5feb<\/span><\/span>\u6587\u6863\u6bd4\u8f83\u5bb9\u6613\u638c\u63e1<\/span><\/span>\n

\u4e0b\u9762\u662f\u5177\u4f53\u7684\u4ee3\u7801\uff0c\u6bd4\u8f83\u5178\u578b\u7684\u4ee3\u7801\u7f16\u5199\u65b9\u5f0f\uff1a<\/span><\/span><\/p>\n

describe(<\/span><\/span>HelloDetoxTest<\/span><\/span><\/p>

, () => { <\/p> beforeEach(\n async<\/span><\/span>\n

() => { <\/p>\n <\/span>await<\/span><\/span>\n

device.reloadReactNative(); <\/p>\n

}); <\/p> it(\n <\/span>\u5e94\u8be5\u6709\u6b22\u8fce\u5c4f\u5e55<\/span><\/span>, <\/span>async<\/span><\/span>\n

() => { <\/p>\n <\/span>await<\/span><\/span> expect(element(<\/span>by<\/span><\/span> .id(<\/span>welcome<\/span><\/span>\n

))).toBeVisible(); <\/p>\n

}); <\/p> it(\n <\/span>should show hello Rect after tap<\/span><\/span>, <\/span>async<\/span><\/span>\n

() => { <\/p>\n <\/span>await<\/span><\/span> element(<\/span>by<\/span><\/span>.id(<\/span>hello_react<\/span><\/span>\n

)).tap() ; <\/p>\n <\/span>await<\/span><\/span> expect(element(<\/span>by<\/span><\/span>.text(<\/span>React!!!<\/span><\/span>\n

))).toBeVisible(); <\/p>\n

}); <\/p> it(\n <\/span>\u70b9\u51fb\u540e\u5e94\u8be5\u663e\u793a\u5c4f\u5e55<\/span><\/span>, <\/span>async<\/span><\/span>\n

() => { <\/p>\n <\/span>await<\/span><\/span> element(<\/span>by<\/span><\/span>.id (<\/span>detox_button<\/span><\/span>\n

)).tap(); <\/p>\n <\/span>await<\/span><\/span> expect(element(<\/span>by<\/span><\/span>.text(<\/span>Detox!!!<\/span><\/span>\n

))).toBeVisible(); <\/p>\n

}); <\/p>});\n <\/span>\n

Espresso<\/span><\/span><\/strong><\/span><\/p>\n

Espresso \u662f\u65b0\u578b\u7684\u7684 Android \u6d4b\u8bd5\u81ea\u52a8\u5316\u6846\u67b6\uff0c\u7531 Google \u5f00\u6e90\uff0cEspresso \u7684 API<\/span> \u4f53\u79ef\u5c0f\u3001\u53ef\u9884\u6d4b\u3001\u6613\u4e8e\u5b66\u4e60<\/span><\/strong>\u3002<\/span><\/span><\/p>\n

\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u5feb\u901f\u7f16\u5199\u7b80\u6d01\u53ef\u9760\u7684 Android UI \u6d4b\u8bd5\u3002<\/span><\/span><\/p>\n

\u5b83\u975e\u5e38\u53ef\u9760\uff0c\u4e0e UI \u7ebf\u7a0b\u540c\u6b65\u5e76\u4e14\u901f\u5ea6\u5f88\u5feb\uff0c\u56e0\u4e3a\u4e0d\u9700\u8981\u4efb\u4f55\u7761\u7720\uff08\u5f53\u5e94\u7528\u7a0b\u5e8f\u7a7a\u95f2\u65f6\uff0c\u6d4b\u8bd5\u5728\u540c\u4e00\u6beb\u79d2\u5185\u8fd0\u884c\uff09\u3002<\/span><\/span><\/p>\n

\u800c\u4e14\u901a\u8fc7\u7b80\u5355\u7684\u914d\u7f6e\uff0c\u53ef\u4ee5\u76f4\u63a5\u96c6\u6210\u5728 appium \u4e2d\u3002<\/span><\/span><\/p>\n

\u603b\u7ed3<\/span><\/span><\/strong><\/span><\/p>\n

\u8fd9\u51e0\u4e2a\u5de5\u5177\u51e0\u4e4e\u6db5\u76d6\u4e86\u6240\u6709\u7684 Android \u81ea\u52a8\u5316\u6d4b\u8bd5\u6280\u672f\u9009\u578b\u4fa7\u91cd\u70b9\u3002\u5728\u638c\u63e1\u597d\u8fd9 4 \u4e2a\u5f53\u4e2d\u7684\u5176\u4e2d\u4e00\u4e2a\u4ee5\u540e\uff0c\u6709\u7cbe\u529b\u4f60\u53ef\u4ee5\u53bb\u7814\u7a76\u4e00\u4e0b\u5176\u4ed6\u7684\u5de5\u5177\uff0c\u6709\u4e0a\u767e\u79cd\u9009\u62e9\uff0c\u6bcf\u79cd\u90fd\u6709\u4fa7\u91cd\u548c\u5177\u4f53\u7684\u573a\u666f\u3002<\/span><\/span><\/p>\u5982\u679c\u4f60\u4e0d\u77e5\u9053\u8981\u9009\u4ec0\u4e48\u5de5\u5177\uff0c\u7528 appium<\/span><\/strong><\/span>\u5982\u679c\u4f60\u5728\u81ea\u52a8\u5316\u6d4b\u8bd5\u65b9\u9762\u7eaf\u5c0f\u767d\uff0c\u7528 airtest<\/span><\/strong><\/span>\u5982\u679c\u516c\u53f8\u7528\u7684 reactive native, \u7528 detox<\/span><\/strong><\/span>Espresso \u9002\u5408\u6539\u5584 appium \u7684\u4f53\u9a8c<\/span><\/strong><\/span>\n\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"

Android \u81ea\u52a8\u5316\u6d4b\u8bd5\u7684\u5de5\u5177\u975e\u5e38\u591a\uff0c\u4f46\u662f\u76ee\u524d\u4e3b\u6d41\u4f7f\u7528\u7684\u5c31\u90a3\u51e0\u4e2a\uff0c\u6211\u4f1a\u8be6\u7ec6\u8bf4\u660e\u4ed6\u4eec\u5404\u81ea\u7684\u60c5\u51b5\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u51b3\u5b9a\u4f7f\u7528\u54ea\u6b3e\u5de5\u5177\u3002 Ap… <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1580","post","type-post","status-publish","format-standard","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/posts\/1580"}],"collection":[{"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/comments?post=1580"}],"version-history":[{"count":1,"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/posts\/1580\/revisions"}],"predecessor-version":[{"id":1581,"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/posts\/1580\/revisions\/1581"}],"wp:attachment":[{"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/media?parent=1580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/categories?post=1580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gyxwsjdxh.com\/wp-json\/wp\/v2\/tags?post=1580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}