/// <summary> /// Find specific item in user's cart. /// If a match is found using Product Numbers, a CartItem object is build and /// returned to the caller. /// </summary> /// <param name="prodNum">description of item to be searched for</param> /// <returns>Cart object to interact with</returns> private CartItem LoadCartItem(string prodNum) { _logger.Trace(" > Attempting to find cart item: " + prodNum); CartItem currentItem = new CartItem(); try { for (int i = 0; i < _cartLineItems.Count; ++i) { // search current cart items; if match make temp obj and return if (_cartLineItems[i].ProductNumber.Text.Equals(prodNum)) { currentItem.DeleteButton = _itemDeleteButtons[i]; currentItem.ProductNumber = _itemProdNums[i]; currentItem.Price = _itemPrices[i]; currentItem.Quantity = _itemQtys[i]; currentItem.ItemTotalAmt = _itemTotals[i]; _logger.Info(" > Cart item found: " + prodNum); break; } } } catch (Exception e) { _logger.Fatal(" > Attempting to find MyCart item [FAILED] - " + e.Message); _logger.Fatal("-- TEST FAILURE @ URL: '" + _driver.Url + "' --"); BaseDriverTest.TakeScreenshot("screenshot"); } return currentItem; }
/// <summary> /// Loads all the items currently in the cart and makes objects out of the /// row information to interact with. Each grid column is seperated into /// lists and then the lists are looped through to apply appropriate row /// elements per object constructed. /// </summary> internal void LoadItemsInCart() { _logger.Trace(" > Attempting to load cart items..."); try { // get row elements _itemDeleteButtons = CartTable.FindElements(By.XPath(Constants.MyCart.XP.ITEM_DEL_BTN)); _itemProdNums = CartTable.FindElements(By.XPath(Constants.MyCart.XP.ITEM_PN)); _itemPrices = CartTable.FindElements(By.XPath(Constants.MyCart.XP.ITEM_PRICE)); _itemQtys = CartTable.FindElements(By.XPath(Constants.MyCart.XP.ITEM_QTY)); _itemTotals = CartTable.FindElements(By.XPath(Constants.MyCart.XP.ITEM_TOTAL)); // make cart item objects to work with for (int i = 0; i < _itemProdNums.Count - 1; ++i) { CartItem item = new CartItem(); item.DeleteButton = _itemDeleteButtons[i]; item.ProductNumber = _itemProdNums[i]; item.Price = _itemPrices[i]; item.Quantity = _itemQtys[i]; item.ItemTotalAmt = _itemTotals[i]; item.Checked = false; _cartLineItems.Add(item); } if (!_cartLineItems.Any()) { CartItem item = new CartItem(); item.DeleteButton = _itemDeleteButtons.First(); item.ProductNumber = _itemProdNums.First(); item.Price = _itemPrices.First(); item.Quantity = _itemQtys.First(); item.ItemTotalAmt = _itemTotals.First(); item.Checked = false; _cartLineItems.Add(item); } _logger.Info(" > Cart items loaded!"); } catch (Exception) { _logger.Fatal(" > Loading MyCart items [FAILED]"); _logger.Fatal("-- TEST FAILURE @ URL: '" + _driver.Url + "' --"); BaseDriverTest.TakeScreenshot("screenshot"); } }