Created
August 13, 2017 11:48
-
-
Save arsenlosenko/fab8f20117dbea64a1e995f3bd189dc4 to your computer and use it in GitHub Desktop.
Example of unittest test suite which is running in the save Xvfb session
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
Checked xvfbwrapper execution on three tests: positive, negative, and failed | |
""" | |
import unittest | |
import time | |
from selenium import webdriver | |
from xvfbwrapper import Xvfb | |
class TestGooglePage(unittest.TestCase): | |
def setUp(self): | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument('--no-sandbox') | |
chrome_options.add_argument('--start-maximized') | |
chrome_options.add_argument('--window-size={0}x{1}'.format(1280, 1024)) | |
chrome_options.add_argument("--window-position=0,0") | |
self.driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=chrome_options) | |
self.driver.implicitly_wait(30) | |
def test_google_page(self): | |
self.driver.get('https://www.google.com.ua/') | |
logo = self.driver.find_element_by_id('hplogo') | |
print(logo.text) | |
assert self.driver.title == "Google", "Title is incorrect" | |
def test_incorrect_title(self): | |
self.driver.get('https://www.google.com.ua/') | |
logo = self.driver.find_element_by_id('hplogo') | |
print(logo.tag_name) | |
assert self.driver.title == "Python", "Title is incorrect" | |
def test_get_unknown_el(self): | |
self.driver.get('https://www.google.com.ua/') | |
logo = self.driver.find_element_by_id('hploqwqo') | |
print(logo.tag_name) | |
assert self.driver.title == "Python", "Title is incorrect" | |
def test_check_open_xvfb(self): | |
print("Check xvfb in htop!") | |
time.sleep(20) | |
def tearDown(self): | |
self.driver.quit() | |
if __name__ == '__main__': | |
suite = unittest.TestSuite() | |
suite.addTest(TestGooglePage('test_google_page')) | |
suite.addTest(TestGooglePage('test_incorrect_title')) | |
suite.addTest(TestGooglePage('test_check_open_xvfb')) | |
suite.addTest(TestGooglePage('test_get_unknown_el')) | |
runner = unittest.TextTestRunner(verbosity=2) | |
with Xvfb(height=1280, width=1024) as xvfb: | |
xvfb.start() | |
runner.run(suite) | |
xvfb.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment