Advertisement
Guest User

Untitled

a guest
Jun 9th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. sys.path.append(os.path.join(os.path.dirname(__file__), "./"))
  5. sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
  6. sys.path.append(os.path.join(os.path.dirname(__file__), "../../"))
  7.  
  8. import xmlrunner
  9. import unittest
  10. from selenium import webdriver
  11. from selenium.webdriver.support.wait import WebDriverWait
  12. from selenium.common.exceptions import NoSuchElementException, TimeoutException
  13. from selenium.webdriver.common.by import By
  14.  
  15.  
  16. class seleniumTest(unittest.TestCase):
  17. def setUp(self):
  18. self.driver = webdriver.Chrome(executable_path=r"C:\Stuff\Selenium\chromedriver.exe")
  19. self.driver.implicitly_wait(1)
  20. self.driver.maximize_window()
  21.  
  22. def tearDown(self):
  23. self.driver.quit()
  24.  
  25. def test_escience_login(self):
  26. try:
  27. self.driver.get('http://e-science.pl/')
  28. loginLink = self.driver.find_element_by_xpath('//*[@id="navbar-collapse-1"]/ul[2]/li[3]/a')
  29. loginLink.click()
  30. WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="username"]'))
  31. username = self.driver.find_element_by_xpath('//*[@id="username"]')
  32. username.send_keys('mpolak226199')
  33. password = self.driver.find_element_by_xpath('//*[@id="password"]')
  34. password.send_keys('Password24!')
  35. password.submit()
  36. WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="navbar-collapse-1"]/ul[2]/li[2]/a'))
  37. except:
  38. self.assertTrue(False)
  39. return
  40.  
  41. self.assertTrue(self.is_element_present(By.XPATH,'//*[@id="navbar-collapse-1"]/ul[2]/li[2]/a'))
  42.  
  43. def test_escience_gitlab(self):
  44. try:
  45. self.driver.get('http://git.e-science.pl/')
  46. username = self.driver.find_element_by_xpath('//*[@id="username"]')
  47. username.send_keys('mpolak226199')
  48. password = self.driver.find_element_by_xpath('//*[@id="password"]')
  49. password.send_keys('Password24!')
  50. password.submit()
  51. WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="content-body"]/div[2]/div[3]/a'))
  52. newProjectLink = self.driver.find_element_by_xpath('//*[@id="content-body"]/div[2]/div[3]/a')
  53. newProjectLink.click()
  54. WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="new_project"]/input[3]'))
  55. except:
  56. self.assertTrue(False)
  57. return
  58.  
  59. self.assertTrue(self.is_element_present(By.XPATH, '//*[@id="new_project"]/input[3]'))
  60.  
  61. def is_element_present(self, how, what):
  62. """
  63. Helper method to confirm the presence of an element on page
  64. :params how: By locator type
  65. :params what: locator value
  66. """
  67. try:
  68. self.driver.find_element(by=how, value=what)
  69. except NoSuchElementException:
  70. return False
  71. return True
  72.  
  73.  
  74. if __name__ == '__main__':
  75. unittest.main(testRunner=xmlrunner.XMLTestRunner(output="./python_unittests_xml"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement