android_tests/lib/android/specs/driver.rb in appium_lib-6.0.0 vs android_tests/lib/android/specs/driver.rb in appium_lib-7.0.0

- old
+ new

@@ -1,8 +1,10 @@ +# rubocop:disable Lint/RescueException + # rake android[driver] describe 'driver' do - def is_sauce + def sauce? ENV['UPLOAD_FILE'] && ENV['SAUCE_USERNAME'] end t 'load_appium_txt' do appium_txt = File.expand_path(File.join(Dir.pwd, 'lib')) @@ -33,20 +35,20 @@ actual[:caps][:app] = File.basename actual[:caps][:app] expected = { caps: { platformName: 'android', app: 'api.apk', appPackage: 'io.appium.android.apis', appActivity: '.ApiDemos', - deviceName: 'Nexus 7', }, + deviceName: 'Nexus 7' }, custom_url: false, export_session: false, default_wait: 1, last_waits: [1, 1], sauce_username: nil, sauce_access_key: nil, port: 4723, device: :android, - debug: true, } + debug: true } if actual != expected diff = HashDiff.diff expected, actual diff = "diff (expected, actual):\n#{diff}" # example: @@ -57,25 +59,20 @@ end end end describe 'Appium::Driver' do - t '@@loaded' do - loaded = $driver.class.class_variable_get :@@loaded - loaded.must_equal true - end - t '$driver.class' do $driver.class.must_equal Appium::Driver end t 'absolute_app_path' do - def absolute_app_path path - $driver.class.absolute_app_path({caps: { app: path } }) + def absolute_app_path(path) + $driver.class.absolute_app_path(caps: { app: path }) end - def validate_path path + def validate_path(path) absolute_app_path(path).must_equal path end validate_path 'sauce-storage:some_storage_suffix' validate_path 'http://www.saucelabs.com' @@ -121,51 +118,49 @@ appium_server_version['build'].keys.sort.must_equal %w(revision version) end t 'server_version' do server_version = appium_server_version['build']['version'] - if is_sauce + if sauce? server_version.must_match 'Sauce OnDemand' else - server_version.must_match /(\d+)\.(\d+).(\d+)/ + server_version.must_match(/(\d+)\.(\d+).(\d+)/) end end -=begin - Skip: - ios_capabilities # save for iOS tests - absolute_app_path # tested already by starting the driver for this test - server_url # sauce labs only -=end + # Skip: + # ios_capabilities # save for iOS tests + # absolute_app_path # tested already by starting the driver for this test + # server_url # sauce labs only + t 'restart' do set_wait 1 # ensure wait is 1 before we restart. restart current_activity.must_equal '.ApiDemos' end t 'driver' do driver.browser.must_equal :Android end -=begin - Skip: - screenshot # this is slow and already tested by Appium - driver_quit # tested by restart - start_driver # tested by restart - no_wait # posts value to server, it's not stored locally - set_wait # posts value to server, it's not stored locally - execute_script # 'mobile: ' is deprecated and plain executeScript unsupported -=end + # Skip: + # screenshot # this is slow and already tested by Appium + # driver_quit # tested by restart + # start_driver # tested by restart + # no_wait # posts value to server, it's not stored locally + # set_wait # posts value to server, it's not stored locally + # execute_script # 'mobile: ' is deprecated and plain executeScript unsupported + t 'default_wait' do set_wait 1 default_wait.must_equal 1 end # returns true unless an error is raised t 'exists' do exists(0, 0) { true }.must_equal true - exists(0, 0) { raise 'error' }.must_equal false + exists(0, 0) { fail 'error' }.must_equal false end # any elements t 'find_elements' do wait do @@ -175,9 +170,23 @@ # any element t 'find_element' do wait do find_element(:class_name, 'android.widget.TextView').class.must_equal Selenium::WebDriver::Element + end + end + + # simple integration sanity test to check for unexpected exceptions + t 'set_location' do + begin + set_location latitude: 55, longitude: -72, altitude: 33 + rescue Selenium::WebDriver::Error::UnknownError => e + # on android this method is expected to fail with this message when running + # on a regular device, or on genymotion. + # error could be many messages, including: + # ERROR running Appium command: port should be a number or string + # ERROR running Appium command: port should be > 0 and < 65536 + raise unless e.message.include?('ERROR running Appium command: port should be') end end # settings t 'get settings' do