DemoBlazeAutomation / Tests / TestsForm.cs
TestsForm.cs
Raw
using FluentAssertions;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoBlazeAutomation.Tests
{
    internal class TestsForm
    {
        [Test]
        public void Main()
        {
            // Inicializar el controlador de Selenium (en este caso, Chrome)
            IWebDriver driver = new ChromeDriver();
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            // Navegar a la página de inicio en Demoblaze
            driver.Navigate().GoToUrl("https://www.demoblaze.com/index.html");

            // Hacer clic en el enlace "Contact" para abrir el formulario de contacto en el modal
            driver.FindElement(By.PartialLinkText("Contact")).Click();

            // Esperar un tiempo para que aparezca el modal (puedes ajustar el tiempo según sea necesario)
            Thread.Sleep(2000);

            // Cambiar al contexto del modal
            IWebElement modal = driver.FindElement(By.XPath("//div[@id='exampleModal']//div[@class='modal-content']"));
            //driver.SwitchTo().Frame(modal);

            // Llenar el formulario de contacto dentro del modal
            driver.FindElement(By.Id("recipient-email")).SendKeys("example@example.com");
            driver.FindElement(By.Id("recipient-name")).SendKeys("John Doe");
            driver.FindElement(By.Id("message-text")).SendKeys("Este es un mensaje de prueba para el formulario de contacto.");

            // Hacer clic en el botón "Send" para enviar el formulario dentro del modal
            driver.FindElement(By.CssSelector("button.btn.btn-primary")).Click();

            // Esperar un tiempo para que la alerta aparezca (puedes ajustar el tiempo según sea necesario)
            Thread.Sleep(2000);

            // Manejar la alerta que aparece después de enviar el formulario
            IAlert alert = driver.SwitchTo().Alert();
            string alertText = alert.Text;
            Console.WriteLine("Alert Text: " + alertText);


            alert.Accept(); // O alert.Dismiss() dependiendo de lo que haga la alerta

            alertText.Should().Be("Thanks for the message!!");
            // Cambiar de nuevo al contexto principal
            driver.SwitchTo().DefaultContent();

            // Cerrar el navegador
            driver.Quit();
        }
    }

}