-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87ca95a
commit 32cd2eb
Showing
14 changed files
with
808 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.keys import Keys | ||
import time | ||
from fetch_otp import EMAIL, fetch_code | ||
|
||
# brew install chromedriver | ||
|
||
def main(): | ||
print("Connect to Chrome") | ||
# Set up Chrome options to connect to the existing Chrome instance | ||
chrome_options = Options() | ||
chrome_options.add_argument('--remote-debugging-port=9222') | ||
# Connect to the existing Chrome instance | ||
driver = webdriver.Chrome(options=chrome_options) | ||
|
||
print("Open a window on Chrome") | ||
# Get the original window handle | ||
original_window = driver.current_window_handle | ||
|
||
print("Waiting for new window...") | ||
WebDriverWait(driver, 30).until(EC.number_of_windows_to_be(2)) | ||
|
||
# Get all window handles | ||
all_windows = driver.window_handles | ||
|
||
print("Find the new window") | ||
new_window = [window for window in all_windows if window != driver.current_window_handle][0] | ||
|
||
print("Switch to the new window") | ||
driver.switch_to.window(new_window) | ||
|
||
wait = WebDriverWait(driver, 60) | ||
|
||
print("Wait for email input...") | ||
email_field = wait.until(EC.presence_of_element_located((By.ID, ':r1:'))) | ||
print("Enter email") | ||
email_field.send_keys(EMAIL) | ||
email_field.send_keys(Keys.RETURN) | ||
|
||
# Wait for the OTP to arrive and page to load | ||
print("Wait for OTP...") | ||
time.sleep(10) | ||
|
||
print("Get OTP from Mailslurp...") | ||
code = fetch_code() | ||
if code: | ||
print(f"Successfully fetched OTP: {code}") | ||
else: | ||
print("Failed to fetch OTP from Gmail") | ||
driver.quit() | ||
|
||
print("Find OTP input...") | ||
otp_field = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[data-testid="passwordless_passcode__TextInput--0__input"]'))) | ||
print("Enter OTP") | ||
otp_field.send_keys(code) | ||
|
||
print("Wait for success page...") | ||
success = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[data-testid="device_success_title"]'))) | ||
print("Connected to Passport!") | ||
|
||
driver.quit() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.keys import Keys | ||
import time | ||
from gmail_fetch_otp import fetch_gmail_code | ||
|
||
EMAIL = '[email protected]' | ||
|
||
# Add chrome.exe to environment variable | ||
# Download chrome driver and add to environment variable | ||
|
||
def main(): | ||
print("Connect to Chrome") | ||
# Set up Chrome options to connect to the existing Chrome instance | ||
chrome_options = Options() | ||
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222") | ||
# Connect to the existing Chrome instance | ||
driver = webdriver.Chrome(options=chrome_options) | ||
|
||
print("Waiting for new window...") | ||
WebDriverWait(driver, 60).until(EC.number_of_windows_to_be(2)) | ||
|
||
# Get all window handles | ||
all_windows = driver.window_handles | ||
|
||
print("Find the new window") | ||
new_window = [window for window in all_windows if window != driver.current_window_handle][0] | ||
|
||
print("Switch to the new window") | ||
driver.switch_to.window(new_window) | ||
|
||
wait = WebDriverWait(driver, 60) | ||
|
||
print("Wait for email input...") | ||
email_field = wait.until(EC.presence_of_element_located((By.ID, ':r1:'))) | ||
print("Enter email") | ||
email_field.send_keys(EMAIL) | ||
email_field.send_keys(Keys.RETURN) | ||
|
||
# Wait for the OTP to arrive and page to load | ||
print("Wait for OTP...") | ||
time.sleep(10) | ||
|
||
print("Get OTP from Gmail...") | ||
code = fetch_gmail_code() | ||
if code: | ||
print(f"Successfully fetched OTP: {code}") | ||
else: | ||
print("Failed to fetch OTP from Gmail") | ||
driver.quit() | ||
|
||
print("Find OTP input...") | ||
otp_field = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[data-testid="passwordless_passcode__TextInput--0__input"]'))) | ||
print("Enter OTP") | ||
otp_field.send_keys(code) | ||
|
||
print("Wait for success page...") | ||
success = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[data-testid="device_success_title"]'))) | ||
print("Connected to Passport!") | ||
|
||
driver.quit() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.keys import Keys | ||
|
||
def main(): | ||
print("Connect to Chrome") | ||
# Set up Chrome options to connect to the existing Chrome instance | ||
chrome_options = Options() | ||
chrome_options.add_argument('--remote-debugging-port=9222') | ||
# Connect to the existing Chrome instance | ||
driver = webdriver.Chrome(options=chrome_options) | ||
|
||
print("Open a window on Chrome") | ||
# Get the original window handle | ||
original_window = driver.current_window_handle | ||
|
||
print("Waiting for new window...") | ||
WebDriverWait(driver, 60).until(EC.number_of_windows_to_be(2)) | ||
|
||
# Get all window handles | ||
all_windows = driver.window_handles | ||
|
||
print("Find the new window") | ||
new_window = [window for window in all_windows if window != driver.current_window_handle][0] | ||
|
||
print("Switch to the new window") | ||
driver.switch_to.window(new_window) | ||
|
||
driver.quit() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.keys import Keys | ||
|
||
def main(): | ||
print("Connect to Chrome") | ||
# Set up Chrome options to connect to the existing Chrome instance | ||
chrome_options = Options() | ||
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222") | ||
# Connect to the existing Chrome instance | ||
driver = webdriver.Chrome(options=chrome_options) | ||
|
||
print("Waiting for new window...") | ||
WebDriverWait(driver, 60).until(EC.number_of_windows_to_be(2)) | ||
|
||
# Get all window handles | ||
all_windows = driver.window_handles | ||
|
||
print("Find the new window") | ||
new_window = [window for window in all_windows if window != driver.current_window_handle][0] | ||
|
||
print("Switch to the new window") | ||
driver.switch_to.window(new_window) | ||
|
||
driver.quit() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import mailslurp_client | ||
from mailslurp_client.api import InboxControllerApi, WaitForControllerApi | ||
import re | ||
|
||
INBOX_ID = "33f17f82-274b-4269-9ce6-c620e89fcd8d" | ||
EMAIL = "[email protected]" | ||
|
||
def get_mailslurp_client(): | ||
configuration = mailslurp_client.Configuration() | ||
configuration.api_key['x-api-key'] = os.getenv('MAILSLURP_API_KEY') | ||
api_client = mailslurp_client.ApiClient(configuration) | ||
waitfor_controller = WaitForControllerApi(api_client) | ||
return waitfor_controller | ||
|
||
def extract_otp_from_email(email_body): | ||
# Pattern to match 6-digit code in Passport emails | ||
pattern = r'<h1[^>]*>(\d{6})</h1>' | ||
match = re.search(pattern, email_body) | ||
if match: | ||
return match.group(1) | ||
return None | ||
|
||
def fetch_code(): | ||
waitfor_controller = get_mailslurp_client() | ||
email = waitfor_controller.wait_for_latest_email(inbox_id=INBOX_ID, timeout=30000, unread_only=True) | ||
if email: | ||
otp = extract_otp_from_email(email.body) | ||
return otp | ||
return None |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.