Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
Created October 13, 2012 14:39
Show Gist options
  • Save ApprenticeGC/3884854 to your computer and use it in GitHub Desktop.
Save ApprenticeGC/3884854 to your computer and use it in GitHub Desktop.
Retrieve TestFlight token info
#!/usr/bin/env python
import argparse
from selenium import webdriver
class TokenRetriever:
#
test_flight_link_address = 'https://testflightapp.com/'
#
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.get(TokenRetriever.test_flight_link_address)
self.email = ''
self.password = ''
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.driver.quit()
def open_main_site(self):
self.driver.get(TokenRetriever.test_flight_link_address)
#
self.save_screenshot('Start to Log In')
def login(self):
try:
login_element = self.driver.find_element_by_link_text('Log In')
login_element.click()
#
self.save_screenshot('Log In')
except NoSuchElementException as e:
print (e.args)
finally:
pass
def fill_info(self):
email_element = self.driver.find_element_by_id('id_username')
password_element = self.driver.find_element_by_id('id_password')
email_element.send_keys(self.email)
password_element.send_keys(self.password)
#
self.save_screenshot('Fill In Login Info.png')
def submit_login_info(self):
submit_element = self.driver.find_element_by_css_selector('input[type=\"submit\"]')
submit_element.click()
#
self.save_screenshot('Dashboard')
def click_team_info(self):
team_info_element = self.driver.find_element_by_link_text('Team Info')
team_info_element.click()
#
self.save_screenshot('Team Info')
def retrieve_team_token(self):
team_token_element = self.driver.find_element_by_css_selector('input[class=\"uneditable-input span9 small\"]')
team_token_value = team_token_element.get_attribute('value')
return team_token_value
def click_account_setting_icon(self):
account_setting_element = self.driver.find_element_by_link_text('Account Settings')
account_setting_element.click()
#
self.save_screenshot('Account Setting Drop-down Menu')
def click_account_setting_dropdown_selection(self):
# Since the link name is the same, use find_elements to get a collection
account_setting_elements = self.driver.find_elements_by_link_text('Account Settings')
# The second element is the drop-down menu selection
account_setting_elements[1].click()
#
self.save_screenshot('User Profile')
def click_api(self):
api_element = self.driver.find_element_by_link_text('API')
api_element.click()
#
self.save_screenshot('User API')
def retrieve_api_token(self):
api_token_element = self.driver.find_element_by_css_selector('input[class=\"uneditable-input flex95 small wordwrap\"]')
api_token_value = api_token_element.get_attribute('value')
return api_token_value
def click_logout_dropdown_selection(self):
logout_element = self.driver.find_element_by_link_text('Log Out')
logout_element.click()
#
self.save_screenshot('Logout')
# Utility method to assist taking screenshot and save it as an image file.
def save_screenshot(self, file_name):
file_name = 'TestFlight' + file_name + '.png'
self.driver.save_screenshot(file_name)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--email', required=True)
parser.add_argument('--password', required=True)
args = parser.parse_args()
team_token = ''
user_api_token =''
# Whenever the with scope is out, __exit__ method is called
# to serve the purpose of cleaning
with TokenRetriever() as token_retriever:
token_retriever.email = args.email
token_retriever.password = args.password
# Actual operation step defined as the following in order
# to retrieve tokens
token_retriever.open_main_site()
token_retriever.login()
token_retriever.fill_info()
token_retriever.submit_login_info()
token_retriever.click_team_info()
#
team_token = token_retriever.retrieve_team_token()
token_retriever.click_account_setting_icon()
token_retriever.click_account_setting_dropdown_selection()
token_retriever.click_api()
#
user_api_token = token_retriever.retrieve_api_token()
token_retriever.click_account_setting_icon()
token_retriever.click_logout_dropdown_selection()
# Simply print out to console, but this could be saved for
# being used later.
print (team_token)
print (user_api_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment