Skip to content

Commit b70abb6

Browse files
ki4070maKazuCocoa
authored andcommitted
Add send sms support (#351)
* Support sendSms function * Added api doc * Add sms unittest * Revert unexpected changes * Update api doc
1 parent 9a7b627 commit b70abb6

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

appium/webdriver/extensions/sms.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
from ..mobilecommand import MobileCommand as Command
17+
18+
19+
class Sms(webdriver.Remote):
20+
21+
def send_sms(self, phone_number, message):
22+
"""Emulate send SMS event on the connected emulator.
23+
24+
:Args:
25+
- phone_number: The phone number of message sender
26+
- message: message: The message to send
27+
28+
:Usage:
29+
self.driver.send_sms('555-123-4567', 'Hey lol')
30+
"""
31+
self.execute(Command.SEND_SMS, {'phoneNumber': phone_number, 'message': message})
32+
33+
def _addCommands(self):
34+
self.command_executor._commands[Command.SEND_SMS] = \
35+
('POST', '/session/$sessionId/appium/device/send_sms')

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ class MobileCommand(object):
7676
GET_CLIPBOARD = 'getClipboard'
7777
COMPARE_IMAGES = 'compareImages'
7878
FINGER_PRINT = 'fingerPrint'
79+
SEND_SMS = 'sendSms'

appium/webdriver/webdriver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from .extensions.screen_record import ScreenRecord
4343
from .extensions.search_context import AppiumSearchContext
4444
from .extensions.settings import Settings
45+
from .extensions.sms import Sms
4546
from .mobilecommand import MobileCommand as Command
4647
from .switch_to import MobileSwitchTo
4748
from .webelement import WebElement as MobileWebElement
@@ -118,7 +119,8 @@ class WebDriver(
118119
Network,
119120
RemoteFS,
120121
ScreenRecord,
121-
Settings
122+
Settings,
123+
Sms
122124
):
123125

124126
def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 (
16+
appium_command,
17+
android_w3c_driver,
18+
get_httpretty_request_body
19+
)
20+
21+
import httpretty
22+
23+
24+
class TestWebDriverSms(object):
25+
26+
@httpretty.activate
27+
def test_send_sms(self):
28+
driver = android_w3c_driver()
29+
httpretty.register_uri(
30+
httpretty.POST,
31+
appium_command('/session/1234567890/appium/device/send_sms'),
32+
)
33+
assert driver.send_sms('555-123-4567', 'Hey lol') is None
34+
35+
d = get_httpretty_request_body(httpretty.last_request())
36+
assert d['phoneNumber'] == '555-123-4567'
37+
assert d['message'] == 'Hey lol'

0 commit comments

Comments
 (0)