"""Given tests.""" import pytest from pytest_bdd import given, then, scenario from pytest_bdd.steps import StepError @given("I have foo") def foo(): return "foo" given("I have alias for foo", fixture="foo") given("I have an alias to the root fixture", fixture="root") @given("I have session foo", scope='session') def session_foo(): return "session foo" @scenario('given.feature', 'Test reusing local fixture') def test_given_with_fixture(): pass @scenario('given.feature', 'Test reusing root fixture') def test_root_alias(): pass
@scenario(u'Steps in .py file have unicode') def test_steps_in_py_file_have_unicode(): pass pattern = r"(?P<content>'\w+')" @pytest.fixture def string(): """String fixture.""" return {'content': ''} given(u"I have an alias with a unicode type for foo", fixture="foo") @given(parsers.parse(u"у мене є рядок який містить '{content}'")) def there_is_a_string_with_content(content, string): """Create string with unicode content.""" string['content'] = content @given("there is an other string with content 'якийсь контент'") def there_is_an_other_string_with_content(string): """Create other string with unicode content.""" string['content'] = u"с каким-то контентом" @then("I should see that the other string equals to content 'якийсь контент'")
import pytest from pytest_bdd import given, then, scenario from pytest_bdd.steps import StepError @given('I have foo') def foo(): return 'foo' given('I have alias for foo', fixture='foo') given('I have an alias to the root fixture', fixture='root') @scenario('given.feature', 'Test reusing local fixture') def test_given_with_fixture(): pass @scenario('given.feature', 'Test reusing root fixture') def test_root_alias(): pass @then('foo should be "foo"') def foo_is_foo(foo): assert foo == 'foo' @then('root should be "root"') def root_is_root(root):
import pytest from pytest_bdd import given, then, scenario from pytest_bdd.steps import StepError @given("I have foo") def foo(): return "foo" given("I have alias for foo", fixture="foo") given("I have an alias to the root fixture", fixture="root") @scenario('given.feature', 'Test reusing local fixture') def test_given_with_fixture(): pass @scenario('given.feature', 'Test reusing root fixture') def test_root_alias(): pass @then('foo should be "foo"') def foo_is_foo(foo): assert foo == 'foo' @then('root should be "root"')
'reuse.feature', 'Given and when using the same fixture should not evaluate it twice', ) def test_reuse(): pass @given('I have an empty list') def empty_list(): return [] @given('I have a fixture (appends 1 to a list)') def appends_1(empty_list): empty_list.append(1) return empty_list given('I have a fixture (appends 1 to a list) in reuse syntax', fixture='appends_1') @when('I use this fixture') def use_fixture(appends_1): pass @then('my list should be [1]') def list_should_be_1(appends_1): assert appends_1 == [1]
@scenario("reuse.feature", "Given and when using the same fixture should not evaluate it twice") def test_reuse(): pass @given("I have an empty list") def empty_list(): return [] @given("I have a fixture (appends 1 to a list)") def appends_1(empty_list): empty_list.append(1) return empty_list given("I have a fixture (appends 1 to a list) in reuse syntax", fixture="appends_1") @when("I use this fixture") def use_fixture(appends_1): pass @then("my list should be [1]") def list_should_be_1(appends_1): assert appends_1 == [1]
response_spec = lookup(response_spec, operation["source"]) response_spec.keys = () response_spec.value = record_value response_spec.__source__ = operation.get("source") context[operation["key"]] = response_spec return wrapper for f in (ROOT_PATH / "features").rglob("given.json"): version = f.parent.name with f.open() as fp: for settings in json.load(fp): given(settings["step"])(build_given(version, settings)) @when("the request is sent") def execute_request(context, api_version): """Execute the prepared request.""" @when("the request with pagination is sent") def execute_request_with_pagination(context): """Execute the prepared request paginated.""" @then(parsers.parse("the response status is {status:d} {description}")) def the_status_is(context, status, description): """Check the status."""
from pytest_bdd import scenario, given, when, then import pytest import os @pytest.fixture def pytestbdd_feature_base_dir(): return os.path.join(os.getcwd(), "features") """Background""" given("an environment that meets the Avalon's demand", fixture="minmum_environment_setup") given("I initiate Avalon", fixture="init_avalon") """Scenarios""" @scenario("maya_publish.feature", "model mesh is triangulate") def test_app_startup(): pass @given('a model which has triangulated faces') def step_impl_given_tri_face(): pass @given('a model which has multiple shape nodes')
@scenario( 'reuse.feature', 'Given and when using the same fixture should not evaluate it twice', ) def test_reuse(): pass @given('I have an empty list') def empty_list(): return [] @given('I have a fixture (appends 1 to a list)') def appends_1(empty_list): empty_list.append(1) return empty_list given('I have a fixture (appends 1 to a list) in reuse syntax', fixture='appends_1') @when('I use this fixture') def use_fixture(appends_1): pass @then('my list should be [1]') def list_should_be_1(appends_1): assert appends_1 == [1]
CALL TESTS FROM FEATURES FOLDER: ''' scenarios('../features/DifferentElements.feature') ''' STEPS FOR THE FEATURE DIFFERENT ELEMENTS: ''' @pytest.fixture(scope='session') def service_in_the_header(home_page): return home_page.header.get_service_submenu_sections() given('I click on "Service" in the header to get the dropdownlist options', fixture='service_in_the_header') @then('I should see <category> subcategory in header:') def check_subcategories(home_page, service_in_the_header, category): home_page.header.check_the_option_is_presented_in_dropdown(expected_option=category, options=service_in_the_header) @pytest.fixture(scope='session') def service_in_the_sidebar(home_page): return home_page.sidebar.get_service_submenu_sections() given('I click on "Service" in the side nav-bar', fixture='service_in_the_sidebar')
import pytest from pytest_bdd import given, then, scenario from pytest_bdd.steps import StepError @given('I have foo') def foo(): return 'foo' given('I have alias for foo', fixture='foo') given('I have an alias to the root fixture', fixture='root') test_given_with_fixture = scenario('given.feature', 'Test reusing local fixture') test_root_alias = scenario('given.feature', 'Test reusing root fixture') @then('foo should be "foo"') def foo_is_foo(foo): assert foo == 'foo' @then('root should be "root"') def root_is_root(root): assert root == 'root' def test_decorate_with_fixture(): """Test given can't be used as decorator when the fixture is specified."""
@then(re.compile('I should see "(?P<text>.+)"')) def i_should_see(browser, text): assert browser.is_text_present(text) @given("I'm not logged in") @given("I'm a visitor") # Step alias def not_logged_in(credentials): """99%% of the cases you test logged in. Specify not logged in state to be explicit. """ credentials['login'] = False @given("I'm an admin") def logged_in(credentials): credentials['login'] = True # Re-use of the fixture given("I have an entry", fixture="entry") @when("I go to the blog") def go_to_blog(browser): browser.visit(urljoin(browser.url, "/"))
"""Admin given steps.""" from pytest_bdd import given, parsers @given('I have an instance') def instance(instance_factory): """Instance.""" return instance_factory() given('I have a CI project', fixture='ci_project') given('I have a release', fixture='release') @given(parsers.parse('I am {user_role}')) def i_am(user_role): """I have an instance.""" return user_role @given('I have a case') def case(case_factory): """Case.""" return case_factory() @given('I have a migration') def migration(migration_factory): """Migration.""" return migration_factory()
from splinter import Browser from pytest_bdd import scenario, given, when, then, scenarios, parsers from .MainPage import MainPage from .AnyPageAbstracts import Base from .DifferentElementsPage import DifferentElements @pytest.fixture(scope="session") def driver(request): with Browser(driver_name="chrome") as b: b.driver.maximize_window() yield b given('a Chrome browser is open', fixture='driver') @pytest.fixture(scope="session") def home_page(driver): home_page = MainPage(driver) home_page.open() yield home_page given('I am on the Home Page', fixture='home_page') @pytest.fixture(scope="session") def elements_page(home_page, driver): home_page.header.go_to_different_elements_page()