fix code, update pylint, other goodies
All checks were successful
Pylint / build (3.12) (push) Successful in 9s
All checks were successful
Pylint / build (3.12) (push) Successful in 9s
This commit is contained in:
parent
fb4af8ac47
commit
63fcdbc922
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
|||||||
**/__pycache/
|
**/__pycache/
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.venv/
|
||||||
|
23
Pipfile
23
Pipfile
@ -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"
|
|
@ -1,2 +1,3 @@
|
|||||||
# behave-framework
|
# behave-framework
|
||||||
|
|
||||||
basic python test framework
|
basic python test framework
|
||||||
|
@ -1,51 +1,38 @@
|
|||||||
|
# pylint: disable=too-few-public-methods
|
||||||
from selenium import webdriver
|
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:
|
class BrowserDriver:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(browser=None, headless=True):
|
def get(browser=None, headless=True):
|
||||||
if browser == "chrome":
|
valid_browsers = ['chrome', 'firefox', 'safari', 'edge']
|
||||||
return chrome(headless)
|
if browser in valid_browsers:
|
||||||
elif browser == "firefox":
|
browser_method = globals()[browser]
|
||||||
return firefox(headless)
|
return browser_method(headless)
|
||||||
elif browser == "edge":
|
|
||||||
return edge(headless)
|
raise ValueError(f"'{browser}' is not a supported browser")
|
||||||
elif browser == "safari":
|
|
||||||
return safari()
|
|
||||||
else:
|
|
||||||
raise ValueError("'{}' is not a supported browser".format(browser))
|
|
||||||
|
|
||||||
|
|
||||||
def chrome(headless=True):
|
def chrome(headless=True):
|
||||||
options = webdriver.ChromeOptions()
|
options = webdriver.ChromeOptions()
|
||||||
options.headless = headless
|
options.headless = headless
|
||||||
options.add_argument('--ignore-certificate-errors')
|
options.add_argument('--ignore-certificate-errors')
|
||||||
return webdriver.Chrome(
|
return webdriver.Chrome(options=options)
|
||||||
ChromeDriverManager().install(),
|
|
||||||
options=options)
|
|
||||||
|
|
||||||
|
|
||||||
def firefox(headless=True):
|
def firefox(headless=True):
|
||||||
options = webdriver.FirefoxOptions()
|
options = webdriver.FirefoxOptions()
|
||||||
options.accept_insecure_certs = True
|
options.accept_insecure_certs = True
|
||||||
options.headless = headless
|
options.headless = headless
|
||||||
gecko_driver = GeckoDriverManager().install()
|
return webdriver.Firefox(options=options)
|
||||||
return webdriver.Firefox(
|
|
||||||
executable_path=gecko_driver,
|
|
||||||
options=options)
|
|
||||||
|
|
||||||
|
|
||||||
def edge(headless=True):
|
def edge(headless=True):
|
||||||
options = EdgeOptions()
|
options = webdriver.EdgeOptions()
|
||||||
options.use_chromium = True
|
options.use_chromium = True
|
||||||
options.headless = headless
|
options.headless = headless
|
||||||
edge_driver = EdgeChromiumDriverManager().install()
|
driver = webdriver.Edge(options=options)
|
||||||
driver = Edge(edge_driver, options=options)
|
|
||||||
return driver
|
return driver
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import configparser
|
import configparser
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
Feature: Browser Demo
|
Feature: Browser Demo
|
||||||
|
|
||||||
Scenario: Load test.io web page with chrome
|
Scenario: Load test.io web page with chrome
|
||||||
Given I have a chrome driver
|
Given I have a chrome driver
|
||||||
When I navigate to test.io
|
When I navigate to test.io
|
||||||
@ -9,12 +10,12 @@ Feature: Browser Demo
|
|||||||
When I navigate to test.io
|
When I navigate to test.io
|
||||||
Then The page is displayed
|
Then The page is displayed
|
||||||
|
|
||||||
@skip
|
|
||||||
Scenario: Load test.io web page with edge
|
Scenario: Load test.io web page with edge
|
||||||
Given I have an edge driver
|
Given I have an edge driver
|
||||||
When I navigate to test.io
|
When I navigate to test.io
|
||||||
Then The page is displayed
|
Then The page is displayed
|
||||||
|
|
||||||
|
@skip
|
||||||
Scenario: Load test.io web page with safari
|
Scenario: Load test.io web page with safari
|
||||||
Given I have a safari driver
|
Given I have a safari driver
|
||||||
When I navigate to test.io
|
When I navigate to test.io
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
# pylint: disable=unused-argument
|
||||||
def before_all(context):
|
def before_all(context):
|
||||||
# -- SET LOG LEVEL: behave --logging-level=ERROR ...
|
# -- SET LOG LEVEL: behave --logging-level=ERROR ...
|
||||||
# on behave command-line or in "behave.ini".
|
# on behave command-line or in "behave.ini".
|
||||||
context.config.setup_logging()
|
context.config.setup_logging()
|
||||||
|
|
||||||
|
|
||||||
|
def after_scenario(context, scenario):
|
||||||
|
context.driver.quit()
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
|
# pylint: disable=no-name-in-module
|
||||||
from behave import then, when, given
|
from behave import then, when, given
|
||||||
|
|
||||||
from browserdriver import BrowserDriver
|
from browserdriver import BrowserDriver
|
||||||
|
|
||||||
|
|
||||||
@given('I have a firefox driver')
|
@given('I have a firefox driver')
|
||||||
def step_impl(context):
|
def get_firefox_driver(context):
|
||||||
context.driver = BrowserDriver.get("firefox")
|
context.driver = BrowserDriver.get("firefox")
|
||||||
|
|
||||||
|
|
||||||
@given('I have a chrome driver')
|
@given('I have a chrome driver')
|
||||||
def step_impl(context):
|
def get_chrome_driver(context):
|
||||||
context.driver = BrowserDriver.get("chrome")
|
context.driver = BrowserDriver.get("chrome")
|
||||||
|
|
||||||
|
|
||||||
@given(u'I have an edge driver')
|
@given('I have an edge driver')
|
||||||
def step_impl(context):
|
def get_edge_driver(context):
|
||||||
context.driver = BrowserDriver.get("edge")
|
context.driver = BrowserDriver.get("edge")
|
||||||
|
|
||||||
|
|
||||||
@given(u'I have a safari driver')
|
@given('I have a safari driver')
|
||||||
def step_impl(context):
|
def get_safari_driver(context):
|
||||||
context.driver = BrowserDriver.get("safari")
|
context.driver = BrowserDriver.get("safari")
|
||||||
|
|
||||||
|
|
||||||
@when('I navigate to test.io')
|
@when('I navigate to test.io')
|
||||||
def step_impl(context):
|
def navigate_to_testio(context):
|
||||||
context.driver.get("https://test.io")
|
context.driver.get("https://test.io")
|
||||||
print(context.driver.title)
|
|
||||||
|
|
||||||
|
|
||||||
@then('The page is displayed')
|
@then('The page is displayed')
|
||||||
def step_impl(context):
|
def page_is_displayed(context):
|
||||||
assert context.driver.title == "QA Testing as a Service | test IO"
|
assert context.driver.title == "Home | Test IO"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from browserdriver import BrowserDriver
|
from browserdriver import BrowserDriver
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
def test_firefox_browser(headless):
|
def test_firefox_browser(headless):
|
||||||
@ -16,14 +15,13 @@ def test_chrome_browser(headless):
|
|||||||
bd.quit()
|
bd.quit()
|
||||||
|
|
||||||
|
|
||||||
def test_safari_browser(headless):
|
def test_safari_browser():
|
||||||
bd = BrowserDriver().get("safari", headless=False)
|
bd = BrowserDriver().get("safari", headless=False)
|
||||||
bd.get('https://test.io')
|
bd.get('https://test.io')
|
||||||
assert "QA Testing as a Service | test IO" == bd.title
|
assert "QA Testing as a Service | test IO" == bd.title
|
||||||
bd.quit()
|
bd.quit()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="Edge has inconsistent implementations across platforms")
|
|
||||||
def test_edge_browser(headless):
|
def test_edge_browser(headless):
|
||||||
bd = BrowserDriver().get("edge", headless=headless)
|
bd = BrowserDriver().get("edge", headless=headless)
|
||||||
bd.get('https://test.io')
|
bd.get('https://test.io')
|
||||||
|
Loading…
Reference in New Issue
Block a user