diff --git a/tests/selenium/python/tests/test_add_member.py b/tests/selenium/python/tests/test_add_member.py new file mode 100644 index 00000000..ddd5e7e8 --- /dev/null +++ b/tests/selenium/python/tests/test_add_member.py @@ -0,0 +1,22 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select +import time + +driver = webdriver.Chrome() + +driver.get("http://localhost:8989/projects/1/add-member") +time.sleep(2) + +driver.find_element(By.ID, "emailMemberInput").send_keys("colaborador@teste.com") +Select(driver.find_element(By.ID, "levelMemberSelect")).select_by_visible_text("Pesquisador") +driver.find_element(By.XPATH, "//button[contains(text(), 'Adicionar')]").click() + +time.sleep(8) + +page_text = driver.find_element(By.TAG_NAME, "body").text +assert "colaborador@teste.com" in page_text, "Colaborador não foi adicionado com sucesso" + +print("Colaborador adicionado com sucesso!") + +driver.quit() diff --git a/tests/selenium/python/tests/test_create_new_project.py b/tests/selenium/python/tests/test_create_new_project.py new file mode 100644 index 00000000..baa7b5d2 --- /dev/null +++ b/tests/selenium/python/tests/test_create_new_project.py @@ -0,0 +1,26 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select +import time + +driver = webdriver.Chrome() + +driver.get("http://localhost:8989/projects/create") +time.sleep(7) + +driver.find_element(By.ID, "titleInput").send_keys("teste criar") +driver.find_element(By.ID, "descriptionTextarea").send_keys("teste criar") +driver.find_element(By.ID, "objectivesTextarea").send_keys("teste criar") + +driver.find_element(By.ID, "feature_review1").click() +driver.find_element(By.XPATH, "//button[contains(text(), 'Create')]").click() + +time.sleep(8) + +assert "/projects" in driver.current_url, "Erro: Não redirecionou para a lista de projetos" +body_text = driver.find_element(By.TAG_NAME, "body").text +assert "teste editar" in body_text, "Erro: Projeto 'teste editar' não encontrado na lista" + +print("Projeto criado e validado com sucesso!") + +driver.quit() diff --git a/tests/selenium/python/tests/test_create_new_project_Bad.py b/tests/selenium/python/tests/test_create_new_project_Bad.py new file mode 100644 index 00000000..5d7f50fe --- /dev/null +++ b/tests/selenium/python/tests/test_create_new_project_Bad.py @@ -0,0 +1,57 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +URL = "http://localhost:8989/projects/create" + +def iniciar_driver(): + driver = webdriver.Chrome() + driver.get(URL) + time.sleep(1.5) + return driver + +def finalizar_driver(driver): + driver.quit() + +def clicar_criar(driver): + driver.find_element(By.XPATH, "//button[contains(text(), 'Create')]").click() + time.sleep(1.5) + +def existe_erro(driver, campo): + try: + erro = driver.find_element(By.XPATH, f"//input[@id='{campo}']/following-sibling::span[contains(@class, 'invalid-feedback')] | //textarea[@id='{campo}']/following-sibling::span[contains(@class, 'invalid-feedback')]") + return erro.is_displayed() + except: + return False + +def teste_todos_os_campos_vazios(): + driver = iniciar_driver() + clicar_criar(driver) + + assert existe_erro(driver, "titleInput"), "Erro: mensagem de validação do título não apareceu" + assert existe_erro(driver, "descriptionTextarea"), "Erro: mensagem de validação da descrição não apareceu" + assert existe_erro(driver, "objectivesTextarea"), "Erro: mensagem de validação dos objetivos não apareceu" + + finalizar_driver(driver) + +def teste_campo_vazio(campo_id, campo_nome): + driver = iniciar_driver() + + driver.find_element(By.ID, "titleInput").send_keys("Título válido") + driver.find_element(By.ID, "descriptionTextarea").send_keys("Descrição válida") + driver.find_element(By.ID, "objectivesTextarea").send_keys("Objetivos válidos") + driver.find_element(By.ID, "feature_review1").click() + + driver.find_element(By.ID, campo_id).clear() + + clicar_criar(driver) + + assert existe_erro(driver, campo_id), f"Erro: mensagem de validação de '{campo_nome}' não apareceu" + + finalizar_driver(driver) + +if __name__ == "__main__": + teste_todos_os_campos_vazios() + teste_campo_vazio("titleInput", "Título") + teste_campo_vazio("descriptionTextarea", "Descrição") + teste_campo_vazio("objectivesTextarea", "Objetivos") \ No newline at end of file diff --git a/tests/selenium/python/tests/test_edit_project.py b/tests/selenium/python/tests/test_edit_project.py new file mode 100644 index 00000000..11d1b5b2 --- /dev/null +++ b/tests/selenium/python/tests/test_edit_project.py @@ -0,0 +1,33 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select +import time + +driver = webdriver.Chrome() + +driver.get("http://localhost:8989/projects/1/edit") +time.sleep(7) + +driver.find_element(By.ID, "titleInput").clear() +driver.find_element(By.ID, "titleInput").send_keys("teste editar") + +driver.find_element(By.ID, "descriptionTextarea").clear() +driver.find_element(By.ID, "descriptionTextarea").send_keys("teste editar") + +driver.find_element(By.ID, "objectivesTextarea").clear() +driver.find_element(By.ID, "objectivesTextarea").send_keys("teste editar") + +select = Select(driver.find_element(By.ID, "copy_planning")) +select.select_by_visible_text("Nenhum") + +driver.find_element(By.ID, "feature_review1").click() +driver.find_element(By.XPATH, "//button[contains(text(), 'Editar')]").click() + +time.sleep(7) + +assert "/projects" in driver.current_url, "Erro: Não redirecionou para a lista de projetos" +body_text = driver.find_element(By.TAG_NAME, "body").text +assert "teste editar" in body_text, "Erro: Projeto 'teste editar' não encontrado na lista" + +print("Projeto criado e editado com sucesso!") +driver.quit() diff --git a/tests/selenium/python/tests/test_edit_project_bad.py b/tests/selenium/python/tests/test_edit_project_bad.py new file mode 100644 index 00000000..6d8d99e1 --- /dev/null +++ b/tests/selenium/python/tests/test_edit_project_bad.py @@ -0,0 +1,65 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +URL = "http://localhost:8989/projects/1/edit" + +def iniciar_driver(): + driver = webdriver.Chrome() + driver.get(URL) + time.sleep(1.5) + return driver + +def finalizar_driver(driver): + driver.quit() + +def clicar_editar(driver): + driver.find_element(By.XPATH, "//button[contains(text(), 'Editar')]").click() + time.sleep(1.5) + +def existe_erro(driver, campo): + try: + erro = driver.find_element(By.XPATH, f"//input[@id='{campo}']/following-sibling::span[contains(@class, 'invalid-feedback')] | //textarea[@id='{campo}']/following-sibling::span[contains(@class, 'invalid-feedback')]") + return erro.is_displayed() + except: + return False + +def teste_todos_os_campos_vazios_edicao(): + driver = iniciar_driver() + + driver.find_element(By.ID, "titleInput").clear() + driver.find_element(By.ID, "descriptionTextarea").clear() + driver.find_element(By.ID, "objectivesTextarea").clear() + + clicar_editar(driver) + + assert existe_erro(driver, "titleInput"), "Erro: mensagem de validação do título não apareceu" + assert existe_erro(driver, "descriptionTextarea"), "Erro: mensagem de validação da descrição não apareceu" + assert existe_erro(driver, "objectivesTextarea"), "Erro: mensagem de validação dos objetivos não apareceu" + + finalizar_driver(driver) + +def teste_campo_vazio_edicao(campo_id, campo_nome): + driver = iniciar_driver() + + driver.find_element(By.ID, "titleInput").clear() + driver.find_element(By.ID, "titleInput").send_keys("Título válido") + + driver.find_element(By.ID, "descriptionTextarea").clear() + driver.find_element(By.ID, "descriptionTextarea").send_keys("Descrição válida") + + driver.find_element(By.ID, "objectivesTextarea").clear() + driver.find_element(By.ID, "objectivesTextarea").send_keys("Objetivos válidos") + + driver.find_element(By.ID, "feature_review1").click() + driver.find_element(By.ID, campo_id).clear() + + clicar_editar(driver) + assert existe_erro(driver, campo_id), f"Erro: mensagem de validação de '{campo_nome}' não apareceu" + finalizar_driver(driver) + +if __name__ == "__main__": + teste_todos_os_campos_vazios_edicao() + teste_campo_vazio_edicao("titleInput", "Título") + teste_campo_vazio_edicao("descriptionTextarea", "Descrição") + teste_campo_vazio_edicao("objectivesTextarea", "Objetivos") diff --git a/tests/selenium/python/tests/test_overview_project.py b/tests/selenium/python/tests/test_overview_project.py new file mode 100644 index 00000000..94d63832 --- /dev/null +++ b/tests/selenium/python/tests/test_overview_project.py @@ -0,0 +1,16 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + + +driver.get("http://localhost:8989/projects/1") +time.sleep(3) + +body_text = driver.find_element(By.TAG_NAME, "body").text + +assert "teste editar" in body_text, "'teste editar' não encontrado no conteúdo do projeto" +print("'teste editar' está presente na descrição ou objetivos.") + +driver.quit() diff --git a/tests/selenium/python/tests/test_user_create_admin.py b/tests/selenium/python/tests/test_user_create_admin.py new file mode 100644 index 00000000..da2e1e14 --- /dev/null +++ b/tests/selenium/python/tests/test_user_create_admin.py @@ -0,0 +1,47 @@ +import unittest +import time +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +class UserRegistrationTest(unittest.TestCase): + def setUp(self): + self.driver = webdriver.Chrome() + self.driver.get("http://localhost:8989/user/create") + + def test_empty_form_submission(self): + driver = self.driver + submit_button = driver.find_element(By.CSS_SELECTOR, "button[type='submit']") + submit_button.click() + time.sleep(1) + + error_elements = driver.find_elements(By.CLASS_NAME, "text-danger") + self.assertTrue(any("usuário" in e.text.lower() or "obrigatório" in e.text.lower() for e in error_elements)) + + def test_invalid_email_submission(self): + driver = self.driver + driver.find_element(By.NAME, "username").send_keys("usuario_teste") + driver.find_element(By.NAME, "email").send_keys("emailinvalido") + driver.find_element(By.NAME, "password").send_keys("Senha123!") + driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click() + time.sleep(1) + + error_elements = driver.find_elements(By.CLASS_NAME, "text-danger") + self.assertTrue(any("email" in e.text.lower() for e in error_elements)) + + def test_valid_form_submission(self): + driver = self.driver + driver.find_element(By.NAME, "username").send_keys("usuario_teste") + driver.find_element(By.NAME, "email").send_keys("usuario_teste@example.com") + driver.find_element(By.NAME, "password").send_keys("SenhaSegura123!") + driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click() + time.sleep(2) + + alert_div = driver.find_element(By.ID, "alert") + self.assertIn("sucesso", alert_div.text.lower()) + + def tearDown(self): + self.driver.quit() + +if __name__ == "__main__": + unittest.main() diff --git a/tests/selenium/python/tests/test_user_management_admin.py b/tests/selenium/python/tests/test_user_management_admin.py new file mode 100644 index 00000000..bcc59d93 --- /dev/null +++ b/tests/selenium/python/tests/test_user_management_admin.py @@ -0,0 +1,40 @@ +import time +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +driver = webdriver.Chrome() +driver.get("http://localhost:8989/user-manager") +wait = WebDriverWait(driver, 10) + +try: + add_user_button = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Adicionar Usuário"))) + add_user_button.click() + assert "/user/create" in driver.current_url.lower() + print("Botão 'Adicionar Usuário' funcional.") + + driver.back() + + edit_buttons = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//a[contains(text(),'Editar')]"))) + if edit_buttons: + edit_buttons[0].click() + assert "edit" in driver.current_url.lower() + print("Botão 'Editar' funcionando.") + else: + print("Nenhum botão 'Editar' encontrado.") + + driver.back() + + toggle_buttons = wait.until(EC.presence_of_all_elements_located( + (By.XPATH, "//a[contains(text(),'Ativar') or contains(text(),'Desativar')]") + )) + if toggle_buttons: + toggle_buttons[0].click() + print("Ativar/Desativar' funciona.") + else: + print("Nenhum botão 'Ativar/Desativar' encontrado.") + +finally: + time.sleep(2) + driver.quit()