ARTICLE AD BOX
import subprocess
import os
from selenium import webdriver
from time import sleep
import getpass
username = getpass.getuser()
sleep(5)
port = str(_AD_.Port)
##print(port)
cmdurl = 'http://localhost:{}'.format(port)
app = str(_AD_.Tool_path)
driver_init = str(_AD_.Batch_file_path)
print(driver_init)
def launch_new_session():
try:
global driver_TT
subprocess.Popen(driver_init)
sleep(5)
driver_TT = webdriver.Remote(command_executor = cmdurl,
desired_capabilities={'chromeOptions': {'binary': app}},
browser_profile=None, proxy=None, keep_alive=False)
session_id = driver_TT.session_id
#print "Session ID : %s" %session_id
file_new = open("C:\\Users\\" + username + "\\Chrome_Launch.txt", "w+")
file_new.write(session_id)
file_new.close()
sleep(float(_AD_.Wait_Time))
except Exception as e:
print ("Error occured while launching TechnicianToolbox")
print(e)
reportlibrary.AddText("Error occured while launching TechnicianToolbox\n"+"Exception : "+str(e)+"\n")
raise Exception
def connect_techniciantoolbox():
try:
global driver_TT
file = open("C:\\Users\\" + username + "\\Chrome_Launch.txt", "r")
sessid = file.readline()
driver_TT = webdriver.Remote(command_executor=cmdurl, keep_alive=True)
driver_TT.close()
driver_TT.session_id = sessid
print(" Previous session connected")
reportlibrary.AddText("Previous session connected")
sleep(20)
except :
print("Launching new session")
reportlibrary.AddText("Launched new session")
launch_new_session()
connect_techniciantoolbox()
ERROR TEXT :
HTTPConnectionPool(host='localhost', port=65009): Max retries exceeded with url: /session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000000DA25F8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
