-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_selenium.py
193 lines (172 loc) · 6.8 KB
/
test_selenium.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
183
184
185
186
187
188
189
190
191
192
193
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import pdb
import os
import sys
#from django.core.management.base import BaseCommand
#from core.models import SmsToken
class Command():
def __init__(self):
self.issavescreen = False
self.url = 'http://localhost:8000/'
self.screenpath = os.path.join(
os.path.dirname(__file__), 'Screenshots')
if not os.path.exists(self.screenpath):
os.makedirs(self.screenpath)
user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64)' \
' AppleWebKit/537.36 (KHTML, like Gecko)' \
' Chrome/37.0.2062.120 Safari/537.36'
self.dcap = dict(DesiredCapabilities.PHANTOMJS)
self.dcap["phantomjs.page.settings.userAgent"] = user_agent
self.timeout = 3
# self.driver = webdriver.PhantomJS(
# service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'],
# desired_capabilities=self.dcap)
chrome_options = Options()
chrome_options.add_argument("--disable-web-security")
self.driver = webdriver.Chrome(chrome_options=chrome_options)
self.driver.set_window_size(1000, 900)
self.driver.set_page_load_timeout(15)
self.driver.wait = WebDriverWait(self.driver, 15)
#self.wait = WebDriverWait(self.driver, self.timeout)
def handle(self):
banks = ['alfa-bank', 'Sberbank', 'Qiwi wallet']
print('Test buy')
for b in banks:
try:
self.checkbuy(b)
except Exception as e:
print(b + " " + str(e))
sys.exit(1)
sellmethods = ['fa-credit-card-alt', 'Qiwi wallet', 'Cash']
print('Test sell')
for b in sellmethods:
try:
self.checksell(b)
except Exception as e:
print(b + " " + str(e))
sys.exit(1)
self.driver.close()
def loginphone(self):
print("Testing Phone")
self.doscreenshot('after check method click')
phone = self.driver.find_elements_by_class_name('phone')
print("Phone", phone)
phone[0].send_keys('1111')
self.doscreenshot('after input phone number')
btnes = self.driver.find_elements_by_class_name('create-acc')
# enter send sms
for btsendsms in btnes:
if btsendsms.get_attribute('class') \
.find('btn-primary') > -1:
btsendsms.click()
break
sleep(0.6)
# input sms code
last_sms = SmsToken.objects.filter().latest('id').sms_token
self.wait.until(EC.element_to_be_clickable(
(By.ID, 'verification_code'))).send_keys(last_sms)
self.doscreenshot('after input code number')
self.driver.execute_script('window.submit_phone()')
def checkbuy(self, paymethod):
print("Check Buy", paymethod)
self.driver.get(self.url)
self.doscreenshot('main_')
self.driver.wait.until(
EC.element_to_be_clickable((By.CLASS_NAME, 'trigger-buy'))).click()
sleep(1.5)
self.doscreenshot('after buy click')
payments = self.driver.\
find_elements_by_class_name('payment-method-icon')
for p in payments:
try:
#print("P", p.get_attribute('alt').lower())
alt = p.get_attribute('alt').lower()
#print("ALT", alt)
except:
continue
#print(alt, paymethod.lower(), p.is_displayed(), p)
if alt == paymethod.lower() and p.is_displayed():
paybank = p
break
# sleep(1)
paybank.click()
# login
sleep(1)
self.loginphone()
# end login
sleep(1)
self.doscreenshot('after verifycate phone')
# press buy
bt_buys = self.driver.find_elements_by_class_name('buy-go')
for b in bt_buys:
if b.get_attribute('class') \
.find('place-order') > -1:
b.click()
break
self.wait.until(
EC.element_to_be_clickable((By.CLASS_NAME, 'unique_ref')))
self.doscreenshot('End_')
print('Ok')
self.driver.delete_all_cookies()
def checksell(self, sellmethon):
print("Check Sell", sellmethon)
self.driver.get(self.url)
self.doscreenshot('main_')
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'trigger-sell'))).click()
self.doscreenshot('after sell click')
if sellmethon == 'fa-credit-card-alt':
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, sellmethon))).click()
self.wait.until(EC.element_to_be_clickable((
By.NAME, 'number'))).send_keys('1111')
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'save-card'))).click()
elif sellmethon == 'Qiwi wallet':
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'payment-method-icon')))
selments = self.driver. \
find_elements_by_class_name('payment-method-icon')
for p in selments:
try:
alt = p.get_attribute('alt').lower()
except:
continue
if alt == sellmethon.lower() and p.is_displayed():
sellbank = p
break
sellbank.click()
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'phone'))).send_keys('1111')
card_go = self.driver.find_elements_by_class_name('save-card')
card_go[1].click()
# cash
else:
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'fa-money'))).click()
sleep(0.5)
self.driver.find_element_by_class_name('next-step').click()
# login
sleep(0.8)
self.loginphone()
# end login
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'sell-go'))).click()
self.wait.until(EC.element_to_be_clickable((
By.CLASS_NAME, 'unique_ref')))
self.doscreenshot('End_')
print('Ok')
self.driver.delete_all_cookies()
def doscreenshot(self, filename):
if self.issavescreen:
self.driver.get_screenshot_as_file(
os.path.join(self.screenpath, filename + '.png'))
if __name__ == "__main__":
a = Command()
a.handle()