def test_auto_chomsky(): '''Standard tests.''' line = chomsky() assert(len(line) >= 1), 'Someone broke Chomsky' line = chomsky(1, 72) assert(len(line) >= 1), 'Someone else broke Chomsky' lines = chomsky(4, 50) assert(len(lines) >= 1), 'Someone got tired of hearing Chomsky'
def setUp(self): """Pretest settings.""" self.ps = PastaSauce() self.desired_capabilities['name'] = self.id() self.teacher = Teacher(use_env_vars=True, pasta_user=self.ps, capabilities=self.desired_capabilities) # create a reading for the student to work self.teacher.login() self.teacher.driver.execute_script("window.resizeTo(1920,1080)") self.teacher.select_course(appearance='ap_biology') self.assignment_name = 't1.18 reading-%s' % randint(100, 999) today = datetime.date.today() begin = today.strftime('%m/%d/%Y') end = (today + datetime.timedelta(days=randint(1, 10))) \ .strftime('%m/%d/%Y') self.teacher.add_assignment(assignment='reading', args={ 'title': self.assignment_name, 'description': chomsky(), 'periods': { 'all': (begin, end) }, 'reading_list': ['1.1'], 'status': 'publish', }) self.teacher.wait.until( expect.visibility_of_element_located( (By.XPATH, '//div[contains(@class,"calendar-container")]'))) self.teacher.logout() # login as a student to work the reading self.student = Student(existing_driver=self.teacher.driver, use_env_vars=True, pasta_user=self.ps, capabilities=self.desired_capabilities) self.student.login() self.student.select_course(appearance='ap_biology') self.student.wait.until( expect.visibility_of_element_located((By.LINK_TEXT, 'This Week'))) reading = self.student.driver.find_element( By.XPATH, '//div[text()="%s"]' % self.assignment_name) self.teacher.driver.execute_script( 'return arguments[0].scrollIntoView();', reading) self.teacher.driver.execute_script('window.scrollBy(0, -80);') reading.click() self.student.driver.set_window_size(width=1300, height=1200)
def answer_assessment(self): """Answer a Tutor assessment.""" self.wait.until( expect.presence_of_element_located( (By.CLASS_NAME, 'openstax-question') ) ) text = chomsky(1, 500) wt = self.wait_time try: self.change_wait_time(3) text_block = self.driver.find_element(By.XPATH, '//textarea') self.change_wait_time(wt) print('Enter free response') Assignment.send_keys(self.driver, text_block, text) self.driver.find_element(By.CLASS_NAME, 'continue').click() except Exception: self.change_wait_time(wt) print('Skip free response') finally: self.page.wait_for_page_load() answers = self.driver.find_elements(By.CLASS_NAME, 'answer-letter') self.sleep(0.8) rand = randint(0, len(answers) - 1) answer = chr(ord('a') + rand) print('Selecting %s' % answer) Assignment.scroll_to(self.driver, answers[0]) if answer == 'a': self.driver.execute_script('window.scrollBy(0, -160);') elif answer == 'd': self.driver.execute_script('window.scrollBy(0, 160);') answers[rand].click() self.sleep(1.0) self.wait.until( expect.element_to_be_clickable( (By.XPATH, '//button[span[text()="Submit"]]') ) ).click() self.wait.until( expect.element_to_be_clickable( (By.CLASS_NAME, 'continue') ) ).click() self.page.wait_for_page_load()
def answer_assessment(self): """Answer a Tutor assessment.""" self.wait.until( expect.presence_of_element_located( (By.CLASS_NAME, 'openstax-question') ) ) text = chomsky(1, 500) wt = self.wait_time try: self.change_wait_time(3) text_block = self.find(By.XPATH, '//textarea') self.change_wait_time(wt) print('Enter free response') Assignment.send_keys(self.driver, text_block, text) self.find(By.CLASS_NAME, 'continue').click() except Exception: self.change_wait_time(wt) print('Skip free response') finally: self.page.wait_for_page_load() answers = self.find_all(By.CLASS_NAME, 'answer-letter') self.sleep(0.8) rand = randint(0, len(answers) - 1) answer = chr(ord('a') + rand) print('Selecting %s' % answer) Assignment.scroll_to(self.driver, answers[0]) if answer == 'a': self.driver.execute_script('window.scrollBy(0, -160);') elif answer == 'd': self.driver.execute_script('window.scrollBy(0, 160);') answers[rand].click() self.sleep(1.0) self.wait.until( expect.element_to_be_clickable( (By.XPATH, '//button[span[text()="Submit"]]') ) ).click() self.wait.until( expect.element_to_be_clickable( (By.CLASS_NAME, 'continue') ) ).click() self.page.wait_for_page_load()
def test_a_user_may_submit_a_message(web_base_url, selenium): """A user may use the contact form to message OpenStax.""" # GIVEN: a user viewing the contact form page topic = Web.TOPICS[Utility.random(end=len(Web.TOPICS) - 1)] _, first, last, _ = Utility.random_name() email = RestMail('{first}.{last}.{id}'.format( first=first, last=last, id=Utility.random_hex(5)).lower()) email.empty() message = chomsky(Utility.random(1, 3)) home = WebHome(selenium, web_base_url).open() contact = home.footer.directory.contact_us() # WHEN: they select a question topic from the drop down # menu # AND: enter a name # AND: enter an e-mail address # AND: enter a message # AND: click on the "Send" button contact.form.topic = topic contact.form.name = '{0} {1}'.format(first, last) contact.form.email = email.address contact.form.message = message confirmation = contact.form.send() # THEN: the contact confirmation page is displayed # AND: a "Thank you for contacting OpenStax!" email is # received assert (confirmation.is_displayed()) assert ('confirmation' in confirmation.location) ''' auto-emails are disabled in the TutorQA sandbox email.wait_for_mail(60) assert('Thank you for contacting OpenStax!' in email.get_mail[-1].subject)''' # WHEN: they click on the "Check out our subjects" # button subjects = confirmation.view_subjects() # THEN: the subjects page is displayed assert (subjects.is_displayed()) assert ('subjects' in subjects.location)
def setUp(self): """Pretest settings.""" self.ps = PastaSauce() self.desired_capabilities["name"] = self.id() self.teacher = Teacher(use_env_vars=True, pasta_user=self.ps, capabilities=self.desired_capabilities) # create a reading for the student to work self.teacher.login() self.assignment_name = "t1.18 reading-%s" % randint(100, 999) today = datetime.date.today() begin = today.strftime("%m/%d/%Y") end = (today + datetime.timedelta(days=randint(1, 10))).strftime("%m/%d/%Y") self.teacher.add_assignment( assignment="reading", args={ "title": self.assignment_name, "description": chomsky(), "periods": {"all": (begin, end)}, "reading_list": ["1.1", "1.2"], "status": "publish", }, ) self.teacher.wait.until( expect.visibility_of_element_located((By.XPATH, '//div[contains(@class,"calendar-container")]')) ) self.teacher.logout() # login as a student to work the reading self.student = Student( existing_driver=self.teacher.driver, use_env_vars=True, pasta_user=self.ps, capabilities=self.desired_capabilities, ) self.student.login() self.student.wait.until(expect.visibility_of_element_located((By.LINK_TEXT, "This Week"))) reading = self.student.driver.find_element(By.XPATH, '//span[text()="%s"]' % self.assignment_name) self.teacher.driver.execute_script("return arguments[0].scrollIntoView();", reading) self.teacher.driver.execute_script("window.scrollBy(0, -80);") reading.click()
def test_student_select_an_exercise_answer_7691(self): """Select an exercise answer.""" self.ps.test_updates['name'] = 'cc1.08.001' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = ['cc1', 'cc1.08', 'cc1.08.001', '7691'] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.get(self.book_url) self.student.sleep(2) self.student.find_all(By.XPATH, '//a[@class="nav next"]')[0].click() self.student.page.wait_for_page_load() try: widget = self.student.find(By.ID, 'coach-wrapper') except: self.student.find_all(By.XPATH, '//a[@class="nav next"]')[0].click() self.student.page.wait_for_page_load() try: self.student.sleep(1) widget = self.student.find(By.ID, 'coach-wrapper') except: self.student.find_all(By.XPATH, '//a[@class="nav next"]')[0].click() self.student.page.wait_for_page_load() self.student.sleep(1) widget = self.student.find(By.ID, 'coach-wrapper') Assignment.scroll_to(self.student.driver, widget) self.student.find( By.XPATH, '//button[span[contains(text(),"Launch Concept Coach")]]').click() self.student.sleep(1.5) base_window = self.student.driver.window_handles[0] self.student.find(By.CSS_SELECTOR, 'div.sign-up').click() self.student.sleep(3) popup = self.student.driver.window_handles[1] self.student.driver.switch_to_window(popup) self.student.find(By.LINK_TEXT, 'Sign up').click() self.student.find(By.ID, 'identity-login-button').click() self.student.find(By.ID, 'signup_first_name').send_keys(self.first_name) self.student.find(By.ID, 'signup_last_name').send_keys(self.last_name) self.student.find(By.ID, 'signup_email_address').send_keys(self.email) self.student.find(By.ID, 'signup_username').send_keys(self.last_name) self.student.find(By.ID, 'signup_password').send_keys(self.student.password) self.student.find(By.ID, 'signup_password_confirmation').send_keys( self.student.password) self.student.find(By.ID, 'create_account_submit').click() self.student.find(By.ID, 'i_agree').click() self.student.find(By.ID, 'agreement_submit').click() self.student.find(By.ID, 'i_agree').click() self.student.find(By.ID, 'agreement_submit').click() self.student.driver.switch_to_window(base_window) self.student.find( By.XPATH, '//input[contains(@label,"Enter the enrollment code")]').send_keys( self.code) self.student.sleep(2) self.student.find(By.CSS_SELECTOR, 'button.enroll').click() self.student.sleep(2) self.student.find(By.CSS_SELECTOR, 'div.field input.form-control').send_keys( self.last_name) self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.student.sleep(5) try: self.student.find(By.XPATH, '//button[text()="Continue"]').click() except: print('Two-step message not seen.') self.student.wait.until( expect.element_to_be_clickable( (By.XPATH, '//div[@class="openstax-question"]//textarea'))).send_keys( chomsky()) self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.student.wait.until( expect.visibility_of_element_located( (By.XPATH, '//div[@class="answer-letter"]'))) answers = self.student.find_all(By.CSS_SELECTOR, 'div.answer-letter') answers[randint(0, len(answers) - 1)].click() self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.ps.test_updates['passed'] = True
def test_student_view_section_completion_report_7732(self): """View section completion report. Steps: Go to Tutor Click on the 'Login' button Enter the student user account in the username and password text boxes Click on the 'Sign in' button If the user has more than one course, click on a CC course name Click on "Contents" Select a section Scroll to bottom of the section Click "Launch Concept Coach" Enter a response into the free response text box Click "Answer" Select a multiple choice answer Click "Submit" Click "Next question" Continue answering questions Expected Result: The user is presented with section completion report that shows "You're done" """ self.ps.test_updates['name'] = 'cc1.09.001' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = ['cc1', 'cc1.09', 'cc1.09.001', '7732'] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.sleep(5) self.student.find(By.XPATH, "//button[@class='toggle btn']").click() self.student.sleep(3) self.student.find( By.XPATH, "//div/ul/li[2]/ul/li[2]/div/span[@class='name-wrapper']" + "/a/span[@class='title']").click() self.student.sleep(1) self.student.find( By.XPATH, "//div[@class='jump-to-cc']/a[@class='btn']").click() self.student.sleep(1) self.student.find(By.XPATH, "//button[@class='btn btn-lg btn-primary']").click() self.student.sleep(5) page = self.student.driver.page_source # Work through Concept Coach while 'or review your work below.' not in page: # Free response try: self.student.find(By.TAG, 'textarea').send_keys(chomsky()) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass # Multiple choice try: answers = self.student.find_all(By.CSS_SELECTOR, 'div.answer-letter') if not isinstance(answers, list): Assignment.scroll_to(self.student.driver, answers) answers.click() else: Assignment.scroll_to(self.student.driver, answers[0]) answers[randint(0, len(answers) - 1)].click() self.student.sleep(0.2) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass self.student.sleep(2) page = self.student.driver.page_source self.ps.test_updates['passed'] = True
def test_student_completion_report_shows_the_section_status_of_7733(self): """Completion report shows the section status. Steps: Click on "Contents" Select a section Scroll to bottom of the section Click "Launch Concept Coach" Enter a response into the free response text box Click "Answer" Select a multiple choice answer Click "Submit" Click "Next question" Continue answering questions Expected Result: The user is presented with the completion report, which shows the section status of completed modules """ self.ps.test_updates['name'] = 'cc1.09.002' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = ['cc1', 'cc1.09', 'cc1.09.002', '7733'] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.find(By.CSS_SELECTOR, 'div.media-nav button').click() self.student.sleep(1) self.student.find(By.XPATH, '//a[span[text()="1.2"]]').click() self.student.sleep(1) self.student.find(By.CSS_SELECTOR, 'div.jump-to-cc a').click() self.student.sleep(0.5) self.student.find(By.CSS_SELECTOR, 'div.concept-coach-launcher button').click() try: self.student.find(By.XPATH, '//button[text()="Continue"]').click() except: print('Two-step message not seen.') # Go to the first question ids = 0 self.student.find(By.XPATH, "//div[@class='task-breadcrumbs']/span").click() # Work through Concept Coach page = self.student.driver.page_source while 'or review your work below.' not in page: self.student.find( By.XPATH, "//span[@class='exercise-identifier-link']/span[2]") ids += 1 action = False # Free response try: self.student.find(By.TAG, 'textarea').send_keys(chomsky()) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass # Multiple choice try: answers = self.student.find_all(By.CSS_SELECTOR, 'div.answer-letter') if not isinstance(answers, list): Assignment.scroll_to(self.student.driver, answers) answers.click() else: Assignment.scroll_to(self.student.driver, answers[0]) answers[randint(0, len(answers) - 1)].click() self.student.sleep(0.2) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass self.student.sleep(2) page = self.student.driver.page_source self.student.sleep(5) section_id = self.student.find( By.CSS_SELECTOR, 'h3.chapter-section-prefix').get_attribute('data-section') problem_id = self.student.find( By.XPATH, '//span[contains(@data-reactid,"help-links.1")]').text assert(section_id == problem_id), \ 'Section ID does not match the problem ID' self.ps.test_updates['passed'] = True
def test_student_select_an_exercise_answer_7691(self): """Select an exercise answer.""" self.ps.test_updates['name'] = 'cc1.08.001' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = [ 'cc1', 'cc1.08', 'cc1.08.001', '7691' ] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.get(self.book_url) self.student.sleep(2) self.student.find_all(By.XPATH, '//a[@class="nav next"]')[0].click() self.student.page.wait_for_page_load() try: widget = self.student.find(By.ID, 'coach-wrapper') except: self.student.find_all(By.XPATH, '//a[@class="nav next"]')[0].click() self.student.page.wait_for_page_load() try: self.student.sleep(1) widget = self.student.find(By.ID, 'coach-wrapper') except: self.student.find_all(By.XPATH, '//a[@class="nav next"]')[0].click() self.student.page.wait_for_page_load() self.student.sleep(1) widget = self.student.find(By.ID, 'coach-wrapper') Assignment.scroll_to(self.student.driver, widget) self.student.find( By.XPATH, '//button[span[contains(text(),"Launch Concept Coach")]]' ).click() self.student.sleep(1.5) base_window = self.student.driver.window_handles[0] self.student.find(By.CSS_SELECTOR, 'div.sign-up').click() self.student.sleep(3) popup = self.student.driver.window_handles[1] self.student.driver.switch_to_window(popup) self.student.find(By.LINK_TEXT, 'Sign up').click() self.student.find(By.ID, 'identity-login-button').click() self.student.find( By.ID, 'signup_first_name' ).send_keys(self.first_name) self.student.find(By.ID, 'signup_last_name').send_keys(self.last_name) self.student.find(By.ID, 'signup_email_address').send_keys(self.email) self.student.find(By.ID, 'signup_username').send_keys(self.last_name) self.student.find( By.ID, 'signup_password' ).send_keys(self.student.password) self.student.find( By.ID, 'signup_password_confirmation' ).send_keys(self.student.password) self.student.find(By.ID, 'create_account_submit').click() self.student.find(By.ID, 'i_agree').click() self.student.find(By.ID, 'agreement_submit').click() self.student.find(By.ID, 'i_agree').click() self.student.find(By.ID, 'agreement_submit').click() self.student.driver.switch_to_window(base_window) self.student.find( By.XPATH, '//input[contains(@label,"Enter the enrollment code")]' ).send_keys(self.code) self.student.sleep(2) self.student.find(By.CSS_SELECTOR, 'button.enroll').click() self.student.sleep(2) self.student.find( By.CSS_SELECTOR, 'div.field input.form-control' ).send_keys(self.last_name) self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.student.sleep(5) try: self.student.find(By.XPATH, '//button[text()="Continue"]').click() except: print('Two-step message not seen.') self.student.wait.until( expect.element_to_be_clickable( (By.XPATH, '//div[@class="openstax-question"]//textarea') ) ).send_keys(chomsky()) self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.student.wait.until( expect.visibility_of_element_located( (By.XPATH, '//div[@class="answer-letter"]') ) ) answers = self.student.find_all(By.CSS_SELECTOR, 'div.answer-letter') answers[randint(0, len(answers) - 1)].click() self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.student.find(By.CSS_SELECTOR, 'button.async-button').click() self.ps.test_updates['passed'] = True
def test_student_view_section_completion_report_7732(self): """View section completion report. Steps: Go to Tutor Click on the 'Login' button Enter the student user account in the username and password text boxes Click on the 'Sign in' button If the user has more than one course, click on a CC course name Click on "Contents" Select a section Scroll to bottom of the section Click "Launch Concept Coach" Enter a response into the free response text box Click "Answer" Select a multiple choice answer Click "Submit" Click "Next question" Continue answering questions Expected Result: The user is presented with section completion report that shows "You're done" """ self.ps.test_updates['name'] = 'cc1.09.001' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = [ 'cc1', 'cc1.09', 'cc1.09.001', '7732' ] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.sleep(5) self.student.find(By.XPATH, "//button[@class='toggle btn']").click() self.student.sleep(3) self.student.find( By.XPATH, "//div/ul/li[2]/ul/li[2]/div/span[@class='name-wrapper']" + "/a/span[@class='title']").click() self.student.sleep(1) self.student.find( By.XPATH, "//div[@class='jump-to-cc']/a[@class='btn']").click() self.student.sleep(1) self.student.find( By.XPATH, "//button[@class='btn btn-lg btn-primary']").click() self.student.sleep(5) page = self.student.driver.page_source # Work through Concept Coach while 'or review your work below.' not in page: # Free response try: self.student.find(By.TAG, 'textarea').send_keys(chomsky()) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass # Multiple choice try: answers = self.student.find_all(By.CSS_SELECTOR, 'div.answer-letter') if not isinstance(answers, list): Assignment.scroll_to(self.student.driver, answers) answers.click() else: Assignment.scroll_to(self.student.driver, answers[0]) answers[randint(0, len(answers) - 1)].click() self.student.sleep(0.2) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass self.student.sleep(2) page = self.student.driver.page_source self.ps.test_updates['passed'] = True
def test_student_completion_report_shows_the_section_status_of_7733(self): """Completion report shows the section status. Steps: Click on "Contents" Select a section Scroll to bottom of the section Click "Launch Concept Coach" Enter a response into the free response text box Click "Answer" Select a multiple choice answer Click "Submit" Click "Next question" Continue answering questions Expected Result: The user is presented with the completion report, which shows the section status of completed modules """ self.ps.test_updates['name'] = 'cc1.09.002' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = [ 'cc1', 'cc1.09', 'cc1.09.002', '7733' ] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.find(By.CSS_SELECTOR, 'div.media-nav button').click() self.student.sleep(1) self.student.find(By.XPATH, '//a[span[text()="1.2"]]').click() self.student.sleep(1) self.student.find(By.CSS_SELECTOR, 'div.jump-to-cc a').click() self.student.sleep(0.5) self.student.find( By.CSS_SELECTOR, 'div.concept-coach-launcher button' ).click() try: self.student.find(By.XPATH, '//button[text()="Continue"]').click() except: print('Two-step message not seen.') # Work through Concept Coach page = self.student.driver.page_source while 'or review your work below.' not in page: # Free response try: self.student.find(By.TAG, 'textarea').send_keys(chomsky()) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass # Multiple choice try: answers = self.student.find_all(By.CSS_SELECTOR, 'div.answer-letter') if not isinstance(answers, list): Assignment.scroll_to(self.student.driver, answers) answers.click() else: Assignment.scroll_to(self.student.driver, answers[0]) answers[randint(0, len(answers) - 1)].click() self.student.sleep(0.2) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) self.student.find(By.CSS_SELECTOR, 'button.continue').click() self.student.sleep(0.3) except: pass self.student.sleep(2) page = self.student.driver.page_source self.student.sleep(5) section_id = self.student.find( By.CSS_SELECTOR, 'h3.chapter-section-prefix' ).get_attribute('data-section') problem_id = self.student.find( By.XPATH, '//span[contains(@data-reactid,"help-links.1")]' ).text assert(section_id == problem_id), \ 'Section ID does not match the problem ID' self.ps.test_updates['passed'] = True