Skip to content

Commit

Permalink
Add bocoup/aria-at as a submodule & implement processing of automated…
Browse files Browse the repository at this point in the history
… test format

See w3c/aria-at#349
  • Loading branch information
zcorpan committed Dec 2, 2020
1 parent f0391fb commit 369c048
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@
[submodule "include/cldr"]
path = include/cldr
url = https://github.com/unicode-org/cldr.git
[submodule "include/w3c-aria-at"]
path = include/w3c-aria-at
url = https://github.com/bocoup/aria-at
branch = automation-prototype
1 change: 1 addition & 0 deletions include/w3c-aria-at
Submodule w3c-aria-at added at 7707e1
59 changes: 59 additions & 0 deletions tests/system/libraries/AssertsLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,62 @@ def strings_match(actual, expected, ignore_case=False):
)
)
raise

@staticmethod
def aria_at(command, actual, expected, ignore_case=False):
try:
# Normalize whitespace in actual.
actual = " ".join(actual.strip().split())
msg = '{}: {}\nActual output: {}'.format(command, expected, actual)
if command == 'assert_contains':
builtIn.should_contain_x_times(
actual,
expected,
1,
msg=msg
)
elif command == 'assert_accname':
builtIn.should_contain_x_times(
actual,
expected,
1,
msg=msg
)
elif command == 'assert_role':
# Normalize ARIA role to NVDA's spoken output for the role.
expected = {
'checkbox': 'check box',
}[expected]
builtIn.should_contain_x_times(
actual,
expected,
1,
msg=msg
)
elif command == 'assert_checked':
actualChecked = 'checked' in actual and not 'not checked' in actual
expectedChecked = expected == 'true'
builtIn.should_be_equal(
actualChecked,
expectedChecked,
msg=msg
)
elif command == 'assert_equals':
builtIn.should_be_equal_as_strings(
actual,
expected,
msg=msg
)
else:
builtIn.should_be_true(
False,
msg='Unknown aria_at assertion: {}'.format(command))
except AssertionError:
builtIn.log(
"repr of actual vs expected (ignore_case={}):\n{}\nvs\n{}".format(
ignore_case,
repr(actual),
repr(expected)
)
)
raise
46 changes: 26 additions & 20 deletions tests/system/robot/chromeTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
_NvdaLib._locations.repoRoot, "include", "w3c-aria-practices", "examples"
)

ARIAATDir = os.path.join(
_NvdaLib._locations.repoRoot, "include", "w3c-aria-at", "tests"
)


def checkbox_labelled_by_inner_element():
_chrome.prepareChrome(
Expand Down Expand Up @@ -235,10 +239,10 @@ def test_ariaTreeGrid_browseMode():
"""
Ensure that ARIA treegrids are accessible as a standard table in browse mode.
"""
testFile = os.path.join(ARIAExamplesDir, "treegrid", "treegrid-1.html")
testFile = os.path.join(ARIAExamplesDir, "treegrid", "treegrid-1.html").replace('\\', '/')
_chrome.prepareChrome(
f"""
<iframe src="{testFile}"></iframe>
<iframe src="file:///{testFile}"></iframe>
"""
)
# Jump to the first heading in the iframe.
Expand Down Expand Up @@ -323,25 +327,27 @@ def ARIAInvalid_spellingAndGrammar():
)


def parseAndRun(instructionsFilePath):
lastSpeech = ''
file = open(instructionsFilePath, 'r', encoding='utf-8')
for line in file:
(command, arg) = line.split(': ')
arg = arg.rstrip()
if command == 'nav':
# TODO(zcorpan): this should open the file directly, not use iframe.
navPath = os.path.join(os.path.dirname(os.path.dirname(instructionsFilePath)), arg).replace('\\', '/')
_chrome.prepareChrome(f"""
<iframe src="file:///{navPath}"></iframe>
""")
elif command == 'press':
lastSpeech = _chrome.getSpeechAfterKey(arg)
else:
_asserts.aria_at(command, lastSpeech, arg)


def test_ariaCheckbox_browseMode():
"""
Navigate to an unchecked checkbox in reading mode.
"""
testFile = os.path.join(ARIAExamplesDir, "checkbox", "checkbox-1", "checkbox-1.html")
_chrome.prepareChrome(
f"""
<iframe src="{testFile}"></iframe>
"""
)
# Jump to the first heading in the iframe.
actualSpeech = _chrome.getSpeechAfterKey("h")
_asserts.strings_match(
actualSpeech,
"frame main landmark Checkbox Example (Two State) heading level 1"
)
# Navigate to the checkbox.
actualSpeech = _chrome.getSpeechAfterKey("x")
_asserts.strings_match(
actualSpeech,
"Sandwich Condiments grouping list with 4 items Lettuce check box not checked"
)
instructionsFile = os.path.join(ARIAATDir, "checkbox", "automated", "test-01-navigate-to-unchecked-checkbox-reading.nvda.txt")
parseAndRun(instructionsFile)

0 comments on commit 369c048

Please sign in to comment.