Skip to content

Instantly share code, notes, and snippets.

@k5n
Created November 1, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k5n/a08b2855d828dc2723160e2d06244a4d to your computer and use it in GitHub Desktop.
Save k5n/a08b2855d828dc2723160e2d06244a4d to your computer and use it in GitHub Desktop.
Calabash-iOSの日本語版ステップ定義
DIR_JA_TO_EN = { '左' => 'left', '右' => 'right', '上' => 'up', '下' => 'down' }
IN_OUT_JA_TO_EN = { 'イン' => 'in', 'アウト' => 'out' }
Given /^アプリ(?:が|を)?実行中$/ do |_|
# no-op exists for backwards compatibility
end
### Touch ###
Then /^画面の\((\d+), *(\d+)\)座標を(?:タッチ|タップ)する$/ do |x, y|
touch(nil, { offset: { x: x.to_i, y: y.to_i } })
sleep(STEP_PAUSE)
end
Then /^"([^\"]*)"を(?:押す|タッチする|タップする)$/ do |name|
touch("view marked: '#{name}'")
sleep(STEP_PAUSE)
end
Then /^(\d+)番目のボタンを(?:押す|タッチする|タップする)$/ do |index|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
touch("button index: #{index - 1}")
sleep(STEP_PAUSE)
end
Then /^"([^\"]*)"ボタンを(?:押す|タッチする|タップする)$/ do |name|
touch("button marked: '#{name}'")
sleep(STEP_PAUSE)
end
Then /^(\d+)番目の(?:入力|テキスト)フィールドを(?:押す|タッチする|タップする)$/ do |index|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
touch("textField index: #{index - 1}")
sleep(STEP_PAUSE)
end
Then /^(?:入力|テキスト)フィールド"([^\"]*)"を(?:押す|タッチする|タップする)$/ do |name|
placeholder_query = "textField placeholder: '#{name}'"
marked_query = "textField marked: '#{name}'"
if !query(placeholder_query).empty?
touch(placeholder_query)
elsif !query(marked_query).empty?
touch(marked_query)
else
screenshot_and_raise "Could not find text field with placeholder '#{name}' or marked as '#{name}'"
end
sleep(STEP_PAUSE)
end
# Note in tables views: this means visible cell index!
Then /^(\d+)番目のリスト項目を(?:押す|選択する|タッチする|タップする)$/ do |index|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
touch("tableViewCell index: #{index - 1}")
sleep(STEP_PAUSE)
end
Then /^リスト項目"([^\"]*)"を(?:押す|選択する|タッチする|タップする)$/ do |cell_name|
if query("tableViewCell marked: '#{cell_name}'").empty?
touch("tableViewCell text: '#{cell_name}'")
else
touch("tableViewCell marked: '#{cell_name}'")
end
sleep(STEP_PAUSE)
end
Then /^スイッチを(?:トグルする|押す|タップする|タッチする|切り替える)$/ do
touch('switch')
sleep(STEP_PAUSE)
end
Then /^"([^\"]*)"スイッチを(?:トグルする|押す|タップする|タッチする|切り替える)$/ do |name|
touch("switch marked: '#{name}'")
sleep(STEP_PAUSE)
end
Then /^現在地を(?:タッチ|タップ)する$/ do
touch("view: 'MKUserLocationView'")
sleep(STEP_PAUSE)
end
Then /^キーボードの(?:完了|検索)を(?:押す|タッチする|タップする)$/ do
tap_keyboard_action_key
sleep(STEP_PAUSE)
end
### Entering text ###
Then /^(?:テキストフィールド|入力フィールド)?"([^\"]*)"に"([^\"]*)"を入力する$/ do |field_name, text_to_type|
touch("textField marked: '#{field_name}'")
wait_for_keyboard
keyboard_enter_text text_to_type
sleep(STEP_PAUSE)
end
Then /^ネイティブキーボードを使って(?:テキストフィールド|入力フィールド)?"([^\"]*)"に"([^\"]*)"を入力する$/ do |field_name, text_to_type|
macro %(I touch the "#{field_name}" text field)
wait_for_keyboard
keyboard_enter_text(text_to_type)
sleep(STEP_PAUSE)
end
Then /^これらでテキストフィールドを埋める:$/ do |table|
table.hashes.each do |row|
macro %(I enter "#{row['text']}" into the "#{row['field']}" text field)
end
end
Then /^(\d+)番目の(?:テキストフィールド|入力フィールド)に"([^\"]*)"を入力する$/ do |index, text|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
touch("textField index: #{index - 1}")
wait_for_keyboard
keyboard_enter_text text
sleep(STEP_PAUSE)
end
Then /^ネイティブキーボードを使って(\d+)番目の(?:テキストフィールド|入力フィールド)に"([^\"]*)"を入力する$/ do |index, text_to_type|
macro %(I touch text field number #{index})
wait_for_keyboard
keyboard_enter_text(text_to_type)
sleep(STEP_PAUSE)
end
Then /^(\d+)番目の(?:テキストフィールド|入力フィールド)を(?:クリア|消去)する$/ do |index|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
clear_text("textField index: #{index - 1}")
end
### See ###
Then /^"([^\"]*)"が(?:見える|現れる)(?:のを|まで)待つ$/ do |expected_mark|
wait_for(WAIT_TIMEOUT) { view_with_mark_exists(expected_mark) }
end
Then /^"([^\"]*)"が見えなくなるまで待つ$/ do |expected_mark|
sleep 1 # wait for previous screen to disappear
wait_for(WAIT_TIMEOUT) { !element_exists("view marked: '#{expected_mark}'") }
end
Then /^"([^\"]*)"ボタンが(?:見える|現れる)(?:のを|まで)待つ$/ do |name|
wait_for(WAIT_TIMEOUT) { element_exists("button marked: '#{name}'") }
end
Then /^ナビゲーションタイトル"([^\"]*)"が(?:見える|現れる)(?:のを|まで)待つ$/ do |expected_mark|
msg = "Waited for '#{WAIT_TIMEOUT}' seconds but did not see the navbar with title '#{expected_mark}'"
wait_for(timeout: WAIT_TIMEOUT, timeout_message: msg ) do
all_items = query("navigationItemView marked: '#{expected_mark}'")
button_items = query('navigationItemButtonView')
non_button_items = all_items.delete_if { |item| button_items.include?(item) }
!non_button_items.empty?
end
end
Then /^(?:テキストフィールド|入力フィールド)"([^\"]*)"を待つ$/ do |placeholder_or_view_mark|
wait_for(WAIT_TIMEOUT) do
element_exists("textField placeholder: '#{placeholder_or_view_mark}'") ||
element_exists("textField marked: '#{placeholder_or_view_mark}'")
end
end
Then /^(\d+)個の(?:テキストフィールド|入力フィールド)を待つ?$/ do |count|
wait_for(WAIT_TIMEOUT) { query(:textField).count >= count.to_i }
end
Then /^(?:少し|ちょっと)?待つ$/ do
sleep 2
end
Then /^(?:幾らか|いくらか|少し長めに)待つ$/ do
sleep 4
end
Then /^(?:長めに|かなり)待つ$/ do
sleep 10
end
When /^([\d\.]+)秒待つ$/ do |num_seconds|
sleep num_seconds.to_f
end
Then /^戻る$/ do
touch('navigationItemButtonView first')
sleep(STEP_PAUSE)
end
Then /^(?:スクリーンショット|スクショ|画面キャプチャ)を撮る$/ do
sleep(STEP_PAUSE)
screenshot_embed
end
Then /^(左|右|上|下)にスワイプする$/ do |dir|
swipe(DIR_JA_TO_EN[dir])
sleep(STEP_PAUSE)
end
Then /^(\d+)番目のビューを(左|右|上|下)にスワイプする$/ do |index, dir|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
swipe(DIR_JA_TO_EN[dir], { query: "scrollView index: #{index - 1}" })
sleep(STEP_PAUSE)
end
Then /^(\d+)番目のビューを\((\d+), *(\d+)\)座標で(左|右|上|下)にスワイプする$/ do |index, x, y, dir|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
swipe(DIR_JA_TO_EN[dir], { offset: { x: x.to_i, y: y.to_i }, query: "scrollView index: #{index - 1}" })
sleep(STEP_PAUSE)
end
Then /^"([^\"]*)"を(左|右|上|下)にスワイプする$/ do |mark, dir|
swipe(dir, { query: "view marked: '#{mark}'" })
sleep(STEP_PAUSE)
end
Then /^(\d+)番目のセルをスワイプする$/ do |index|
index = index.to_i
screenshot_and_raise("Index should be positive (was: #{index})") if index <= 0
cell_swipe({ query: "tableViewCell index: #{index - 1}" })
sleep(STEP_PAUSE)
end
### Pinch ###
Then /^ピンチ(イン|アウト)する$/ do |in_out|
pinch(IN_OUT_JA_TO_EN[in_out])
sleep(STEP_PAUSE)
end
Then /^"([^\"]*)"をピンチ(イン|アウト)する$/ do |name, in_out|
pinch(IN_OUT_JA_TO_EN[in_out], { query: "view marked: '#{name}'" })
sleep(STEP_PAUSE)
end
# Note "up/left/right" seems to be missing on the web base
Then /^(左|右|上|下)にスクロールする$/ do |dir|
scroll('scrollView index: 0', DIR_JA_TO_EN[dir])
sleep(STEP_PAUSE)
end
Then /^"([^\"]*)"を(左|右|上|下)にスクロールする$/ do |name, dir|
scroll("view marked: '#{name}'", DIR_JA_TO_EN[dir])
sleep(STEP_PAUSE)
end
### Playback ###
Then /^記録"([^\"]*)"を再生する$/ do |filename|
playback(filename)
sleep(STEP_PAUSE)
end
Then /^記録"([^\"]*)"を"([^\"]*)"の上で再生する$/ do |filename, name|
playback(filename, { query: "view marked: '#{name}'" })
sleep(STEP_PAUSE)
end
Then /^記録"([^\"]*)"を"([^\"]*)"の上でオフセット\((\d+),(\d+)\)で再生する$/ do |filename, name, x, y|
playback(filename, { query: "view marked:'#{name}'", offset: { x: x.to_i, y: y.to_i } })
sleep(STEP_PAUSE)
end
Then /^記録"([^\"]*)"を逆再生する$/ do |filename|
playback(filename, { reverse: true })
sleep(STEP_PAUSE)
end
Then /^記録"([^\"]*)"を"([^\"]*)"の上で逆再生する$/ do |filename, name|
playback(filename, { query: "view marked: '#{name}'", reverse: true })
sleep(STEP_PAUSE)
end
Then /^記録"([^\"]*)"を"([^\"]*)"の上でオフセット\(offset (\d+),(\d+)\)で逆再生する$/ do |filename, name, x, y|
playback(filename, { query: "view marked: '#{name}'", offset: { x: x.to_i, y: y.to_i }, reverse: true })
sleep(STEP_PAUSE)
end
### Device orientation ###
Then /^デバイスを(左|右)に回転する$/ do |dir|
rotate(DIR_JA_TO_EN[dir].to_sym)
sleep 5 # Servo wait
end
Then /^アプリを(\d+)秒間バックグラウンドにする$/ do |secs|
secs = secs.to_f
send_app_to_background(secs)
sleep(secs + 10)
end
### Assertions ###
Then /^"([^\"]*)"が(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |expected_mark|
until element_exists("view marked:'#{expected_mark}'") ||
element_exists("view text:'#{expected_mark}'")
screenshot_and_raise "No element found with mark or text: #{expected_mark}"
end
end
Then /^"([^\"]*)"が(?:見えていない|見えない|表示されていない|表示されない)(?:はず)?$/ do |expected_mark|
res = query("view marked: '#{expected_mark}'")
res.concat query("view text: '#{expected_mark}'")
unless res.empty?
screenshot_and_raise "Expected no element with text nor accessibilityLabel: #{expected_mark}, found #{res.join(', ')}"
end
end
Then /^"([^\"]*)"ボタンが(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |expected_mark|
check_element_exists("button marked: '#{expected_mark}'")
end
Then /^"([^\"]*)"ボタンが(?:見えていない|見えない|表示されていない|表示されない)(?:はず)?$/ do |expected_mark|
check_element_does_not_exist("button marked: '#{expected_mark}'")
end
Then /^"([^\"]*)"で始まる文字列が(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |text|
if query("view {text BEGINSWITH '#{text}'}").empty?
screenshot_and_raise "No text found starting with: #{text}"
end
end
Then /^"([^\"]*)"を含む文字列が(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |text|
if query("view {text LIKE '*#{text}*'}").empty?
screenshot_and_raise "No text found containing: #{text}"
end
end
Then /^"([^\"]*)"で終わる文字列が(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |text|
if query("view {text ENDSWITH '#{text}'}").empty?
screenshot_and_raise "No text found ending with: #{text}"
end
end
Then /^(\d+)個の(?:入力|テキスト)フィールドが(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |count|
cnt = query(:textField).count
if cnt < count.to_i
screenshot_and_raise "Expected at least #{count} text/input fields, found #{cnt}"
end
end
Then /^"([^\"]*)"(?:入力|テキスト)フィールドが(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do |expected_mark|
unless element_exists("textField placeholder: '#{expected_mark}'") ||
element_exists("textField marked: '#{expected_mark}'")
screenshot_and_raise "Expected textfield with placeholder or accessibilityLabel: #{expected_mark}"
end
end
Then /^"([^\"]*)"(?:入力|テキスト)フィールドが(?:見えていない|表示されていない|見えない|表示されない)(?:はず)?$/ do |expected_mark|
res = query("textField placeholder: '#{expected_mark}'")
res.concat query("textField marked: '#{expected_mark}'")
unless res.empty?
screenshot_and_raise "Expected no textfield with placeholder nor accessibilityLabel: #{expected_mark}, found #{res}"
end
end
Then /^地図が(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do
check_element_exists("view: 'MKMapView'")
end
Then /^現在地が(?:見えている|表示されている|見える|表示される)(?:はず)?$/ do
check_element_exists("view: 'MKUserLocationView'")
end
### Date Picker ###
# time_str can be in any format that Time can parse
Then(/^日付選択の(?:時刻|時間|時分)を"([^"]*)"に変更する$/) do |time_str|
target_time = Time.parse(time_str)
current_date = date_time_from_picker
current_date = DateTime.new(current_date.year,
current_date.mon,
current_date.day,
target_time.hour,
target_time.min,
0,
target_time.gmt_offset)
picker_set_date_time current_date
sleep(STEP_PAUSE)
end
# date_str can be in any format that Date can parse
Then(/^日付選択の(?:日付|年月日)を"([^"]*)"に変更する$/) do |date_str|
target_date = Date.parse(date_str)
current_time = date_time_from_picker
date_time = DateTime.new(target_date.year,
target_date.mon,
target_date.day,
current_time.hour,
current_time.min,
0,
Time.now.sec,
current_time.offset)
picker_set_date_time date_time
sleep(STEP_PAUSE)
end
# date_str can be in any format that Date can parse
Then(/^日付選択の(?:日付|年月日)を"([^"]*)"に(?:時刻|時間|時分)を"([^"]*)"に変更する$/) do |date_str, time_str|
macro %(I change the date picker time to "#{time_str}")
macro %(I change the date picker date to "#{date_str}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment