
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class HamperAuthenticator(object):

	def __init__(self, driver, email, password):
		super(HamperAuthenticator, self).__init__()
		self.email 	  = email
		self.password = password
		self.driver = webdriver.Firefox()
		self.cookie_jar = self.driver.get_cookies()

	def sign_in(self):
		# Open the profile URL. This will forward to the sign in page if session is invalid
		self.driver.get("https://developer.apple.com/account/ios/profile/")

		email_element = self.driver.find_element_by_name("appleId")
		email_element.send_keys(self.email)

		password_element = self.driver.find_element_by_name("accountPassword")
		password_element.send_keys(self.password)

		self.driver.find_element_by_id("submitButton2").click()
		self.cookie_jar = self.driver.get_cookies()
		
		return self.cookie_jar






from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class HamperAuthenticator(object):

	def __init__(self, email, password):
		super(HamperAuthenticator, self).__init__()
		self.email 	  = email
		self.password = password

	def sign_in(self, driver):
		# Open the profile URL. This will forward to the sign in page if session is invalid
		driver.get("https://developer.apple.com/account/ios/profile/")

		email_element = driver.find_element_by_name("appleId")
		email_element.send_keys(self.email)

		password_element = driver.find_element_by_name("accountPassword")
		password_element.send_keys(self.password)

		driver.find_element_by_id("submitButton2").click()
		
		return driver
Use parameter to pass Webdriver object to share execution
Use parameter to pass Webdriver object to share execution

  
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  
  class HamperAuthenticator(object):
  
- 	def __init__(self, driver, email, password):
+ 	def __init__(self, email, password):
  		super(HamperAuthenticator, self).__init__()
  		self.email 	  = email
  		self.password = password
- 		self.driver = webdriver.Firefox()
- 		self.cookie_jar = self.driver.get_cookies()
  
- 	def sign_in(self):
+ 	def sign_in(self, driver):
  		# Open the profile URL. This will forward to the sign in page if session is invalid
- 		self.driver.get("https://developer.apple.com/account/ios/profile/")
+ 		driver.get("https://developer.apple.com/account/ios/profile/")
  
- 		email_element = self.driver.find_element_by_name("appleId")
+ 		email_element = driver.find_element_by_name("appleId")
  		email_element.send_keys(self.email)
  
- 		password_element = self.driver.find_element_by_name("accountPassword")
+ 		password_element = driver.find_element_by_name("accountPassword")
  		password_element.send_keys(self.password)
  
- 		self.driver.find_element_by_id("submitButton2").click()
+ 		driver.find_element_by_id("submitButton2").click()
- 		self.cookie_jar = self.driver.get_cookies()
  		
+ 		return driver
- 		return self.cookie_jar
- 
- 
- 
- 
- 
Use parameter to pass Webdriver object to share execution
## Code Before:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class HamperAuthenticator(object):

	def __init__(self, driver, email, password):
		super(HamperAuthenticator, self).__init__()
		self.email 	  = email
		self.password = password
		self.driver = webdriver.Firefox()
		self.cookie_jar = self.driver.get_cookies()

	def sign_in(self):
		# Open the profile URL. This will forward to the sign in page if session is invalid
		self.driver.get("https://developer.apple.com/account/ios/profile/")

		email_element = self.driver.find_element_by_name("appleId")
		email_element.send_keys(self.email)

		password_element = self.driver.find_element_by_name("accountPassword")
		password_element.send_keys(self.password)

		self.driver.find_element_by_id("submitButton2").click()
		self.cookie_jar = self.driver.get_cookies()
		
		return self.cookie_jar





## Instruction:
Use parameter to pass Webdriver object to share execution
## Code After:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class HamperAuthenticator(object):

	def __init__(self, email, password):
		super(HamperAuthenticator, self).__init__()
		self.email 	  = email
		self.password = password

	def sign_in(self, driver):
		# Open the profile URL. This will forward to the sign in page if session is invalid
		driver.get("https://developer.apple.com/account/ios/profile/")

		email_element = driver.find_element_by_name("appleId")
		email_element.send_keys(self.email)

		password_element = driver.find_element_by_name("accountPassword")
		password_element.send_keys(self.password)

		driver.find_element_by_id("submitButton2").click()
		
		return driver