""" Problem Page. """ from bok_choy.page_object import PageObject from selenium.webdriver.common.keys import Keys from common.test.acceptance.pages.common.utils import click_css class ProblemPage(PageObject): """ View of problem page. """ url = None CSS_PROBLEM_HEADER = '.problem-header' def is_browser_on_page(self): return self.q(css='.xblock-student_view').present @property def problem_name(self): """ Return the current problem name. """ self.wait_for_element_visibility(self.CSS_PROBLEM_HEADER, 'wait for problem header') return self.q(css='.problem-header').text[0] @property def problem_text(self): """ Return the text of the question of the problem. """ return self.q(css="div.problem p").text @property def problem_input_content(self): """ Return the text of the question of the problem. """ return self.q(css="div.wrapper-problem-response").text[0] @property def problem_content(self): """ Return the content of the problem """ return self.q(css="div.problems-wrapper").text[0] @property def problem_meta(self): """ Return the problem meta text """ return self.q(css=".problems-wrapper .problem-progress").text[0] @property def message_text(self): """ Return the "message" text of the question of the problem. """ return self.q(css="div.problem span.message").text[0] @property def extract_hint_text_from_html(self): """ Return the "hint" text of the problem from html """ hints_html = self.q(css="div.problem .notification-hint .notification-message li").html return [hint_html.split(' element: Problem clarification text hidden by an icon in rendering Text """ self.q(css='div.problem .clarification:nth-child({index}) span[data-tooltip]'.format(index=index + 1)).click() @property def visible_tooltip_text(self): """ Get the text seen in any tooltip currently visible on the page. """ self.wait_for_element_visibility('body > .tooltip', 'A tooltip is visible.') return self.q(css='body > .tooltip').text[0] def is_solution_tag_present(self): """ Check if solution/explanation is shown. """ solution_selector = '.solution-span div.detailed-solution' return self.q(css=solution_selector).is_present() def is_choice_highlighted(self, choice, choices_list): """ Check if the given answer/choice is highlighted for choice group. """ choice_status_xpath = ('//fieldset/div[contains(@class, "field")][{{0}}]' '/label[contains(@class, "choicegroup_{choice}")]' '/span[contains(@class, "status {choice}")]'.format(choice=choice)) any_status_xpath = '//fieldset/div[contains(@class, "field")][{0}]/label/span' for choice in choices_list: if not self.q(xpath=choice_status_xpath.format(choice)).is_present(): return False # Check that there is only a single status span, as there were some bugs with multiple # spans (with various classes) being appended. if not len(self.q(xpath=any_status_xpath.format(choice)).results) == 1: return False return True def is_correct_choice_highlighted(self, correct_choices): """ Check if correct answer/choice highlighted for choice group. """ return self.is_choice_highlighted('correct', correct_choices) def is_submitted_choice_highlighted(self, correct_choices): """ Check if submitted answer/choice highlighted for choice group. """ return self.is_choice_highlighted('submitted', correct_choices) @property def problem_question(self): """ Return the question text of the problem. """ return self.q(css="div.problem .wrapper-problem-response legend").text[0] @property def problem_question_descriptions(self): """ Return a list of question descriptions of the problem. """ return self.q(css="div.problem .wrapper-problem-response .question-description").text @property def problem_progress_graded_value(self): """ Return problem progress text which contains weight of problem, if it is graded, and the student's current score. """ self.wait_for_element_visibility('.problem-progress', "Problem progress is visible") return self.q(css='.problem-progress').text[0] @property def status_sr_text(self): """ Returns the text in the special "sr" region used for display status. """ return self.q(css='#reader-feedback').text[0]