Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.test import TestCase
- from django.contrib.staticfiles.testing import StaticLiveServerTestCase
- from selenium.webdriver.firefox.webdriver import WebDriver
- from django.contrib.auth.models import User
- import time
- class SeleniumTests(StaticLiveServerTestCase):
- fixtures = ['wybory_data.json']
- @classmethod
- def setUpClass(cls):
- cls.user = User.objects.create_user(username='login', password='haslo')
- cls.driver = WebDriver()
- super(SeleniumTests, cls).setUpClass()
- @classmethod
- def tearDownClass(cls):
- cls.driver.quit()
- super(SeleniumTests, cls).tearDownClass()
- def test_login(self):
- self.driver.get('%s%s' % (self.live_server_url, '/'))
- assert "Wybory 2005" in self.driver.title
- # przejdz do strony logowania
- login_button = self.driver.find_element_by_class_name('btn')
- button_text = login_button.get_attribute('value')
- if button_text == 'Wyloguj':
- login_button.click()
- login_button.click()
- assert "Logowanie" in self.driver.title
- # zaloguj sie
- username_input = self.driver.find_element_by_name("username")
- username_input.send_keys('login')
- password_input = self.driver.find_element_by_name("password")
- password_input.send_keys('haslo')
- time.sleep(5)
- self.driver.find_element_by_xpath('//input[@value="Zaloguj"]').click()
- time.sleep(1)
- assert "Niepoprawny login lub hasło." not in self.driver.page_source
- assert "Logowanie" not in self.driver.title
- assert "Wybory 2005" in self.driver.title
- # policz ile bylo glosow przed zmianami
- komorka_wazne_glosy = self.driver.find_element_by_xpath\
- ('//table[@id="dane_tabela"]/tbody/tr[position()=5]/td[position()=2]')
- lacznie_glosow = int(komorka_wazne_glosy.text)
- # wybierz odpowiednie gminy do wyszukiwania
- self.driver.find_element_by_xpath("//select[@id='wyszukiwanie-po-czym']/option[@value='wojewodztwa']").click()
- self.driver.find_element_by_xpath("//select[@id='wyszukiwanie-parametr']/option[@value='łódzkie']").click()
- self.driver.find_element_by_xpath("//input[@id='przycisk-wyszukaj']").click()
- time.sleep(7)
- # edytuj pierwsza od gory gmine
- formularz = self.driver.find_element_by_xpath("//form[@class='formularz-modyfikuj' and position()=1]")
- wazne_glosy_1 = formularz.find_element_by_xpath("//input[@name='liczba_waznych_glosow_na_kandydata_1']")
- wartosc_1 = int(wazne_glosy_1.get_attribute('value'))
- wazne_glosy_1.clear()
- wazne_glosy_1.send_keys(wartosc_1 - 21)
- wazne_glosy_2 = formularz.find_element_by_xpath("//input[@name='liczba_waznych_glosow_na_kandydata_2']")
- wartosc_2 = int(wazne_glosy_2.get_attribute('value'))
- wazne_glosy_2.clear()
- wazne_glosy_2.send_keys(wartosc_2 - 21)
- formularz.find_element_by_xpath("//input[@value='Edytuj']").click()
- time.sleep(7)
- assert "Dane Gminy zaktualizowane." in self.driver.page_source
- self.driver.find_element_by_class_name('close').click()
- time.sleep(2)
- # sprawdz czy komorka sie prawidlowo odswiezyla
- komorka_wazne_glosy = self.driver.find_element_by_xpath\
- ('//table[@id="dane_tabela"]/tbody/tr[position()=5]/td[position()=2]')
- nowe_lacznie_glosow = int(komorka_wazne_glosy.text)
- assert nowe_lacznie_glosow == lacznie_glosow - 42
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement