using DemoBlazeAutomation.POM; using NUnit.Framework; using OpenQA.Selenium.Chrome; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using static DemoBlazeAutomation.POM.BasePage; namespace DemoBlazeAutomation.Tests { internal class TestGetValueCartFromTable { private IWebDriver _driver; protected HomePage HomePage; protected ProductDetailPage ProductDetailPage; [SetUp] public void Initialize() { // Inicializar el controlador de Selenium _driver = new ChromeDriver(); _driver.Manage().Window.Maximize(); _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); // Navegar a la página de inicio en Demoblaze _driver.Navigate().GoToUrl("https://www.demoblaze.com/index.html"); HomePage = new HomePage(_driver); ProductDetailPage = new ProductDetailPage(_driver); } [Test] /// <summary> /// Verificar la lista de productos en formato Models, objetos C# public void CartCheck() { Thread.Sleep(2000); HomePage.ClickProduct("Samsung galaxy s6"); ProductDetailPage.AddToCart(); HomePage.GoToSection("Home"); //Thread.Sleep(3000); //HomePage.ClickProduct("Nokia lumia 1520"); //ProductDetailPage.AddToCart(); //HomePage.GoToSection("Home"); HomePage.GoToSection("Cart"); var title1 = HomePage.GetValueFromTable("//div[@class='table-responsive']", 1, 1); var price1 = HomePage.GetValueFromTable("//div[@class='table-responsive']", 1, 2); var cantidadElementos = TotalElementsFromTable("//div[@class='table-responsive']"); Console.WriteLine(price1); Console.WriteLine(title1); Console.WriteLine(cantidadElementos); } public string GetValueFromTable(string locator, int row, int column) { string cellINeed = locator + "/table/tbody/tr[" + row + "]/td[" + column + "]"; return _driver.FindElement(By.XPath(cellINeed)).Text; } public int TotalElementsFromTable(string locator) { // Encontrar la tabla utilizando el localizador proporcionado IWebElement table = _driver.FindElement(By.XPath(locator)); // Encontrar todos los elementos de fila en la tabla ReadOnlyCollection<IWebElement> rows = table.FindElements(By.XPath(".//tbody/tr")); // Contar el número de filas en la tabla int rowCount = rows.Count; return rowCount; } [TearDown] public void TearDown() { _driver.Quit(); } } }