
from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .utils import wait_for


class FormTestMixin:

    # default search element
    form_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
        (By.XPATH, '//form[@action="{}"]',),
        (By.XPATH, '//form[@name="{}"]',),
        (By.XPATH, '//form/*',),
    )

    @wait_for
    def get_form(self, *args, **kwargs):
        """ Return form element or None. """
        return self.find_element(
            self.form_search_list, *args, **kwargs)

    input_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
    )

    @wait_for
    def set_input(self, field, value, **kwargs):
        input = self.find_element(
            self.input_search_list, field, **kwargs)
        input.clear()
        input.send_keys(value)
        return input


from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .utils import wait_for


class FormTestMixin:

    # default search element
    form_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
        (By.XPATH, '//form[@action="{}"]',),
        (By.XPATH, '//form[@name="{}"]',),
        (By.XPATH, '//form',),
    )

    @wait_for
    def get_form(self, *args, **kwargs):
        """ Return form element or None. """
        return self.find_element(
            self.form_search_list, *args, **kwargs)

    input_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
    )

    @wait_for
    def get_input(self, field, **kwargs):
        """ Return matching input field. """
        return self.find_element(
            self.input_search_list, field, **kwargs)

    def set_input(self, field, value, **kwargs):
        """ Clear the field and enter value. """
        element = self.get_input(field, **kwargs)
        element.clear()
        element.send_keys(value)
        return element

Split get_input from set_input in FormTestMixin.
Split get_input from set_input in FormTestMixin.

In order to reduce side-effects, this commit moves the @wait_for to
a get_input method and set_input operates immediately.

  
  from __future__ import absolute_import
  
  from selenium.webdriver.common.by import By
  
  from .utils import wait_for
  
  
  class FormTestMixin:
  
      # default search element
      form_search_list = (
          (By.ID, '{}',),
          (By.NAME, '{}',),
          (By.XPATH, '//form[@action="{}"]',),
          (By.XPATH, '//form[@name="{}"]',),
-         (By.XPATH, '//form/*',),
+         (By.XPATH, '//form',),
      )
  
      @wait_for
      def get_form(self, *args, **kwargs):
          """ Return form element or None. """
          return self.find_element(
              self.form_search_list, *args, **kwargs)
  
      input_search_list = (
          (By.ID, '{}',),
          (By.NAME, '{}',),
      )
  
      @wait_for
+     def get_input(self, field, **kwargs):
+         """ Return matching input field. """
+         return self.find_element(
+             self.input_search_list, field, **kwargs)
+ 
      def set_input(self, field, value, **kwargs):
-         input = self.find_element(
-             self.input_search_list, field, **kwargs)
+         """ Clear the field and enter value. """
+         element = self.get_input(field, **kwargs)
-         input.clear()
+         element.clear()
-         input.send_keys(value)
+         element.send_keys(value)
-         return input
+         return element
  
Split get_input from set_input in FormTestMixin.
## Code Before:

from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .utils import wait_for


class FormTestMixin:

    # default search element
    form_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
        (By.XPATH, '//form[@action="{}"]',),
        (By.XPATH, '//form[@name="{}"]',),
        (By.XPATH, '//form/*',),
    )

    @wait_for
    def get_form(self, *args, **kwargs):
        """ Return form element or None. """
        return self.find_element(
            self.form_search_list, *args, **kwargs)

    input_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
    )

    @wait_for
    def set_input(self, field, value, **kwargs):
        input = self.find_element(
            self.input_search_list, field, **kwargs)
        input.clear()
        input.send_keys(value)
        return input

## Instruction:
Split get_input from set_input in FormTestMixin.
## Code After:

from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .utils import wait_for


class FormTestMixin:

    # default search element
    form_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
        (By.XPATH, '//form[@action="{}"]',),
        (By.XPATH, '//form[@name="{}"]',),
        (By.XPATH, '//form',),
    )

    @wait_for
    def get_form(self, *args, **kwargs):
        """ Return form element or None. """
        return self.find_element(
            self.form_search_list, *args, **kwargs)

    input_search_list = (
        (By.ID, '{}',),
        (By.NAME, '{}',),
    )

    @wait_for
    def get_input(self, field, **kwargs):
        """ Return matching input field. """
        return self.find_element(
            self.input_search_list, field, **kwargs)

    def set_input(self, field, value, **kwargs):
        """ Clear the field and enter value. """
        element = self.get_input(field, **kwargs)
        element.clear()
        element.send_keys(value)
        return element
