-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_sim.py
120 lines (91 loc) · 3.72 KB
/
user_sim.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import base64
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import sys
if len(sys.argv) < 3 or (sys.argv[1] != 'guest' and len(sys.argv) < 4):
print ("user_sim <login> <passwd> <iterations> OR user_sim guest <iterations>")
sys.exit(1)
user = sys.argv[1]
if user != 'guest':
passwd = sys.argv[2]
iteration = int(sys.argv[3])
else:
iteration = int(sys.argv[2])
# instance of Options class allows
# us to configure Headless Chrome
options = Options()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
# this parameter tells Chrome that
# it should be run without UI (Headless)
#options.headless = True
# initializing webdriver for Chrome with our options
driver = webdriver.Chrome(options=options)
wait = WebDriverWait(driver, 90)
for i in range(1, iteration + 1):
driver.get("http://localhost:8080/server/nocache/login.html")
time.sleep(0.5)
if user != 'guest':
e1 = driver.find_element(By.ID,"login_username")
e1.send_keys(user)
e2 = driver.find_element(By.ID,"login_password")
e2.send_keys(passwd)
bt = driver.find_element(By.ID, 'login_button')
bt.click()
else:
if i == 1:
bt = driver.find_element(By.ID, 'guest_button')
bt.click()
time.sleep(1)
driver.get("http://localhost:8080/submit/nocache/index.html")
# We can also get some information
# about page in browser.
# So let's output webpage title into
# terminal to be sure that the browser
# is actually running.
print(driver.title)
wait.until(EC.presence_of_element_located((By.ID,'jobdivspinnerdiv')))
spin = driver.find_element(By.ID, 'jobdivspinnerdiv')
wait.until(EC.invisibility_of_element(spin));
time.sleep(0.5)
driver.get("http://localhost:8080/submit/nocache/index.html")
wait.until(EC.presence_of_element_located((By.ID,'jobdivspinnerdiv')))
spin = driver.find_element(By.ID, 'jobdivspinnerdiv')
wait.until(EC.invisibility_of_element(spin));
time.sleep(0.5)
driver.get("http://localhost:8080/submit/nocache/index.html")
wait.until(EC.presence_of_element_located((By.ID,'jobdivspinnerdiv')))
spin = driver.find_element(By.ID, 'jobdivspinnerdiv')
wait.until(EC.invisibility_of_element(spin));
time.sleep(0.5)
#Open results viewer
start = time.time()
res_btn = driver.find_element(By.CLASS_NAME, 'butn.launch-button')
res_btn.click()
#wait for results tab to open
while (len(driver.window_handles) < 2):
time.sleep(0.1)
jobs_list = driver.window_handles[0]
results = driver.window_handles[1]
driver.switch_to.window(results)
wait.until(EC.presence_of_element_located((By.CLASS_NAME,'store-noconnect-msg-div')))
res_spin = driver.find_element(By.CLASS_NAME, 'store-noconnect-msg-div')
wait.until(EC.invisibility_of_element(res_spin));
print("")
print("Result page time: " + str(time.time() - start) + " secs")
print("")
time.sleep( 15 )
driver.close()
driver.switch_to.window(jobs_list)
if user != 'guest' or i == iteration:
#wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@title="Logout"]')))
bt = driver.find_element(By.XPATH, '//*[@title="Logout"]')
bt.click()
wait.until(EC.presence_of_element_located((By.ID,'logindiv')))
time.sleep(0.5)
# close browser after our manipulations
driver.close()