File tree Expand file tree Collapse file tree
test/unit/webdriver/device Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
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+ from selenium import webdriver
16+
17+ from appium .webdriver .mobilecommand import MobileCommand as Command
18+
19+
20+ class Display (webdriver .Remote ):
21+
22+ def get_display_density (self ):
23+ """Get the display density, Android only
24+
25+ :Returns:
26+ int: The display density of the Android device(dpi)
27+
28+ :Usage:
29+ self.driver.get_display_density()
30+ """
31+ return self .execute (Command .GET_DISPLAY_DENSITY )['value' ]
32+
33+ # pylint: disable=protected-access
34+
35+ def _addCommands (self ):
36+ self .command_executor ._commands [Command .GET_DISPLAY_DENSITY ] = \
37+ ('GET' , '/session/$sessionId/appium/device/display_density' )
Original file line number Diff line number Diff line change @@ -78,20 +78,21 @@ class MobileCommand(object):
7878 GET_CURRENT_ACTIVITY = 'getCurrentActivity'
7979 GET_CURRENT_PACKAGE = 'getCurrentPackage'
8080 GET_SYSTEM_BARS = 'getSystemBars'
81+ GET_DISPLAY_DENSITY = 'getDisplayDensity'
8182 TOGGLE_WIFI = 'toggleWiFi'
8283 TOGGLE_LOCATION_SERVICES = 'toggleLocationServices'
8384 END_TEST_COVERAGE = 'endTestCoverage'
8485 GET_PERFORMANCE_DATA_TYPES = 'getPerformanceDataTypes'
8586 GET_PERFORMANCE_DATA = 'getPerformanceData'
8687 GET_NETWORK_CONNECTION = 'getNetworkConnection'
8788 SET_NETWORK_CONNECTION = 'setNetworkConnection'
88- SET_NETWORK_SPEED = 'setNetworkSpeed'
8989
9090 # Android Emulator
9191 SEND_SMS = 'sendSms'
9292 MAKE_GSM_CALL = 'makeGsmCall'
9393 SET_GSM_SIGNAL = 'setGsmSignal'
9494 SET_GSM_VOICE = 'setGsmVoice'
95+ SET_NETWORK_SPEED = 'setNetworkSpeed'
9596 SET_POWER_CAPACITY = 'setPowerCapacity'
9697 SET_POWER_AC = 'setPowerAc'
9798
Original file line number Diff line number Diff line change 2929from .errorhandler import MobileErrorHandler
3030from .extensions .action_helpers import ActionHelpers
3131from .extensions .android .activities import Activities
32+ from .extensions .android .display import Display
3233from .extensions .android .gsm import Gsm
3334from .extensions .android .network import Network
3435from .extensions .android .performance import Performance
@@ -114,6 +115,7 @@ class WebDriver(
114115 Clipboard ,
115116 Context ,
116117 DeviceTime ,
118+ Display ,
117119 Gsm ,
118120 HardwareActions ,
119121 ImagesComparison ,
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
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+ from test .unit .helper .test_helper import android_w3c_driver , appium_command
16+
17+ import httpretty
18+
19+
20+ class TestWebDriverDisplay (object ):
21+
22+ @httpretty .activate
23+ def test_get_display_density (self ):
24+ driver = android_w3c_driver ()
25+ httpretty .register_uri (
26+ httpretty .GET ,
27+ appium_command ('/session/1234567890/appium/device/display_density' ),
28+ body = '{"value": 560}'
29+ )
30+ assert driver .get_display_density () == 560
You can’t perform that action at this time.
0 commit comments