{"id":142,"date":"2015-08-11T16:06:44","date_gmt":"2015-08-11T08:06:44","guid":{"rendered":"http:\/\/www.zhuyanbin.com\/?p=142"},"modified":"2016-12-09T23:13:11","modified_gmt":"2016-12-09T15:13:11","slug":"android-studio%e5%af%bc%e5%85%a5uiautomator%e6%b5%8b%e8%af%95%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=142","title":{"rendered":"Android Studio\u5bfc\u5165uiautomator\u6d4b\u8bd5\u6846\u67b6"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u6700\u8fd1\u56e0\u4e3a\u9700\u8981\u7528\u5230<a class=\"replace_word\" title=\"Android\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/android\" target=\"_blank\">Android<\/a>\u7684\u81ea\u52a8\u5316<a class=\"replace_word\" title=\"\u8f6f\u4ef6\u6d4b\u8bd5\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/softwaretest\" target=\"_blank\">\u6d4b\u8bd5<\/a>,\u4e8e\u662f\u627e\u5230\u4e86uiautomator\u548cespresso\u8fd9\u4e24\u4e2a\u6846\u67b6(\u8fd9\u91cc\u4ee5uiautomator\u4e3a\u4f8b).\u7531\u4e8e\u5728Android Studio(\u4ee5\u4e0b\u7b80\u79f0AS)\u4e2d\u4f7f\u7528uiautomator\u8fd9\u65b9\u9762\u7684\u8d44\u6599\u5f88\u5c11,\u56fd\u5185\u8fd9\u65b9\u9762\u7684\u535a\u5ba2\u57fa\u672c\u6ca1\u6709,\u56fd\u5916\u7684\u8d44\u6599\u4e5f\u90fd\u5f88\u5c11.\u53ef\u80fd\u662f\u56e0\u4e3a\u6bd4\u8f83\u65b0\u7684\u539f\u56e0\u5427.\u867d\u7136Android\u5b98\u7f51\u6709\u6559\u7a0b,\u4f46\u6700\u7ec8\u8fd8\u662f\u6298\u817e\u4e86\u597d\u4e45\u624d\u89e3\u51b3.\u5199\u8fd9\u7bc7\u535a\u5ba2\u4e00\u65b9\u9762\u5e0c\u671b\u5927\u5bb6\u80fd\u591f\u5c11\u8d70\u4e00\u4e9b\u5f2f\u8def,\u53e6\u4e00\u65b9\u9762\u4e5f\u7b97\u662f\u6211\u81ea\u5df1\u7684\u5b66\u4e60\u7b14\u8bb0\u5427.<\/p>\n<p><strong>\u8bf4\u660e:<\/strong>\u6211\u7684AS\u7248\u672c\u662f1.2.1.1<\/p>\n<p>\u5173\u4e8e\u4ec0\u4e48\u662fuiautomator\u548cespresso,\u8fd9\u91cc\u5c31\u4e0d\u505a\u4ecb\u7ecd\u4e86.<\/p>\n<p>\u4f7f\u7528\u4e4b\u524d\u9996\u5148\u5f97\u4fdd\u8bc1\u4f60\u7684<code>Android Support Repository<\/code>\u5df2\u7ecf\u6210\u529f\u5b89\u88c5<\/p>\n<p><a href=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-271\" src=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/1-1.png\" alt=\"\" width=\"707\" height=\"57\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/1-1.png 707w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/1-1-300x24.png 300w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/a><\/p>\n<p>\u5b89\u88c5\u6210\u529f\u540e,\u6839\u636eAndroid\u5b98\u7f51\u7ed9\u51fa\u7684\u6559\u7a0b,\u9996\u5148\u7b2c\u4e00\u6b65\u662f\u5728<code>build.gradle<\/code>\u4e2d\u6dfb\u52a0\u4f9d\u8d56:<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs matlab has-numbering\">dependencies <span class=\"hljs-cell\">{\r\n        androidTestCompile <span class=\"hljs-string\">'com.android.support.test:runner:0.2'<\/span>\r\n        androidTestCompile <span class=\"hljs-string\">'com.android.support.test:rules:0.2'<\/span>\r\n        androidTestCompile <span class=\"hljs-string\">'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'<\/span>\r\n}<\/span><\/code><\/pre>\n<p>\u7136\u540e\u6dfb\u52a0<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs haskell has-numbering\"><span class=\"hljs-default\">defaultConfig {<\/span>\r\n        testInstrumentationRunner <span class=\"hljs-string\">\"android.support.test.runner.AndroidJUnitRunner\"<\/span>\r\n}<\/code><\/pre>\n<p>\u6dfb\u52a0\u5b8c\u4f9d\u8d56\u540e<code>Sync Project with Gradle Files<\/code>,\u4f46\u662f\u540c\u6b65\u540e\u6211\u53d1\u73b0\u4e0a\u9762\u76f8\u5173\u7684\u5e93\u6587\u4ef6\u5e76\u6ca1\u6709\u88ab\u6dfb\u52a0\u8fdb\u6765.\u5bf9\u6bd4\u5f88\u591a\u8d44\u6599\u540e,\u6211\u5f88\u786e\u4fe1\u4e0d\u662f\u6211\u5728\u5199\u6cd5\u7684\u95ee\u9898.\u5c31\u662f\u8fd9\u4e2a\u95ee\u9898\u6298\u817e\u4e86\u6211\u597d\u51e0\u5929\u7684!<br \/>\n<a href=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-272\" src=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/2.png\" alt=\"\" width=\"319\" height=\"208\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/2.png 319w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/2-300x196.png 300w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/a><\/p>\n<p>\u6700\u540e\u7684\u89e3\u51b3\u529e\u6cd5\u662f\u5148\u628a<code>androidTestCompile<\/code>\u6362\u6210<code>compile<\/code>,\u540c\u6b65\u4e00\u4e0b,\u6b64\u65f6\u4f1a\u53d1\u73b0\u5e93\u6587\u4ef6\u5df2\u7ecf\u88ab\u6dfb\u52a0\u8fdb\u6765\u4e86.<br \/>\n<a href=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-273\" src=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/3.png\" alt=\"\" width=\"333\" height=\"305\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/3.png 333w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/3-300x275.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/a><\/p>\n<p>\u6700\u540e\u518d\u5c06<code>compile<\/code>\u6362\u56de<code>androidTestCompile<\/code>,\u89e3\u51b3~<br \/>\n<a href=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-274\" src=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2015\/08\/4.png\" alt=\"\" width=\"333\" height=\"305\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/4.png 333w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2015\/08\/4-300x275.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/a><\/p>\n<p>\u7a81\u7136\u5c31\u89c9\u5f97\u81ea\u5df1\u88ab\u5751\u4e86,\u4e5f\u4e0d\u77e5\u9053\u8fd9\u7b97\u4e0d\u7b97\u662fAS\u7684\u4e00\u4e2aBUG\u2026<\/p>\n<p>\u5982\u679c\u540c\u6b65\u4e4b\u540e\u53d1\u73b0\u8bf8\u5982\u6b64\u7c7b\u7684\u9519\u8bef:<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs ruby has-numbering\"> <span class=\"hljs-constant\">Warning<\/span><span class=\"hljs-symbol\">:Conflict<\/span> with dependency <span class=\"hljs-string\">'com.android.support:support-annotations'<\/span>. <span class=\"hljs-constant\">Resolved<\/span> versions <span class=\"hljs-keyword\">for<\/span> app (<span class=\"hljs-number\">22.1<\/span>.<span class=\"hljs-number\">1<\/span>) <span class=\"hljs-keyword\">and<\/span> test app (<span class=\"hljs-number\">22.0<\/span>.<span class=\"hljs-number\">0<\/span>) differ.<\/code><\/pre>\n<p>\u5148\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u7528<code>.\/gradlew -q app:dependencies<\/code>\u67e5\u770b\u9879\u76ee\u4f9d\u8d56\u5173\u7cfb(Windows\u7528\u6237\u8bf7\u4f7f\u7528<code>gradlew.bat -q app:dependencies<\/code>), \u7136\u540e\u4fee\u6539build.gradle,\u5426\u5219\u5728\u540e\u9762\u8fd0\u884c\u6d4b\u8bd5\u65f6\u53ef\u80fd\u4f1a\u62a5\u4f9d\u8d56\u5173\u7cfb\u7684\u9519\u8bef.<br \/>\n\u53ef\u80fd\u9700\u8981\u4e3agradlew\u52a0\u4e0a\u53ef\u6267\u884c\u6743\u9650.<\/p>\n<p><strong>\u8bf4\u660e:<\/strong>\u6211\u8fd9\u91cc\u4f1a\u62a5\u8fd9\u4e2a\u8b66\u544a\u662f\u56e0\u4e3a\u65b0\u5efa\u9879\u76ee\u7684\u65f6\u5019AS\u5e2e\u6211\u81ea\u52a8\u6dfb\u52a0\u4e86<code>compile 'com.android.support:appcompat-v7:22.1.1'<\/code>\u4f9d\u8d56,\u5c06<code>22.1.1<\/code>\u6539\u4e3a<code>22.0.0<\/code>\u5373\u53ef.<\/p>\n<p>\u7136\u540e\u8fd8\u8981\u5728<code>build.gradle<\/code>\u4e2d\u6dfb\u52a0:<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs matlab has-numbering\">packagingOptions <span class=\"hljs-cell\">{\r\n    exclude <span class=\"hljs-string\">'LICENSE.txt'<\/span>\r\n}<\/span><\/code><\/pre>\n<p>\u4e0d\u6dfb\u52a0\u7684\u8bdd\u8fd0\u884c\u65f6\u5019\u8fd8\u662f\u4f1a\u62a5\u9519\u7684.<\/p>\n<p>\u6700\u540e,\u786e\u4fdd\u6b64\u65f6\u6709android\u8bbe\u5907\u5728\u8fd0\u884c(\u865a\u62df\u5668\u6216\u624b\u673a\u90fd\u53ef\u4ee5,\u8981\u6c42\u662f\u7cfb\u7edf\u7248\u672c\u898118\u621618\u4ee5\u4e0a),\u7136\u540e\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e0b\u8f93\u5165\u547d\u4ee4:<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs  has-numbering\">.\/gradlew cC<\/code><\/pre>\n<p>\u5982\u65e0\u610f\u5916\u7684\u8bdd,\u5e94\u8be5\u53ef\u4ee5\u770b\u5230<code>BUILD SUCCESS<\/code>\u4e86!<\/p>\n<p>\u5982\u679c\u4e0d\u60f3\u7528\u547d\u4ee4\u884c\u7684\u8bdd,\u4e5f\u53ef\u4ee5<code>Edit Configurations<\/code>,\u7136\u540e\u70b9\u51fb<code>+<\/code> \u2013&gt; <code>Android Test<\/code>,\u7136\u540e\u9009\u62e9\u5bf9\u5e94\u7684Module,\u7136\u540e\u5728\u4e0b\u9762\u7684<code>Specific Instrumentation Runner<\/code>\u9009\u62e9<\/p>\n<pre><code>android.support.test.runner.AndroidJUnitRunner\r\n<\/code><\/pre>\n<p>\u9009\u62e9OK,\u7136\u540e\u70b9\u51fb\u542f\u52a8\u6309\u94ae.\u5982\u65e0\u610f\u5916\u7684\u8bdd,\u5e94\u8be5\u53ef\u4ee5\u770b\u5230\u4e00\u6761\u7eff\u8272\u7684\u8fdb\u5ea6\u6761\u4e86!<\/p>\n<p>\u5173\u4e8e\u53e6\u5916\u4e00\u4e2a\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6Espresso,\u5bfc\u5165\u65b9\u6cd5\u548cuiautomator\u4e00\u6837,\u4e0d\u540c\u7684\u53ea\u662f\u4f9d\u8d56\u800c\u5df2.<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs matlab has-numbering\">dependencies <span class=\"hljs-cell\">{\r\n    androidTestCompile <span class=\"hljs-string\">'com.android.support.test:runner:0.2'<\/span>\r\n    androidTestCompile <span class=\"hljs-string\">'com.android.support.test:rules:0.2'<\/span>\r\n    androidTestCompile <span class=\"hljs-string\">'com.android.support.test.espresso:espresso-core:2.1'<\/span>\r\n}<\/span><\/code><\/pre>\n<p>\u5173\u4e8e\u6d4b\u8bd5\u6846\u67b6\u7684\u5bfc\u5165\u5c31\u5148\u8bf4\u8fd9\u4e48\u591a\u4e86,\u6709\u5173\u8fd9\u4e9b\u6846\u67b6\u7684\u4f7f\u7528\u7f51\u4e0a\u7684\u8d44\u6599\u5e94\u8be5\u4e5f\u662f\u6bd4\u8f83\u591a\u7684\u4e86,\u53ea\u4e0d\u8fc7\u6709\u4e00\u4e9bAPI\u5df2\u7ecf\u88ab\u5f03\u7528\u4e86.\u7b49\u6211\u719f\u6089\u4e86\u8fd9\u4e24\u5927\u6846\u67b6\u7684\u4f7f\u7528\u518d\u6765\u5199\u76f8\u5173\u7684\u535a\u5ba2\u5427.<\/p>\n<p>&nbsp;<\/p>\n<p>link:\u00a0http:\/\/blog.csdn.net\/u011504118\/article\/details\/46318693<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u6700\u8fd1\u56e0\u4e3a\u9700\u8981\u7528\u5230Android\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5,\u4e8e\u662f\u627e\u5230\u4e86uiautomator\u548cespresso\u8fd9 <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=142\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[26],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-android","tag-android"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=142"}],"version-history":[{"count":3,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions\/275"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}