Skip to content

Commit

Permalink
Merge pull request #130 from StatCan/feature-129-tass-converter-add-t…
Browse files Browse the repository at this point in the history
…erminating-character-for-case-template-in-excel

[Feature][tass-converter] Updated Excel Scenario converter behaviour
  • Loading branch information
ty-desj authored Apr 18, 2024
2 parents 53840c0 + d00f8a9 commit ccb09ea
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 19 deletions.
23 changes: 14 additions & 9 deletions tass-converter/src/tass/converter/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def convert(path):
conf_file["Test_suites"] = []
conf_file["Test_cases"] = []
conf_file["Steps"] = {} # Will be converted to list later.
wb = openpyxl.load_workbook(path) # Open conf file.
wb = openpyxl.load_workbook(path, data_only=True) # Open conf file.

test_run = [] # Holds all test_run worksheet names.
test_suite = [] # Holds all test_suite worksheet names.
Expand Down Expand Up @@ -48,6 +48,8 @@ def convert_test_case(test_case, conf, wb):
tc["title"] = wb[case]['D1'].value
tc["steps"] = []
for row in wb[case].iter_rows(min_row=3, max_col=6):
if (row[0] is None or row[0] == ''):
continue
print(row)
steps = {}
parameters = {}
Expand All @@ -63,10 +65,14 @@ def convert_test_case(test_case, conf, wb):
max_row=row_num,
min_col=4):

if (col[0].value is not None):
header = wb[case].cell(2, col[0].column).value
header = wb[case].cell(2, col[0].column).value

if (header == '//end//'):
break

if (col[0].value is not None and header == 'locator'):
if (col[0].value is not None):

if (header == 'locator'):
locator = col[0].value.split(',')

if (len(locator) == 2):
Expand All @@ -77,15 +83,14 @@ def convert_test_case(test_case, conf, wb):
else:
parameters['locator'] = locator[0]

elif (col[0].value is not None and header == 'page'):
elif (header == 'page'):
parameters['page'] = col[0].value.split(',', 1)

elif (col[0].value is not None and 'action' in header):
elif ('action' in header):
parameters['action'] = col[0].value.split(',', 1)

elif (col[0].value is not None
and header == 'locator_args'):
parameters['locator_args'] = col[0].value.split(',')
elif (header == 'locator_args'):
parameters['locator_args'] = str(col[0].value).split(',')

else:
parameters[header] = col[0].value
Expand Down
83 changes: 73 additions & 10 deletions tass-converter/src/tass/converter/page_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ElementType(StrEnum):
CHECKSPECIFY = auto()
DROPDOWN = auto()
INTEGER = auto()
LEADINGZERO = "integerleadingzeros"
TEXT = auto()
PHONE = auto()
EMAIL = auto()
Expand Down Expand Up @@ -93,12 +94,14 @@ def parse_sheet(sheet, specs_out):
radio_group = row[2].value
case (ElementType.TEXT |
ElementType.INTEGER |
ElementType.LEADINGZERO |
ElementType.PHONE |
ElementType.EMAIL |
ElementType.CURRENCY |
ElementType.POSTALNOVAL |
ElementType.COMMENTBOX):
ElementType.POSTALNOVAL):
ele.append([ElementType.TEXT, row[2].value])
case ElementType.COMMENTBOX:
ele.append([ElementType.COMMENTBOX, row[2].value])
case ElementType.DROPDOWN:
ele.append([ElementType.DROPDOWN, row[2].value])
case ElementType.CHECK | ElementType.CHECKSPECIFY:
Expand Down Expand Up @@ -147,70 +150,125 @@ def convert_to_json(pages_path):
page_number = 0

def parse_info(id, rostered):
if rostered:
if rostered == 1:
return (
f'//input[contains(@name, ".Instance") and @value={{}}]'
f'/following-sibling::*/descendant::div[contains(@id, "{id}")]'
)
elif rostered == 2:
return (
f'//input[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::div[contains(@id, "{id}")]'
)
else:
return f'//div[contains(@id, "{id}")]/ul/li[{{}}]'

def parse_radio(id, val, rostered):
if rostered:
if rostered == 1:
return (
f'//input[contains(@name, ".Instance") and @value={{}}]'
'/following-sibling::*'
f'/descendant::input[contains(@name, ".{id}")'
f' and @value={val}]'
)
elif rostered == 2:
return (
f'//input[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::input[contains(@name, "{id}")'
f' and @value="{val}"]'
)
else:
return f'//input[contains(@name, ".{id}") and @value={val}]'

def parse_radiotext(id, rostered):
if rostered:
if rostered == 1:
return (
f'//input[contains(@name, ".Instance") and @value={{}}]'
f'/following-sibling::*/descendant::input[@value="{id}"]'
)
elif rostered == 2:
return (
f'//input[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::input[@value="{id}"]'
)
else:
return f'//input[@value="{id}"]'

def parse_check(id, rostered):
if rostered:
if rostered == 1:
return (
f'//input[contains(@name, ".Instance") and @value={{}}]'
'/following-sibling::*'
f'/descendant::input[contains(@name, ".{id}")'
' and @type="checkbox"]'
)
elif rostered == 2:
return (
f'//input[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::input[contains(@name, "{id}")'
f' and @type="checkbox"]'
)
else:
return f'//input[@name="{id}" and @type="checkbox"]'

def parse_dropdown(id, rostered):
if rostered:
if rostered == 1:
return (
f'//input[contains(@name, ".Instance") and @value={{}}]'
'/following-sibling::*'
f'/descendant::select[contains(@name, ".{id}")]'
)
elif rostered == 2:
return (
f'//input[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::select[contains(@name, "{id}")]'
)
else:
return f'//select[@name="{id}"]'

def parse_text(id, rostered):
if rostered:
if rostered == 1:
return (
f'//input[contains(@name, ".Instance") and @value={{}}]'
'/following-sibling::*'
f'/descendant::input[contains(@name, ".{id}")]'
f'/descendant::input[contains(@name, ".{id}")'
f' and not(@type="radio") and not(@type="checkbox")]'
)
elif rostered == 2:
return (
f'//input[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::input[contains(@name, "{id}")'
f' and not(@type="radio") and not(@type="checkbox")]'
)
else:
return f'//input[@name="{id}"]'

def parse_comment(id, rostered):
if rostered == 1:
return (
f'//textarea[contains(@name, ".Instance") and @value={{}}]'
'/following-sibling::*'
f'/descendant::input[contains(@name, ".{id}")'
f' and not(@type="radio") and not(@type="checkbox")]'
)
elif rostered == 2:
return (
f'//textarea[@id="__instance" and @value={{}}]'
f'/following-sibling::*/descendant::input[contains(@name, "{id}")'
f' and not(@type="radio") and not(@type="checkbox")]'
)
else:
return f'//textarea[@name="{id}"]'

for count, row in enumerate(ws.iter_rows(min_row=2, max_col=6), 2):
print("This is the row:", row)
row_type = row[0].value
element_id = row[1].value
rostered = row[2].value and row[2].value == 1

if (row[2].value and (row[2].value == 1 or row[2].value == 2)):
rostered = row[2].value
else:
rostered = 0
if row_type == Element.BREAK:
print("Page Number:", page_number)
if not page and not elements:
Expand Down Expand Up @@ -276,6 +334,11 @@ def parse_text(id, rostered):
"by": "xpath",
"value": parse_text(element_id, rostered)
}
elif row_type == ElementType.COMMENTBOX:
elements[element_id] = {
"by": "xpath",
"value": parse_comment(element_id, rostered)
}
elif row_type == ElementType.DROPDOWN:
elements[element_id] = {
"by": "xpath",
Expand Down

0 comments on commit ccb09ea

Please sign in to comment.