Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ class MobileCommand(object):
SHAKE = 'shake'
RESET = 'reset'
HIDE_KEYBOARD = 'hideKeyboard'
GET_NETWORK_CONNECTION = 'getNetworkConnection'
SET_NETWORK_CONNECTION = 'setNetworkConnection'
35 changes: 35 additions & 0 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from selenium import webdriver

from .connectiontype import ConnectionType
from .mobilecommand import MobileCommand as Command
from .errorhandler import MobileErrorHandler
from .switch_to import MobileSwitchTo
Expand Down Expand Up @@ -569,6 +570,36 @@ def open_notifications(self):
self.execute(Command.OPEN_NOTIFICATIONS, {})
return self

@property
def network_connection(self):
"""Returns an integer bitmask specifying the network connection type.
Android only.
Possible values are available through the enumeration `appium.webdriver.ConnectionType`
"""
return self.execute(Command.GET_NETWORK_CONNECTION, {})['value']

def set_network_connection(self, connectionType):
"""Sets the network connection type. Android only.
Possible values:
Value (Alias) | Data | Wifi | Airplane Mode
-------------------------------------------------
0 (None) | 0 | 0 | 0
1 (Airplane Mode) | 0 | 0 | 1
2 (Wifi only) | 0 | 1 | 0
4 (Data only) | 1 | 0 | 0
6 (All network on) | 1 | 1 | 0
These are available through the enumeration `appium.webdriver.ConnectionType`

:Args:
- connectionType - a member of the enum appium.webdriver.ConnectionType
"""
data = {
'parameters': {
'type': connectionType.value
}
}
return self.execute(Command.SET_NETWORK_CONNECTION, data)['value']

def _addCommands(self):
self.command_executor._commands[Command.CONTEXTS] = \
('GET', '/session/$sessionId/contexts')
Expand Down Expand Up @@ -625,6 +656,10 @@ def _addCommands(self):
('POST', '/session/$sessionId/appium/device/hide_keyboard')
self.command_executor._commands[Command.OPEN_NOTIFICATIONS] = \
('POST', '/session/$sessionId/appium/device/open_notifications')
self.command_executor._commands[Command.GET_NETWORK_CONNECTION] = \
('GET', '/session/$sessionId/network_connection')
self.command_executor._commands[Command.SET_NETWORK_CONNECTION] = \
('POST', '/session/$sessionId/network_connection')


# monkeypatched method for WebElement
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing'
],
install_requires=['selenium>=2.41.0']
install_requires=['selenium>=2.41.0', 'enum34']
)
49 changes: 49 additions & 0 deletions test/functional/android/network_connection_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 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.

import unittest


from appium import webdriver
from appium.webdriver.connectiontype import ConnectionType
import desired_capabilities


# the emulator is sometimes slow and needs time to think
SLEEPY_TIME = 1


class NetworkConnectionTests(unittest.TestCase):
def setUp(self):
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

def tearDown(self):
self.driver.quit()


def test_get_network_connection(self):
nc = self.driver.network_connection
self.assertIsInstance(nc, int)

def test_set_network_connection(self):
nc = self.driver.set_network_connection(ConnectionType.DATA_ONLY)
self.assertIsInstance(nc, int)
self.assertEqual(nc, ConnectionType.DATA_ONLY.value)


if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(NetworkConnectionTests)
unittest.TextTestRunner(verbosity=2).run(suite)