def select_PivotFields_Chart(PivotTable, PivotSht, wb, *argv): try: PivotTable.PivotFields(argv[0]).Orientation = argv[3] PivotTable.PivotFields(argv[0]).Position = 1 PivotTable.PivotFields(argv[1]).Orientation = argv[3] PivotTable.PivotFields(argv[0]).Position = 2 time.sleep(0.5) im = imageGrab.grab() im.save(screenshot_path + 'Step10_Columns_to_Axis.png') logInfoError('info', 'Step7-Columns are dragged successfully to Axis') DataField = PivotTable.AddDataField(PivotTable.PivotFields(argv[2])) DataField.NumberFormat = '##0.00' time.sleep(0.5) im = imageGrab.grab() im.save(screenshot_path + 'Step11_Columns_to_Axis.png') logInfoError('info', 'Step11-Columns are dragged successfully to Axis') # Create Chart chart = PivotSht.Shapes.AddChart2(201) time.sleep(0.5) im = imageGrab.grab() im.save(screenshot_path + 'Step12_Pivot_Chart.png') logInfoError('info', 'Step12-Pivot chart should be loaded') wb.Save() wb.Close() except Exception as e: logInfoError('error', 'Step10tp12-Columns and Chart not created {}'.format(e)) raise e
def qcConnect_Donwloadfile(qcServer, qcUser, qcPassword, qcDomain, qcProject, qcTC_Folder, TestCase_Name): # Connect to qc Server try: qcConn = win32.Dispatch('TDApiOle80.TDConnection.1') qcConn.InitConnectionEx(qcServer) qcConn.Login(qcUser, qcPassword) qcConn.Connect(qcDomain, qcProject) im = imageGrab.grab() im.save(screenshot_path + 'Step2_Connect_QCServer.png') logInfoError('info', 'Step2-Connect to QC Successfully') # Download file attached to test cases TreeObj = qcConn.TreeManager folder = TreeObj.NodeByPath(qcTC_Folder) testList = folder.FindTests(TestCase_Name) if (len(testList)) == 0: im = imageGrab.grab() im.save(screenshot_path + 'Step2_No_TC_Found.png') logInfoError('error', 'No TC found in folder-{}'.format(qcTC_Folder)) else: for tst in range(len(testList)): teststorage = testList[tst].ExtendedStorage teststorage.ClientPath = resources_path + testList[tst].name teststorage.Load('', True) time.sleep(5) im = imageGrab.grab() im.save(screenshot_path + 'Step2_Downloadfile.png') logInfoError('info', 'Stpe2-Completed Download') except Exception as e: im = imageGrab.grab() im.save(screenshot_path + 'Step2_QCServer_Error.png') logInfoError('error', 'Could not Connect to QC Server-{}'.format(e))
def xl_type_CopyPaste(unzipfileName, xlpath): # Type cell with value and copy paste the value to different cells try: path = os.getcwd().replace('\'', '\\') + '\\' wb = xlApp.Workbooks.Open(path + xlpath + unzipfileName) ws = wb.Worksheets(1) xlApp.Visible = True im = imageGrab.grab() im.save(screenshot_path + 'Step1_Validate_Application.png') hwnd = win32gui.GetForegroundWindow() win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) ws.Cells(28, 3).Value = '=COUNTA(C8:C24)' wb.Save() im = imageGrab.grab() im.save(screenshot_path + 'Step3to4_Type_Formula.png') logInfoError('info', 'Step3to4-Type formula to Cell C28 Successfully') time.sleep(1) wCol = 'E' for col in range(0, 5): ws.Range('C28').Copy() ws.Range(wCol + '28').PasteSpecial(Paste=constants.xlPasteValues) wCol = chr(ord(wCol) + 2) wb.Save() im = imageGrab.grab() im.save(screenshot_path + 'Step5_Copy_Cell_Paste.png') logInfoError('info', 'Step5-Copy C28, Paste Cell to Alternate Cells') return (wb, ws) except Exception as e: im = imageGrab.grab() im.save(screenshot_path + 'Step5_Copy_Cell_Paste_Error.png') logInfoError('error', 'Step5-Could not Open Excel {}'.format(e)) raise e
def get_screen(): screenshot_name = get_analyzable_relative_path() + "screen.png" image = auto_gui.grab() image.save(screenshot_name) return Image.open(screenshot_name)
def xl_format_Cells(wb, ws): try: y = 'C' for j in range(0, 6): ws.Range(y + '28').HorizontalAlignment = 3 strCol = '%02x%02x%02x' % (0, 165, 255) ws.Range(y + '28').Interior.Color = int(strCol, 16) for id in range(7, 13): ws.Range(y + '28').Borders(id).LineStyle = 1 ws.Range(y + '28').Borders(id).Weight = 2 y = chr(ord(y) + 2) wb.Save() im = imageGrab.grab() im.save(screenshot_path + 'Step6to9_Format_Cells.png') logInfoError('info', 'Step6to9-Format Cells and Highlight') except Exception as e: im = imageGrab.grab() im.save(screenshot_path + 'Step8to9_Couldnot_Format_Cells.png') logInfoError('error', 'Step6to9-Could not format the cells') raise e
def get_screen(): screenshot_location = Constants.MAIN_FILE_LOCATION + "/runtime/captures" Utils.make_directories_to_target(screenshot_location) screenshot_name = screenshot_location + "/screen_hour_" + str(Constants.HOURS_RUNNING) + ".png" Constants.HOURS_RUNNING += 1 image = auto_gui.grab() image.save(screenshot_name) return Image.open(screenshot_name)
def extract_ZipFile(resources_path): try: filelist = os.listdir(resources_path) for file in filelist: if file.startswith('Adobe'): with ZipFile(resources_path + file, 'r') as zip: #zip.printdir() zip.extractall(resources_path) os.startfile(resources_path) time.sleep(1) im = imageGrab.grab() im.save(screenshot_path + 'Step2_Unzip_file.png') logInfoError( 'info', 'Step2-Unzip file {} successfully'.format( zip.infolist()[0].filename)) return (zip.infolist()[0].filename) except Exception as e: im = imageGrab.grab() im.save(screenshot_path + 'Step2_File Not found.png') logInfoError('error', 'Step2-Could not Unzip file {}'.format(e)) raise e
def print_file_close(wb, flpath, flname): try: Cur_printer = printer.GetDefaultPrinter() print(Cur_printer) printer.SetDefaultPrinter(Cur_printer) wb.Save() wb.Close() win32api.ShellExecute(0, 'print', flpath + flname, Cur_printer, ',', 0) im = imageGrab.grab() im.save(screenshot_path + 'Step10to11_Print_Close_File.png') logInfoError( 'info', 'Step10to11-Successfully printed file {} on printer {}'.format( flname, Cur_printer)) except Exception as e: im = imageGrab.grab() im.save(screenshot_path + 'Step10to11_Print_error.png') logInfoError( 'error', 'Step10to11-Could not print file {} on printer {}'.format( flname, Cur_printer)) raise e
def select_PivotFields_Sort(PivotTable, *argv): try: PivotTable.PivotFields(argv[0]).Orientation = argv[2] DataField = PivotTable.AddDataField(PivotTable.PivotFields(argv[1])) DataField.NumberFormat = '##0.00' time.sleep(0.5) im = imageGrab.grab() im.save(screenshot_path + 'Step6_Pivot_Table_Loaded.png') logInfoError('info', 'Step6-Pivot table should loaded as per selection') # Sort field Hostname descending order PivotTable.PivotFields(argv[0]).AutoSort(constants.xlAscending, DataField) time.sleep(0.5) im = imageGrab.grab() im.save(screenshot_path + 'Step7_Pivot_Table_Sorted.png') logInfoError('info', 'Step7-The pivot table should load with sorting') except Exception as e: logInfoError('error', 'Step6to7-Pivot loading and sorting error {}'.format(e)) raise e
def take_screen_shot(self): """ makes the system aware of the screen's size and takes a screenshot """ user32 = windll.user32 user32.SetProcessDPIAware() screen_shot = pyautogui.grab(region=(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)) save_path = self.data_info.get_type_path("jpg") # create a non existing name if not os.path.exists(save_path): os.makedirs(save_path) i = 1 + len(os.listdir(save_path)) screen_shot.save(save_path + "\\screenshot%i.jpg" % i)
def validate_xl(unzipfileName, xlpath): # Type cell with value and copy paste the value to different cells try: path = os.getcwd().replace('\'', '\\') + '\\' wb = xlApp.Workbooks.Open(path + xlpath + unzipfileName) xlApp.Visible = True hwnd = win32gui.GetForegroundWindow() win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) time.sleep(1) im = imageGrab.grab() im.save(screenshot_path + 'Step3_Open_Data_File.png') logInfoError('info', 'Step3-File Opened Successfully') # Select the Source Range ws = wb.Sheets('Sheet1') PivotRangeSrc = ws.UsedRange PivotRangeSrc.Select() return (wb, PivotRangeSrc) except Exception as e: logInfoError('error', 'Step3-Data file Not Found {}'.format(e)) raise e
def create_PivotTable(wb, PivotRangeSrc, PivotTblName, stepNo): try: # Select destination Range PivotSht = wb.Worksheets.Add() PivotRangeDest = PivotSht.Range('A1') PivotTableName = PivotTblName except Exception as e: logInfoError('error', 'Select Destination Error {}'.format(e)) raise e # Create Pivot table try: PivotCache = wb.PivotCaches().Create(SourceType=constants.xlDatabase, SourceData=PivotRangeSrc) PivotTable = PivotCache.CreatePivotTable( TableDestination=PivotRangeDest, TableName=PivotTableName) time.sleep(0.5) im = imageGrab.grab() im.save(screenshot_path + stepNo + '_Highlight_All_Column.png') logInfoError('info', stepNo + '-Highlighted all columns') return (PivotTable, PivotSht) except Exception as e: logInfoError('error', stepNo + '-Range Selection error {}'.format(e)) raise e
cap = cv2.VideoCapture(0) x = 0 i = 0 while x < 10000000: if x % 2000000 == 0: print(i) i = i + 1 x = x + 1 print("Go!") while True: first = time.time() #Image Grabbing image_np = py.grab(region=(650, 220, 700, 300)) image_mod = cv2.cvtColor(np.array(image_np), cv2.COLOR_BGR2GRAY) image_np = cv2.cvtColor(np.array(image_np), cv2.COLOR_BGR2RGB) edges = cv2.Canny(image_mod, 100, 200) #Object detection matcher = cv2.matchTemplate(image_mod, template, cv2.TM_CCOEFF) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(matcher) top_left = min_loc bottom_right = (top_left[0] + w, top_left[1] + h) cv2.rectangle(image_np, top_left, bottom_right, 255, 2) #Decision making and key pressing #py.keyDown(' ') #py.keyUp(' ') #Image Display cv2.imshow("Winning", cv2.resize(edges, (700, 300)))
def take_screenshot(): image = auto_gui.grab() save_image(image, get_testing_path(), "screenie.png") return Image.open(get_testing_path() + "screenie.png")