Skip to content

Commit

Permalink
convert rest
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Mar 21, 2024
1 parent 68e8d73 commit 4e777b5
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 200 deletions.
76 changes: 40 additions & 36 deletions android_tests/lib/android/specs/android/element/alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,54 @@
# limitations under the License.

# rake "android[android/element/alert]"
describe 'android/element/alert' do
def open_alert
# trigger the alert
wait { button('OK Cancel dialog with a message').click }
end
class AndroidTest
class Element
class Alert < Minitest::Test
def open_alert
# trigger the alert
wait { button('OK Cancel dialog with a message').click }
end

t 'alert_click' do
# nav to alert activity
wait { find('app').click }
wait { find('alert').click }
def test_01_alert_click
# nav to alert activity
wait { find('app').click }
wait { find('alert').click }

# test
wait { open_alert }
wait { alert_click('OK') }
end
# test
wait { open_alert }
wait { alert_click('OK') }
end

t 'alert_accept' do
wait { open_alert }
wait { alert_accept }
end
def test_02_alert_accept
wait { open_alert }
wait { alert_accept }
end

t 'alert_accept_text' do
wait { open_alert }
wait { alert_accept_text.must_equal 'OK' }
wait { alert_accept }
end
def test_03_alert_accept_text
wait { open_alert }
wait { assert_equal alert_accept_text, 'OK' }
wait { alert_accept }
end

t 'alert_dismiss' do
wait { open_alert }
wait { alert_dismiss }
end
def test_04_alert_dismiss
wait { open_alert }
wait { alert_dismiss }
end

t 'alert_dismiss_text' do
wait { open_alert }
def test_05_alert_dismiss_text
wait { open_alert }

# alert dialog button placement changed:
# 'OK Cancel dialog with a long message'
# Android L: 'Something, Cancel, Ok'
# Android 19: 'Cancel, Something, Ok'
# alert dialog button placement changed:
# 'OK Cancel dialog with a long message'
# Android L: 'Something, Cancel, Ok'
# Android 19: 'Cancel, Something, Ok'

wait { alert_dismiss_text.downcase.must_equal 'cancel' }
wait { alert_dismiss }
wait { assert_equal alert_dismiss_text.downcase, 'cancel' }
wait { alert_dismiss }

# nav to start activity
2.times { back }
# nav to start activity
2.times { back }
end
end
end
end
86 changes: 47 additions & 39 deletions android_tests/lib/android/specs/android/element/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,62 @@
# limitations under the License.

# rake "android[android/element/button]"
describe 'android/element/button' do
def before_first
# nav to buttons activity
wait { find('App').click }
wait { find('Activity').click }
wait { find('Animation').click }
end
class AndroidTest
class Element
class Button < Minitest::Test
def before_first
# nav to buttons activity
wait { find('App').click }
wait { find('Activity').click }
wait { find('Animation').click }
end

def after_last
# nav back to home activity
3.times { back }
end
def after_last
# nav back to home activity
3.times { back }
end

def fade_in
'Fade in'
end
def fade_in
'Fade in'
end

t { before_first }
def test_01_before_first
before_first
end

t 'button' do
# by index
2.times { wait { button(1).text.upcase.must_equal fade_in.upcase } }
def test_02_button
# by index
2.times { wait { assert_equal button(1).text.upcase, fade_in.upcase } }

# by name contains
wait { button('ade').text.upcase.must_equal fade_in.upcase }
end
# by name contains
wait { assert_equal button('ade').text.upcase, fade_in.upcase }
end

t 'buttons' do
exp = ['ZOOM IN', 'MODERN ZOOM IN', 'THUMBNAIL ZOOM']
wait { buttons('zoom').map(&:text).map(&:upcase).must_equal exp }
wait { buttons.length.must_equal 6 }
end
def test_03_buttons
exp = ['ZOOM IN', 'MODERN ZOOM IN', 'THUMBNAIL ZOOM']
wait { assert_equal buttons('zoom').map(&:text).map(&:upcase), exp }
wait { assert_equal buttons.length, 6 }
end

t 'first_button' do
wait { first_button.text.upcase.must_equal fade_in.upcase }
end
def test_04_first_button
wait { assert_equal first_button.text.upcase, fade_in.upcase }
end

t 'last_button' do
wait { last_button.text.upcase.must_equal 'THUMBNAIL ZOOM' }
end
def test_05_last_button
wait { assert_equal last_button.text.upcase, 'THUMBNAIL ZOOM' }
end

t 'button_exact' do
wait { button_exact(fade_in).text.upcase.must_equal fade_in.upcase }
end
def test_06_button_exact
wait { assert_equal button_exact(fade_in).text.upcase, fade_in.upcase }
end

t 'buttons_exact' do
2.times { wait { buttons_exact(fade_in).first.text.upcase.must_equal fade_in.upcase } }
end
def test_07_buttons_exact
2.times { wait { assert_equal buttons_exact(fade_in).first.text.upcase, fade_in.upcase } }
end

t { after_last }
def test_08_after_last
after_last
end
end
end
end
94 changes: 49 additions & 45 deletions android_tests/lib/android/specs/android/element/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,64 @@
# limitations under the License.

# rake "android[android/element/generic]"
describe 'android/element/generic' do
def content
'Content'
end
class AndroidTest
class Element
class Generic < Minitest::Test
def content
'Content'
end

def partial
'tent'
end
def partial
'tent'
end

t 'find works before and after get_source' do
wait { find(partial).text.must_equal content }
wait { get_source.class.must_equal String }
wait { find(partial).text.must_equal content }
end
def test_01_find_works_before_and_after_get_source
wait { assert_equal find(partial).text, content }
wait { assert_equal get_source.class, String }
wait { assert_equal find(partial).text, content }
end

t 'find' do
wait { find(partial).text.must_equal content }
end
def test_01_find
wait { assert_equal find(partial).text, content }
end

t 'finds' do
wait { finds(partial).first.text.must_equal content }
end
def test_01_finds
wait { assert_equal finds(partial).first.text, content }
end

t 'find_exact' do
wait { find_exact(content).text.must_equal content }
end
def test_01_find_exact
wait { assert_equal find_exact(content).text, content }
end

t 'finds_exact' do
wait { finds_exact(content).first.text.must_equal content }
end
def test_01_finds_exact
wait { assert_equal finds_exact(content).first.text, content }
end

# scroll_to is broken
t 'scroll_to' do
wait { scroll_to('Views').click }
wait { scroll_to('scrollbars').text.must_equal 'ScrollBars' }
# scroll_to is broken
def test_01_scroll_to
wait { scroll_to('Views').click }
wait { assert_equal scroll_to('scrollbars').text, 'ScrollBars' }

wait { find('ScrollBars').click }
wait { text('style').click }
wait { scroll_to('Developers', 1).text.must_include 'What would it take to build a better mobile phone?' }
back
back
# back to start activity
back
end
wait { find('ScrollBars').click }
wait { text('style').click }
wait { assert scroll_to('Developers', 1).text.include? 'What would it take to build a better mobile phone?' }
back
back
# back to start activity
back
end

t 'scroll_to_exact' do
wait { scroll_to('Views').click }
def test_01_scroll_to_exact
wait { scroll_to('Views').click }

wait { scroll_to_exact('ScrollBars').text.must_equal 'ScrollBars' }
wait { find('ScrollBars').click }
wait { text('style').click }
back
back
# back to start activity
back
wait { assert_equal scroll_to_exact('ScrollBars').text, 'ScrollBars' }
wait { find('ScrollBars').click }
wait { text('style').click }
back
back
# back to start activity
back
end
end
end
end
70 changes: 38 additions & 32 deletions android_tests/lib/android/specs/android/element/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,43 @@
# limitations under the License.

# rake "android[android/element/text]"
describe 'android/element/text' do
def must_raise_no_element
proc { yield }.must_raise Selenium::WebDriver::Error::NoSuchElementError
end

t 'text' do
wait { ['API Demos', "Access'ibility"].must_include text(1).text }
wait { text('mos').text.must_equal 'API Demos' }
end

t 'texts' do
wait { texts('i').length.must_equal 7 }
wait { texts.length.must_equal 13 }
end

t 'first_text' do
wait { ['API Demos', "Access'ibility"].must_include first_text.text }
end

t 'last_text' do
wait { ['API Demos', 'Views'].must_include last_text.text }
end

t 'text_exact' do
must_raise_no_element { text_exact 'mos' }

# should pass
wait { text_exact('API Demos').text.must_equal 'API Demos' }
end

t 'texts_exact' do
wait { texts_exact('API Demos').length.must_equal 1 }
class AndroidTest
class Element
class Text < Minitest::Test
def must_raise_no_element
assert_raises Selenium::WebDriver::Error::NoSuchElementError do
yield
end
end

def test_01_text
wait { assert ['API Demos', "Access'ibility"].include? text(1).text }
wait { assert_equal text('mos').text, 'API Demos' }
end

def test_02_texts
wait { assert_equal texts('i').length, 7 }
wait { assert_equal texts.length, 13 }
end

def test_03_first_text
wait { assert ['API Demos', "Access'ibility"].include? first_text.text }
end

def test_04_last_text
wait { assert ['API Demos', 'Views'].include? last_text.text }
end

def test_05_text_exact
must_raise_no_element { text_exact 'mos' }

# should pass
wait { assert_equal text_exact('API Demos').text, 'API Demos' }
end

def test_06_texts_exact
wait { assert_equal texts_exact('API Demos').length, 1 }
end
end
end
end
Loading

0 comments on commit 4e777b5

Please sign in to comment.