-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (51 loc) · 2.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os
from dotenv import load_dotenv
import pyotp
import unittest
load_dotenv()
class LoginTesting(unittest.TestCase):
def setUp(self):
# Configure drive
self.driver = webdriver.Chrome("C:/WebDriver/bin/chromedriver")
def test_login(self):
driver = self.driver
# Open Web Browser
driver.implicitly_wait(30)
driver.set_page_load_timeout(50)
driver.get("https://eureka-monash.com")
wait = WebDriverWait(driver,10)
# Check if correct broswer connected (check if browser name is correct)
self.assertIn("Eureka", driver.title, msg="wrong website" )
# Conifgure main page (to handle redirection of windows)
main_page = driver.current_window_handle
# Logging in from Home Page
driver.find_element_by_id("top-nav__name").click()
driver.find_element_by_tag_name("button").click()
for handle in driver.window_handles:
if handle != main_page:
login_page = handle
# Switch to Auth Page
driver.switch_to.window(login_page)
# Input Credentials & Proceeding
driver.find_element_by_css_selector("input[type=email]").send_keys(os.getenv("USER_NAME"))
driver.find_element_by_class_name("VfPpkd-LgbsSe").click()
# At Monash page, input user name and password
driver.find_element_by_name("username").send_keys(os.getenv("USER_NAME"))
driver.find_element_by_name("password").send_keys(os.getenv("PASSWORD"))
driver.find_element_by_id("okta-signin-submit").click()
totp = pyotp.TOTP(os.getenv("SECRET_KEY"))
authField = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@name='answer']")))
token = totp.now()
authField.send_keys(token)
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='submit']")))
driver.find_element_by_xpath("//input[@type='submit']").click()
driver.find_element_by_class_name("VfPpkd-LgbsSe").click()
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()