-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserinteraction.py
More file actions
194 lines (158 loc) · 4.7 KB
/
userinteraction.py
File metadata and controls
194 lines (158 loc) · 4.7 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
import subprocess
import config
import time
import random
user = config.user
password = config.password
# Login
def first_login():
# Tap login and emnail text field
subprocess.run('adb shell "input tap 800 550 \n input tap 300 850 \n" ')
# Write username letter by letter
usercommand = ''
for letter in user:
usercommand = usercommand + f'input text {letter}\n'
subprocess.run(f'adb shell \"{usercommand}\"')
# Tap password field
subprocess.run('adb shell input tap 300 1000\n')
# Enter password letter by letter
passwordcommand = ''
for letter in password:
passwordcommand = passwordcommand+ f'input text {letter}\n'
subprocess.run(f'adb shell \"{passwordcommand}\"')
# Back button
subprocess.run('adb shell input keyevent KEYCODE_BACK')
# Tap connect
subprocess.run('adb shell input tap 800 1300\n')
# Login
def login():
# Tap login and emnail text field
subprocess.run('adb shell "input tap 800 550 \n input tap 300 850 \n" ')
# Not necesary to write username
# Tap password field
subprocess.run('adb shell input tap 300 1000\n')
# Enter password letter by letter
passwordcommand = ''
for letter in password:
passwordcommand = passwordcommand+ f'input text {letter}\n'
subprocess.run(f'adb shell \"{passwordcommand}\"')
# Back button
subprocess.run('adb shell input keyevent KEYCODE_BACK')
# Tap connect
subprocess.run('adb shell input tap 800 1300\n')
def logout():
# Tap account
subprocess.run('adb shell input tap 1400 2000')
time.sleep(2)
# Swipe up
subprocess.run('adb shell input swipe 800 1800 800 400')
time.sleep(2)
# Tap close session
subprocess.run('adb shell input tap 800 1200')
def tap(x, y):
subprocess.run(f'adb shell input tap {x} {y}')
time.sleep(1)
def tapHome():
tap(150, 2000)
def tapMenu():
tap(450, 2000)
def tapBasket():
tap(750, 2000)
def tapFav():
tap(1050, 2000)
def tapAcc():
tap(1350, 2000)
def tapAddtoBasket():
tap(750, 2000)
def backButton():
subprocess.run('adb shell input keyevent 4')
time.sleep(1)
def swipe(direction):
if direction == 'down':
subprocess.run('adb shell input swipe 800 400 800 1800')
if direction == 'up':
subprocess.run('adb shell input swipe 800 1800 800 400')
time.sleep(1)
def randomthings(seed, n):
random.seed(seed)
# Possible tappable coordinate ranges
# Adjust to the actual device resolution.
MIN_X, MAX_X = 100, 1500
MIN_Y, MAX_Y = 200, 2000
# Actions with weights → higher weight = more frequent
# You can tweak these numbers to change frequencies
actions = [
("tap", 10), # most frequent
("swipe_up", 6), # very frequent
("swipe_down", 6), # very frequent
("back", 2),
("tapHome", 1),
("tapMenu", 1),
("tapBasket", 1),
("tapFav", 1),
("tapAcc", 1),
("tapAddtoBasket",1),
]
names = [a[0] for a in actions]
weights = [a[1] for a in actions]
for _ in range(n):
action = random.choices(names, weights=weights, k=1)[0]
if action == "tap":
x = random.randint(MIN_X, MAX_X)
y = random.randint(MIN_Y, MAX_Y)
tap(x, y)
elif action == "swipe_up":
swipe("up")
elif action == "swipe_down":
swipe("down")
elif action == "back":
backButton()
elif action == "tapHome":
tapHome()
elif action == "tapMenu":
tapMenu()
elif action == "tapBasket":
tapBasket()
elif action == "tapFav":
tapFav()
elif action == "tapAcc":
tapAcc()
elif action == "tapAddtoBasket":
tapAddtoBasket()
time.sleep(1)
def traverseApp():
tapHome()
swipe('up')
# add favourite
tap(366, 310)
# add favourite
tap(800, 310)
# Click product
tap(1000, 500)
# Add to basket
time.sleep(2)
tapAddtoBasket()
# Go back
backButton()
# Go to search
tapMenu()
# Search product parfume
tap(750, 850)
# Women perfume
tap(750, 850)
# Eau de toilette
tap(750, 950)
# Hermes
tap(400, 1000)
# Add to basket
time.sleep(2)
tapAddtoBasket()
# Go back
backButton()
backButton()
if __name__ == "__main__":
login()
time.sleep(1)
traverseApp()
time.sleep(0.5)
randomthings(567, 50)