Made a new command css_has_class that will safely check the class and get around stale elements

This commit is contained in:
JonahStanley
2013-07-03 15:57:11 -04:00
parent d86502bdc1
commit 8b0e7c5782
2 changed files with 14 additions and 7 deletions

View File

@@ -223,13 +223,7 @@ def shows_captions(step, show_captions):
# Prevent cookies from overriding course settings
world.browser.cookies.delete('hide_captions')
if show_captions == 'does not':
attempt = 0
while attempt < 5:
try:
assert world.css_find('.video')[0].has_class('closed')
except:
attempt += 1
assert_true(attempt < 5, "There was a stale reference exception in accessing the class of the video")
assert world.css_has_class('.video', 'closed')
else:
assert world.is_css_not_present('.video.closed')

View File

@@ -182,6 +182,19 @@ def css_html(css_selector, index=0, max_attempts=5):
return ''
@world.absorb
def css_has_class(css_selector, class_name, index=0, max_attempts=5):
attempt = 0
found = False
while attempt < max_attempts and not found:
try:
return world.css_find(css_selector)[index].has_class(class_name)
found = True
except:
attempt += 1
return False
@world.absorb
def css_visible(css_selector):
assert is_css_present(css_selector), "{} is not present".format(css_selector)