ios_tests/lib/ios/specs/common/helper.rb in appium_lib-6.0.0 vs ios_tests/lib/ios/specs/common/helper.rb in appium_lib-7.0.0

- old
+ new

@@ -1,52 +1,49 @@ # rake ios[common/helper] describe 'common/helper.rb' do - def before_first screen.must_equal catalog end t 'before_first' do before_first end wait_opts = { timeout: 0.2, interval: 0.2 } # max_wait, interval -=begin -There's no `must_not_raise` as the opposite of must_raise + # There's no `must_not_raise` as the opposite of must_raise + # + # By default code is expected to not raise exceptions. + # must_not_raise is a no-op. -By default code is expected to not raise exceptions. -must_not_raise is a no-op. -=end - # wait is a success unless an error is raised # max_wait=0 is infinity to use 0.1 t 'wait' do # successful wait should not raise error wait(wait_opts) { true } wait(wait_opts) { false } wait(wait_opts) { nil } # failed wait should error - proc { wait(wait_opts) { raise } }.must_raise Selenium::WebDriver::Error::TimeOutError + proc { wait(wait_opts) { fail } }.must_raise Selenium::WebDriver::Error::TimeOutError # regular rescue will not handle exceptions outside of StandardError hierarchy # must rescue Exception explicitly to rescue everything - proc { wait(wait_opts) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError - proc { wait(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError + proc { wait(wait_opts) { fail NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError + proc { wait(timeout: 0.2, interval: 0.0) { fail NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError # invalid keys are rejected proc { wait(invalidkey: 2) { true } }.must_raise RuntimeError end t 'ignore' do # ignore should rescue all exceptions ignore { true } ignore { false } ignore { nil } - ignore { raise } - ignore { raise NoMemoryError } + ignore { fail } + ignore { fail NoMemoryError } end # wait_true is a success unless the value is not true t 'wait_true' do # successful wait should not error @@ -55,16 +52,17 @@ # failed wait should error proc { wait_true(wait_opts) { false } }.must_raise Selenium::WebDriver::Error::TimeOutError proc { wait_true(wait_opts) { nil } }.must_raise Selenium::WebDriver::Error::TimeOutError # raise should error - proc { wait_true(wait_opts) { raise } }.must_raise Selenium::WebDriver::Error::TimeOutError + proc { wait_true(wait_opts) { fail } }.must_raise Selenium::WebDriver::Error::TimeOutError # regular rescue will not handle exceptions outside of StandardError hierarchy # must rescue Exception explicitly to rescue everything - proc { wait_true(wait_opts) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError - proc { wait_true(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError + proc { wait_true(wait_opts) { fail NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError + proc { wait_true(timeout: 0.2, interval: 0.0) { fail NoMemoryError } } + .must_raise Selenium::WebDriver::Error::TimeOutError # invalid keys are rejected proc { wait_true(invalidkey: 2) { true } }.must_raise RuntimeError end @@ -72,21 +70,25 @@ t 'back' do # start page tag('UIANavigationBar').name.must_equal 'UICatalog' # nav to new page. - wait_true { text('buttons').click; tag('UIANavigationBar').name == 'Buttons' } + wait_true do + text('buttons').click + tag('UIANavigationBar').name == 'Buttons' + end + tag('UIANavigationBar').name.must_equal 'Buttons' # go back back_click # start page tag('UIANavigationBar').name.must_equal 'UICatalog' end t 'session_id' do # Sauce doesn't return '-' so make them optional. - session_id.must_match /\h{8}-?\h{4}-?\h{4}-?\h{4}-?\h{12}/ + session_id.must_match(/\h{8}-?\h{4}-?\h{4}-?\h{4}-?\h{12}/) end t 'xpath' do xpath('//UIAStaticText').name.must_equal 'UICatalog' end @@ -101,15 +103,15 @@ t 'ele_index' do ele_index('UIAStaticText', 2).name.must_equal uibutton_text end - # todo: 'string_attr_exact' + # TODO: 'string_attr_exact' t 'find_ele_by_attr' do el_id = find_ele_by_attr('UIAStaticText', 'name', uibutton_text).instance_variable_get :@id - el_id.must_match /\d+/ + el_id.must_match(/\d+/) end t 'find_eles_by_attr' do # '!' clears the input buffer in Pry so make sure there's # no space after the ! @@ -121,11 +123,11 @@ found = !find_eles_by_attr('UIAStaticText', 'name', 'zz').empty? found.must_equal false set_wait end - # todo: 'string_attr_include' + # TODO: 'string_attr_include' t 'find_ele_by_attr_include' do el_text = find_ele_by_attr_include('UIAStaticText', :name, 'button').text el_text.must_equal uibutton_text @@ -179,25 +181,24 @@ t 'get_page_class' do # 8 local. 9 on sauce. get_page_class.split("\n").length.must_be :>=, 8 end -=begin -todo: -get_page_class -page_class -tag -tags -px_to_window_rel -lazy_load_strings -xml_keys -xml_values -resolve_id -string_visible_contains -xpath_visible_contains -xpaths_visible_contains -string_visible_exact -xpath_visible_exact -xpaths_visible_exact -raise_no_element_error -=end + + # TODO: write tests + # get_page_class + # page_class + # tag + # tags + # px_to_window_rel + # lazy_load_strings + # xml_keys + # xml_values + # resolve_id + # string_visible_contains + # xpath_visible_contains + # xpaths_visible_contains + # string_visible_exact + # xpath_visible_exact + # xpaths_visible_exact + # raise_no_element_error end