forked from chengguopiao/Gallery_stress
/
stress.py
182 lines (145 loc) · 7.15 KB
/
stress.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/python
# coding:utf-8
from devicewrapper.android import device as d
import commands
import re
import subprocess
import os
import string
import time
import sys
import util
import unittest
u=util.Util()
#Written by Piao chengguo
commands.getoutput('adb shell am start -n com.android.videoeditor/.ProjectsActivity')
# PATH
# key
#################################
PACKAGE_NAME = 'com.intel.android.gallery3d'
ACTIVITY_NAME = PACKAGE_NAME + '.app.Gallery'
class GalleryTest(unittest.TestCase):
def setUp(self):
super(GalleryTest,self).setUp()
def tearDown(self):
super(GalleryTest,self).tearDown()
self._pressBack(4)
time.sleep(1)
########################################################
# Test case 1
def testLaunchGalleryFromMS(self):
self._creatMovieStudioProject()
d(resourceId = 'com.android.videoeditor:id/thumbnail').click.wait()
assert d(resourceId = 'com.android.videoeditor:id/add_new_media_item_menu').wait.exists(timeout=1000),'enter project fail'
for i in range(0,100):
time.sleep(2)
d(resourceId = 'com.android.videoeditor:id/add_new_media_item_menu').click.wait()
assert d(text = 'Import image').wait.exists(timeout = 1000),'enter import image menu fail'
d(text = 'Import image').click.wait()
time.sleep(1)
self._selectIntelGallery()
self._pressBack(1)
# Test case 2
def testLaunchGalleryFromMMS(self):
self._launchMMS()
d(description ='Attach').click.wait()
assert d(text = 'Attach').wait.exists(timeout =1000),'enter attach mode fail'
d(text = 'Pictures').click.wait()
assert d(text ='Open from').wait.exists(timeout =2000)
for i in range(0,100):
d(className = 'android.widget.LinearLayout')[12].click.wait()
assert d(packageName = 'com.intel.android.gallery3d').wait.exists(timeout =2000),'enter gallery fail'
self._pressBack(1)
time.sleep(1)
# test case 3
def testLaunchGalleryFromEmail(self):
self._launchemail()
d(resourceId = 'com.android.email:id/compose').click.wait()
time.sleep(1)
assert d(className = 'android.widget.ImageButton').wait.exists(timeout=1000),'enter new email fail'
d(className = 'android.widget.ImageButton').click.wait()
assert d(text = 'Attach picture').wait.exists(timeout=1000),'enter menu fail'
d(text = 'Attach picture').click.wait()
for i in range(0,100):
d(className = 'android.widget.LinearLayout')[12].click.wait()
assert d(packageName = 'com.intel.android.gallery3d').wait.exists(timeout =2000),'enter gallery fail'
self._pressBack(1)
time.sleep(1)
def testLaunchGalleryFromContact(self):
self._launchContact()
assert d(resourceId = 'com.android.contacts:id/menu_add_contact').wait.exists(timeout=1000),'unable to add new contacts'
d(resourceId = 'com.android.contacts:id/menu_add_contact').click.wait()
if d(text ='Add account').wait.exists(timeout =1000):
d(text ='Keep local').click.wait()
assert d(text = 'Done').wait.exists(timeout=1000),'create new contact fail'
d(resourceId = 'com.android.contacts:id/frame').click.wait()
time.sleep(1)
assert d(text = 'Choose photo from Gallery').wait.exists(timeout=1000),'enter select photo menu fail'
d(text = 'Choose photo from Gallery').click.wait()
time.sleep(2)
assert d(text = 'Open from').wait.exists(timeout=2000),'enter choose photo from gallery menu fail'
for i in range(0,100):
d(className = 'android.widget.LinearLayout')[12].click.wait()
assert d(packageName = 'com.intel.android.gallery3d').wait.exists(timeout =2000),'enter gallery fail'
self._pressBack(1)
time.sleep(1)
###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
def _creatMovieStudioProject(self):
commands.getoutput('adb shell am start -n com.android.videoeditor/.ProjectsActivity')
time.sleep(2)
assert d(resourceId = 'com.android.videoeditor:id/thumbnail').wait.exists(timeout=1000)
d(resourceId = 'com.android.videoeditor:id/thumbnail').click.wait()
if d(resourceId = 'com.android.videoeditor:id/add_new_media_item_menu').wait.exists(timeout = 3000):
print 'created new project'
else:
assert d(text = 'Project name').wait.exists(timeout=1000),'fail'
time.sleep(1)
d(text = 'Project name').click()
time.sleep(1)
d(text = "Project name").set_text("newproject")
time.sleep(1)
d(text = 'OK').click.wait()
time.sleep(1)
assert d(resourceId = 'com.android.videoeditor:id/add_new_media_item_menu').wait.exists(timeout = 3000),'fail'
time.sleep(1)
self._pressBack(1)
def _selectIntelGallery(self):
if d(resourceId = 'android:id/home').wait.exists(timeout=1000):
assert d(packageName = 'com.intel.android.gallery3d').wait.exists(timeout =2000),'enter gallery fail'
else:
d(text = 'com.intel.android.gallery3d').click.wait()
time.sleep(1)
d(text = 'Always').click.wait()
time.sleep(1)
assert d(packageName = 'com.intel.android.gallery3d').wait.exists(timeout =2000),'enter gallery fail'
def _launchMMS(self):
commands.getoutput('adb shell am start -n com.android.mms/.ui.ConversationList')
time.sleep(1)
d(resourceId = 'com.android.mms:id/action_compose_new').click.wait()
assert d(resourceId = 'com.android.mms:id/send_button_sms').wait.exists(timeout = 3000),'enter MMS send screen fail'
def _launchemail(self):
commands.getoutput('adb shell am start -n com.android.email/.activity.Welcome')
time.sleep(2)
if d(text ='Account setup').wait.exists(timeout=1000):
print 'login the email account'
else:
assert d(resourceId = 'com.android.email:id/compose').wait.exists(timeout=2000),'enter email fail'
time.sleep(1)
def _launchContact(self):
commands.getoutput('adb shell am start -n com.android.contacts/.activities.PeopleActivity')
time.sleep(2)
if d(resourceId = 'com.android.contacts:id/menu_add_contact').wait.exists(timeout=1000):
pass
else:
if d(text ='Make it Google').wait.exists(timeout=2000):
d(text ='Not now').click.wait()
if d(text ='Create a new contact').wait.exists(timeout=2000):
print 'pls login the account'
else:
d().swipe.right()
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
def _pressBack(self,touchtimes):
for i in range(1,touchtimes+1):
d.press('back')
if __name__ =='__main__':
unittest.main()