refactored pytest portion of the framework

This commit is contained in:
Greg Gauthier 2020-10-10 22:40:06 +01:00
parent 6491caabf9
commit 6ac43e67bf
6 changed files with 31 additions and 47 deletions

View File

@ -7,11 +7,11 @@ from webdriver_manager.chrome import ChromeDriverManager
class BrowserDriver:
@staticmethod
def get(browser=None):
def get(browser=None, headless=True):
if browser == "chrome":
return chrome()
return chrome(headless)
elif browser == "firefox":
return firefox()
return firefox(headless)
elif browser == "edge":
return edge()
elif browser == "safari":
@ -20,21 +20,23 @@ class BrowserDriver:
raise ValueError("'{}' is not a supported browser".format(browser))
def chrome():
def chrome(headless=True):
options = webdriver.ChromeOptions()
options.headless = True
options.headless = headless
options.add_argument('--ignore-certificate-errors')
return webdriver.Chrome(ChromeDriverManager().install(), options=options)
return webdriver.Chrome(
ChromeDriverManager().install(),
options=options)
def firefox():
def firefox(headless=True):
options = webdriver.FirefoxOptions()
options.accept_insecure_certs = True
options.headless = True
options.headless = headless
gecko_driver = GeckoDriverManager().install()
return webdriver.Firefox(
executable_path=gecko_driver,
firefox_options=options)
options=options)
def edge():

View File

@ -1,39 +1,13 @@
import configparser
import pytest
import fixtures
config = configparser.ConfigParser()
def pytest_addoption(parser):
""" attaches optional cmd-line args to the pytest machinery """
parser.addoption('--properties',
action='store',
default='staging',
help='the name of the environment for which you need properties.')
parser.addoption('--fixture',
action='store',
default='default',
help='the name of the environment for which you need fixture accounts.')
@pytest.fixture(scope="session", autouse=True)
def service_base_url(pytestconfig):
"""
The url of the live sme-service under test
"""
env = pytestconfig.getoption("env")
return _read_config_section(fixtures, env)['target_url']
@pytest.fixture(scope="session", autouse=True)
def fixture_data(pytestconfig):
"""
The fixture data items for the account under test
"""
#env = pytestconfig.getoption("env")
return _read_config_section(fixtures, "env")
def headless():
return _str_to_bool(_read_config_section("fixtures.ini", "dev")["headless"])
def _read_config_section(source, section):
@ -41,6 +15,5 @@ def _read_config_section(source, section):
return config[section]
def _read_fixture_file(fixtures):
fixture_data = config.read(fixtures)
return fixture_data
def _str_to_bool(s):
return s.lower() in ['true', '1', 'yes']

4
fixtures.ini Normal file
View File

@ -0,0 +1,4 @@
[dev]
env = dev
headless = True
target_url = "https://google.com/"

View File

3
pytest.ini Normal file
View File

@ -0,0 +1,3 @@
[pytest]
testpaths = pytests

View File

@ -1,15 +1,17 @@
from browserdriver import BrowserDriver
def setup_module(module):
global bd
bd = BrowserDriver().get("firefox")
def teardown_module(module):
def test_firefox_browser(headless):
bd = BrowserDriver().get("firefox", headless=headless)
bd.get('https://test.io')
print(bd.current_url, bd.title)
assert "QA Testing as a Service | test IO" == bd.title
bd.quit()
def test_load_browser():
def test_chrome_browser(headless):
bd = BrowserDriver().get("chrome", headless=headless)
bd.get('https://test.io')
print(bd.current_url, bd.title)
assert "QA Testing as a Service | test IO" == bd.title
bd.quit()