Skip to content

Commit 167117c

Browse files
committed
Add support for open_notifications
1 parent 0f04cb6 commit 167117c

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MobileCommand(object):
1919
SWITCH_TO_CONTEXT = 'switchToContext'
2020
TOUCH_ACTION = 'touchAction'
2121
MULTI_ACTION = 'multiAction'
22+
OPEN_NOTIFICATIONS = 'openNotifications'
2223

2324
# Appium Commands
2425
GET_APP_STRINGS = 'getAppStrings'

appium/webdriver/webdriver.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ def shake(self):
542542
self.execute(Command.SHAKE)
543543
return self
544544

545+
def open_notifications(self):
546+
"""Open notification shade in Android (API Level 18 and above)
547+
"""
548+
self.execute(Command.OPEN_NOTIFICATIONS, {})
549+
return self
550+
545551
def _addCommands(self):
546552
self.command_executor._commands[Command.CONTEXTS] = \
547553
('GET', '/session/$sessionId/contexts')
@@ -594,6 +600,8 @@ def _addCommands(self):
594600
('POST', '/session/$sessionId/appium/app/reset')
595601
self.command_executor._commands[Command.HIDE_KEYBOARD] = \
596602
('POST', '/session/$sessionId/appium/device/hide_keyboard')
603+
self.command_executor._commands[Command.OPEN_NOTIFICATIONS] = \
604+
('POST', '/session/$sessionId/appium/device/open_notifications')
597605

598606

599607
# monkeypatched method for WebElement

test/functional/android/appium_tests.py

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import json
1818
from time import sleep
1919

20+
from selenium.common.exceptions import NoSuchElementException
21+
2022
from appium import webdriver
2123
import desired_capabilities
2224

@@ -53,47 +55,6 @@ def test_current_activity(self):
5355
activity = self.driver.current_activity
5456
self.assertEqual('.ApiDemos', activity)
5557

56-
def test_set_value(self):
57-
el = self.driver.find_element_by_class_name('android.widget.ListView')
58-
js_params = {'element': el.id, 'text': "Views"}
59-
self.driver.execute_script("mobile: scrollTo", js_params)
60-
61-
el = self.driver.find_element_by_name('Views')
62-
el.click()
63-
64-
el = self.driver.find_element_by_name('Auto Complete')
65-
el.click()
66-
67-
el = self.driver.find_element_by_name('4. Contacts')
68-
el.click()
69-
70-
el = self.driver.find_element_by_class_name('android.widget.EditText')
71-
self.driver.set_value(el, 'Isaac')
72-
73-
text = el.get_attribute('text')
74-
self.assertEqual('Isaac', text)
75-
76-
def test_element_set_value(self):
77-
el = self.driver.find_element_by_class_name('android.widget.ListView')
78-
js_params = {'element': el.id, 'text': "Views"}
79-
self.driver.execute_script("mobile: scrollTo", js_params)
80-
81-
el = self.driver.find_element_by_name('Views')
82-
el.click()
83-
84-
el = self.driver.find_element_by_name('Auto Complete')
85-
el.click()
86-
87-
el = self.driver.find_element_by_name('4. Contacts')
88-
el.click()
89-
sleep(SLEEPY_TIME)
90-
91-
el = self.driver.find_element_by_class_name('android.widget.EditText')
92-
el.set_value('Isaac')
93-
94-
text = el.get_attribute('text')
95-
self.assertEqual('Isaac', text)
96-
9758
def test_pull_file(self):
9859
data = self.driver.pull_file('data/local/tmp/strings.json')
9960
strings = json.loads(data.decode('base64', 'strict'))
@@ -157,6 +118,36 @@ def test_reset(self):
157118
el = self.driver.find_element_by_name('App')
158119
self.assertIsNotNone(el)
159120

121+
def test_open_notifications(self):
122+
self.driver.find_element_by_android_uiautomator('new UiSelector().text("App")').click()
123+
self.driver.find_element_by_android_uiautomator('new UiSelector().text("Notification")').click()
124+
self.driver.find_element_by_android_uiautomator('new UiSelector().text("Status Bar")').click()
125+
126+
self.driver.find_element_by_android_uiautomator('new UiSelector().text(":-|")').click()
127+
128+
self.driver.open_notifications()
129+
sleep(1)
130+
self.assertRaises(NoSuchElementException, \
131+
self.driver.find_element_by_android_uiautomator, 'new UiSelector().text(":-|")')
132+
133+
els = self.driver.find_elements_by_class_name('android.widget.TextView')
134+
# sometimes numbers shift
135+
title = False
136+
body = False
137+
for el in els:
138+
text = el.text
139+
if text == 'Mood ring':
140+
title = True
141+
elif text == 'I am ok':
142+
body = True
143+
self.assertTrue(title)
144+
self.assertTrue(body)
145+
146+
self.driver.keyevent(4)
147+
sleep(1)
148+
self.driver.find_element_by_android_uiautomator('new UiSelector().text(":-|")')
149+
160150

161151
if __name__ == "__main__":
162-
unittest.main()
152+
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)
153+
unittest.TextTestRunner(verbosity=2).run(suite)

0 commit comments

Comments
 (0)