Start adding login method
This commit is contained in:
parent
7c21f445b1
commit
819f8cd92f
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
|
||||||
def initialize_webdriver():
|
def initialize_webdriver():
|
||||||
return webdriver.Firefox()
|
return webdriver.Firefox()
|
||||||
|
@ -8,6 +10,11 @@ def initialize_webdriver():
|
||||||
def navigate_to_filegarden(browser):
|
def navigate_to_filegarden(browser):
|
||||||
browser.get("https://filegarden.com/login")
|
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():
|
def main():
|
||||||
with initialize_webdriver() as browser:
|
with initialize_webdriver() as browser:
|
||||||
navigate_to_filegarden(browser)
|
navigate_to_filegarden(browser)
|
||||||
|
|
|
@ -1,23 +1,39 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import unittest
|
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
|
import jardin
|
||||||
|
|
||||||
class TestJardin(unittest.TestCase):
|
class TestJardin(unittest.TestCase):
|
||||||
@patch("selenium.webdriver.Firefox")
|
@patch("jardin.webdriver.Firefox")
|
||||||
def test_initialize_webdriver_calls_Firefox(self, mockFirefox):
|
def test_initialize_webdriver_calls_Firefox(self, mockFirefox):
|
||||||
jardin.initialize_webdriver()
|
jardin.initialize_webdriver()
|
||||||
|
|
||||||
mockFirefox.assert_called_once()
|
mockFirefox.assert_called_once()
|
||||||
|
|
||||||
@patch("selenium.webdriver.Firefox")
|
@patch("jardin.webdriver.Firefox")
|
||||||
def test_navigate_to_filegarden(self, mockFirefox):
|
def test_navigate_to_filegarden(self, mockFirefox):
|
||||||
jardin.navigate_to_filegarden(mockFirefox)
|
jardin.navigate_to_filegarden(mockFirefox)
|
||||||
|
|
||||||
mockFirefox.get.assert_called_once_with("https://filegarden.com/login")
|
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.initialize_webdriver")
|
||||||
@patch("jardin.navigate_to_filegarden")
|
@patch("jardin.navigate_to_filegarden")
|
||||||
def test_main_calls_methods_in_correct_order(self,
|
def test_main_calls_methods_in_correct_order(self,
|
||||||
|
|
Loading…
Reference in New Issue