From 9a5326bca50be73b9f078412d7d486a7683ce5c5 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Tue, 2 Jul 2013 16:46:20 -0400 Subject: [PATCH] Made a css_html to obtain the html of the css element. This works like css_click in that it will retry if there was a stale element reference exception --- .../contentstore/features/course-updates.py | 6 ++---- cms/djangoapps/contentstore/features/grading.py | 2 +- .../contentstore/features/static-pages.py | 2 +- cms/djangoapps/contentstore/features/upload.py | 4 ++-- common/djangoapps/terrain/ui_helpers.py | 15 +++++++++++++++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cms/djangoapps/contentstore/features/course-updates.py b/cms/djangoapps/contentstore/features/course-updates.py index d838061698..e7fbb2f90c 100644 --- a/cms/djangoapps/contentstore/features/course-updates.py +++ b/cms/djangoapps/contentstore/features/course-updates.py @@ -60,8 +60,7 @@ def change_date(_step, new_date): @step(u'I should see the date "([^"]*)"$') def check_date(_step, date): date_css = 'span.date-display' - date_html = world.css_find(date_css) - assert date == date_html.html + assert date == world.css_html(date_css) @step(u'I modify the handout to "([^"]*)"$') @@ -74,8 +73,7 @@ def edit_handouts(_step, text): @step(u'I see the handout "([^"]*)"$') def check_handout(_step, handout): handout_css = 'div.handouts-content' - handouts = world.css_find(handout_css) - assert handout in handouts.html + assert handout in world.css_html(handout_css) def change_text(text): diff --git a/cms/djangoapps/contentstore/features/grading.py b/cms/djangoapps/contentstore/features/grading.py index 4e59897c1c..dc41cda30f 100644 --- a/cms/djangoapps/contentstore/features/grading.py +++ b/cms/djangoapps/contentstore/features/grading.py @@ -47,7 +47,7 @@ def confirm_change(step): range_css = '.range' all_ranges = world.css_find(range_css) for i in range(len(all_ranges)): - assert all_ranges[i].html != '0-50' + assert world.css_html(range_css, index=i) != '0-50' @step(u'I change assignment type "([^"]*)" to "([^"]*)"$') diff --git a/cms/djangoapps/contentstore/features/static-pages.py b/cms/djangoapps/contentstore/features/static-pages.py index a16a3246da..2331f9a138 100644 --- a/cms/djangoapps/contentstore/features/static-pages.py +++ b/cms/djangoapps/contentstore/features/static-pages.py @@ -54,6 +54,6 @@ def get_index(name): page_name_css = 'section[data-type="HTMLModule"]' all_pages = world.css_find(page_name_css) for i in range(len(all_pages)): - if all_pages[i].html == '\n {name}\n'.format(name=name): + if world.css_html(page_name_css, index=i) == '\n {name}\n'.format(name=name): return i return -1 diff --git a/cms/djangoapps/contentstore/features/upload.py b/cms/djangoapps/contentstore/features/upload.py index 47d770dc47..fe6b58b119 100644 --- a/cms/djangoapps/contentstore/features/upload.py +++ b/cms/djangoapps/contentstore/features/upload.py @@ -67,7 +67,7 @@ def no_duplicate(_step, file_name): all_names = world.css_find(names_css) only_one = False for i in range(len(all_names)): - if file_name == all_names[i].html: + if file_name == world.css_html(names_css, index=i): only_one = not only_one assert only_one @@ -100,7 +100,7 @@ def get_index(file_name): names_css = 'td.name-col > a.filename' all_names = world.css_find(names_css) for i in range(len(all_names)): - if file_name == all_names[i].html: + if file_name == world.css_html(names_css, index=i): return i return -1 diff --git a/common/djangoapps/terrain/ui_helpers.py b/common/djangoapps/terrain/ui_helpers.py index 6adaf5db89..615e596c91 100644 --- a/common/djangoapps/terrain/ui_helpers.py +++ b/common/djangoapps/terrain/ui_helpers.py @@ -167,6 +167,21 @@ def css_text(css_selector): return "" +@world.absorb +def css_html(css_selector, index=0, max_attempts=5): + """ + Returns the HTML of a css_selector and will retry if there is a StaleElementReferenceException + """ + assert is_css_present(css_selector) + attempt = 0 + while attempt < max_attempts: + try: + return world.browser.find_by_css(css_selector)[index].html + except: + attempt += 1 + return '' + + @world.absorb def css_visible(css_selector): assert is_css_present(css_selector)