fix code, update pylint, other goodies
All checks were successful
Pylint / build (3.12) (push) Successful in 9s

This commit is contained in:
Greg Gauthier 2024-07-23 15:00:35 +01:00
parent fb4af8ac47
commit 63fcdbc922
10 changed files with 37 additions and 68 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
**/__pycache/
.idea/
.vscode/
.venv/

23
Pipfile
View File

@ -1,23 +0,0 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
flask = "*"
pytest = "*"
behave = "*"
selenium = "*"
webdriver_manager = "*"
msedge-selenium-tools = "*"
[packages]
flask = "*"
pytest = "*"
behave = "*"
selenium = "*"
webdriver_manager = "*"
msedge-selenium-tools = "*"
[requires]
python_version = "3.6"

View File

@ -1,2 +1,3 @@
# behave-framework
basic python test framework

View File

@ -1,9 +1,9 @@
[behave]
default_format = pretty
show_skipped = true
show_timings = true
show_skipped = true
show_timings = true
stdout_capture = yes
logging-level = ERROR
logging-level = ERROR
default_tags = ~@skip
[behave.userdata]

View File

@ -1,51 +1,38 @@
# pylint: disable=too-few-public-methods
from selenium import webdriver
from msedge.selenium_tools import Edge, EdgeOptions
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
class BrowserDriver:
@staticmethod
def get(browser=None, headless=True):
if browser == "chrome":
return chrome(headless)
elif browser == "firefox":
return firefox(headless)
elif browser == "edge":
return edge(headless)
elif browser == "safari":
return safari()
else:
raise ValueError("'{}' is not a supported browser".format(browser))
valid_browsers = ['chrome', 'firefox', 'safari', 'edge']
if browser in valid_browsers:
browser_method = globals()[browser]
return browser_method(headless)
raise ValueError(f"'{browser}' is not a supported browser")
def chrome(headless=True):
options = webdriver.ChromeOptions()
options.headless = headless
options.add_argument('--ignore-certificate-errors')
return webdriver.Chrome(
ChromeDriverManager().install(),
options=options)
return webdriver.Chrome(options=options)
def firefox(headless=True):
options = webdriver.FirefoxOptions()
options.accept_insecure_certs = True
options.headless = headless
gecko_driver = GeckoDriverManager().install()
return webdriver.Firefox(
executable_path=gecko_driver,
options=options)
return webdriver.Firefox(options=options)
def edge(headless=True):
options = EdgeOptions()
options = webdriver.EdgeOptions()
options.use_chromium = True
options.headless = headless
edge_driver = EdgeChromiumDriverManager().install()
driver = Edge(edge_driver, options=options)
driver = webdriver.Edge(options=options)
return driver

View File

@ -1,6 +1,6 @@
import configparser
import pytest
import pytest
config = configparser.ConfigParser()

View File

@ -1,4 +1,5 @@
Feature: Browser Demo
Scenario: Load test.io web page with chrome
Given I have a chrome driver
When I navigate to test.io
@ -9,12 +10,12 @@ Feature: Browser Demo
When I navigate to test.io
Then The page is displayed
@skip
Scenario: Load test.io web page with edge
Given I have an edge driver
When I navigate to test.io
Then The page is displayed
@skip
Scenario: Load test.io web page with safari
Given I have a safari driver
When I navigate to test.io

View File

@ -1,5 +1,9 @@
# pylint: disable=unused-argument
def before_all(context):
# -- SET LOG LEVEL: behave --logging-level=ERROR ...
# on behave command-line or in "behave.ini".
context.config.setup_logging()
def after_scenario(context, scenario):
context.driver.quit()

View File

@ -1,34 +1,34 @@
# pylint: disable=no-name-in-module
from behave import then, when, given
from browserdriver import BrowserDriver
@given('I have a firefox driver')
def step_impl(context):
def get_firefox_driver(context):
context.driver = BrowserDriver.get("firefox")
@given('I have a chrome driver')
def step_impl(context):
def get_chrome_driver(context):
context.driver = BrowserDriver.get("chrome")
@given(u'I have an edge driver')
def step_impl(context):
@given('I have an edge driver')
def get_edge_driver(context):
context.driver = BrowserDriver.get("edge")
@given(u'I have a safari driver')
def step_impl(context):
@given('I have a safari driver')
def get_safari_driver(context):
context.driver = BrowserDriver.get("safari")
@when('I navigate to test.io')
def step_impl(context):
def navigate_to_testio(context):
context.driver.get("https://test.io")
print(context.driver.title)
@then('The page is displayed')
def step_impl(context):
assert context.driver.title == "QA Testing as a Service | test IO"
def page_is_displayed(context):
assert context.driver.title == "Home | Test IO"

View File

@ -1,5 +1,4 @@
from browserdriver import BrowserDriver
import pytest
def test_firefox_browser(headless):
@ -16,14 +15,13 @@ def test_chrome_browser(headless):
bd.quit()
def test_safari_browser(headless):
def test_safari_browser():
bd = BrowserDriver().get("safari", headless=False)
bd.get('https://test.io')
assert "QA Testing as a Service | test IO" == bd.title
bd.quit()
@pytest.mark.skip(reason="Edge has inconsistent implementations across platforms")
def test_edge_browser(headless):
bd = BrowserDriver().get("edge", headless=headless)
bd.get('https://test.io')