设置执行案例的模拟器
Cucumber 有一个配置文件,在执行 Cucumber 运行案例时,首先会调用此文件。
在Cucumber执行的目录,即 features 目录同级,建一个.config(隐藏文件,在终端里使用命令)目录。config目录下,新建一个 Cucumber.xml文件 将如下内容copy 至此文件保存:
<code class="hljs java has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span>: -r features -r features_ios_support --tags ~<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@wip</span> --tags ~<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@manual</span> --tags ~<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@ignore</span> --tags ~<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@stg</span> --tags ~<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@android</span>_only DEVICE_TARGET=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'iPhone 6 (8.1 Simulator)'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
- -r:加载目录 可以指定加载顺序,ruby 特性后加载的类的方法会将先加载的覆盖
- –tags:可以给指定案例添加 tag 执行时,只执行选定 tag
- DEVICE_TARGET:指定使用哪个版本的模拟器运行案例,如果是真机直接写 DeviceID
可以使用如下命令查看本机设备列表:
<code class="hljs lasso has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">➜ ~ instruments <span class="hljs-attribute" style="box-sizing: border-box;">-s</span> devices
Known Devices:
Rigel<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>Xu (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8.4</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span>cac0899307dfb6f6bec507fcad641fe6b76ca3c9<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;">
iPad Retina (8.4 Simulator) </span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span>ACFDE3E0<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">85</span>F8<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>DC3<span class="hljs-attribute" style="box-sizing: border-box;">-A6A5</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7537769</span>F0CE3<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;">
iPhone 6 (8.1 Simulator) </span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11</span>CA78D9<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">395</span>D<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>FBE<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9347</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>B3CC20B75AC<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;">
iPhone 6 Plus (8.4 Simulator) </span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">85</span>C3A98F<span class="hljs-attribute" style="box-sizing: border-box;">-BDBB</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>BBF<span class="hljs-attribute" style="box-sizing: border-box;">-A485</span><span class="hljs-attribute" style="box-sizing: border-box;">-D2301E4ED5BA</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>
webView操作及滚动
使用scoll(“webView”) 是无法滚动 webView 的,在 Calabash 的 GoogleGroup 里查到可以使用 swipe 来滚动,亲测可用swipe :up, offset:{x:100,y:250}外 webView 操作某一元素可以使用如下方式:
<code class="hljs erlang has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-title" style="box-sizing: border-box;">touch</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"webView css:'img#banner1'"</span>)</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
css之后是 css 的选择器,为使我们的测试脚本写起来方便,建议在web 页面开发的时间为不同的控件使用不同的 id 。
查看 Calabash 源码
安装完 Calabash-Cucumber 后,可以在对应 ruby 的 gems 里找到相应版本的 Calabash-Cucumber,如:
<code class="hljs lasso has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">ruby<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.2</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.2</span>/gems/Calabash<span class="hljs-attribute" style="box-sizing: border-box;">-Cucumber</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.14</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.3</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
使用编辑器打开整个目录,可以看到如下结构:
bin
doc
dylibs
features
features-skeleton
lib
LICENSE
scripts
staticlib
Calabash 的所有东西,都在这里了,核心源码在 lib/Calabash-Cucumber 目录下,有时如果不知道一些命令,或者查不到解决方法,可以直接看源码。
附:
Calabash官网
Google Group
Calabash-iOS Wiki