Link3
De Wiki de EGC
from pyexpat import model
from django.test import TestCase
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from base.tests import BaseTestCase
from voting.models import Question, Voting
class AdminTestCase(StaticLiveServerTestCase):
def setUp(self):
#Load base test functionality for decide
self.base = BaseTestCase()
self.base.setUp()
options = webdriver.ChromeOptions()
options.headless = False
self.driver = webdriver.Chrome(options=options)
super().setUp()
def tearDown(self):
super().tearDown()
self.driver.quit()
self.base.tearDown()
def test_simpleVisualizer(self):
q = Question(desc='test question')
q.save()
v = Voting(name='test voting', question=q)
v.save()
response =self.driver.get(f'{self.live_server_url}/visualizer/{v.pk}/')
vState= self.driver.find_element(By.TAG_NAME,"h2").text
self.assertTrue(vState, "Votación no comenzada")
def test_simpleCorrectLogin(self):
self.driver.get(f'{self.live_server_url}/admin/')
self.driver.find_element(By.ID,'id_username').send_keys("admin")
self.driver.find_element(By.ID,'id_password').send_keys("qwerty",Keys.ENTER)
print(self.driver.current_url)
#In case of a correct loging, a element with id 'user-tools' is shown in the upper right part
self.assertTrue(len(self.driver.find_elements(By.ID,'user-tools'))==1)