Posts

Showing posts from 2015

5 useful email expressions

https://www.youtube.com/watch?v=itLLVAJjXNI#action=share

Python: Dictionary

Quick diving into "dictionary" of the python. Actually, this is example of code was written as a simple explanation for my little brother how to work with dictionary. This is simple example, without deep diving for many possible situations.

Python. How to handle CheckBox verification

Check-box verification in simple way. [code language="python"] from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Firefox() driver.get("http://blah_blah.com") try: elem= driver.find_element(By.NAME, "chk_email") if (elem.is_selected()): print("Checkbox is selected...now deselecting") elem.click() else: print("Checkbox is not selected..now selecting") elem.click() driver.close() except Exception as e: print ("Exception occurred", format(e)); finally: driver.quit() print ("done") [/code]

Python: Let’s call “datetime”!

For QA engineer very often situation, when need keep test results created by scheduling. I would like to share with you, one very simple and the same time very powerfull tool. It’s calling “datetime”. This module will add timestamp inside your code. In your input you can see next attributes: date, time (hours, minutes, seconds and microseconds) and also timezone information if need. Also, for more fast align output files in you file browser you can include that information inside a name of created output file. Quick Example: [code language="python"] import datetime t = datetime.date.today() y = datetime.datetime.today() f = open(str(t) + ‘.datime.log’, ‘a’) # 'a' - will add new test results inside existing file. # Task a = 3 b = 3 c = a * b # Action f.write(‘\nData: ‘ + str(y)) f.write(‘\nResult: ‘ + str(c)) f.close() [/code] Output: Data: 2015-10-26 09:35:59.941000 Result: 9

Python: fnmatch – Compare filenames by patterns.

[code language="python"] """ "fnmatch" module compares file names against glob-style patterns such as used by Unix shells. Find more information: https://pymotw.com/2/fnmatch/ http://www.pythonforbeginners.com/fnmatch/os-walk-and-fnmatch-in-python """ import os from fnmatch import fnmatch root = '//Users//computerLoginName//Documents//' extension = 'test*.py' counts = 0 for path, dirs, files in os.walk(root): for name in files: if fnmatch(name, extension): print(os.path, name) # count repeated files inside directory #num_files = len([f for f in os.listdir(path)if os.path.isfile(os.path.join(path, f))]) #print(num_files) # count number of files counts += 1 print(counts) [/code]

Python: Read data from spreadsheet.

[code language="python"] """ Spreadsheet with some definitions: |   |          A        |     B     |  C  | | 1 |    4/5/2014 13:34 | Apples    | 73  | | 2 |     4/5/2014 3:41 | Cherries  | 85  | | 3 |    4/6/2014 12:46 | Pears     | 14  | | 4 |     4/8/2014 2:07 | Apples    | 152 | """ # Install openpyxl: pip install openpyxl # code: >>> import openpyxl >>> import os >>> os.chdir('c:\\users\\all\\documents') # file located in folder "documents" >>> >>> >>> workbook = openpyxl.load_workbook('example.xlsx') >>> type(workbook) <class 'openpyxl.workbook.workbook.Workbook'> >>> sheet = workbook.get_sheet_by_name('Sheet1') >>> type(sheet) <class 'openpyxl.worksheet.worksheet.Worksheet'> >>> workbook.get_sheet_names() ['Sheet1', 'Sheet2', 'Sheet3'] >>> sheet['A1'...