Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SE-1917 Replace hacky sleeps with webdriver waits #275

Merged
merged 3 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions problem_builder/tests/integration/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
import time

import mock
from xblock.fields import String
from xblockutils.base_test import SeleniumBaseTest, SeleniumXBlockTest
Expand All @@ -45,35 +43,31 @@ def popup_check(self, mentoring, item_feedbacks, prefix='', do_submit=True):
submit = mentoring.find_element_by_css_selector('.submit input.input-main')

for index, expected_feedback in enumerate(item_feedbacks):
# TODO: replace time.sleep with waiting for elements the selenium way
time.sleep(2)

self.wait_until_exists(prefix + " .choice")
choice_wrapper = mentoring.find_elements_by_css_selector(prefix + " .choice")[index]
if do_submit:
# clicking on actual radio button
self.wait_until_exists(".choice-selector input")
choice_wrapper.find_element_by_css_selector(".choice-selector input").click()
submit.click()
self.wait_until_disabled(submit)
# XXX: temporary workaround; replace sleep with selenium wait for element
time.sleep(3)
self.wait_until_exists(".choice-result")
item_feedback_icon = choice_wrapper.find_element_by_css_selector(".choice-result")
# XXX: temporary workaround; replace sleep with selenium wait for element
time.sleep(3)
self.wait_until_clickable(item_feedback_icon)
item_feedback_icon.click() # clicking on item feedback icon
# XXX: temporary workaround; replace sleep with selenium wait for element
time.sleep(3)
self.wait_until_exists(".choice-tips")
item_feedback_popup = choice_wrapper.find_element_by_css_selector(".choice-tips")
self.assertTrue(item_feedback_popup.is_displayed())
self.assertEqual(item_feedback_popup.text, expected_feedback)

self.wait_until_clickable(item_feedback_popup)
item_feedback_popup.click()
# XXX: temporary workaround; replace sleep with selenium wait for element
time.sleep(3)
self.wait_until_visible(item_feedback_popup)
self.assertTrue(item_feedback_popup.is_displayed())

mentoring.find_element_by_css_selector('.title').click()
# XXX: temporary workaround; replace sleep with selenium wait for element
time.sleep(3)
self.wait_until_hidden(item_feedback_popup)
self.assertFalse(item_feedback_popup.is_displayed())


Expand Down Expand Up @@ -135,9 +129,17 @@ def click_choice(self, container, choice_text):
break

def expect_checkmark_visible(self, visible):
if visible:
self.wait_until_visible(self.checkmark)
else:
self.wait_until_hidden(self.checkmark)
self.assertEqual(self.checkmark.is_displayed(), visible)

def expect_submit_enabled(self, enabled):
if enabled:
self.wait_until_clickable(self.submit_button)
else:
self.wait_until_disabled(self.submit_button)
self.assertEqual(self.submit_button.is_enabled(), enabled)


Expand Down
4 changes: 0 additions & 4 deletions problem_builder/tests/integration/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

# Imports ###########################################################

import time

from .base_test import (GetChoices, MentoringAssessmentBaseTest,
ProblemBuilderBaseTest)

Expand Down Expand Up @@ -98,8 +96,6 @@ def test_simple_flow(self):
# The checkbox should be checked (since that's the value we submitted earlier),
# and "Submit" should be disabled (to discourage submitting the same answer):
self.expect_checkbox_checked(True)
# XXX: hack; use web driver wait correctly
time.sleep(3)
self.expect_checkmark_visible(True)
self.expect_submit_enabled(False)

Expand Down
14 changes: 6 additions & 8 deletions problem_builder/tests/integration/test_step_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,27 @@ def peek_at_review(self, step_builder, controls, expected, extended_feedback=Fal

def popup_check(self, step_builder, item_feedbacks, prefix='', do_submit=True):
for index, expected_feedback in enumerate(item_feedbacks):
# TODO: replace time.sleep with waiting for elements the selenium way
time.sleep(2)

self.wait_until_exists(prefix + " .choice")
self.wait_until_exists(prefix + " .choice .choice-label")
choice_wrapper = step_builder.find_elements_by_css_selector(prefix + " .choice")[index]
choice_label = step_builder.find_elements_by_css_selector(prefix + " .choice .choice-label")[index]
choice_label.click()
time.sleep(2)

self.wait_until_exists(".choice-result")
item_feedback_icon = choice_wrapper.find_element_by_css_selector(".choice-result")
item_feedback_icon.click()
time.sleep(2)

self.wait_until_exists(".choice-tips")
item_feedback_popup = choice_wrapper.find_element_by_css_selector(".choice-tips")
self.assertTrue(item_feedback_popup.is_displayed())
self.assertEqual(item_feedback_popup.text, expected_feedback)

item_feedback_popup.click()
time.sleep(2)
self.assertTrue(item_feedback_popup.is_displayed())

step_builder.find_elements_by_css_selector(prefix + ' .question-title')[0].click()
time.sleep(2)
self.wait_until_hidden(item_feedback_popup)
self.assertFalse(item_feedback_popup.is_displayed())

def extended_feedback_checks(self, step_builder, controls, expected_results):
Expand Down Expand Up @@ -811,8 +810,7 @@ def check_quadrant_labels(self, step_builder, plot_controls, hidden, labels=['Q1

def click_overlay_button(self, overlay_button, overlay_on, color_on=None, color_off=HTMLColors.GREY):
overlay_button.click()
# XXX: hack; actually wait for change
time.sleep(3)
time.sleep(3) # give some time for changes
button_border_colors = [
overlay_button.value_of_css_property('border-top-color'),
overlay_button.value_of_css_property('border-right-color'),
Expand Down