class EntrySeleleniumTests(StaticLiveServerTestCase): """Selenium tests for the entry form""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if not settings.DEBUG: settings.DEBUG = True def setUp(self): """Handles login and things""" call_command('flush', interactive=False, verbosity=0) # Clears db call_command('loaddata', 'groups', commit=False, verbosity=0) call_command('loaddata', 'school', commit=False, verbosity=0) call_command('loaddata', 'permissions', commit=False, verbosity=0) call_command('loaddata', 'auth_users', commit=False, verbosity=0) call_command('loaddata', 'student', commit=False, verbosity=0) call_command('loaddata', 'advisor', commit=False, verbosity=0) call_command('loaddata', 'coordinator', commit=False, verbosity=0) call_command('loaddata', 'activityoptions', commit=False, verbosity=0) call_command('loaddata', 'learningobjectiveoptions', commit=False, verbosity=0) call_command('loaddata', 'sample_entries', commit=False, verbosity=0) self.selenium = WebDriver() self.selenium.set_window_size(1024, 800) self.selenium.get('{0}/{1}'.format(self.live_server_url, '')) self.selenium.find_element_by_xpath('//*[@id="djHideToolBarButton"]').click() self.selenium.implicitly_wait(10) self.selenium.find_element_by_link_text('Login').click() # Click on the student button in the gateway self.selenium.find_element_by_xpath('/html/body/center/md-content/div/div/div[1]/a').click() self.selenium\ .find_element_by_xpath("//img[@src='/static/journal/activities/img" "/journal_sign.png']") super() def tearDown(self): self.selenium.quit() super() def test_text_entry(self): """Test to ensure that a student can add a text entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) # Insert text entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(entry) # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(entry in box_text) def test_image_entry(self): """Test to ensure that a student can add an image entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[2]').click() entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(entry) # click on the inset image button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.implicitly_wait(10) self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists on the page. self.selenium.find_element_by_xpath("//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']") def test_video_entry(self): """Test to ensure that a student can add a video entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) # Insert video self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[3]').click() entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(entry) # click on the insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.implicitly_wait(10) self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') self.selenium.find_element_by_xpath('//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') def test_image_text_entry(self): """Test to ensure that a student can add image+text entries""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) # Insert text entry = 'I think I will bring my cat out next time with a flower.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(entry) # Insert the image self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[2]').click() image_entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(image_entry) # Click on the insert image button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.implicitly_wait(10) self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure the text is on the entries page box_text = self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(entry in box_text) # Ensure the image is on the entries page self.selenium.find_element_by_xpath("//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']") def test_video_text_entry(self): """Test to ensure that a student can add an text+video entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) # Insert text entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(entry) # Insert video self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[3]').click() video_entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(video_entry) # Click on the insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button')\ .click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a/div')\ .text self.assertTrue(entry in box_text) self.selenium.find_element_by_xpath('//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') def test_text_image_video_entry(self): """Test to ensure that a student can add an text+image+video entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) # Insert text text_entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(text_entry) # Insert image button self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[2]').click() image_entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(image_entry) # Click on the inset image button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[3]').click() video_entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(video_entry) # Click on the insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(text_entry in box_text) self.selenium.find_element_by_xpath("//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']") self.selenium.find_element_by_xpath('//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') def test_delete_entry(self): """Test to ensure that a student can delete an entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue('Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame(self.selenium.find_element_by_id('id_entry_iframe')) # Insert text text_entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(text_entry) # Insert image button self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[2]').click() image_entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(image_entry) # Click on the inset image button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[5]/div[3]/button[3]').click() video_entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(video_entry) # Click on the insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(text_entry in box_text) self.selenium.find_element_by_xpath("//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']") self.selenium.find_element_by_xpath('//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') # Click on the entry that was created self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a').click() # Click on the delete button self.selenium.find_element_by_class_name('btn-danger').click() self.selenium.find_element_by_xpath('//*[@id="delete-modal"]/div/div/div[3]/a').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that the entry created is no longer on the entries page main_text = self.selenium.find_element_by_class_name('main').text # Check for text self.assertFalse(text_entry in main_text) # Check for image image_entry_xpath = "//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']" self.assertFalse(image_entry_xpath in main_text) # Check for video video_entry_xpath = '//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]' self.assertFalse(video_entry_xpath in main_text)
class Tests(): loged = False username = None selenium = None def __init__(self): # crea driver self.selenium = WebDriver() self.selenium.implicitly_wait(3) def backend_login(self, usuari, contrasenya): # accedeix a URL self.selenium.get('%s%s' % ("http://*****:*****@value="Iniciar sessió"]').click() try: boto_logout = self.selenium.find_element_by_xpath( '//a[text()="Finalitzar sessió"]') except NoSuchElementException as e: raise Exception("ERROR en login de l'usuari: " + usuari) self.logat = True self.username = usuari def backend_logout(self): self.selenium.find_element_by_xpath( '//a[text()="Finalitzar sessió"]').click() def ves_al_menu_principal(self): # anar a menu principal self.selenium.find_element_by_xpath('//a[@href="/admin/"]').click() # aqui va la "chicha" def crea_empresa(self, nom): self.ves_al_menu_principal() # afegim empresa self.selenium.find_element_by_xpath( '//a[@href="/admin/borsApp/empresa/add/"]').click() self.selenium.find_element_by_name('nom').send_keys(nom) # accedir dins iframe direcció self.selenium.switch_to_frame("id_direccio_ifr") self.selenium.find_element_by_xpath('//body').send_keys("c. Tal, 1") # tornar al main frame self.selenium.switch_to_default_content() self.selenium.find_element_by_name('poblacio').send_keys("Cornellà") self.selenium.find_element_by_name('cp').send_keys("08940") self.selenium.find_element_by_name('telefon').send_keys("931112233") nom2 = nom.replace(' ', '_') self.selenium.find_element_by_name('email').send_keys("info@" + nom2 + ".com") self.selenium.find_element_by_xpath('//input[@value="Desar"]').click() # check self.selenium.find_element_by_xpath('//li[@class="success"]') def ajusta_usuari_empresa(self, usuari, contrasenya): # se suposa que estem logats com a admin_centre self.ves_al_menu_principal() # menu usuaris self.selenium.find_element_by_xpath('//a[text()="Usuaris"]').click() # accedim a l'usuari de l'empresa acabada de crear # el nom de l'usuari és igual al de l'empresa, al menys pels tests self.selenium.find_element_by_xpath('//a[text()="' + usuari + '"]').click() # anem a canvi de contasenya self.selenium.find_element_by_xpath( '//a[@href="../password/"]').click() self.selenium.find_element_by_name('password1').send_keys(contrasenya) self.selenium.find_element_by_name('password2').send_keys(contrasenya) self.selenium.find_element_by_xpath( '//input[@value="Canviar contrasenya"]').click() # comprovem usuari creat OK # TODO: millorar test (comprovar no errors/warnings) #self.selenium.find_element_by_xpath('//li[@class="success" and contains(text(),"fou afegit amb èxit")]') self.selenium.find_element_by_xpath('//li[@class="success"]') def crea_oferta_caducada(self): self.ves_al_menu_principal() # menu ofertes self.selenium.find_element_by_xpath( '//a[@href="/admin/borsApp/oferta/add/"]').click() # omplim form self.selenium.find_element_by_name('inici_0').clear() self.selenium.find_element_by_name('inici_1').clear() self.selenium.find_element_by_name('final_0').clear() self.selenium.find_element_by_name('final_1').clear() self.selenium.find_element_by_name('inici_0').send_keys("01/01/2019") self.selenium.find_element_by_name('inici_1').send_keys("10:30:00") self.selenium.find_element_by_name('final_0').send_keys("10/02/2019") self.selenium.find_element_by_name('final_1').send_keys("10:30:00") self.selenium.find_element_by_name('titol').send_keys( "oferta test caducada 1") # select2 empresa (FK) self.selenium.find_element_by_xpath( '//span[@id="select2-id_empresa-container"]').click() self.selenium.find_element_by_xpath('//li[text()="' + self.username + '"]').click() # select2 cicles (m2m) self.selenium.find_element_by_xpath( '//div[@class="form-row field-cicles"]').click() self.selenium.find_element_by_xpath( '//input[@class="select2-search__field"]').send_keys("web\n") # direccio té el RichTextField amb un iframe pel mig # accedir dins iframe direcció self.selenium.switch_to_frame("id_descripcio_ifr") self.selenium.find_element_by_xpath('//body').send_keys( "oferta test caducada.\nbla bla...") # tornar al main frame self.selenium.switch_to_default_content() # submit self.selenium.find_element_by_xpath('//input[@value="Desar"]').click() # comprovem oferta creada OK self.selenium.find_element_by_xpath('//li[@class="success"]') def veu_oferta_caducada1(self): self.ves_al_menu_principal() self.selenium.find_element_by_xpath('//a[text()="Ofertes"]').click() self.selenium.find_element_by_xpath( '//a[text()="oferta test caducada 1"]').click() def no_veu_oferta_caducada1(self): self.ves_al_menu_principal() try: self.selenium.find_element_by_xpath( '//a[text()="Ofertes"]').click() self.selenium.find_element_by_xpath( '//a[text()="oferta test caducada 1"]').click() raise Exception( "ERROR: l'usuari no autoritzat '%s' pot veure les ofertes de l'empresa 1" % (self.username, )) except NoSuchElementException as e: # si no el troba, esta OK pass except Exception as e: raise e
class EntrySeleleniumTests(StaticLiveServerTestCase): """Selenium tests for the entry form""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if not settings.DEBUG: settings.DEBUG = True def setUp(self): """Handles login and things""" call_command('flush', interactive=False, verbosity=0) # Clears db call_command('loaddata', 'groups', commit=False, verbosity=0) call_command('loaddata', 'school', commit=False, verbosity=0) call_command('loaddata', 'permissions', commit=False, verbosity=0) call_command('loaddata', 'auth_users', commit=False, verbosity=0) call_command('loaddata', 'student', commit=False, verbosity=0) call_command('loaddata', 'advisor', commit=False, verbosity=0) call_command('loaddata', 'coordinator', commit=False, verbosity=0) call_command('loaddata', 'activityoptions', commit=False, verbosity=0) call_command('loaddata', 'learningobjectiveoptions', commit=False, verbosity=0) call_command('loaddata', 'sample_entries', commit=False, verbosity=0) self.selenium = WebDriver() self.selenium.set_window_size(1024, 800) self.selenium.get('{0}/{1}'.format(self.live_server_url, '')) self.selenium.find_element_by_xpath( '//*[@id="djHideToolBarButton"]').click() self.selenium.implicitly_wait(10) self.selenium.find_element_by_link_text('Login').click() # Click on the student button in the gateway self.selenium.find_element_by_xpath( '/html/body/center/md-content/div/div/div[1]/a').click() self.selenium\ .find_element_by_xpath("//img[@src='/static/journal/activities/img" "/journal_sign.png']") super() def tearDown(self): self.selenium.quit() super() def test_text_entry(self): """Test to ensure that a student can add a text entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) # Insert text entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(entry) # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(entry in box_text) def test_image_entry(self): """Test to ensure that a student can add an image entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[2]').click() entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(entry) # click on the inset image button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.implicitly_wait(10) self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists on the page. self.selenium.find_element_by_xpath( "//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']" ) def test_video_entry(self): """Test to ensure that a student can add a video entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) # Insert video self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[3]').click() entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(entry) # click on the insert video button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.implicitly_wait(10) self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') self.selenium.find_element_by_xpath( '//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') def test_image_text_entry(self): """Test to ensure that a student can add image+text entries""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) # Insert text entry = 'I think I will bring my cat out next time with a flower.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(entry) # Insert the image self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[2]').click() image_entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(image_entry) # Click on the insert image button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.implicitly_wait(10) self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure the text is on the entries page box_text = self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(entry in box_text) # Ensure the image is on the entries page self.selenium.find_element_by_xpath( "//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']" ) def test_video_text_entry(self): """Test to ensure that a student can add an text+video entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) # Insert text entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(entry) # Insert video self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[3]').click() video_entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(video_entry) # Click on the insert video button self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button')\ .click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/a/div')\ .text self.assertTrue(entry in box_text) self.selenium.find_element_by_xpath( '//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') def test_text_image_video_entry(self): """Test to ensure that a student can add an text+image+video entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) # Insert text text_entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(text_entry) # Insert image button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[2]').click() image_entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(image_entry) # Click on the inset image button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Insert video button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[3]').click() video_entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(video_entry) # Click on the insert video button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(text_entry in box_text) self.selenium.find_element_by_xpath( "//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']" ) self.selenium.find_element_by_xpath( '//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') def test_delete_entry(self): """Test to ensure that a student can delete an entry""" # Click on the first activity box: Walking around the block self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div/div[1]/div/div[3]/a/div').click() self.selenium.find_element_by_link_text('Add an entry').click() # The following has 2 matching: Just walking and Adding entry...block header_text = self.selenium.find_elements_by_tag_name('h3')[1].text self.assertTrue( 'Adding entry for Walking around the block!' in header_text) # Switching to iframe focus self.selenium.switch_to_frame( self.selenium.find_element_by_id('id_entry_iframe')) # Insert text text_entry = 'I think I will bring my cat out next time.' self.selenium.find_element_by_class_name('note-editable')\ .send_keys(text_entry) # Insert image button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[2]').click() image_entry = 'http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/input')\ .send_keys(image_entry) # Click on the inset image button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[1]/div/div/div[3]/button').click() # Insert video button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[5]/div[3]/button[3]').click() video_entry = 'https://www.youtube.com/watch?v=Rk_bV0RJRhs&index=20&list=PLJU_WCB1rA2SFwFy3lEvY_NH23ql1-Cgi' self.selenium.find_element_by_xpath('/html/body/div[2]/div[2]/div[4]/div/div/div[2]/div/input')\ .send_keys(video_entry) # Click on the insert video button self.selenium.find_element_by_xpath( '/html/body/div[2]/div[2]/div[4]/div/div/div[3]/button').click() # Switch back out of the iframe. self.selenium.switch_to_default_content() # Click on the submit button self.selenium.find_element_by_class_name('btn-success').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that entry exists as the first box on the page. box_text = self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div[2]/div[1]/a/div').text self.assertTrue(text_entry in box_text) self.selenium.find_element_by_xpath( "//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']" ) self.selenium.find_element_by_xpath( '//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]') # Click on the entry that was created self.selenium.find_element_by_xpath( '/html/body/div[1]/div[2]/div[2]/div[1]/a').click() # Click on the delete button self.selenium.find_element_by_class_name('btn-danger').click() self.selenium.find_element_by_xpath( '//*[@id="delete-modal"]/div/div/div[3]/a').click() # Ensure that we are back on the entries page. self.selenium.find_element_by_link_text('Add an entry') # Ensure that the entry created is no longer on the entries page main_text = self.selenium.find_element_by_class_name('main').text # Check for text self.assertFalse(text_entry in main_text) # Check for image image_entry_xpath = "//img[@src='http://images.jfdaily.com/jiefang/wenyu/new/201409/W020140919421426345484.jpg']" self.assertFalse(image_entry_xpath in main_text) # Check for video video_entry_xpath = '//iframe[@src="//www.youtube.com/embed/Rk_bV0RJRhs"]' self.assertFalse(video_entry_xpath in main_text)