Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97790

How to keep selenium webdriver running as part of before_tag hook using fixture in behave framework?

$
0
0

I am using behave framework for testing and some features files do not require a browser to run against. So I am trying to use fixtures with tags as described in https://behave.readthedocs.io/en/latest/tutorial.html#controlling-things-with-tags. The problem is that the CLEANUP-FIXTURE PART ran right after the driver is started.

environment.py



@fixture
def selenium_webdriver(context):
    # -- SETUP-FIXTURE PART:
    context.driver = webdriver.Remote(
        command_executor='http://my-selenium-server:4444/wd/hub',
        desired_capabilities=DesiredCapabilities.CHROME)
    context.driver.set_page_load_timeout(30)
    context.driver.maximize_window()
    yield context.driver
    # -- CLEANUP-FIXTURE PART:
    context.driver.quit()

fixture_registry1 = {
    "fixture.selenium_webdriver": selenium_webdriver
}

def before_tag(context, tag):
    if tag.startswith("fixture.selenium_webdriver"):
        return use_fixture_by_tag(tag, context, fixture_registry1)

test.feature

@fixture.selenium_webdriver
Feature: Test

  Scenario: My Scenario
    Given Something
    When I do anything
    Then Something happens

During scenarios execution, the driver starts successfully, however, it ends right after. I have tried to comment the lines under CLEANUP-FIXTURE PART: to keep it running, but the behave kind of lost connection with the selenium session. Any thoughts on how to only starts selenium webdriver for specifics tags and features?


Viewing all articles
Browse latest Browse all 97790

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>