Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions appium/webdriver/extensions/android/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from selenium import webdriver

from appium.webdriver.mobilecommand import MobileCommand as Command


class Display(webdriver.Remote):

def get_display_density(self):
"""Get the display density, Android only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful here to describe the meaning of the returned units

:Usage:
self.driver.get_display_density()
"""
return self.execute(Command.GET_DISPLAY_DENSITY)['value']

# pylint: disable=protected-access

def _addCommands(self):
self.command_executor._commands[Command.GET_DISPLAY_DENSITY] = \
('GET', '/session/$sessionId/appium/device/display_density')
1 change: 1 addition & 0 deletions appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class MobileCommand(object):
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
GET_CURRENT_PACKAGE = 'getCurrentPackage'
GET_SYSTEM_BARS = 'getSystemBars'
GET_DISPLAY_DENSITY = 'getDisplayDensity'
TOGGLE_WIFI = 'toggleWiFi'
TOGGLE_LOCATION_SERVICES = 'toggleLocationServices'
END_TEST_COVERAGE = 'endTestCoverage'
Expand Down
2 changes: 2 additions & 0 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .errorhandler import MobileErrorHandler
from .extensions.action_helpers import ActionHelpers
from .extensions.android.activities import Activities
from .extensions.android.display import Display
from .extensions.android.gsm import Gsm
from .extensions.android.network import Network
from .extensions.android.performance import Performance
Expand Down Expand Up @@ -114,6 +115,7 @@ class WebDriver(
Clipboard,
Context,
DeviceTime,
Display,
Gsm,
HardwareActions,
ImagesComparison,
Expand Down
30 changes: 30 additions & 0 deletions test/unit/webdriver/device/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from test.unit.helper.test_helper import android_w3c_driver, appium_command

import httpretty


class TestWebDriverDisplay(object):

@httpretty.activate
def test_get_display_density(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890/appium/device/display_density'),
body='{"value": 560}'
)
assert driver.get_display_density() == 560