下载完代码后,进入工程目录中,在命令行中输入:calabash-android gen,此命令会在工程目录下生成目录features,目录结构如下图:
1
2
3
4
5
6
7
8
9
|
features
|_support
| |_app_installation_hooks.rb
| |_app_life_cycle_hooks.rb
| |_env.rb
| |_hooks.rb
|_step_definitions
| |_calabash_steps.rb
|_my_first.feature
|
step_definions目录中存放用户自定义的features, my_first.feature用来书写测试的步骤。
基本用法之截屏
在my_first.feature中写下如下代码
1
2
3
4
|
Feature: Startup feature
Scenario: I can start my app
Then I wait
for
15
seconds
Then I take a screenshot
|
在命令行输入 calabash-android run HackNews.apk,应用程序会被安装到手机或模拟器中,15秒之后,会自动截屏,图片保存在当前工程目录下。也可以自定义截图保存的路径:
1
|
<code>SCREENSHOT_PATH=/tmp/foo/ calabash-android run</code>
|
基本用法之自定义feature
在step_definitions中新建文件touch_steps.rb,添加代码如下:
1
2
3
4
5
|
# -- Touch --#
Then /^I (?:press|touch) on screen (d+) from the left and (d+) from the top$/
do
|x, y|
touch(nil, {:offset => {:x => x.to_i, :y => y.to_i}})
sleep(
3
)
end
|
1
|
Then I touch on screen
100
from the left and
150
from the top
|