diff --git a/test_script.py b/test_script.py index afc7753..fff7385 100644 --- a/test_script.py +++ b/test_script.py @@ -1,11 +1,15 @@ -""" -A simple selenium test example written by python -""" +# Check here selenium-python doc to select elements in the DOM +# https://selenium-python.readthedocs.io/locating-elements.html + +# How to get elements' absolute XPath with your browser +# https://stackoverflow.com/questions/59961926/how-to-get-absolute-xpath-in-chrome-or-firefox import unittest from selenium import webdriver from selenium.common.exceptions import NoSuchElementException +url = "" + class TestTemplate(unittest.TestCase): """Include test cases on a given url""" @@ -13,7 +17,7 @@ def setUp(self): """Start web driver""" chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--no-sandbox') - chrome_options.add_argument('--headless') + chrome_options.add_argument('--headless') # Comment this line if you want to see the browser while executing the navigation chrome_options.add_argument('--disable-gpu') self.driver = webdriver.Chrome(chrome_options=chrome_options) self.driver.implicitly_wait(10) @@ -23,23 +27,33 @@ def tearDown(self): self.driver.quit() def test_case_1(self): - """Find and click top-right button""" + """Test case 1 brief description""" try: - self.driver.get('https://www.oursky.com/') - el = self.driver.find_element_by_class_name('btn-header') - el.click() + self.driver.get(url) + self.driver.set_window_size(1024, 768) + self.driver.find_element_by_xpath('').click() except NoSuchElementException as ex: self.fail(ex.msg) def test_case_2(self): - """Find and click Learn more button""" + """Test case 2 brief description""" try: - self.driver.get('https://www.oursky.com/') - el = self.driver.find_element_by_xpath(".//*[@id='tag-line-wrap']/span/a") - el.click() + self.driver.get(url) + self.driver.set_window_size(1024, 768) + self.driver.find_element_by_xpath('').click() except NoSuchElementException as ex: self.fail(ex.msg) - + + def test_case_3(self): + """Test case 3 brief description""" + try: + self.driver.get(url) + self.driver.set_window_size(1024, 768) + self.driver.find_element_by_xpath('').send_keys("Lorem ipsum") + self.driver.find_element_by_xpath('').click() + except NoSuchElementException as ex: + self.fail(ex.msg) + if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(TestTemplate) unittest.TextTestRunner(verbosity=2).run(suite)