44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
import time
|
|
import unittest
|
|
from flask_test_server import start_flask_in_thread
|
|
|
|
class ContactPageSeleniumTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
# Start Flask server in background
|
|
cls.flask_thread = start_flask_in_thread()
|
|
cls.base_url = "http://127.0.0.1:5000/contact"
|
|
# Możesz zmienić na Firefox, jeśli nie masz ChromeDriver
|
|
cls.driver = webdriver.Chrome()
|
|
cls.driver.implicitly_wait(5)
|
|
time.sleep(2) # Ensure server is up
|
|
|
|
def test_contact_form_submission(self):
|
|
self.driver.get(self.base_url)
|
|
name_input = self.driver.find_element(By.ID, "name")
|
|
message_input = self.driver.find_element(By.ID, "message")
|
|
name_input.send_keys("Selenium")
|
|
message_input.send_keys("To jest test Selenium.")
|
|
# Find all submit buttons and click the second one (contact form)
|
|
submit_btns = self.driver.find_elements(By.XPATH, "//button[@type='submit']")
|
|
submit_btns[1].click()
|
|
# Wait for the success message to appear
|
|
wait = WebDriverWait(self.driver, 5)
|
|
success_msg = wait.until(
|
|
EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), 'Dziękujemy za kontakt!')]"))
|
|
)
|
|
self.assertTrue(success_msg.is_displayed())
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.driver.quit()
|
|
# No direct way to stop Flask dev server, but thread will exit with process
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|