153 lines
4.7 KiB
PHP
153 lines
4.7 KiB
PHP
<?php
|
|
require_once('vendor/autoload.php');
|
|
|
|
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
|
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
|
use Facebook\WebDriver\WebDriverBy;
|
|
use Facebook\WebDriver\WebDriverExpectedCondition;
|
|
use Facebook\WebDriver\WebDriverWait;
|
|
|
|
// Nodo de Selenium Hub
|
|
$host = 'http://localhost:4444/wd/hub';
|
|
|
|
//URL test
|
|
$url = "https://mi.gugler.com.ar";
|
|
|
|
$userData = [
|
|
'email' => 'cuenta.falsa123@micorreo.com',
|
|
'password' => 'abc123456',
|
|
'name' => 'User',
|
|
'lastname' => 'Test',
|
|
'dni' => '99008866',
|
|
'address' => 'Calle Falsa 123',
|
|
'birthdate' => '1990-01-01',
|
|
'phone' => '1234567890',
|
|
];
|
|
|
|
// Configuración de los nodos para Chrome y Firefox
|
|
$drivers = [
|
|
'chrome' => DesiredCapabilities::chrome(),
|
|
'firefox' => DesiredCapabilities::firefox(),
|
|
'edge' => array("platform" => "linux","browserName" => "MicrosoftEdge"),
|
|
];
|
|
|
|
function ingresar($driver, $url) {
|
|
$driver->get($url);
|
|
|
|
//Ingresar al sitio
|
|
$title = $driver->getTitle();
|
|
if (strpos($title, "Mi Gugler") !== false) {
|
|
echo "\033[32m✔ Test 1 [Ingresar al sitio] aprobado:\033[0m El título contiene 'Mi Gugler'.\n";
|
|
} else {
|
|
echo "\033[31m✘ Test 1 [Ingresar al sitio] fallido:\033[0m El título no contiene 'Mi Gugler'.\n";
|
|
}
|
|
|
|
sleep(2);
|
|
}
|
|
|
|
|
|
function iniciarSesionError($driver, $wait, $url, $email, $password) {
|
|
$driver->get($url.'/login');
|
|
|
|
try {
|
|
$wait->until(function ($driver) {
|
|
return $driver->executeScript("return document.readyState") === "complete";
|
|
});
|
|
|
|
$loginInputEmail = $wait->until(
|
|
WebDriverExpectedCondition::elementToBeClickable(
|
|
WebDriverBy::cssSelector('input[type="text"]')
|
|
)
|
|
);
|
|
|
|
$loginInputEmail->click();
|
|
sleep(1);
|
|
|
|
foreach (str_split($email) as $char) {
|
|
$loginInputEmail->sendKeys($char);
|
|
sleep(0.75);
|
|
}
|
|
|
|
echo "\033[32m✔ Test 3 [Iniciar sesión]:\033[0m Se completó el campo de email.\n";
|
|
|
|
sleep(0.5);
|
|
$loginInputPassword = $wait->until(
|
|
WebDriverExpectedCondition::elementToBeClickable(
|
|
WebDriverBy::cssSelector('input[type="password"]')
|
|
)
|
|
);
|
|
|
|
$loginInputPassword->click();
|
|
sleep(1);
|
|
|
|
$password = 'wrongpassword12345'; // Cambiar a una contraseña incorrecta para probar el error
|
|
foreach (str_split($password) as $char) {
|
|
$loginInputPassword->sendKeys($char);
|
|
sleep(0.75);
|
|
}
|
|
|
|
echo "\033[32m✔ Test 3 [Iniciar sesión]:\033[0m Se completó el campo de contraseña.\n";
|
|
|
|
sleep(1);
|
|
$loginButton = $wait->until(
|
|
WebDriverExpectedCondition::elementToBeClickable(
|
|
WebDriverBy::cssSelector('button[aria-label="Ingresar"]')
|
|
)
|
|
);
|
|
|
|
$loginButton->click();
|
|
|
|
$divErrorMensaje = $wait->until(
|
|
WebDriverExpectedCondition::presenceOfElementLocated(
|
|
WebDriverBy::cssSelector('div#errorLogin')
|
|
)
|
|
);
|
|
|
|
if ($divErrorMensaje->isDisplayed()) {
|
|
$mensaje = $divErrorMensaje->getText();
|
|
|
|
$mensajeEsperado = "No se pudo iniciar sesion. Por favor verifique su nombre de usuario y contraseña.";
|
|
|
|
if ($mensaje !== $mensajeEsperado) {
|
|
echo "\033[31m✘ Test 3 [Iniciar sesión]:\033[0m Mensaje de error inesperado: '$mensaje'. Se esperaba el mensaje \" $mensajeEsperado \" \n";
|
|
} else {
|
|
echo "\033[31m✘ Test 3 [Iniciar sesión]:\033[0m Error de inicio de sesión detectado correctamente.\n";
|
|
}
|
|
|
|
} else {
|
|
echo "\033[31m✘ Test 3 [Iniciar sesión]:\033[0m No se mostró el mensaje de error esperado.\n";
|
|
}
|
|
|
|
sleep(2);
|
|
|
|
echo "\033[32m✔ Test 3 [Iniciar sesión]:\033[0m Inicio de sesión completado correctamente.\n";
|
|
|
|
} catch (Exception $e) {
|
|
echo "\033[31m✘ Test 3 [Iniciar sesión]:\033[0m No se pudo completar el formulario: " . $e->getMessage() . "\n";
|
|
$driver->quit();
|
|
}
|
|
}
|
|
|
|
foreach ($drivers as $browser => $capabilities) {
|
|
echo "Ejecutando pruebas en $browser...\n";
|
|
|
|
$driver = RemoteWebDriver::create($host, $capabilities);
|
|
$driver->manage()->window()->maximize();
|
|
|
|
$wait = new WebDriverWait($driver, 10);
|
|
|
|
sleep(5);
|
|
|
|
echo "[$browser] - Prueba 1: Ingresar al sitio ...\n";
|
|
ingresar($driver, $url);
|
|
|
|
echo "[$browser] - Prueba 2: Iniciar sesion ERROR ...\n";
|
|
iniciarSesionError($driver, $wait, $url, $userData['email'], $userData['password']);
|
|
|
|
echo "[$browser] - Prueba finalizada ...\n";
|
|
|
|
$driver->quit();
|
|
}
|
|
|
|
echo "Pruebas completadas en todos los navegadores.\n";
|