Skip to content

Commit 588478e

Browse files
committed
add selenium server mgnt tool codes
1 parent 87f7ee6 commit 588478e

9 files changed

+130
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
call C:\Selenium\bin\kill_browsers_process.bat
2+
call C:\Selenium\bin\kill_drivers_process.bat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
rem just kills stray local IE/chrome/firefox browser processes.
3+
4+
taskkill /im chrome.exe /t /f
5+
taskkill /im firefox.exe /t /f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@echo off
2+
rem just kills stray local IE/chrome/firefox drivers instances.
3+
4+
taskkill /im chromedriver.exe /t /f
5+
taskkill /im IEDriverServer.exe /t /f
6+
taskkill /im geckodriver.exe /t /f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\Shared\python\python.exe C:\Selenium\status_server\reset_ui_test_env.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\Selenium\openjdk-1.8.0.191\bin\java -jar C:\Selenium\lib\selenium-server-standalone-3.141.59.jar -port 8443 -role hub
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\Selenium\openjdk-1.8.0.191\bin\java -Dwebdriver.ie.driver=c:/Selenium/drivers/IEDriverServer.exe -Dwebdriver.chrome.driver=c:/Selenium/drivers/chromedriver.exe -Dwebdriver.gecko.driver=c:/Selenium/drivers/geckodriver.exe -jar C:\Selenium\lib\selenium-server-standalone-3.141.59.jar -role node -hub http://localhost:8443/grid/register
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
rem stop Selenium standalone server.
3+
4+
taskkill /im java.exe /t /f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
rem unregister driver nodes from Selenium standalone server.
3+
4+
taskkill /im java.exe /t /f

selenium_server/reset_ui_test_env.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import subprocess
2+
import time
3+
4+
from http.server import BaseHTTPRequestHandler, HTTPServer
5+
6+
HOST_NAME = ''
7+
PORT_NUMBER = 9000
8+
9+
CLEAN_DRIVERS_CACHE = r'C:\\Selenium\\bin\\kill_browsers_drivers_proc.bat'
10+
START_HUB = 'start C:\\Selenium\\bin\\start_selenium_hub.bat'
11+
REGISTER_NODES = 'start C:\\Selenium\\bin\\start_selenium_node.bat'
12+
STOP_HUB = r'C:\\Selenium\\bin\\stop_selenium_hub.bat'
13+
UNREGISTER_NODES = r'C:\\Selenium\\bin\\unregister_selenium_node.bat'
14+
15+
16+
class SeleniumHubHandler(BaseHTTPRequestHandler):
17+
18+
def do_HEAD(self):
19+
paths = {
20+
'/clean': self.clean_driver_cache,
21+
'/start': self.start_hub,
22+
'/stop': self.stop_hub,
23+
'/restart': self.restart_hub
24+
}
25+
26+
if self.path in paths:
27+
self.respond_head(paths[self.path])
28+
else:
29+
self.respond_bad_request_error(self.path)
30+
31+
def do_GET(self):
32+
self.do_HEAD()
33+
34+
def respond_head(self, symbol):
35+
response = self.handle_http(symbol, self.path)
36+
self.wfile.write(response)
37+
38+
def handle_http(self, batch_file, path):
39+
batch_file()
40+
41+
self.send_response(200)
42+
self.send_header('Content-type', 'text/html')
43+
self.end_headers()
44+
45+
content = '''
46+
<html>
47+
<head>
48+
<title>UI Automation Test Hub</title>
49+
</head>
50+
<body>
51+
<p>You accessed path: {}.</p>
52+
</body>
53+
</html>
54+
'''.format(path)
55+
return bytes(content, 'UTF-8')
56+
57+
def clean_driver_cache(self):
58+
subprocess.call(CLEAN_DRIVERS_CACHE)
59+
time.sleep(1)
60+
61+
def start_hub(self):
62+
subprocess.Popen(START_HUB, shell=True)
63+
time.sleep(1)
64+
subprocess.Popen(REGISTER_NODES, shell=True)
65+
66+
def stop_hub(self):
67+
subprocess.call(UNREGISTER_NODES)
68+
time.sleep(1)
69+
subprocess.call(STOP_HUB)
70+
71+
def restart_hub(self):
72+
self.stop_hub()
73+
time.sleep(2)
74+
self.start_hub()
75+
76+
def respond_bad_request_error(self, path):
77+
self.send_response(400)
78+
self.send_header('Content-type', 'text/html')
79+
self.end_headers()
80+
81+
content = '''
82+
<html>
83+
<head>
84+
<title>UI Automation Test Hub</title>
85+
</head>
86+
<body>
87+
<p>You accessed path: {}, which is not legal.</p>
88+
</body>
89+
</html>
90+
'''.format(path)
91+
self.wfile.write(bytes(content, 'UTF-8'))
92+
93+
94+
if __name__ == '__main__':
95+
server_class = HTTPServer
96+
httpd = server_class((HOST_NAME, PORT_NUMBER), SeleniumHubHandler)
97+
print(time.asctime(), 'Server Starts - %s:%s' % (HOST_NAME, PORT_NUMBER))
98+
99+
try:
100+
httpd.serve_forever()
101+
except KeyboardInterrupt:
102+
print(time.asctime(), 'Force management server to stop.')
103+
pass
104+
105+
httpd.server_close()
106+
print(time.asctime(), 'Server Stops - %s:%s' % (HOST_NAME, PORT_NUMBER))

0 commit comments

Comments
 (0)