behave and pytest in the same framework

This commit is contained in:
Greg Gauthier 2020-10-09 18:34:54 +01:00
parent b2a56eb83a
commit 14ea594425
10 changed files with 94 additions and 7 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
*.lock
*.iml
*.pyc
*.log
**/.DS_Store
**/__pycache/
.idea/
.vscode/

View File

@ -8,14 +8,14 @@ flask = "*"
pytest = "*"
behave = "*"
selenium = "*"
django = "*"
webdriver_manager = "*"
[packages]
flask = "*"
pytest = "*"
behave = "*"
selenium = "*"
djanjgo = "*"
webdriver_manager = "*"
[requires]
python_version = "3.8"

42
browserdriver/__init__.py Executable file
View File

@ -0,0 +1,42 @@
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.chrome import ChromeDriverManager
class BrowserDriver:
@staticmethod
def get(browser=None):
if browser == "chrome":
return chrome()
elif browser == "firefox":
return firefox()
elif browser == "edge":
return edge()
elif browser == "safari":
return safari()
else:
raise ValueError("'{}' is not a supported browser".format(browser))
def chrome():
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
return webdriver.Chrome(ChromeDriverManager().install(), options=options)
def firefox():
options = webdriver.FirefoxOptions()
options.accept_insecure_certs = True
gecko_driver = GeckoDriverManager().install()
return webdriver.Firefox(executable_path=gecko_driver, firefox_options=options)
def edge():
return webdriver.Edge(DesiredCapabilities.EDGE)
def safari():
# Because safari driver is bundled with safari
return webdriver.Safari()

View File

View File

@ -0,0 +1,5 @@
Feature: Browser Demo
Scenario: Load test.io web page
Given I have a chrome driver
When I navigate to test.io
Then The page is displayed

View File

@ -1,5 +1,5 @@
Feature: Demo Feature
Scenario: Demo1
Scenario: Demo
Given A sentence
When The sentence is inspected
Then The word "the" should be found

View File

@ -0,0 +1,18 @@
from behave import then, when, given
from browserdriver import BrowserDriver
@given('I have a chrome driver')
def step_impl(context):
context.driver = BrowserDriver.get("chrome")
@when('I navigate to test.io')
def step_impl(context):
context.driver.get("https://test.io")
@then('The page is displayed')
def step_impl(context):
assert context.driver.title == "QA Testing as a Service | test IO"

View File

@ -1,13 +1,16 @@
@given(u'A sentence')
from behave import then, when, given
@given('A sentence')
def step_impl(context):
return True
@when(u'The sentence is inspected')
@when('The sentence is inspected')
def step_impl(context):
return True
@then(u'The word "the" should be found')
@then('The word "the" should be found')
def step_impl(context):
return True

15
unittests/test_basic.py Normal file
View File

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

View File