|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +module Appium |
| 16 | + module Core |
| 17 | + class Base |
| 18 | + # |
| 19 | + # @api private |
| 20 | + # |
| 21 | + module HasLocation |
| 22 | + # Get the location of the device. |
| 23 | + # |
| 24 | + # @return [::Selenium::WebDriver::Location] |
| 25 | + # |
| 26 | + # @example |
| 27 | + # |
| 28 | + # driver.location #=> ::Selenium::WebDriver::Location.new(10, 10, 10) |
| 29 | + # |
| 30 | + def location |
| 31 | + @bridge.location |
| 32 | + end |
| 33 | + |
| 34 | + # Set the location of the device. |
| 35 | + # |
| 36 | + # @param [::Selenium::WebDriver::Location] location Set the location. |
| 37 | + # |
| 38 | + # @example |
| 39 | + # |
| 40 | + # driver.location = ::Selenium::WebDriver::Location.new(10, 10, 10) |
| 41 | + # |
| 42 | + def location=(location) |
| 43 | + unless location.is_a?(::Selenium::WebDriver::Location) |
| 44 | + raise TypeError, "expected #{::Selenium::WebDriver::Location}, got #{location.inspect}:#{location.class}" |
| 45 | + end |
| 46 | + |
| 47 | + @bridge.set_location location.latitude, location.longitude, location.altitude |
| 48 | + end |
| 49 | + |
| 50 | + # Set the location of the device. |
| 51 | + # |
| 52 | + # @param [String, Number] latitude Set the latitude. |
| 53 | + # @param [String, Number] longitude Set the longitude. |
| 54 | + # @param [String, Number] altitude Set the altitude. |
| 55 | + # @param [String, Number] speed Set the speed to apply the location on Android real devices @since Appium 1.21.0. |
| 56 | + # @param [::Selenium::WebDriver::Location] |
| 57 | + # |
| 58 | + # @example |
| 59 | + # |
| 60 | + # driver.location = ::Selenium::WebDriver::Location.new(10, 10, 10) |
| 61 | + # |
| 62 | + def set_location(latitude, longitude, altitude, speed: nil) |
| 63 | + if speed.nil? |
| 64 | + self.location = ::Selenium::WebDriver::Location.new(Float(latitude), Float(longitude), Float(altitude)) |
| 65 | + else |
| 66 | + loc = ::Selenium::WebDriver::Location.new(Float(latitude), Float(longitude), Float(altitude)) |
| 67 | + @bridge.set_location loc.latitude, loc.longitude, loc.altitude, speed: Float(speed) |
| 68 | + end |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | +end |
0 commit comments