-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormTest.java
More file actions
135 lines (113 loc) · 5.58 KB
/
FormTest.java
File metadata and controls
135 lines (113 loc) · 5.58 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package softesting.selenium;
import net.serenitybdd.junit5.SerenityJUnit5Extension;
import net.serenitybdd.annotations.Managed;
import net.serenitybdd.annotations.Title;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import softesting.selenium.pages.FormPage;
import utils.EvidenceCaptureUtil;
import utils.TestLogger;
import java.io.IOException;
import java.time.Duration;
@ExtendWith(SerenityJUnit5Extension.class)
public class FormTest {
private static final Logger logger = LoggerFactory.getLogger(FormTest.class);
private static final String URL = "http://64.227.54.255/Softesting/Frontend/Caso1.html";
private static final boolean debugMode = true;
@Managed(driver = "chrome", options = "start-maximized,disable-notifications")
private WebDriver driver;
private FormPage formPage;
@BeforeEach
public void setUp() {
formPage = new FormPage(driver);
driver.get(URL);
logger.info("Navegado a URL: {}", URL);
TestLogger.logInfo("Browser abierto y navegado a la URL");
}
@Test
@Title("CP01 - Envío de formulario con datos completos")
public void testCompleteFormSubmission() throws IOException {
formPage.enterNombre("Juan Martin Alvarez");
formPage.enterEmail("juan.alvarez@outlook.com");
formPage.enterBarrio("Modelia");
formPage.enterAsunto("Petición de prueba");
formPage.enterMensaje("Este es un mensaje de prueba");
EvidenceCaptureUtil.captureAndAddToReport(driver, "CP01 - Envío de formulario con datos completos",
"Formulario lleno antes de enviar"); // Captura de screenshot
String mensajeAlerta = formPage.enviarFormularioYCapturarAlerta(); // Captura del error y método usado para
// obtenerlo
Assertions.assertTrue(mensajeAlerta.contains("UPPPPS ALGO HA FALLADO"),
"Mensaje recibido: " + mensajeAlerta);
}
@Test
@Title("CP02 - Llenar el formulario sin nombre")
public void testFormSubmissionWithoutName() {
driver.findElement(By.id("nombre")).click(); // Enfocar el campo nombre
formPage.enterEmail("test@test.com");
formPage.enterBarrio("Usaquén");
EvidenceCaptureUtil.captureAndAddToReport(driver, "CP02 - Llenar el formulario sin nombre",
"Formulario sin nombre"); // Captura de screenshot
formPage.enterAsunto("Reclamo");
formPage.enterMensaje("Falta mi nombre");
String error = formPage.getErrorNombre(); // Captura del error y método usado para obtenerlo
Assertions.assertEquals("El nombre debe ser mayor a 4 letras y no debe incluir caracteres especiales", error);
}
@Test
@Title("CP03 - Formulario con email inválido")
public void testFormSubmissionWithInvalidEmail() {
formPage.enterNombre("Ana Gómez");
formPage.enterEmail("emailinvalido");
formPage.enterBarrio("Chapinero");
formPage.enterAsunto("Sugerencia");
formPage.enterMensaje("Email mal formado");
EvidenceCaptureUtil.captureAndAddToReport(driver, "CP03 - Formulario con email inválido",
"Formulario sin correo"); // Captura de screenshot
String error = formPage.getErrorEmail(); // Captura del error y método usado para obtenerlo
Assertions.assertEquals(
"El Email debe ser mayor a 4 caracteres y debe llevar @ y . no debe incluir caracteres especiales",
error);
}
@Test
@Title("CP04 - Envío de formulario sin barrio")
public void testFormSubmissionWithoutBarrio() {
formPage.enterNombre("Carlos Ruiz");
formPage.enterEmail("carlos@test.com");
driver.findElement(By.name("barrio")).click();
formPage.enterAsunto("Felicitaciones");
formPage.enterMensaje("Mensaje de prueba");
EvidenceCaptureUtil.captureAndAddToReport(driver, "CP04 - Envío de formulario sin barrio",
"Formulario sin barrio"); // Captura de screenshot
String error = formPage.getErrorBarrio(); // Captura del error y método usado para obtenerlo
Assertions.assertEquals("El nombre debe ser mayor a 4 letras", error);
}
@Test
@Title("CP05 - Envío de formulario sin asunto")
public void testFormSubmissionWithoutSubject() {
formPage.enterNombre("Luisa Pérez");
formPage.enterEmail("luisa@test.com");
formPage.enterBarrio("Chapinero");
driver.findElement(By.name("asunto")).click();
formPage.enterMensaje("Mensaje mínimo");
EvidenceCaptureUtil.captureAndAddToReport(driver, "CP05 - Envío de formulario sin asunto",
"Formulario sin asunto"); // Captura de screenshot
String error = formPage.getErrorAsunto(); // Captura del error y método usado para obtenerlo
Assertions.assertEquals("El nombre debe ser mayor a 4 letras", error);
}
@AfterEach
public void tearDown() {
logger.info("========== Test finalizado ==========");
if (debugMode) {
new WebDriverWait(driver, Duration.ofSeconds(8))
.until(ExpectedConditions.titleIs("Simulacro Funcional")); // o cualquier título actual de la página
}
}
}