Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- from selenium.common.exceptions import NoSuchElementException
- from BasicActions import BasicActions
- class SearchTest(unittest.TestCase):
- BasicActions = BasicActions()
- @classmethod
- def setUpClass(cls):
- cls.driver = cls.BasicActions.driver
- cls.driver.maximize_window()
- cls.homepage = "http://the-internet.herokuapp.com/"
- def test1_equal_text(self):
- self.BasicActions.go_to_home_page(self.homepage)
- self.driver.find_element_by_xpath("//div[@id='content']/ul/li[1]/a").click()
- text = self.driver.find_element_by_xpath("//div[@class='example']/h3").text
- self.assertEqual(self.check_text_version(), text)
- def test2_link_powered_by(self):
- # self.BasicActions.go_to_home_page(self.homepage)
- # self.driver.find_element_by_xpath("//div[@id='content']/ul/li[1]/a").click()
- self.assertTrue(self.is_element_present_by_xpath("//div[@class='large-4 large-centered columns']/div/a"))
- def test3_link_following(self):
- self.BasicActions.go_to_home_page(self.homepage)
- self.driver.find_element_by_xpath("//div[@id='content']/ul/li[1]/a").click()
- link = self.driver.find_element_by_link_text('Elemental Selenium')
- link.click()
- self.assertEqual(self.driver.current_url, "http://elementalselenium.com/")
- @classmethod
- def tearDownClass(cls):
- cls.driver.quit()
- def is_element_present_by_xpath(self, xpath):
- try:
- self.driver.find_element_by_xpath(xpath)
- except NoSuchElementException:
- return False
- return True
- def check_text_version(self):
- text = self.driver.find_element_by_xpath("//div[@class='example']/h3").text
- if text == "A/B Test Variation 1":
- return text
- else:
- return text
- if __name__ == '__main__':
- unittest.main(verbosity=2)
Advertisement
Add Comment
Please, Sign In to add comment