From c53aac459697aebec81dacccc92a712a697ba367 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Mon, 8 Jul 2013 10:51:51 -0400 Subject: [PATCH] CMS acceptance tests now should not get stale element exception errors --- .../contentstore/features/advanced-settings.py | 4 ++-- .../contentstore/features/checklists.py | 2 +- cms/djangoapps/contentstore/features/common.py | 14 ++++++++++---- .../contentstore/features/course-settings.py | 2 +- .../contentstore/features/course-team.py | 2 +- .../contentstore/features/course-updates.py | 2 +- .../contentstore/features/grading.py | 12 ++++++------ .../contentstore/features/problem-editor.py | 4 ++-- .../contentstore/features/section.py | 4 ++-- cms/djangoapps/contentstore/features/signup.py | 18 ++++++++++++------ .../features/studio-overview-togglesection.py | 10 +++++----- .../contentstore/features/subsection.py | 4 ++-- cms/djangoapps/contentstore/features/video.py | 2 +- 13 files changed, 46 insertions(+), 34 deletions(-) diff --git a/cms/djangoapps/contentstore/features/advanced-settings.py b/cms/djangoapps/contentstore/features/advanced-settings.py index c08216c8e6..cdba6d9cb2 100644 --- a/cms/djangoapps/contentstore/features/advanced-settings.py +++ b/cms/djangoapps/contentstore/features/advanced-settings.py @@ -99,7 +99,7 @@ def assert_policy_entries(expected_keys, expected_values): def get_index_of(expected_key): for counter in range(len(world.css_find(KEY_CSS))): # Sometimes get stale reference if I hold on to the array of elements - key = world.css_find(KEY_CSS)[counter].value + key = world.css_value(KEY_CSS, index=counter) if key == expected_key: return counter @@ -108,7 +108,7 @@ def get_index_of(expected_key): def get_display_name_value(): index = get_index_of(DISPLAY_NAME_KEY) - return world.css_find(VALUE_CSS)[index].value + return world.css_value(VALUE_CSS, index=index) def change_display_name_value(step, new_value): diff --git a/cms/djangoapps/contentstore/features/checklists.py b/cms/djangoapps/contentstore/features/checklists.py index fe20fb9b77..13d3ca99b7 100644 --- a/cms/djangoapps/contentstore/features/checklists.py +++ b/cms/djangoapps/contentstore/features/checklists.py @@ -61,7 +61,7 @@ def i_select_a_link_to_the_course_outline(step): @step('I am brought to the course outline page$') def i_am_brought_to_course_outline(step): - assert_in('Course Outline', world.css_find('.outline .page-header')[0].text) + assert_in('Course Outline', world.css_text('.outline .page-header')) assert_equal(1, len(world.browser.windows)) diff --git a/cms/djangoapps/contentstore/features/common.py b/cms/djangoapps/contentstore/features/common.py index 61c24728f4..4d4e099c8b 100644 --- a/cms/djangoapps/contentstore/features/common.py +++ b/cms/djangoapps/contentstore/features/common.py @@ -144,10 +144,16 @@ def log_into_studio( world.is_css_present(signin_css) world.css_click(signin_css) - login_form = world.browser.find_by_css('form#login_form') - login_form.find_by_name('email').fill(email) - login_form.find_by_name('password').fill(password) - login_form.find_by_name('submit').click() + attempt = 0 + while attempt < 5: + try: + login_form = world.browser.find_by_css('form#login_form') + login_form.find_by_name('email').fill(email) + login_form.find_by_name('password').fill(password) + login_form.find_by_name('submit').click() + break + except: + attempt += 1 assert_true(world.is_css_present('.new-course-button')) diff --git a/cms/djangoapps/contentstore/features/course-settings.py b/cms/djangoapps/contentstore/features/course-settings.py index 53a3fa7870..da72d893cf 100644 --- a/cms/djangoapps/contentstore/features/course-settings.py +++ b/cms/djangoapps/contentstore/features/course-settings.py @@ -162,7 +162,7 @@ def verify_date_or_time(css, date_or_time): """ Verifies date or time field. """ - assert_equal(date_or_time, world.css_find(css).first.value) + assert_equal(date_or_time, world.css_value(css)) def i_see_the_set_dates(): diff --git a/cms/djangoapps/contentstore/features/course-team.py b/cms/djangoapps/contentstore/features/course-team.py index c126773db6..71d9d9fb02 100644 --- a/cms/djangoapps/contentstore/features/course-team.py +++ b/cms/djangoapps/contentstore/features/course-team.py @@ -47,7 +47,7 @@ def other_user_login(_step, name): @step(u's?he does( not)? see the course on (his|her) page') def see_course(_step, doesnt_see_course, gender): class_css = 'span.class-name' - all_courses = world.css_find(class_css) + all_courses = world.css_find(class_css, wait_time=1) all_names = [item.html for item in all_courses] if doesnt_see_course: assert not _COURSE_NAME in all_names diff --git a/cms/djangoapps/contentstore/features/course-updates.py b/cms/djangoapps/contentstore/features/course-updates.py index e7fbb2f90c..9506191a76 100644 --- a/cms/djangoapps/contentstore/features/course-updates.py +++ b/cms/djangoapps/contentstore/features/course-updates.py @@ -24,7 +24,7 @@ def add_update(_step, text): @step(u'I should( not)? see the update "([^"]*)"$') def check_update(_step, doesnt_see_update, text): update_css = 'div.update-contents' - update = world.css_find(update_css) + update = world.css_find(update_css, wait_time=1) if doesnt_see_update: assert len(update) == 0 or not text in update.html else: diff --git a/cms/djangoapps/contentstore/features/grading.py b/cms/djangoapps/contentstore/features/grading.py index e75d8f23ad..636722502c 100644 --- a/cms/djangoapps/contentstore/features/grading.py +++ b/cms/djangoapps/contentstore/features/grading.py @@ -90,8 +90,8 @@ def add_assignment_type(step, new_name): add_button_css = '.add-grading-data' world.css_click(add_button_css) name_id = '#course-grading-assignment-name' - f = world.css_find(name_id)[4] - f._element.send_keys(new_name) + new_assignment = world.css_find(name_id)[-1] + new_assignment._element.send_keys(new_name) @step(u'I have populated the course') @@ -118,8 +118,8 @@ def i_see_the_assignment_type(_step, name): def get_type_index(name): name_id = '#course-grading-assignment-name' - f = world.css_find(name_id) - for i in range(len(f)): - if f[i].value == name: - return i + all_types = world.css_find(name_id) + for index in range(len(all_types)): + if world.css_value(name_id, index=index) == name: + return index return -1 diff --git a/cms/djangoapps/contentstore/features/problem-editor.py b/cms/djangoapps/contentstore/features/problem-editor.py index 8691a6772e..5d12b23d90 100644 --- a/cms/djangoapps/contentstore/features/problem-editor.py +++ b/cms/djangoapps/contentstore/features/problem-editor.py @@ -169,7 +169,7 @@ def edit_latex_source(step): @step('my change to the High Level Source is persisted') def high_level_source_persisted(step): def verify_text(driver): - return world.css_find('.problem').text == 'hi' + return world.css_text('.problem') == 'hi' world.wait_for(verify_text) @@ -177,7 +177,7 @@ def high_level_source_persisted(step): @step('I view the High Level Source I see my changes') def high_level_source_in_editor(step): open_high_level_source() - assert_equal('hi', world.css_find('.source-edit-box').value) + assert_equal('hi', world.css_value('.source-edit-box')) def verify_high_level_source_links(step, visible): diff --git a/cms/djangoapps/contentstore/features/section.py b/cms/djangoapps/contentstore/features/section.py index 93fa0adf3e..4b69b9b37e 100644 --- a/cms/djangoapps/contentstore/features/section.py +++ b/cms/djangoapps/contentstore/features/section.py @@ -70,7 +70,7 @@ def i_click_to_edit_section_name(_step): def i_see_complete_section_name_with_quote_in_editor(_step): css = '.section-name-edit input[type=text]' assert world.is_css_present(css) - assert_equal(world.browser.find_by_css(css).value, 'Section with "Quote"') + assert_equal(world.css_value(css), 'Section with "Quote"') @step('the section does not exist$') @@ -85,7 +85,7 @@ def i_see_a_release_date_for_my_section(_step): css = 'span.published-status' assert world.is_css_present(css) - status_text = world.browser.find_by_css(css).text + status_text = world.css_text(css) # e.g. 11/06/2012 at 16:25 msg = 'Will Release:' diff --git a/cms/djangoapps/contentstore/features/signup.py b/cms/djangoapps/contentstore/features/signup.py index 398f8d074d..be396c8699 100644 --- a/cms/djangoapps/contentstore/features/signup.py +++ b/cms/djangoapps/contentstore/features/signup.py @@ -7,12 +7,18 @@ from common import * @step('I fill in the registration form$') def i_fill_in_the_registration_form(step): - register_form = world.browser.find_by_css('form#register_form') - register_form.find_by_name('email').fill('robot+studio@edx.org') - register_form.find_by_name('password').fill('test') - register_form.find_by_name('username').fill('robot-studio') - register_form.find_by_name('name').fill('Robot Studio') - register_form.find_by_name('terms_of_service').check() + attempt = 0 + while attempt < 5: + try: + register_form = world.browser.find_by_css('form#register_form') + register_form.find_by_name('email').fill('robot+studio@edx.org') + register_form.find_by_name('password').fill('test') + register_form.find_by_name('username').fill('robot-studio') + register_form.find_by_name('name').fill('Robot Studio') + register_form.find_by_name('terms_of_service').check() + break + except: + attempt += 1 @step('I press the Create My Account button on the registration form$') diff --git a/cms/djangoapps/contentstore/features/studio-overview-togglesection.py b/cms/djangoapps/contentstore/features/studio-overview-togglesection.py index 1fbd965871..9ab17fbdac 100644 --- a/cms/djangoapps/contentstore/features/studio-overview-togglesection.py +++ b/cms/djangoapps/contentstore/features/studio-overview-togglesection.py @@ -92,7 +92,7 @@ def i_expand_a_section(step): def i_see_the_span_with_text(step, text): span_locator = '.toggle-button-sections span' assert_true(world.is_css_present(span_locator)) - assert_equal(world.css_find(span_locator).value, text) + assert_equal(world.css_value(span_locator), text) assert_true(world.css_visible(span_locator)) @@ -108,13 +108,13 @@ def i_do_not_see_the_span_with_text(step, text): def all_sections_are_expanded(step): subsection_locator = 'div.subsection-list' subsections = world.css_find(subsection_locator) - for s in subsections: - assert_true(s.visible) + for index in range(len(subsections)): + assert_true(world.css_visible(subsection_locator, index=index)) @step(u'all sections are collapsed$') def all_sections_are_collapsed(step): subsection_locator = 'div.subsection-list' subsections = world.css_find(subsection_locator) - for s in subsections: - assert_false(s.visible) + for index in range(len(subsections)): + assert_false(world.css_visible(subsection_locator, index=index)) diff --git a/cms/djangoapps/contentstore/features/subsection.py b/cms/djangoapps/contentstore/features/subsection.py index 1134e53280..e280ec615d 100644 --- a/cms/djangoapps/contentstore/features/subsection.py +++ b/cms/djangoapps/contentstore/features/subsection.py @@ -50,7 +50,7 @@ def i_click_to_edit_subsection_name(step): def i_see_complete_subsection_name_with_quote_in_editor(step): css = '.subsection-display-name-input' assert world.is_css_present(css) - assert_equal(world.css_find(css).value, 'Subsection With "Quote"') + assert_equal(world.css_value(css), 'Subsection With "Quote"') @step('I have set a release date and due date in different years$') @@ -69,7 +69,7 @@ def i_mark_it_as_homework(step): @step('I see it marked as Homework$') def i_see_it_marked__as_homework(step): - assert_equal(world.css_find(".status-label").value, 'Homework') + assert_equal(world.css_value(".status-label"), 'Homework') ############ ASSERTIONS ################### diff --git a/cms/djangoapps/contentstore/features/video.py b/cms/djangoapps/contentstore/features/video.py index 190f8e9f1e..cb59193f17 100644 --- a/cms/djangoapps/contentstore/features/video.py +++ b/cms/djangoapps/contentstore/features/video.py @@ -8,7 +8,7 @@ from lettuce import world, step @step('when I view the video it does not have autoplay enabled') def does_not_autoplay(_step): assert world.css_find('.video')[0]['data-autoplay'] == 'False' - assert world.css_find('.video_control')[0].has_class('play') + assert world.css_has_class('.video_control', 'play') @step('creating a video takes a single click')