behave and pytest in the same framework
This commit is contained in:
parent
b2a56eb83a
commit
14ea594425
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,8 @@
|
|||||||
*.lock
|
*.lock
|
||||||
*.iml
|
*.iml
|
||||||
|
*.pyc
|
||||||
|
*.log
|
||||||
|
**/.DS_Store
|
||||||
|
**/__pycache/
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
4
Pipfile
4
Pipfile
@ -8,14 +8,14 @@ flask = "*"
|
|||||||
pytest = "*"
|
pytest = "*"
|
||||||
behave = "*"
|
behave = "*"
|
||||||
selenium = "*"
|
selenium = "*"
|
||||||
django = "*"
|
webdriver_manager = "*"
|
||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
flask = "*"
|
flask = "*"
|
||||||
pytest = "*"
|
pytest = "*"
|
||||||
behave = "*"
|
behave = "*"
|
||||||
selenium = "*"
|
selenium = "*"
|
||||||
djanjgo = "*"
|
webdriver_manager = "*"
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
python_version = "3.8"
|
python_version = "3.8"
|
42
browserdriver/__init__.py
Executable file
42
browserdriver/__init__.py
Executable 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()
|
5
features/browser_demo.feature
Normal file
5
features/browser_demo.feature
Normal 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
|
@ -1,5 +1,5 @@
|
|||||||
Feature: Demo Feature
|
Feature: Demo Feature
|
||||||
Scenario: Demo1
|
Scenario: Demo
|
||||||
Given A sentence
|
Given A sentence
|
||||||
When The sentence is inspected
|
When The sentence is inspected
|
||||||
Then The word "the" should be found
|
Then The word "the" should be found
|
||||||
|
18
features/steps/browser_demo.py
Normal file
18
features/steps/browser_demo.py
Normal 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"
|
@ -1,13 +1,16 @@
|
|||||||
@given(u'A sentence')
|
from behave import then, when, given
|
||||||
|
|
||||||
|
|
||||||
|
@given('A sentence')
|
||||||
def step_impl(context):
|
def step_impl(context):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@when(u'The sentence is inspected')
|
@when('The sentence is inspected')
|
||||||
def step_impl(context):
|
def step_impl(context):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@then(u'The word "the" should be found')
|
@then('The word "the" should be found')
|
||||||
def step_impl(context):
|
def step_impl(context):
|
||||||
return True
|
return True
|
15
unittests/test_basic.py
Normal file
15
unittests/test_basic.py
Normal 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
|
Loading…
Reference in New Issue
Block a user