-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
219 lines (205 loc) · 6.97 KB
/
main.py
File metadata and controls
219 lines (205 loc) · 6.97 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import json
import pyfiglet
import automation_tests
import sys
from unittest import main, TestLoader, TestSuite, TextTestRunner
from clint.textui import colored
from automation_tests import *
from selenium import webdriver
from textwrap import dedent
from time import sleep
from count import *
website = 'https://www.way2automation.com/way2auto_jquery/index.php'
def intro():
print('-'*100)
sleep(0.5)
print(colored.green(pyfiglet.figlet_format(" Automation", font = "slant")))
print(colored.green(pyfiglet.figlet_format(" Testing in", font = "slant")))
sleep(0.5)
print(colored.green(pyfiglet.figlet_format(" python using", font = "slant")))
print(colored.green(pyfiglet.figlet_format(" Selenium", font = "slant")))
sleep(0.5)
print('-'*100)
sleep(1)
print(f'Performing test on {website}')
print('using python-selenium(https://selenium-python.readthedocs.io/)')
print('What do you want to test today(Enter `exit` if you want to quit)...')
sleep(0.5)
def outro():
print('\n')
print(colored.yellow(pyfiglet.figlet_format(" Come Again!!", font = "slant")))
sleep(0.5)
print(colored.yellow(pyfiglet.figlet_format(" Bye!!", font = "speed")))
def select_browser():
print(
dedent('''
Select a web browser(beta):
1. chrome
2. firefox'''
)
)
valid = False
while not valid:
try:
browser = str(input('\n > '))
browser = browser.lower()
if browser == '1' or browser == 'chrome':
browser = "webdriver.Chrome()"
valid = True
elif browser == '2' or browser == 'firefox':
browser = "webdriver.Firefox()"
valid = True
elif browser == 'exit':
outro()
sys.exit()
else:
print("Please enter a valid choice")
except EOFError:
pass
sleep(1)
return browser
def simulate_login(browser):
print("\nYou can simulate Signup and Signin " + colored.red("(press ENTER to skip)"))
print(dedent('''
1. SignUp
2. SignIn
'''))
valid = False
while not valid:
try:
process = str(input(' > '))
process = process.lower()
if process == '1' or process == 'signup':
driver = eval(browser)
driver.set_window_size(1920, 1080)
driver.get(website)
authenticate = Authenticate(driver)
authenticate.register()
driver.close()
valid = True
elif process == '2' or process == 'signin':
driver = eval(browser)
driver.set_window_size(1920, 1080)
driver.get(website)
authenticate = Authenticate(driver)
authenticate.login()
driver.close()
valid = True
elif process == '':
valid = True
elif process == 'exit':
outro()
sys.exit()
else:
print("Please enter a valid choice")
except EOFError:
pass
def count_modules(browser):
valid = False
while not valid:
try:
count_modules = str(input("\nWould you like to count available modules? [yes|No]" + colored.red("(press ENTER to skip)")))
count_modules = count_modules.lower()
if count_modules == 'y' or count_modules == 'yes':
print('counting... --- ', end='')
print(total_modules(browser))
valid = True
elif count_modules == 'n' or count_modules == 'no' or count_modules == '':
valid = True
elif count_modules == 'exit':
outro()
sys.exit()
else:
print("Please enter a valid choice")
except EOFError:
pass
sleep(0.5)
print("The modules are subdivided into several sections:")
options = json.load(open('section_options.json'))
for key, value in options.items():
print(' {:>3}: {}'.format(key, value.replace('_', ' ')))
valid = False
while not valid:
try:
section = str(input("\nEnter a section name to get the number of modules present there" + colored.red("(press ENTER to skip)")))
section = section.replace(' ', '_')
section = section.lower()
if section in options:
print('counting sections... --- ', end='')
print(no_of_modules_in_section(browser, section))
valid = True
elif section in options.values():
print('counting sections... --- ', end='')
section = get_key(section)
print(no_of_modules_in_section(browser, section))
valid = True
elif section == '':
valid = True
elif section == 'exit':
outro()
sys.exit()
else:
print("Please enter a valid choice")
except EOFError:
pass
sleep(1)
def select_module():
print("\nEnter a module to test")
options = json.load(open('options.json'))
for key, value in options.items():
print(f' {key}: {value}')
valid = False
while not valid:
try:
module = str(input('\n > '))
module = module.lower()
if module in options:
module = options.get(module)
valid = True
elif module in options.values():
valid = True
elif module == 'exit':
outro()
sys.exit()
else:
print("Please enter a valid choice")
except EOFError:
pass
sleep(1)
return module
def test_module(choice, browser):
try:
if choice == 'all':
main(module=automation_tests)
else:
suite = unittest.TestSuite()
suite.addTest(AutomationTest("test_"+choice))
runner = unittest.TextTestRunner()
runner.run(suite)
except ValueError as error:
print("Oops!!, module test not available")
def test_more():
try:
choice = str(input("Do you wish to continue[yes|No]? > "))
choice = choice.lower()
if choice == 'y' or choice == "yes":
return True
elif choice == "n" or choice == "no":
outro()
sys.exit()
except EOFError:
pass
if __name__ == "__main__":
try:
intro()
browser = select_browser()
simulate_login(browser)
count_modules(browser)
flag = True
while flag:
module = select_module()
test_module(module, browser)
flag = test_more()
outro()
except KeyboardInterrupt:
outro()