lib/appium_lib/driver.rb in appium_lib-9.15.1 vs lib/appium_lib/driver.rb in appium_lib-9.15.2

- old
+ new

@@ -197,11 +197,11 @@ end # Save global reference to last created Appium driver for top level methods. $driver = self if global_driver - self # return newly created driver + self # rubocop:disable Lint/Void # return newly created driver end private # @private @@ -252,27 +252,29 @@ public # Returns a hash of the driver attributes def driver_attributes + # rubocop:disable Layout/AlignHash { - caps: @core.caps, - automation_name: @core.automation_name, - custom_url: @core.custom_url, - export_session: @core.export_session, - export_session_path: @core.export_session_path, - default_wait: @core.default_wait, - sauce_username: @sauce.username, - sauce_access_key: @sauce.access_key, - sauce_endpoint: @sauce.endpoint, - port: @core.port, - device: @core.device, - debug: @appium_debug, - listener: @listener, - wait_timeout: @core.wait_timeout, - wait_interval: @core.wait_interval + caps: @core.caps, + automation_name: @core.automation_name, + custom_url: @core.custom_url, + export_session: @core.export_session, + export_session_path: @core.export_session_path, + default_wait: @core.default_wait, + sauce_username: @sauce.username, + sauce_access_key: @sauce.access_key, + sauce_endpoint: @sauce.endpoint, + port: @core.port, + device: @core.device, + debug: @appium_debug, + listener: @listener, + wait_timeout: @core.wait_timeout, + wait_interval: @core.wait_interval } + # rubocop:enable Layout/AlignHash end def device_is_android? @core.device == :android end @@ -326,12 +328,13 @@ # Return true if the target Appium server is over REQUIRED_VERSION_XCUITEST. # If the Appium server is under REQUIRED_VERSION_XCUITEST, then error is raised. # @return [Boolean] def check_server_version_xcuitest if automation_name_is_xcuitest? && - !@appium_server_status.empty? && - (@appium_server_status['build']['version'] < REQUIRED_VERSION_XCUITEST) + !@appium_server_status.empty? && + (@appium_server_status['build']['version'] < REQUIRED_VERSION_XCUITEST) + raise(Appium::Core::Error::NotSupportedAppiumServer, "XCUITest requires Appium version >= #{REQUIRED_VERSION_XCUITEST}") end true end @@ -349,10 +352,11 @@ # @return [Hash] def appium_server_version @core.appium_server_version rescue Selenium::WebDriver::Error::WebDriverError => ex raise ::Appium::Core::Error::ServerError unless ex.message.include?('content-type=""') + # server (TestObject for instance) does not respond to status call {} end alias remote_status appium_server_version @@ -383,10 +387,11 @@ # if app isn't set then an error is raised. # # @return [String] APP_PATH as an absolute path def self.absolute_app_path(opts) raise 'opts must be a hash' unless opts.is_a? Hash + caps = opts[:caps] || {} app_path = caps[:app] raise 'absolute_app_path invoked and app is not set!' if app_path.nil? || app_path.empty? # Sauce storage API. http://saucelabs.com/docs/rest#storage return app_path if app_path.start_with? 'sauce-storage:' @@ -401,10 +406,11 @@ # Get the server url # @return [String] the server url def server_url return @core.custom_url if @core.custom_url return @sauce.server_url if @sauce.sauce_server_url? + "http://127.0.0.1:#{@core.port}/wd/hub" end # Restarts the driver # @return [Driver] the driver @@ -515,10 +521,11 @@ @driver.manage.timeouts.implicit_wait = wait rescue Selenium::WebDriver::Error::UnknownError => e unless e.message.include?('The operation requested is not yet implemented by Espresso driver') raise ::Appium::Core::Error::ServerError end + {} end # Set implicit wait to zero. def no_wait @@ -560,11 +567,11 @@ # the element exists unless an error is raised. exists = true begin yield # search for element - rescue + rescue StandardError exists = false # error means it's not there end # restore wait @driver.manage.timeouts.implicit_wait = post_check if post_check != pre_check @@ -577,9 +584,55 @@ # @param [*args] args The args to pass to the script # @return [Object] def execute_script(script, *args) @driver.execute_script script, *args end + + ### + # Wrap calling selenium webdrier APIs via ruby_core + ### + # Get the window handles of open browser windows + def execute_async_script(script, *args) + @driver.execute_async_script script, *args + end + + def window_handles + @driver.window_handles + end + + # Get the current window handle + def window_handle + @driver.window_handle + end + + def navigate + @driver.navigate + end + + def manage + @driver.manage + end + + def get(url) + @driver.get(url) + end + + def current_url + @driver.current_url + end + + def title + @driver.title + end + + # @return [TargetLocator] + # @see TargetLocator + def switch_to + @driver.switch_to + end + ### + # End core + ### # Calls @driver.find_elements_with_appium # # @example #