Start adding login method

This commit is contained in:
The Magician 2023-10-20 12:25:19 +01:00
parent 7c21f445b1
commit 819f8cd92f
2 changed files with 26 additions and 3 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
def initialize_webdriver():
return webdriver.Firefox()
@ -8,6 +10,11 @@ def initialize_webdriver():
def navigate_to_filegarden(browser):
browser.get("https://filegarden.com/login")
def login_with_password(browser, email, password):
emailInput = browser.find_element(By.ID, "email")
emailInput.send_keys(email)
emailInput.send_keys(Keys.RETURN)
def main():
with initialize_webdriver() as browser:
navigate_to_filegarden(browser)

View File

@ -1,23 +1,39 @@
#!/usr/bin/python3
import unittest
from unittest.mock import patch
from unittest.mock import patch, call
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import jardin
class TestJardin(unittest.TestCase):
@patch("selenium.webdriver.Firefox")
@patch("jardin.webdriver.Firefox")
def test_initialize_webdriver_calls_Firefox(self, mockFirefox):
jardin.initialize_webdriver()
mockFirefox.assert_called_once()
@patch("selenium.webdriver.Firefox")
@patch("jardin.webdriver.Firefox")
def test_navigate_to_filegarden(self, mockFirefox):
jardin.navigate_to_filegarden(mockFirefox)
mockFirefox.get.assert_called_once_with("https://filegarden.com/login")
@patch("jardin.webdriver.Firefox")
def test_login_with_password_performs_login_steps(self, mockFirefox):
mockEmail = "email@mail.com"
mockPassword = "p4$$w0rd"
jardin.login_with_password(mockFirefox, mockEmail, mockPassword)
mockFirefox.find_element.assert_called_with(By.ID, "email")
mockFirefox.find_element.return_value.send_keys.assert_has_calls([
call(mockEmail),
call(Keys.RETURN)
])
@patch("jardin.initialize_webdriver")
@patch("jardin.navigate_to_filegarden")
def test_main_calls_methods_in_correct_order(self,