通過執行指令碼自動開啟應用,可以使用xcode工具中的instruments來實現。執行命令如下:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">instruments </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">w </span><span class="str" style="color: rgb(0, 136, 0);"><udid></span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">t </span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Applications</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Xcode</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">app</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Contents</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Applications</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Instruments</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">app</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Contents</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">PlugIns</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">AutomationInstrument</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">bundle</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Contents</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Resources</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="typ" style="color: rgb(102, 0, 102);">Automation</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">tracetemplate </span><span class="str" style="color: rgb(0, 136, 0);"><full_path_to_application></span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">e UIASCRIPT </span><span class="pun" style="color: rgb(102, 102, 0);"><</span><span class="pln" style="color: rgb(0, 0, 0);">path_to_script</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">js</span><span class="pun" style="color: rgb(102, 102, 0);">></span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">e UIARESULTSPATH </span><span class="str" style="color: rgb(0, 136, 0);"><output_results_path></span></p>
其中Automation.tracetemplate是UIAutomation的模板檔案,一般在mac裝置中固定路徑。
<full_path_to_application> 應用的appId,需要加雙引號
<path_to_script.js> 執行的測試js指令碼路徑,需要加雙引號
<output_results_path> 測試的輸出路徑,需要加雙引號,可不填
編寫簡單的測試指令碼進行驗證:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="kwd" style="color: rgb(0, 0, 136);">var</span><span class="pln" style="color: rgb(0, 0, 0);"> target </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">UIATarget</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">localTarget</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">target</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">delay</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="lit" style="color: rgb(0, 102, 102);">15</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p>
執行指令碼的結果是開啟應用15秒後關閉。