-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
87 lines (67 loc) · 2.35 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
from time import sleep
import unittest
import argparse
import json
import re
import sys
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
class RequestPermissionTests(unittest.TestCase):
def setUp(self):
desired_caps = {
"deviceName":"Android",
"app" : PATH("./app-debug.apk"),
"app-package":"com.urucas.appiumtests",
"appWaitActivity": "com.urucas.appiumtests.activities.MainActivity",
"browserName" : "",
"platformName":"Android",
}
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
def tearDown(self):
# end the session
self.driver.quit()
def test_request_permission(self):
sleep(.5)
contexts = self.driver.contexts
el = self.driver.find_element_by_id("openRequestBtt")
self.assertIsNotNone(el)
el.click()
sleep(.5)
el = self.driver.find_element_by_id("requestBtt")
self.assertIsNotNone(el)
el.click()
sleep(.3)
# search for allow button
el = self.driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
self.assertIsNotNone(el)
el.click()
sleep(.3)
# check for new request permission state
el = self.driver.find_element_by_id("stateTextView")
self.assertIsNotNone(el)
self.assertIn("granted", el.text)
sleep(.3)
# click request permission again
el = self.driver.find_element_by_id("requestBtt")
self.assertIsNotNone(el)
el.click()
sleep(.3)
# search for deny button
el = self.driver.find_element_by_id("com.android.packageinstaller:id/permission_deny_button")
self.assertIsNotNone(el)
el.click()
sleep(.5)
# check for new request permission state
el = self.driver.find_element_by_id("stateTextView")
self.assertIsNotNone(el)
self.assertIn("denied", el.text)
sleep(.3)
if __name__ == '__main__':
# run test suite
suite = unittest.TestLoader().loadTestsFromTestCase(RequestPermissionTests)
ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful()
sys.exit(ret)