-1
我使用簡單的測試框架將* .xlsx文件的內容轉換爲硒瀏覽器測試。這允許高層次的抽象,但是由於它是一個二進制文件,所以很討厭在git中工作。是否有辦法強制自動生成的文件與觸發其生成的其餘提交一起提交?
excel的測試文件的格式是:
Column A -> Action
Column B -> Identity (which text field, etc)
Column C onwards -> Value
我寫了下面的代碼,成功地轉換Excel文件到一個文本文件(*以.json),本質上只是一個列表的列表(使訂單保持不變,並且不會引入額外的關鍵字)。
#!/usr/bin/env python
"""
This script takes a GUI test in xlsx format and outputs a text interpretation.
"""
import argparse
import json
from openpyxl import load_workbook
from openpyxl.cell import get_column_letter
def main(xlsx_test):
ws = load_workbook(filename=xlsx_test, data_only=True).active
col_size = len(ws.column_dimensions)
row_size = len(ws.row_dimensions)
full_document = []
for col in xrange(2, col_size):
col_letter = get_column_letter(col + 1)
test_document = []
for row in xrange(row_size):
cell_reference = col_letter + str(row + 1)
cell_value = ws[cell_reference].value
if cell_value:
action = ws['A' + str(row + 1)].value
identity = ws['B' + str(row + 1)].value
if not action:
action = ""
if not identity:
identity = ""
test_item = [action, identity, cell_value]
test_document.append(test_item)
if test_document:
full_document.append(test_document)
with open(xlsx_test + '.json', 'w') as outfile:
json.dump(full_document, outfile, indent=4)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate text verion of tests')
test_file = parser.add_argument(
'--input',
type=str,
nargs='?',
help='the file to generate text version of tests from'
)
args = parser.parse_args()
if args.input is None:
print '''No file selected'''
else:
main(args.input)
要運行它,我將執行在bash腳本如下:
python /path/to/this/script.py --input='/path/to/test.xlsx'
我想的文本文件,其產生與XLSX二進制只是讓我們得到了一個一起被提交git改變歷史。
我一直在閱讀預先提交的鉤子(我很樂意在每個貢獻者的機器上設置,但我很努力確定它是否將一個額外的生成文件包含到提交中。將是偉大的,因爲我不知道該怎麼試試此刻
我還必須弄清楚我是否可以遍歷提交文件列表中的擴展名爲* .xlsx,並將路徑作爲上面的python腳本的參數,在一個循環中,我問的是這樣做的嗎?