Guest User

Untitled

a guest
Oct 21st, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. import unittest
  2. from selenium.common.exceptions import NoSuchElementException
  3. from BasicActions import BasicActions
  4.  
  5.  
  6. class SearchTest(unittest.TestCase):
  7.     BasicActions = BasicActions()
  8.  
  9.     @classmethod
  10.     def setUpClass(cls):
  11.         cls.driver = cls.BasicActions.driver
  12.         cls.driver.maximize_window()
  13.         cls.homepage = "http://the-internet.herokuapp.com/"
  14.  
  15.     def test1_equal_text(self):
  16.         self.BasicActions.go_to_home_page(self.homepage)
  17.         self.driver.find_element_by_xpath("//div[@id='content']/ul/li[1]/a").click()
  18.         text = self.driver.find_element_by_xpath("//div[@class='example']/h3").text
  19.         self.assertEqual(self.check_text_version(), text)
  20.  
  21.     def test2_link_powered_by(self):
  22.         # self.BasicActions.go_to_home_page(self.homepage)
  23.         # self.driver.find_element_by_xpath("//div[@id='content']/ul/li[1]/a").click()
  24.         self.assertTrue(self.is_element_present_by_xpath("//div[@class='large-4 large-centered columns']/div/a"))
  25.  
  26.     def test3_link_following(self):
  27.         self.BasicActions.go_to_home_page(self.homepage)
  28.         self.driver.find_element_by_xpath("//div[@id='content']/ul/li[1]/a").click()
  29.         link = self.driver.find_element_by_link_text('Elemental Selenium')
  30.         link.click()
  31.         self.assertEqual(self.driver.current_url, "http://elementalselenium.com/")
  32.  
  33.     @classmethod
  34.     def tearDownClass(cls):
  35.         cls.driver.quit()
  36.  
  37.     def is_element_present_by_xpath(self, xpath):
  38.         try:
  39.             self.driver.find_element_by_xpath(xpath)
  40.         except NoSuchElementException:
  41.             return False
  42.         return True
  43.  
  44.     def check_text_version(self):
  45.         text = self.driver.find_element_by_xpath("//div[@class='example']/h3").text
  46.         if text == "A/B Test Variation 1":
  47.             return text
  48.         else:
  49.             return text
  50.  
  51.  
  52. if __name__ == '__main__':
  53.     unittest.main(verbosity=2)
Advertisement
Add Comment
Please, Sign In to add comment