input: Write a function to automate the login process in a given website using Selenium in Python. If the login is successful, the function should print "Login successful!" and close the web driver. If the website is not accessible or the login fails, the function should handle the exception gracefully.
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  import time
  
  def automate_login(website_url, username_str, password_str):
      try:
          # Initialize web driver
          driver = webdriver.Chrome()
  
          # Navigate to the target web page
          driver.get(website_url)
  
          # Locate username field
          username = driver.find_element_by_name('username')
  
          # Enter username
          username.send_keys(username_str)
  
          # Locate password field
          password = driver.find_element_by_name('password')
  
          # Enter password
          password.send_keys(password_str)
  
          # Locate submit button
          submit_button = driver.find_element_by_name('submit')
  
          # Click submit button
          submit_button.click()
  
          # Wait for login process to complete
          time.sleep(5)
  
          # Login successful
          print('Login successful!')
  
      except Exception as e:
          print(f"Login failed: {e}")
      finally:
          driver.close()
  
  assert automate_login('http://www.example.com', 'username', 'password')=='Login successful!'
  assert automate_login('http://www.nonexistentwebsite.com', 'username', 'password')=='Login failed: [some exception message]'
output: def automate_login(website_url, username_str, password_str):
      try:
          driver = webdriver.Chrome()
          driver.get(website_url)
          username = driver.find_element_by_name('username')
          username.send_keys(username_str)
          password = driver.find_element_by_name('password')
          password.send_keys(password_str)
          submit_button = driver.find_element_by_name('submit')
          submit_button.click()
          time.sleep(5)
          print('Login successful!')
      except Exception as e:
          print(f"Login failed: {e}")
      finally:
          driver.close()