Guest User

Untitled

a guest
Nov 17th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.62 KB | None | 0 0
  1. # REDESIGN 11/12/18
  2.  
  3. # MAIN: Three images across row
  4. 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")],
  5. [sg.ReadButton('', image_filename="license.png", key = "license"), sg.T("", size=(37,1)), sg.ReadButton('', image_filename = "exit.png", key = "exit")]]
  6.  
  7. layout = [[sg.Column(maindisplay)]]
  8.  
  9. ##########################
  10. ### GUI VARS ###
  11. ##########################
  12.  
  13. MY_WINDOW_ICON = "topanga.ico"
  14. 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(
  15. layout).Finalize()
  16.  
  17.  
  18. ##########################
  19. ### MAIN LOOP ###
  20. ##########################
  21.  
  22.  
  23. win2_active = False
  24. win3_active = False
  25. win4_active = False
  26.  
  27. while True:
  28.  
  29. b, values = window.Read(timeout = 100) # read input values from GUI
  30.  
  31. if b =="license":
  32. sg.PopupOK("Visit Github.com/eagleEggs/Test-Anatomy for more details")
  33. logging.info("Window 1: Pressed License")
  34.  
  35. if b == "exit":
  36. logging.info("Window 1: Pressed Exit")
  37. break
  38.  
  39. if b == "config": # main menu config button press
  40. win2_active = True
  41. logging.info("Window 2 Active: Pressed Config")
  42. configlayoutloop = [[sg.Image(filename="gconfigurations.png")],
  43. [sg.Text('URL:', size=(20, 0)), sg.InputText(shelfdb['ok'][1], key='appuri', do_not_clear=True)],
  44. [sg.Text('Browser:', size=(20, 0)), sg.InputCombo(ddVals, default_value=shelfdb['ok'][0], key="browsertype", size=(42, 10))],
  45. [sg.Text('App Name:', size=(20, 0)),
  46. sg.InputText(shelfdb['ok'][2], key='appname', do_not_clear=True)],
  47. [sg.Text('Tester Name:', size=(20, 0)),
  48. sg.InputText(shelfdb['ok'][16], key='testername', do_not_clear=True)],
  49.  
  50. [sg.Image(filename="econfigurations.png")],
  51. [sg.Text('Email From:', size=(20, 0)),
  52. sg.InputText(shelfdb['ok'][4], key='emailfrom', do_not_clear=True)],
  53. [sg.Text('Email To:', size=(20, 0)),
  54. sg.InputText(shelfdb['ok'][3], key='emailto', do_not_clear=True)],
  55. [sg.Text('Email Username:', size=(20, 0)),
  56. sg.InputText(shelfdb['ok'][5], key='emailusername', do_not_clear=True)],
  57. [sg.Text('Email Password:', size=(20, 0)),
  58. sg.InputText('', key='emailpassword', do_not_clear=True)],
  59. [sg.Text('Email Server:', size=(20, 0)),
  60. sg.InputText('', key='emailserver', do_not_clear=True)],
  61. [sg.T("")],
  62. [sg.Text('Existing Project UUID:', key="projectUUIDID", size=(20, 0)),
  63. sg.InputText('', key='projectUUID', do_not_clear=True)],
  64. [sg.Image(filename="rconfigurations.png")],
  65. [sg.Checkbox('HTML Generation', size=(15, 0),
  66. key='htmlcheck', default = shelfdb['ok'][9]), sg.Checkbox('Email Reporting', size=(15, 0),
  67. key='emailcheck', default = shelfdb['ok'][11]), sg.Checkbox('Enable MySQLDB', size=(15, 0),
  68. key='databasecheck', default = shelfdb['ok'][7])],
  69. [sg.Checkbox('PDF Generation', size=(15, 0), key='pdfcheck', default = shelfdb['ok'][8]),
  70. sg.Checkbox('Graph Generation', size=(15, 0),key='graphcheck', default = shelfdb['ok'][10]),
  71. sg.Checkbox('Persist Project', size=(15, 0),key='persistcheck')],
  72. [sg.Checkbox('Load Existing UUID', size=(15, 0),key='persistcheck')],
  73. [sg.Image(filename="dconfigurations.png")],
  74. [sg.Text('MySQL Database IP:', size = (18, 1)),
  75. sg.InputText(shelfdb['ok'][12], key='dbip', do_not_clear=True, change_submits = True)],
  76. [sg.Text('MySQL Username:', size = (18, 1)),
  77. sg.InputText(shelfdb['ok'][13], key='dbun', do_not_clear=True)],
  78. [sg.Text('MySQL Password:', size = (18, 1)),
  79. sg.InputText('', key='dbpw', do_not_clear=True)],
  80. [sg.Text('MySQL Port:', size = (18, 1)),
  81. sg.InputText(shelfdb['ok'][15], key='dbport', do_not_clear=True)],
  82. [sg.Text('')],
  83. [sg.ReadButton("", tooltip='Start Testing Environment', key="Launch2", image_filename="HLlaunch.png"),
  84. sg.ReadButton("", image_filename = "save.png", key = "config_save"),
  85. sg.ReadButton("", image_filename = "load.png", key = "config_load"),
  86. sg.ReadButton("", image_filename = "home.png", key = "home"),
  87. ]]
  88.  
  89. window2 = sg.Window('Test Anatomy - Configuration', grab_anywhere=False, no_titlebar=False, auto_size_text=False, icon=MY_WINDOW_ICON).Layout( [[sg.Column(configlayoutloop)]])
  90.  
  91. if b == "test": # main menu test button press
  92. win4_active = True
  93. logging.info("Window 2 Active: Pressed Test")
  94. window4 = sg.Window(
  95. 'Test Anatomy - Test', grab_anywhere=True, no_titlebar=True).Layout(
  96. [[sg.T("")],
  97. [sg.T('Topanga ∩(^-^)∩ Test Anatomy', justification="center")],
  98. [sg.T("")]])
  99.  
  100. if win4_active:
  101. b, values = window4.Read(timeout=0)
  102. if b != sg.TIMEOUT_KEY:
  103. print("win4 ", b)
  104. if b == 'Exit' or b is None:
  105. win4_active = False
  106. logging.info("Window 4 Set Inactive")
  107. window4.Hide()
  108. if b == "Main Menu":
  109. win4_active = False
  110. logging.info("Window 4 Set Inactive")
  111. window4.Hide()
  112. if b == "Launch":
  113. logging.info("Getting Subclient Shelf Info")
  114. app = Github(shelfdb['engine'][0], shelfdb['engine'][1], shelfdb['engine'][2])
  115. appdb = Database(shelfdb['engine'][13], shelfdb['engine'][12], shelfdb['engine'][14], shelfdb['engine'][15])
  116.  
  117. app.OpenSite()
  118.  
  119. if b == "build": # main menu build button press
  120. win3_active = True
  121. logging.info("Window 3 Active: Pressed Build")
  122.  
  123. EHX_column = [[sg.Image(filename="econfig.png", )],
  124. [sg.Multiline(".text-gray-dark", size=(35, 2), enter_submits=True, key='enterElement', do_not_clear=True)],
  125. [sg.InputCombo(ddElements, key="elementtype", size=(35, 10))],
  126. [sg.InputCombo(ddCols, key="colortype", size=(35, 10))],
  127. [sg.ReadButton('', key="highlight", border_width=0, size=(33, 5), image_filename="HLimg.png", tooltip="Highlight Element")]]
  128.  
  129. ddbuildactions = ["Select Command", "Open Site", "Click Element", "Type Text", "Wait", "Wait for Element"]
  130.  
  131. buildcolumn = [[sg.Image(filename = "scriptoptionsconfig.png")], [sg.InputCombo(ddbuildactions, key="buildactions", size=(35, 10))],
  132. #[sg.InputCombo(ddbuildactions2, key="buildactions2", size=(35, 10))],
  133. [sg.InputText("Add Arguments to Command", key = "enterText", size=(38, 10))],
  134. [sg.T("")],
  135. [sg.T("")],
  136. [sg.ReadButton('', key="addButt", image_filename="addButt.png", border_width=0, tooltip = "Add the command to your script")]]
  137.  
  138.  
  139. BuildModeColBox = [[sg.Image(filename="sbuilder.png")],[sg.Multiline(size=(81, 22), enter_submits=True, key='buildscriptbox', do_not_clear=True,
  140. background_color="white", auto_size_text = True)],
  141. [sg.Image(filename="boptions.png")],
  142. [sg.T("Save Name:"), sg.InputText('RailID_JiraID_YN_Title', key='testName', do_not_clear=True, size=(25, 0))],
  143. [sg.ReadButton("", border_width=0, tooltip='Test This Case', image_filename="testcode.png",
  144. key="testbuildcase"),
  145. sg.ReadButton("", border_width=0, tooltip='Save This Case', image_filename="save.png", key="savecase"),
  146. sg.ReadButton("", border_width=0, tooltip='Load a Case', image_filename="load.png", key="loadcase"),
  147. sg.ReadButton("", image_filename="log.png", border_width=0, key="log"),
  148. sg.ReadButton("", image_filename="folder.png", border_width=0, key="folder"),
  149. sg.ReadButton("", image_filename="bnotes.png", border_width=0, key="notes"),
  150. sg.ReadButton("", image_filename="home.png", border_width=0, key="Main Menu", tooltip="Main Menu")]]
  151.  
  152. BuildModeCol = [[sg.Column(buildcolumn, size=(1, 1)),
  153. sg.Column(BuildModeColBox, size=(1, 1))]]
  154.  
  155. window3 = sg.Window('Test Anatomy - Build', grab_anywhere=False, no_titlebar=False,
  156. auto_size_text=True, icon=MY_WINDOW_ICON).Layout(
  157. [[sg.Column(EHX_column), sg.Column(buildcolumn)], [sg.Column(BuildModeColBox)]]
  158. )
  159.  
  160. buildscriptbox = window3.FindElement('buildscriptbox') # def __init__(self, *args): super(BuildApp, self).__init__(*args))
  161. buildscriptbox.Update("""class BuildApp(Engine):
  162. \n""")
  163.  
  164. if win3_active: # build
  165. b, values = window3.Read(timeout=0)
  166. if b != sg.TIMEOUT_KEY:
  167. print("win3 ", b)
  168. if b == 'Exit' or b is None:
  169. win3_active = False
  170. logging.info("Window 3 Set Inactive")
  171. window3.Hide()
  172.  
  173. if b == "Main Menu":
  174. win3_active = False
  175. logging.info("Window 3 Set Inactive")
  176. window3.Hide()
  177.  
  178. if b == "highlight": # this grabs content from sb3 and puts it in script form for highlighting through API
  179. try:
  180. if values['elementtype'] == "CSS Selector":
  181. scriptvar = str.strip(values['enterElement'])
  182. exec("lite = driver.engine.find_element_by_css_selector(\"{}\")\ndriver.EHX_Highlight(lite)".format(scriptvar))
  183. logging.info("Scratchbox: Executed Command Successfully")
  184. except:
  185. logging.info("Scratchbox: Failed Executing Command")
  186. sg.PopupError("There was an issue Highlighting, Check Element")
  187.  
  188. if values['elementtype'] == "XPATH":
  189. try:
  190. scriptvar = str.strip(values['enterElement'])
  191. exec("lite = driver.engine.find_element_by_xpath(\"{}\")\ndriver.EHX_Highlight(lite)".format(scriptvar))
  192. logging.info("Scratchbox: Executed Command Successfully")
  193. except:
  194. logging.info("Scratchbox: Failed Executing Command")
  195. sg.PopupError("There was an issue Highlighting, Check Element")
  196.  
  197. if values['elementtype'] == "ID":
  198. try:
  199. scriptvar = str.strip(values['enterElement'])
  200. exec("lite = driver.engine.find_element_by_id(\"{}\")\ndriver.EHX_Highlight(lite)".format(scriptvar))
  201. logging.info("Scratchbox: Executed Command Successfully")
  202. except:
  203. logging.info("Scratchbox: Failed Executing Command")
  204. sg.PopupError("There was an issue Highlighting, Check Element")
  205.  
  206. if b == "addButt":
  207. if values['buildactions'] == "Click Element" or values['buildactions'] == "Click Input":
  208. buildscriptbox = window3.FindElement('buildscriptbox')
  209. buildscriptbox.Update(" driver.ClickWebElement(""{}"",""{}"")\n".format(repr(str.strip(values['elementtype'])), repr(str.strip(values['enterElement']))), append=True)
  210. logging.info("BUILDMODE: Using Object: Updated Script with: Click Button")
  211.  
  212. if values['buildactions'] == "Open Site":
  213. buildscriptbox = window3.FindElement('buildscriptbox')
  214. buildscriptbox.Update(" driver.OpenSite()\n", append=True)
  215. logging.info("BUILDMODE: Using Object: Updated Script with: Open Site")
  216.  
  217. if values['buildactions'] == "Type Text":
  218. buildscriptbox = window3.FindElement('buildscriptbox')
  219. buildscriptbox.Update(" driver.TypeWords(""{}"", ""{}"", ""{}"")\n".format(repr(str.strip(values['elementtype'])), repr(str.strip(values['enterElement'])), repr(str.strip(values['enterText']))), append=True)
  220. logging.info("BUILDMODE: Using Object: Updated Script with: Type Words")
  221.  
  222. if values['buildactions'] == "Wait":
  223. buildscriptbox = window3.FindElement('buildscriptbox')
  224. buildscriptbox.Update(" driver.Waiter(""{}"")\n".format(repr(str.strip(values['enterText']))), append=True)
  225. logging.info("BUILDMODE: Using Object: Updated Script with: Type Words")
  226.  
  227. if values['buildactions'] == "Wait for Element":
  228. buildscriptbox = window3.FindElement('buildscriptbox')
  229. buildscriptbox.Update(" driver.WaitForElement(""{}"", ""{}"", ""{}"")\n".format(repr(str.strip(values['elementtype'])), repr(str.strip(values['enterElement'])), repr(str.strip(values['enterText']))), append=True)
  230. logging.info("BUILDMODE: Using Object: Updated Script with: Type Words")
  231.  
  232. if b == "testbuildcase":
  233.  
  234. try:
  235. cmd = exec(values['buildscriptbox'])
  236. logging.info("Build Mode - Testing Case: Executed Command Successfully: {}".format(values['buildscriptbox']))
  237. sg.PopupOK("Case Ran Successfully")
  238. except:
  239. logging.error("Error Importing Test Case Module")
  240. sg.PopupOK("Error Importing Test Case Module")
  241.  
  242. if b == "savecase":
  243. try:
  244. f = open('{}\{}.py'.format(driver.folder, values['testName']), 'w')
  245. f.write(values['buildscriptbox'])
  246. sg.PopupOK("Case Saved")
  247. except:
  248. logging.warning("Cannot save Build Code")
  249. sg.PopupError("Cannot save Build Code")
  250.  
  251. if b == "loadcase":
  252.  
  253. try:
  254. loadfile = sg.PopupGetFile(message="Select a Test Case to Import")
  255. f = open(loadfile, 'r')
  256. buildscriptbox.Update(f.read())
  257. except:
  258. logging.warning("Cannot load Test Script")
  259. sg.PopupOK("Could not load Test Script")
  260.  
  261. if b == "notes":
  262. try:
  263. os.system('start notepad.exe')
  264. except:
  265. logging.warning("Cannot write to notes file. Must Init a Topanga first")
  266.  
  267. if b == "folder":
  268.  
  269. try:
  270. os.system('start {}'.format(driver.folder))
  271. except:
  272. logging.warning("Issue opening Project Folder - Perhaps you didn't start a project yet?")
  273. sg.PopupOK("Perhaps you didn't start a project yet?\nSet configs and click launch!")
  274.  
  275. if win2_active:
  276. b, values = window2.Read(timeout=0)
  277.  
  278. if b != sg.TIMEOUT_KEY:
  279. print("win2 ", b)
  280. if b == 'Exit' or b is None:
  281. win2_active = False
  282. logging.info("Window 2 Set Inactive: Pressed Exit")
  283. window2.Close()
  284.  
  285. if b == "home":
  286. win2_active = False
  287. logging.info("Window 2 Set Inactive: Pressed Main Menu")
  288. window2.Close()
  289.  
  290. if b == "Launch2":
  291. try:
  292. driver = Github(shelfdb['ok'][0], shelfdb['ok'][1], shelfdb['ok'][2])
  293. driver.OpenSite()
  294. logging.info("Instantiating Application")
  295. except:
  296. logging.warning("Issue Instantiating Application")
  297.  
  298. if b == "config_save":
  299. logging.info("Window 2: Pressed Save")
  300.  
  301. testersname = window2.FindElement('testername')
  302. browsertype = window2.FindElement('browsertype')
  303. appuri = window2.FindElement('appuri')
  304. appname = window2.FindElement('appname')
  305. emailfrom = window2.FindElement('emailfrom')
  306. emailto = window2.FindElement('emailto')
  307. emailusername = window2.FindElement('emailusername')
  308. emailpassword = window2.FindElement('emailpassword')
  309. databasecheck = window2.FindElement('databasecheck')
  310. pdfcheck = window2.FindElement('pdfcheck')
  311. htmlcheck = window2.FindElement('htmlcheck')
  312. graphcheck = window2.FindElement('graphcheck')
  313. emailcheck = window2.FindElement('emailcheck')
  314. dbip = window2.FindElement('dbip')
  315. dbun = window2.FindElement('dbun')
  316. dbpw = window2.FindElement('dbpw')
  317. dbport = window2.FindElement('dbport')
  318. persistcheck = window2.FindElement('persistcheck') # UID
  319. projectUUID = window2.FindElement('projectUUID') # UID
  320.  
  321. shelfdb['ok'] = [values["browsertype"],
  322. values["appuri"],
  323. values["appname"],
  324. values["emailto"],
  325. values["emailfrom"],
  326. values["emailusername"],
  327. values["emailpassword"],
  328. values["databasecheck"],
  329. values["pdfcheck"],
  330. values["htmlcheck"],
  331. values["graphcheck"],
  332. values["emailcheck"],
  333. values["dbip"],
  334. values["dbun"],
  335. values["dbpw"],
  336. values["dbport"],
  337. values['persistcheck'],
  338. values['testername']]
  339. if projectUUID == True:
  340. shelfdb['uuid'] = [app.UUID]
  341.  
  342. if b == "config_load":
  343. try:
  344. logging.info("Window 2: Pressed Load")
  345.  
  346. # SITE
  347. browsertype.Update(shelfdb['ok'][0])
  348. appuri.Update(shelfdb['ok'][1])
  349. appname.Update(shelfdb['ok'][2])
  350.  
  351. # EMAIL
  352. emailto.Update(shelfdb['ok'][3])
  353. emailfrom.Update(shelfdb['ok'][4])
  354. emailusername.Update(shelfdb['ok'][5])
  355. emailpassword.Update(shelfdb['ok'][6])
  356.  
  357. # CHECKBOX SETTINGS
  358. databasecheck.Update(shelfdb['ok'][7])
  359. pdfcheck.Update(shelfdb['ok'][8])
  360. htmlcheck.Update(shelfdb['ok'][9])
  361. graphcheck.Update(shelfdb['ok'][10])
  362. emailcheck.Update(shelfdb['ok'][11])
  363.  
  364. # DATABASE SETTINGS
  365. dbip.Update(shelfdb['ok'][12])
  366. dbun.Update(shelfdb['ok'][13])
  367. dbpw.Update(shelfdb['ok'][14])
  368. dbport.Update(shelfdb['ok'][15])
  369. persistcheck.Update(shelfdb['ok'][16])
  370. testersname.Update(shelfdb['ok'][17])
  371.  
  372. if projectUUID == True:
  373. savedUUID = shelfdb['uuid'][0]
  374. projectUUID.Update(savedUUID)
  375.  
  376. logging.info("Loading Config - Success")
  377.  
  378. except:
  379. logging.error("Loading Config - Failed")
  380.  
  381. if b == "Load/Reload": # graph button to load graph
  382. appdb.SetPlot()
  383. fig_photo = appdb.PlotDraw(window.FindElement('canvas_graph').TKCanvas, fig)
  384.  
  385. if b == "log":
  386. try:
  387. os.system('start cmtrace topanga.log')
  388.  
  389. except:
  390. logging.warning("Issue opening Log")
  391. sg.PopupOK("Issue opening Log")
  392.  
  393. if b == "Generate Graph":
  394. # graphWindow = sg.Window("Topanga ∩(^-^)∩ Graphical", auto_size_text=False).Layout(layout_graph).Finalize()
  395. GenerateGraph()
  396. # figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
  397. # fig_photo = Graphing(graphWindow.FindElement('canvas_graph').TKCanvas, fig)
  398. # graphWindow.Read()
  399.  
  400. if b is None:
  401. logging.info("Used X to Exit Application")
  402. break
  403.  
  404. else:
  405. pass
Add Comment
Please, Sign In to add comment