Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions test_script.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
"""
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 = "<YOUR_URL>"

class TestTemplate(unittest.TestCase):
"""Include test cases on a given url"""

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)
Expand All @@ -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('<ELEMENT_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('<ELEMENT_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('<ELEMENT_XPATH>').send_keys("Lorem ipsum")
self.driver.find_element_by_xpath('<ELEMENT_XPATH>').click()
except NoSuchElementException as ex:
self.fail(ex.msg)

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestTemplate)
unittest.TextTestRunner(verbosity=2).run(suite)