Skip to content

Instantly share code, notes, and snippets.

@eagleEggs
Last active November 18, 2018 00:35
Show Gist options
  • Save eagleEggs/f15c87472acc7f2f31dee5b94f1e9f51 to your computer and use it in GitHub Desktop.
Save eagleEggs/f15c87472acc7f2f31dee5b94f1e9f51 to your computer and use it in GitHub Desktop.
Main Loop - TA
# REDESIGN 11/12/18
# MAIN: Three images across row
maindisplay = [[sg.T("")],[sg.Button(image_filename = "main_config.png", key = "config"), sg.Button(image_filename = "main_build.png", key = "build"), sg.Button(image_filename = "main_test.png", key = "test")],
[sg.ReadButton('', image_filename="license.png", key = "license"), sg.T("", size=(37,1)), sg.ReadButton('', image_filename = "exit.png", key = "exit")]]
layout = [[sg.Column(maindisplay)]]
##########################
### GUI VARS ###
##########################
MY_WINDOW_ICON = "topanga.ico"
window = sg.Window("Test Anatomy - Main Menu", grab_anywhere=True, no_titlebar=True, auto_size_text=False, icon=MY_WINDOW_ICON, border_depth=0).Layout(
layout).Finalize()
##########################
### MAIN LOOP ###
##########################
win2_active = False
win3_active = False
win4_active = False
while True:
b, values = window.Read(timeout = 100) # read input values from GUI
if b =="license":
sg.PopupOK("Visit Github.com/eagleEggs/Test-Anatomy for more details")
logging.info("Window 1: Pressed License")
if b == "exit":
logging.info("Window 1: Pressed Exit")
break
if b == "config": # main menu config button press
win2_active = True
logging.info("Window 2 Active: Pressed Config")
configlayoutloop = [[sg.Image(filename="gconfigurations.png")],
[sg.Text('URL:', size=(20, 0)), sg.InputText(shelfdb['ok'][1], key='appuri', do_not_clear=True)],
[sg.Text('Browser:', size=(20, 0)), sg.InputCombo(ddVals, default_value=shelfdb['ok'][0], key="browsertype", size=(42, 10))],
[sg.Text('App Name:', size=(20, 0)),
sg.InputText(shelfdb['ok'][2], key='appname', do_not_clear=True)],
[sg.Text('Tester Name:', size=(20, 0)),
sg.InputText(shelfdb['ok'][16], key='testername', do_not_clear=True)],
[sg.Image(filename="econfigurations.png")],
[sg.Text('Email From:', size=(20, 0)),
sg.InputText(shelfdb['ok'][4], key='emailfrom', do_not_clear=True)],
[sg.Text('Email To:', size=(20, 0)),
sg.InputText(shelfdb['ok'][3], key='emailto', do_not_clear=True)],
[sg.Text('Email Username:', size=(20, 0)),
sg.InputText(shelfdb['ok'][5], key='emailusername', do_not_clear=True)],
[sg.Text('Email Password:', size=(20, 0)),
sg.InputText('', key='emailpassword', do_not_clear=True)],
[sg.Text('Email Server:', size=(20, 0)),
sg.InputText('', key='emailserver', do_not_clear=True)],
[sg.T("")],
[sg.Text('Existing Project UUID:', key="projectUUIDID", size=(20, 0)),
sg.InputText('', key='projectUUID', do_not_clear=True)],
[sg.Image(filename="rconfigurations.png")],
[sg.Checkbox('HTML Generation', size=(15, 0),
key='htmlcheck', default = shelfdb['ok'][9]), sg.Checkbox('Email Reporting', size=(15, 0),
key='emailcheck', default = shelfdb['ok'][11]), sg.Checkbox('Enable MySQLDB', size=(15, 0),
key='databasecheck', default = shelfdb['ok'][7])],
[sg.Checkbox('PDF Generation', size=(15, 0), key='pdfcheck', default = shelfdb['ok'][8]),
sg.Checkbox('Graph Generation', size=(15, 0),key='graphcheck', default = shelfdb['ok'][10]),
sg.Checkbox('Persist Project', size=(15, 0),key='persistcheck')],
[sg.Checkbox('Load Existing UUID', size=(15, 0),key='persistcheck')],
[sg.Image(filename="dconfigurations.png")],
[sg.Text('MySQL Database IP:', size = (18, 1)),
sg.InputText(shelfdb['ok'][12], key='dbip', do_not_clear=True, change_submits = True)],
[sg.Text('MySQL Username:', size = (18, 1)),
sg.InputText(shelfdb['ok'][13], key='dbun', do_not_clear=True)],
[sg.Text('MySQL Password:', size = (18, 1)),
sg.InputText('', key='dbpw', do_not_clear=True)],
[sg.Text('MySQL Port:', size = (18, 1)),
sg.InputText(shelfdb['ok'][15], key='dbport', do_not_clear=True)],
[sg.Text('')],
[sg.ReadButton("", tooltip='Start Testing Environment', key="Launch2", image_filename="HLlaunch.png"),
sg.ReadButton("", image_filename = "save.png", key = "config_save"),
sg.ReadButton("", image_filename = "load.png", key = "config_load"),
sg.ReadButton("", image_filename = "home.png", key = "home"),
]]
window2 = sg.Window('Test Anatomy - Configuration', grab_anywhere=False, no_titlebar=False, auto_size_text=False, icon=MY_WINDOW_ICON).Layout( [[sg.Column(configlayoutloop)]])
if b == "test": # main menu test button press
win4_active = True
logging.info("Window 2 Active: Pressed Test")
window4 = sg.Window(
'Test Anatomy - Test', grab_anywhere=True, no_titlebar=True).Layout(
[[sg.T("")],
[sg.T('Topanga ∩(^-^)∩ Test Anatomy', justification="center")],
[sg.T("")]])
if win4_active:
b, values = window4.Read(timeout=0)
if b != sg.TIMEOUT_KEY:
print("win4 ", b)
if b == 'Exit' or b is None:
win4_active = False
logging.info("Window 4 Set Inactive")
window4.Hide()
if b == "Main Menu":
win4_active = False
logging.info("Window 4 Set Inactive")
window4.Hide()
if b == "Launch":
logging.info("Getting Subclient Shelf Info")
app = Github(shelfdb['engine'][0], shelfdb['engine'][1], shelfdb['engine'][2])
appdb = Database(shelfdb['engine'][13], shelfdb['engine'][12], shelfdb['engine'][14], shelfdb['engine'][15])
app.OpenSite()
if b == "build": # main menu build button press
win3_active = True
logging.info("Window 3 Active: Pressed Build")
EHX_column = [[sg.Image(filename="econfig.png", )],
[sg.Multiline(".text-gray-dark", size=(35, 2), enter_submits=True, key='enterElement', do_not_clear=True)],
[sg.InputCombo(ddElements, key="elementtype", size=(35, 10))],
[sg.InputCombo(ddCols, key="colortype", size=(35, 10))],
[sg.ReadButton('', key="highlight", border_width=0, size=(33, 5), image_filename="HLimg.png", tooltip="Highlight Element")]]
ddbuildactions = ["Select Command", "Open Site", "Click Element", "Type Text", "Wait", "Wait for Element"]
buildcolumn = [[sg.Image(filename = "scriptoptionsconfig.png")], [sg.InputCombo(ddbuildactions, key="buildactions", size=(35, 10))],
#[sg.InputCombo(ddbuildactions2, key="buildactions2", size=(35, 10))],
[sg.InputText("Add Arguments to Command", key = "enterText", size=(38, 10))],
[sg.T("")],
[sg.T("")],
[sg.ReadButton('', key="addButt", image_filename="addButt.png", border_width=0, tooltip = "Add the command to your script")]]
BuildModeColBox = [[sg.Image(filename="sbuilder.png")],[sg.Multiline(size=(81, 22), enter_submits=True, key='buildscriptbox', do_not_clear=True,
background_color="white", auto_size_text = True)],
[sg.Image(filename="boptions.png")],
[sg.T("Save Name:"), sg.InputText('RailID_JiraID_YN_Title', key='testName', do_not_clear=True, size=(25, 0))],
[sg.ReadButton("", border_width=0, tooltip='Test This Case', image_filename="testcode.png",
key="testbuildcase"),
sg.ReadButton("", border_width=0, tooltip='Save This Case', image_filename="save.png", key="savecase"),
sg.ReadButton("", border_width=0, tooltip='Load a Case', image_filename="load.png", key="loadcase"),
sg.ReadButton("", image_filename="log.png", border_width=0, key="log"),
sg.ReadButton("", image_filename="folder.png", border_width=0, key="folder"),
sg.ReadButton("", image_filename="bnotes.png", border_width=0, key="notes"),
sg.ReadButton("", image_filename="home.png", border_width=0, key="Main Menu", tooltip="Main Menu")]]
BuildModeCol = [[sg.Column(buildcolumn, size=(1, 1)),
sg.Column(BuildModeColBox, size=(1, 1))]]
window3 = sg.Window('Test Anatomy - Build', grab_anywhere=False, no_titlebar=False,
auto_size_text=True, icon=MY_WINDOW_ICON).Layout(
[[sg.Column(EHX_column), sg.Column(buildcolumn)], [sg.Column(BuildModeColBox)]]
)
buildscriptbox = window3.FindElement('buildscriptbox') # def __init__(self, *args): super(BuildApp, self).__init__(*args))
buildscriptbox.Update("""class BuildApp(Engine):
\n""")
if win3_active: # build
b, values = window3.Read(timeout=0)
if b != sg.TIMEOUT_KEY:
print("win3 ", b)
if b == 'Exit' or b is None:
win3_active = False
logging.info("Window 3 Set Inactive")
window3.Hide()
if b == "Main Menu":
win3_active = False
logging.info("Window 3 Set Inactive")
window3.Hide()
if b == "highlight": # this grabs content from sb3 and puts it in script form for highlighting through API
try:
if values['elementtype'] == "CSS Selector":
scriptvar = str.strip(values['enterElement'])
exec("lite = driver.engine.find_element_by_css_selector(\"{}\")\ndriver.EHX_Highlight(lite)".format(scriptvar))
logging.info("Scratchbox: Executed Command Successfully")
except:
logging.info("Scratchbox: Failed Executing Command")
sg.PopupError("There was an issue Highlighting, Check Element")
if values['elementtype'] == "XPATH":
try:
scriptvar = str.strip(values['enterElement'])
exec("lite = driver.engine.find_element_by_xpath(\"{}\")\ndriver.EHX_Highlight(lite)".format(scriptvar))
logging.info("Scratchbox: Executed Command Successfully")
except:
logging.info("Scratchbox: Failed Executing Command")
sg.PopupError("There was an issue Highlighting, Check Element")
if values['elementtype'] == "ID":
try:
scriptvar = str.strip(values['enterElement'])
exec("lite = driver.engine.find_element_by_id(\"{}\")\ndriver.EHX_Highlight(lite)".format(scriptvar))
logging.info("Scratchbox: Executed Command Successfully")
except:
logging.info("Scratchbox: Failed Executing Command")
sg.PopupError("There was an issue Highlighting, Check Element")
if b == "addButt":
if values['buildactions'] == "Click Element" or values['buildactions'] == "Click Input":
buildscriptbox = window3.FindElement('buildscriptbox')
buildscriptbox.Update(" driver.ClickWebElement(""{}"",""{}"")\n".format(repr(str.strip(values['elementtype'])), repr(str.strip(values['enterElement']))), append=True)
logging.info("BUILDMODE: Using Object: Updated Script with: Click Button")
if values['buildactions'] == "Open Site":
buildscriptbox = window3.FindElement('buildscriptbox')
buildscriptbox.Update(" driver.OpenSite()\n", append=True)
logging.info("BUILDMODE: Using Object: Updated Script with: Open Site")
if values['buildactions'] == "Type Text":
buildscriptbox = window3.FindElement('buildscriptbox')
buildscriptbox.Update(" driver.TypeWords(""{}"", ""{}"", ""{}"")\n".format(repr(str.strip(values['elementtype'])), repr(str.strip(values['enterElement'])), repr(str.strip(values['enterText']))), append=True)
logging.info("BUILDMODE: Using Object: Updated Script with: Type Words")
if values['buildactions'] == "Wait":
buildscriptbox = window3.FindElement('buildscriptbox')
buildscriptbox.Update(" driver.Waiter(""{}"")\n".format(repr(str.strip(values['enterText']))), append=True)
logging.info("BUILDMODE: Using Object: Updated Script with: Type Words")
if values['buildactions'] == "Wait for Element":
buildscriptbox = window3.FindElement('buildscriptbox')
buildscriptbox.Update(" driver.WaitForElement(""{}"", ""{}"", ""{}"")\n".format(repr(str.strip(values['elementtype'])), repr(str.strip(values['enterElement'])), repr(str.strip(values['enterText']))), append=True)
logging.info("BUILDMODE: Using Object: Updated Script with: Type Words")
if b == "testbuildcase":
try:
cmd = exec(values['buildscriptbox'])
logging.info("Build Mode - Testing Case: Executed Command Successfully: {}".format(values['buildscriptbox']))
sg.PopupOK("Case Ran Successfully")
except:
logging.error("Error Importing Test Case Module")
sg.PopupOK("Error Importing Test Case Module")
if b == "savecase":
try:
f = open('{}\{}.py'.format(driver.folder, values['testName']), 'w')
f.write(values['buildscriptbox'])
sg.PopupOK("Case Saved")
except:
logging.warning("Cannot save Build Code")
sg.PopupError("Cannot save Build Code")
if b == "loadcase":
try:
loadfile = sg.PopupGetFile(message="Select a Test Case to Import")
f = open(loadfile, 'r')
buildscriptbox.Update(f.read())
except:
logging.warning("Cannot load Test Script")
sg.PopupOK("Could not load Test Script")
if b == "notes":
try:
os.system('start notepad.exe')
except:
logging.warning("Cannot write to notes file. Must Init a Topanga first")
if b == "folder":
try:
os.system('start {}'.format(driver.folder))
except:
logging.warning("Issue opening Project Folder - Perhaps you didn't start a project yet?")
sg.PopupOK("Perhaps you didn't start a project yet?\nSet configs and click launch!")
if win2_active:
b, values = window2.Read(timeout=0)
if b != sg.TIMEOUT_KEY:
print("win2 ", b)
if b == 'Exit' or b is None:
win2_active = False
logging.info("Window 2 Set Inactive: Pressed Exit")
window2.Close()
if b == "home":
win2_active = False
logging.info("Window 2 Set Inactive: Pressed Main Menu")
window2.Close()
if b == "Launch2":
try:
driver = Github(shelfdb['ok'][0], shelfdb['ok'][1], shelfdb['ok'][2])
driver.OpenSite()
logging.info("Instantiating Application")
except:
logging.warning("Issue Instantiating Application")
if b == "config_save":
logging.info("Window 2: Pressed Save")
testersname = window2.FindElement('testername')
browsertype = window2.FindElement('browsertype')
appuri = window2.FindElement('appuri')
appname = window2.FindElement('appname')
emailfrom = window2.FindElement('emailfrom')
emailto = window2.FindElement('emailto')
emailusername = window2.FindElement('emailusername')
emailpassword = window2.FindElement('emailpassword')
databasecheck = window2.FindElement('databasecheck')
pdfcheck = window2.FindElement('pdfcheck')
htmlcheck = window2.FindElement('htmlcheck')
graphcheck = window2.FindElement('graphcheck')
emailcheck = window2.FindElement('emailcheck')
dbip = window2.FindElement('dbip')
dbun = window2.FindElement('dbun')
dbpw = window2.FindElement('dbpw')
dbport = window2.FindElement('dbport')
persistcheck = window2.FindElement('persistcheck') # UID
projectUUID = window2.FindElement('projectUUID') # UID
shelfdb['ok'] = [values["browsertype"],
values["appuri"],
values["appname"],
values["emailto"],
values["emailfrom"],
values["emailusername"],
values["emailpassword"],
values["databasecheck"],
values["pdfcheck"],
values["htmlcheck"],
values["graphcheck"],
values["emailcheck"],
values["dbip"],
values["dbun"],
values["dbpw"],
values["dbport"],
values['persistcheck'],
values['testername']]
if projectUUID == True:
shelfdb['uuid'] = [app.UUID]
if b == "config_load":
try:
logging.info("Window 2: Pressed Load")
# SITE
browsertype.Update(shelfdb['ok'][0])
appuri.Update(shelfdb['ok'][1])
appname.Update(shelfdb['ok'][2])
# EMAIL
emailto.Update(shelfdb['ok'][3])
emailfrom.Update(shelfdb['ok'][4])
emailusername.Update(shelfdb['ok'][5])
emailpassword.Update(shelfdb['ok'][6])
# CHECKBOX SETTINGS
databasecheck.Update(shelfdb['ok'][7])
pdfcheck.Update(shelfdb['ok'][8])
htmlcheck.Update(shelfdb['ok'][9])
graphcheck.Update(shelfdb['ok'][10])
emailcheck.Update(shelfdb['ok'][11])
# DATABASE SETTINGS
dbip.Update(shelfdb['ok'][12])
dbun.Update(shelfdb['ok'][13])
dbpw.Update(shelfdb['ok'][14])
dbport.Update(shelfdb['ok'][15])
persistcheck.Update(shelfdb['ok'][16])
testersname.Update(shelfdb['ok'][17])
if projectUUID == True:
savedUUID = shelfdb['uuid'][0]
projectUUID.Update(savedUUID)
logging.info("Loading Config - Success")
except:
logging.error("Loading Config - Failed")
if b == "Load/Reload": # graph button to load graph
appdb.SetPlot()
fig_photo = appdb.PlotDraw(window.FindElement('canvas_graph').TKCanvas, fig)
if b == "log":
try:
os.system('start cmtrace topanga.log')
except:
logging.warning("Issue opening Log")
sg.PopupOK("Issue opening Log")
if b == "Generate Graph":
# graphWindow = sg.Window("Topanga ∩(^-^)∩ Graphical", auto_size_text=False).Layout(layout_graph).Finalize()
GenerateGraph()
# figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
# fig_photo = Graphing(graphWindow.FindElement('canvas_graph').TKCanvas, fig)
# graphWindow.Read()
if b is None:
logging.info("Used X to Exit Application")
break
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment