Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- sys.path.append(os.path.join(os.path.dirname(__file__), "./"))
- sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
- sys.path.append(os.path.join(os.path.dirname(__file__), "../../"))
- import xmlrunner
- import unittest
- from selenium import webdriver
- from selenium.webdriver.support.wait import WebDriverWait
- from selenium.common.exceptions import NoSuchElementException, TimeoutException
- from selenium.webdriver.common.by import By
- class seleniumTest(unittest.TestCase):
- def setUp(self):
- self.driver = webdriver.Chrome(executable_path=r"C:\Stuff\Selenium\chromedriver.exe")
- self.driver.implicitly_wait(1)
- self.driver.maximize_window()
- def tearDown(self):
- self.driver.quit()
- def test_escience_login(self):
- try:
- self.driver.get('http://e-science.pl/')
- loginLink = self.driver.find_element_by_xpath('//*[@id="navbar-collapse-1"]/ul[2]/li[3]/a')
- loginLink.click()
- WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="username"]'))
- username = self.driver.find_element_by_xpath('//*[@id="username"]')
- username.send_keys('mpolak226199')
- password = self.driver.find_element_by_xpath('//*[@id="password"]')
- password.send_keys('Password24!')
- password.submit()
- WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="navbar-collapse-1"]/ul[2]/li[2]/a'))
- except:
- self.assertTrue(False)
- return
- self.assertTrue(self.is_element_present(By.XPATH,'//*[@id="navbar-collapse-1"]/ul[2]/li[2]/a'))
- def test_escience_gitlab(self):
- try:
- self.driver.get('http://git.e-science.pl/')
- username = self.driver.find_element_by_xpath('//*[@id="username"]')
- username.send_keys('mpolak226199')
- password = self.driver.find_element_by_xpath('//*[@id="password"]')
- password.send_keys('Password24!')
- password.submit()
- WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="content-body"]/div[2]/div[3]/a'))
- newProjectLink = self.driver.find_element_by_xpath('//*[@id="content-body"]/div[2]/div[3]/a')
- newProjectLink.click()
- WebDriverWait(self.driver, 5).until(lambda x: x.find_elements_by_xpath('//*[@id="new_project"]/input[3]'))
- except:
- self.assertTrue(False)
- return
- self.assertTrue(self.is_element_present(By.XPATH, '//*[@id="new_project"]/input[3]'))
- def is_element_present(self, how, what):
- """
- Helper method to confirm the presence of an element on page
- :params how: By locator type
- :params what: locator value
- """
- try:
- self.driver.find_element(by=how, value=what)
- except NoSuchElementException:
- return False
- return True
- if __name__ == '__main__':
- unittest.main(testRunner=xmlrunner.XMLTestRunner(output="./python_unittests_xml"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement