title: How to check if the user is created in the database and delete it
body: <p>I have currently written my signup test using python page object method. I want to add logging in to the database and checking the user i created and then deleted it. I would like to add that in my teardown method. How can I achieve it using sql to make a more robust test</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  import unittest
  import sys
  
  
  class BaseTestCase(object):
  
  
      def setUp(self):
          self.driver = webdriver.Firefox()
          self.driver.maximize_window()
          self.driver.get("https://marketplace.appdirect.com/login")
          self.assertEqual("Log In | AppDirect", self.driver.title)
  
  
  
      def tearDown(self):
          if sys.exc_info()[0]:
              test_method_name = self._testMethodName
              # if the test fails, the code below will take a screenshot
              self.driver.save_screenshot("/Users/Desktop/AppDirect/Screenshots" + test_method_name + ".png") 
          self.driver.quit()
  
  
  from selenium                                 import webdriver
  from selenium.webdriver.support.ui            import WebDriverWait
  from selenium.webdriver.support.select        import Select
  from selenium.webdriver.support               import expected_conditions as EC
  from selenium.webdriver.common.by             import By
  from abc                                      import abstractmethod
  
  
  
  
  class LocatorMode:
  
   XPATH = "xpath"
   CSS_SELECTOR = "cssSelector"
   NAME = "name"
   ID = "id"
   TAG_NAME = "tagName"
  
  
  class BasePage(object):
  
   def __init__(self, driver):
       self.driver = driver
  
  
   @abstractmethod
   def _verify_page(self):
       """
       This method verifies that we are on the correct page.
       """
       return 
  
   def wait_for_element_visibility(self, waitTime, locatorMode, Locator):
       element = None
       if   locatorMode == LocatorMode.ID:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.visibility_of_element_located((By.ID, Locator)))
       elif locatorMode == LocatorMode.NAME:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.visibility_of_element_located((By.NAME, Locator)))
       elif locatorMode == LocatorMode.XPATH:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.visibility_of_element_located((By.XPATH, Locator)))
       elif locatorMode == LocatorMode.CSS_SELECTOR:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.visibility_of_element_located((By.CSS_SELECTOR, Locator)))
       else:
           raise Exception("Unsupported locator strategy.")
       return element
  
  
   def wait_until_element_clickable(self, waitTime, locatorMode, Locator):
       element = None
       if   locatorMode == LocatorMode.ID:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.element_to_be_clickable((By.ID, Locator)))
       elif locatorMode == LocatorMode.NAME:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.element_to_be_clickable((By.NAME, Locator)))
       elif locatorMode == LocatorMode.XPATH:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.element_to_be_clickable((By.XPATH, Locator)))
       elif locatorMode == LocatorMode.CSS_SELECTOR:
            element = WebDriverWait(self.driver, waitTime).\
                    until(EC.element_to_be_clickable((By.CSS_SELECTOR, Locator)))
       else:
           raise Exception("Unsupported locator strategy.")
       return element
  
  
  
   def find_element(self, locatorMode, Locator):
       element = None
       if locatorMode == LocatorMode.ID:
          element = self.driver.find_element_by_id(Locator)
       elif locatorMode == LocatorMode.NAME:
          element = self.driver.find_element_by_name(Locator)
       elif locatorMode == LocatorMode.XPATH:
          element = self.driver.find_element_by_xpath(Locator)
       elif locatorMode == LocatorMode.CSS_SELECTOR: 
          element = self.driver.find_element_by_css_selector(Locator)
       else:
          raise Exception("Unsupported locator strategy.")
       return element
  
  
   def fill_out_field(self, locatorMode, Locator, text):
       self.find_element(locatorMode, Locator).clear()
       self.find_element(locatorMode, Locator).send_keys(text)
  
   def click(self, waitTime, locatorMode, Locator):
       self.wait_until_element_clickable(waitTime, locatorMode, Locator).click()
  
  
  
  class IncorrectPageException(Exception):
   """
   This exception is raised when we try to instantiate the wrong page.
   """
  
  
  from selenium import webdriver
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  import unittest
  import sys
  
  
  class SignupPage(BasePage):
  
       def clickSignupButton(self. driver):
          self.click(10, "xpath", "//a[contains(.,'Sign Up')]")
          self.assertEqual("Sign Up for AppDirect", self.driver.title)
  
      def setEmail(self, email):
          self.fill_out_field("id", "id_email", email)
          self.click(10, "xpath", "//button[@name='userSignupButton']")
  
      def setName(self, first, last):
          self.fill_out_field("id", "id_first_name", first)
          self.fill_out_field("id", "id_last_name", last)
  
      def setPassword(self, password):
          self.fill_out_field("id", "id_password", password)
          self.fill_out_field("id", "id_password_confirmation", password)
  
      def setProductName(self, name):
          self.fill_out_field("id", "id_first_product_name", name)
  
        def submit(self):
          self.click(10, "cssSelector", "#create_account_form button")
  
  from selenium import webdriver
  import unittest
  from BaseTestCase import BaseTestCase
  from BasePage import BasePage
  from SignupPage import SignupPage
  
  
  
  
  class SignupTest(BaseTestCase, unittest.TestCase):
  
  
      def setUp(self):
          super(SignupTest, self).setUp()
  
  
      # Positive Test Case
      def test_SignupTest(self):
          # enter the username, password, email etc
  
  
  
      def tearDown(self):
          super(SignupTest, self).tearDown()
  
  
  
  if __name__ == "__main__":
      unittest.main()
  </code></pre>
  
  <p>I know that adding it in the teardown method will be a great code. Any thoughts???</p>