This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example test script for quick try
- Loading branch information
1 parent
bbf6d14
commit aaf630f
Showing
2 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
A simple selenium test example written by python | ||
""" | ||
|
||
import unittest | ||
from selenium import webdriver | ||
from selenium.common.exceptions import NoSuchElementException | ||
|
||
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('--disable-gpu') | ||
self.driver = webdriver.Chrome(chrome_options=chrome_options) | ||
self.driver.implicitly_wait(10) | ||
|
||
def tearDown(self): | ||
"""Stop web driver""" | ||
self.driver.quit() | ||
|
||
def test_case_1(self): | ||
"""Find and click top-right button""" | ||
try: | ||
self.driver.get('https://www.oursky.com/') | ||
el = self.driver.find_element_by_class_name('btn-header') | ||
el.click() | ||
except NoSuchElementException as ex: | ||
self.fail(ex.msg) | ||
|
||
def test_case_2(self): | ||
"""Find and click Learn more button""" | ||
try: | ||
self.driver.get('https://www.oursky.com/') | ||
el = self.driver.find_element_by_xpath(".//*[@id='tag-line-wrap']/span/a") | ||
el.click() | ||
except NoSuchElementException as ex: | ||
self.fail(ex.msg) | ||
|
||
if __name__ == '__main__': | ||
suite = unittest.TestLoader().loadTestsFromTestCase(TestTemplate) | ||
unittest.TextTestRunner(verbosity=2).run(suite) |