Advertisement
Guest User

Untitled

a guest
May 13th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. from django.test import TestCase
  2. from django.contrib.staticfiles.testing import StaticLiveServerTestCase
  3. from selenium.webdriver.firefox.webdriver import WebDriver
  4. from django.contrib.auth.models import User
  5. import time
  6.  
  7. class SeleniumTests(StaticLiveServerTestCase):
  8.     fixtures = ['wybory_data.json']
  9.  
  10.     @classmethod
  11.     def setUpClass(cls):
  12.         cls.user = User.objects.create_user(username='login', password='haslo')
  13.         cls.driver = WebDriver()
  14.         super(SeleniumTests, cls).setUpClass()
  15.  
  16.     @classmethod
  17.     def tearDownClass(cls):
  18.         cls.driver.quit()
  19.         super(SeleniumTests, cls).tearDownClass()
  20.  
  21.     def test_login(self):
  22.         self.driver.get('%s%s' % (self.live_server_url, '/'))
  23.         assert "Wybory 2005" in self.driver.title
  24.  
  25.         # przejdz do strony logowania
  26.         login_button = self.driver.find_element_by_class_name('btn')
  27.         button_text = login_button.get_attribute('value')
  28.         if button_text == 'Wyloguj':
  29.             login_button.click()
  30.         login_button.click()
  31.         assert "Logowanie" in self.driver.title
  32.  
  33.         # zaloguj sie
  34.         username_input = self.driver.find_element_by_name("username")
  35.         username_input.send_keys('login')
  36.         password_input = self.driver.find_element_by_name("password")
  37.         password_input.send_keys('haslo')
  38.         time.sleep(5)
  39.         self.driver.find_element_by_xpath('//input[@value="Zaloguj"]').click()
  40.         time.sleep(1)
  41.         assert "Niepoprawny login lub hasło." not in self.driver.page_source
  42.         assert "Logowanie" not in self.driver.title
  43.         assert "Wybory 2005" in self.driver.title
  44.  
  45.         # policz ile bylo glosow przed zmianami
  46.         komorka_wazne_glosy = self.driver.find_element_by_xpath\
  47.                     ('//table[@id="dane_tabela"]/tbody/tr[position()=5]/td[position()=2]')
  48.         lacznie_glosow = int(komorka_wazne_glosy.text)
  49.  
  50.         # wybierz odpowiednie gminy do wyszukiwania
  51.         self.driver.find_element_by_xpath("//select[@id='wyszukiwanie-po-czym']/option[@value='wojewodztwa']").click()
  52.         self.driver.find_element_by_xpath("//select[@id='wyszukiwanie-parametr']/option[@value='łódzkie']").click()
  53.         self.driver.find_element_by_xpath("//input[@id='przycisk-wyszukaj']").click()
  54.         time.sleep(7)
  55.  
  56.         # edytuj pierwsza od gory gmine
  57.         formularz = self.driver.find_element_by_xpath("//form[@class='formularz-modyfikuj' and position()=1]")
  58.         wazne_glosy_1 = formularz.find_element_by_xpath("//input[@name='liczba_waznych_glosow_na_kandydata_1']")
  59.         wartosc_1 = int(wazne_glosy_1.get_attribute('value'))
  60.         wazne_glosy_1.clear()
  61.         wazne_glosy_1.send_keys(wartosc_1 - 21)
  62.         wazne_glosy_2 = formularz.find_element_by_xpath("//input[@name='liczba_waznych_glosow_na_kandydata_2']")
  63.         wartosc_2 = int(wazne_glosy_2.get_attribute('value'))
  64.         wazne_glosy_2.clear()
  65.         wazne_glosy_2.send_keys(wartosc_2 - 21)
  66.         formularz.find_element_by_xpath("//input[@value='Edytuj']").click()
  67.         time.sleep(7)
  68.         assert "Dane Gminy zaktualizowane." in self.driver.page_source
  69.         self.driver.find_element_by_class_name('close').click()
  70.         time.sleep(2)
  71.  
  72.         # sprawdz czy komorka sie prawidlowo odswiezyla
  73.         komorka_wazne_glosy = self.driver.find_element_by_xpath\
  74.                     ('//table[@id="dane_tabela"]/tbody/tr[position()=5]/td[position()=2]')
  75.         nowe_lacznie_glosow = int(komorka_wazne_glosy.text)
  76.  
  77.         assert nowe_lacznie_glosow == lacznie_glosow - 42
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement