title: Adding common attributes to a Behave method
body: <p>Using the great <a href="http://pythonhosted.org/behave/" rel="noreferrer">Behave</a> framework, but having trouble with my lack of OOP skills. </p>
  
  <p>Behave has an inbuilt context namespace where objects can be shared between test execution steps. After initializing my WebDriver session, I keep passing it between my steps using this <code>context</code> to hold everything. Functionality is fine, but as you can see below, it is anything but DRY. </p>
  
  <p>How/where can I add these attributes to the <code>step_impl()</code> or <code>context</code> once only?</p>
  
  <p><strong>environment.py</strong></p>
  
  <pre><code>from selenium import webdriver
  
  def before_feature(context, scenario):
      """Initialize WebDriver instance"""
  
      driver = webdriver.PhantomJS(service_args=service_args, desired_capabilities=dcap)
  
      """
      Do my login thing..
      """
  
      context.driver = driver
      context.wait = wait
      context.expected_conditions = expected_conditions
      context.xenv = env_data
  </code></pre>
  
  <p><strong>steps.py</strong></p>
  
  <pre><code>@given('that I have opened the blah page')
  def step_impl(context):
  
      driver = context.driver
      wait = context.wait
      expected_conditions = context.expected_conditions
      xenv = context.xenv
  
      driver.get("http://domain.com")
      driver.find_element_by_link_text("blah").click()
      wait.until(expected_conditions.title_contains("Blah page"))
  
  @given(u'am on the yada subpage')
  def step_impl(context):
      driver = context.driver
      wait = context.wait
      expected_conditions = context.expected_conditions
      xenv = context.xenv
  
      if driver.title is not "MySubPage/":
          driver.get("http://domain.MySubPage/")
          wait.until(expected_conditions.title_contains("Blah | SubPage"))
  
  @given(u'that I have gone to another page')
  def step_impl(context):
      driver = context.driver
      wait = context.wait
      expected_conditions = context.expected_conditions
      xenv = context.xenv
  
      driver.get("http://domain.com/MyOtherPahge/")
  </code></pre>