Alex Lonyay

Alex Lonyay

  • NA
  • 123
  • 9.7k

How to divide single class to different classes and use one base class

Oct 12 2020 7:35 AM
I have one file which is of common method and has too many methods inside a single class file, now I want to create hierarchy so it can be divided further with the help of abstraction, I tried few things but then I got confused on how to access different methods?
 
Main File
  1. using Base;    
  2. using Constants;    
  3. using Entities;    
  4. using Extensions;    
  5. using SeleniumExtensions;    
  6. using Helpers;    
  7. using Model;    
  8. using AtlasNav;    
  9. using Model.PaymentOptions;    
  10. using Pages.DesignPages.DesignViews;    
  11. using Pages.UserAccount_Pages;    
  12. using Repositories;    
  13. using Pages;    
  14. using Pages.CheckoutPages;    
  15. using Pages.CMSPages;    
  16. using Pages.KlarnaCheckoutPages;    
  17. using Pages.SellerStorePages;    
  18. using Framework.DataAccessLayer.EntitiyFramework.Repositories;    
  19. using Microsoft.VisualStudio.TestTools.UnitTesting;    
  20. using OpenQA.Selenium;    
  21. using OpenQA.Selenium.Chrome;    
  22. using OpenQA.Selenium.Support.UI;    
  23. using System;    
  24. using System.Collections.Generic;    
  25. using System.Linq;    
  26. using System.Net.Http.Headers;    
  27. using TestConfigurationCDO = Config.TestConfigurationCDO;    
  28.     
  29. namespace ManualRegressionSuite.CommonMethods    
  30. {   public class CommonMethods : Base    
  31.     {    
  32.         public TestConfigurationCDO _testConfiguration;    
  33.         WebDriverWait wait;    
  34.         public IList<Site> _sites;    
  35.         public string _bolUkSiteUrl;    
  36.         public string _cmsSiteUrl;    
  37.         public Site _site;    
  38.     
  39.         public CommonMethods(SharedParameters test_properties)    
  40.         {    
  41.             this.shared_parameters = test_properties;    
  42.             this.Driver = test_properties.Driver;    
  43.             this._testConfiguration = test_properties.testConfiguration;    
  44.             this._sites = test_properties.sites;    
  45.             this._bolUkSiteUrl = test_properties.SiteBag.domain_url;    
  46.             this._cmsSiteUrl = test_properties.SiteBag.cms_url;    
  47.             this._site = test_properties.site;    
  48.         }    
  49.         /// <summary>    
  50.         ///    
  51.         /// </summary>    
  52.         public void CommonMethod_SellerLogIn()    
  53.         {    
  54.             var site = shared_parameters.site.GetName();    
  55.     
  56.             var homePage = GetInstance<HomePage>();    
  57.             homePage.To_SignInPage(site);    
  58.     
  59.             var signInPage = GetInstance<SignInPage>();    
  60.             signInPage.To_SellerLandingPage();    
  61.         }    
  62.         /// <summary>    
  63.         /// Below method will navigate to Product Page through Atlas Navigation    
  64.         /// </summary>    
  65.         /// <param name="productId"></param>    
  66.         public void CommonMetho_GoToProductPage(int productId)    
  67.         {    
  68.             var homePage = GetInstance<HomePage>();    
  69.             homePage.To_ProductPage(productId);    
  70.         }    
  71.         /// <summary>    
  72.         /// Below method will:    
  73.         ///    
  74.         /// </summary>    
  75.         /// <param name="param"></param>    
  76.         public void CommonMethod_DesignProduct(WorkflowParameters param)    
  77.         {    
  78.             var generalProductPage = GetInstance<MasterProductPage>();    
  79.             generalProductPage.To_DesignPage();    
  80.     
  81.             var designPage = GetInstance<DesignPage, DesignPageArgs>(new DesignPageArgs());    
  82.             designPage.basketToolbarView.UpdateProductQuantity(param.quantity.ToString());    
  83.                 
  84.             designPage.Design(param.designMethod);    
  85.         }    
  86.         /// <summary>    
  87.         /// Below method will Add product to Basket    
  88.         /// </summary>    
  89.         public void CommonMethod_AddToBasket()    
  90.         {    
  91.             var designPage = GetInstance<DesignPage, DesignPageArgs>(new DesignPageArgs());    
  92.             designPage.AddToCart();    
  93.         }    
  94.         /// <summary>    
  95.         /// Below method will review the basket item:    
  96.         /// </summary>    
  97.         /// <param name="productId"></param>    
  98.         public void CommonMethod_BasketReview(int productId)    
  99.         {    
  100.             var basketPage = GetInstance<BasketPage, BasketPageArgs>(new BasketPageArgs());    
  101.     
  102.             var check = basketPage.BasketPriceView.CheckBasketPrice();    
  103.             Assert.IsTrue(check);    
  104.     
  105.             var isPresent = basketPage.BasketItemsView.Validate_ItemIsInBasket(productId);    
  106.             Assert.IsTrue(isPresent);    
  107.     
  108.             Assert.IsTrue(!ImageHelpers.IsEmpty(basketPage.BasketItemsView.GetItemImage(productId)));    
  109.         }    
  110.         /// <summary>    
  111.         ///    
  112.         /// </summary>    
  113.         /// <param name="param"></param>    
  114.         /// <returns></returns>    
  115.         public string CommonMethod_PurchaseItem(WorkflowParameters param)    
  116.         {    
  117.             var basketPage = GetInstance<BasketPage, BasketPageArgs>(new BasketPageArgs());    
  118.     
  119.             basketPage.To_CheckoutPage(param.paymentOptions.portal);    
  120.     
  121.             var checkoutPage = GetInstance<CheckoutPage>();    
  122.             checkoutPage.To_OrderSummaryPage(param.paymentOptions);    
  123.                 
  124.             var orderConfirmPage = GetInstance<OrderConfirmPage>();    
  125.             var _order = orderConfirmPage.To_Self_CheckOrderDatabase();    
  126.     
  127.             return _order.OrderId.ToString(); ;    
  128.         }    
  129.         /// <summary>    
  130.         ///    
  131.         /// </summary>    
  132.         /// <param name="OrderId"></param>    
  133.         public void CommonMethod_CMSVerification(string OrderId)    
  134.         {    
  135.             var cmsLoginPage = GetInstance<CMSLoginPage>();    
  136.             cmsLoginPage.To_CMSLandingPage();    
  137.     
  138.             var cmsLandingPage = GetInstance<CMSLandingPage>();    
  139.             cmsLandingPage.To_OrderPage_OrderCheck(OrderId);    
  140.     
  141.             var cmsOrderPage = GetInstance<CMSOrderPage>();    
  142.             cmsOrderPage.orderDetailsView.To_Self_CheckPrices(shared_parameters.price);    
  143.                 
  144.             var check = cmsOrderPage.orderDetailsView.IsOrderAuthorised(OrderId.ToInt());    
  145.             Assert.IsTrue(check);    
  146.         }    
  147.         /// <summary>    
  148.         ///    
  149.         /// </summary>    
  150.         public void CommonMethod_CMSDespatchNoteVerification()    
  151.         {    
  152.             var cmsOrderPage = GetInstance<CMSOrderPage>();    
  153.             cmsOrderPage.ChangeStatus_ByDropDown(OrderStatus.Dispatched);    
  154.     
  155.             cmsOrderPage.deliveryDetailsView.Check_DespatchNote();    
  156.         }    
  157.         /// <summary>    
  158.         ///    
  159.         /// </summary>    
  160.         public void CommonMethod_CreateStore()    
  161.         {    
  162.             var sellerLandingPage = GetInstance<SellerLandingPage>();    
  163.             sellerLandingPage.To_SellerMyStoresPage();    
  164.     
  165.             var sellerMyStoresPage = GetInstance<SellerMyStoresPage>();    
  166.             var uniqueName = sellerMyStoresPage.To_Self_CreateStore();    
  167.         }    
  168.         /// <summary>    
  169.         ///    
  170.         /// </summary>    
  171.         public void CommonMethod_NavigateToMyProductsPage()    
  172.         {    
  173.     
  174.         }    
  175.         /// <summary>    
  176.         ///    
  177.         /// </summary>    
  178.         public void CommonMethod_CreateProduct()    
  179.         {    
  180.     
  181.         }    
  182.         /// <summary>    
  183.         ///    
  184.         /// </summary>    
  185.         public void CommonMethod_AddProductToStore()    
  186.         {    
  187.     
  188.         }    
  189.     }    
  190.     public class WorkflowParameters    
  191.     {    
  192.         public int productId = default(int);    
  193.         public int orderId = default(int);    
  194.         public DesignMethod designMethod = default(DesignMethod);    
  195.         public bool signedIn = default(bool);    
  196.         public bool increaseBasketQty = default(bool);    
  197.         public bool signedInCMS = default(bool);    
  198.         public bool editable = default(bool);    
  199.         public Site _site = default(Site);    
  200.         public PaymentOptions paymentOptions = default(PaymentOptions);    
  201.         public bool checkOrderAuthorise = default(bool);    
  202.         public int quantity = default(int);    
  203.     }    
  204. }  
Now I want to create hierarchy such that main file common method will have on definitions of method and 2 separate class files will be there one for CMS Common Methods and one for WebSite Common methods
  1. using Base;    
  2. using Constants;    
  3. using Extensions;    
  4. using Pages.CMSPages;    
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;    
  6. using System;    
  7. using System.Collections.Generic;    
  8. using System.Linq;    
  9. using System.Text;    
  10. using System.Threading.Tasks;    
  11.     
  12. namespace ManualRegressionSuite.CommonMethods    
  13. {    
  14.     public class CMSCommonMethods : Base    
  15.     {    
  16.         /// <summary>    
  17.         ///    
  18.         /// </summary>    
  19.         /// <param name="OrderId"></param>    
  20.         public void CommonMethod_CMSVerification(string OrderId)    
  21.         {    
  22.             var cmsLoginPage = GetInstance<CMSLoginPage>();    
  23.             cmsLoginPage.To_CMSLandingPage();    
  24.     
  25.             var cmsLandingPage = GetInstance<CMSLandingPage>();    
  26.             cmsLandingPage.To_OrderPage_OrderCheck(OrderId);    
  27.     
  28.             var cmsOrderPage = GetInstance<CMSOrderPage>();    
  29.             cmsOrderPage.orderDetailsView.To_Self_CheckPrices(shared_parameters.price);    
  30.     
  31.             var check = cmsOrderPage.orderDetailsView.IsOrderAuthorised(OrderId.ToInt());    
  32.             Assert.IsTrue(check);    
  33.         }    
  34.         /// <summary>    
  35.         ///    
  36.         /// </summary>    
  37.         public void CommonMethod_CMSDespatchNoteVerification()    
  38.         {    
  39.             var cmsOrderPage = GetInstance<CMSOrderPage>();    
  40.             cmsOrderPage.ChangeStatus_ByDropDown(OrderStatus.Dispatched);    
  41.     
  42.             cmsOrderPage.deliveryDetailsView.Check_DespatchNote();    
  43.         }    
  44.     }    
  45. }  
  1. using Base;    
  2. using Entities;    
  3. using Helpers;    
  4. using Pages;    
  5. using Pages.CheckoutPages;    
  6. using Pages.SellerStorePages;    
  7. using Microsoft.VisualStudio.TestTools.UnitTesting;    
  8. using System;    
  9. using System.Collections.Generic;    
  10. using System.Linq;    
  11. using System.Text;    
  12. using System.Threading.Tasks;    
  13.     
  14. namespace ManualRegressionSuite.CommonMethods    
  15. {    
  16.     public class WebSiteCommonMethods:Base    
  17.     {    
  18.         /// <summary>    
  19.         ///    
  20.         /// </summary>    
  21.         public void CommonMethod_SellerLogIn()    
  22.         {    
  23.             var site = shared_parameters.site.GetName();    
  24.     
  25.             var homePage = GetInstance<HomePage>();    
  26.             homePage.To_SignInPage(site);    
  27.     
  28.             var signInPage = GetInstance<SignInPage>();    
  29.             signInPage.To_SellerLandingPage();    
  30.         }    
  31.         /// <summary>    
  32.         /// Below method will navigate to Product Page through Atlas Navigation    
  33.         /// </summary>    
  34.         /// <param name="productId"></param>    
  35.         public void CommonMetho_GoToProductPage(int productId)    
  36.         {    
  37.             var homePage = GetInstance<HomePage>();    
  38.             homePage.To_ProductPage(productId);    
  39.         }    
  40.         /// <summary>    
  41.         /// Below method will:    
  42.         ///    
  43.         /// </summary>    
  44.         /// <param name="param"></param>    
  45.         public void CommonMethod_DesignProduct(WorkflowParameters param)    
  46.         {    
  47.             var generalProductPage = GetInstance<MasterProductPage>();    
  48.             generalProductPage.To_DesignPage();    
  49.     
  50.             var designPage = GetInstance<DesignPage, DesignPageArgs>(new DesignPageArgs());    
  51.             designPage.basketToolbarView.UpdateProductQuantity(param.quantity.ToString());    
  52.     
  53.             designPage.Design(param.designMethod);    
  54.         }    
  55.         /// <summary>    
  56.         /// Below method will Add product to Basket    
  57.         /// </summary>    
  58.         public void CommonMethod_AddToBasket()    
  59.         {    
  60.             var designPage = GetInstance<DesignPage, DesignPageArgs>(new DesignPageArgs());    
  61.             designPage.AddToCart();    
  62.         }    
  63.         /// <summary>    
  64.         /// Below method will review the basket item:    
  65.         /// </summary>    
  66.         /// <param name="productId"></param>    
  67.         public void CommonMethod_BasketReview(int productId)    
  68.         {    
  69.             var basketPage = GetInstance<BasketPage, BasketPageArgs>(new BasketPageArgs());    
  70.     
  71.             var check = basketPage.BasketPriceView.CheckBasketPrice();    
  72.             Assert.IsTrue(check);    
  73.     
  74.             var isPresent = basketPage.BasketItemsView.Validate_ItemIsInBasket(productId);    
  75.             Assert.IsTrue(isPresent);    
  76.     
  77.             Assert.IsTrue(!ImageHelpers.IsEmpty(basketPage.BasketItemsView.GetItemImage(productId)));    
  78.         }    
  79.         /// <summary>    
  80.         ///    
  81.         /// </summary>    
  82.         /// <param name="param"></param>    
  83.         /// <returns></returns>    
  84.         public string CommonMethod_PurchaseItem(WorkflowParameters param)    
  85.         {    
  86.             var basketPage = GetInstance<BasketPage, BasketPageArgs>(new BasketPageArgs());    
  87.     
  88.             basketPage.To_CheckoutPage(param.paymentOptions.portal);    
  89.     
  90.             var checkoutPage = GetInstance<CheckoutPage>();    
  91.             checkoutPage.To_OrderSummaryPage(param.paymentOptions);    
  92.     
  93.             var orderConfirmPage = GetInstance<OrderConfirmPage>();    
  94.             var _order = orderConfirmPage.To_Self_CheckOrderDatabase();    
  95.     
  96.             return _order.OrderId.ToString(); ;    
  97.         }    
  98.     
  99.         /// <summary>    
  100.         ///    
  101.         /// </summary>    
  102.         public void CommonMethod_CreateStore()    
  103.         {    
  104.             var sellerLandingPage = GetInstance<SellerLandingPage>();    
  105.             sellerLandingPage.To_SellerMyStoresPage();    
  106.     
  107.             var sellerMyStoresPage = GetInstance<SellerMyStoresPage>();    
  108.             var uniqueName = sellerMyStoresPage.To_Self_CreateStore();    
  109.         }    
  110.         /// <summary>    
  111.         ///    
  112.         /// </summary>    
  113.         public void CommonMethod_NavigateToMyProductsPage()    
  114.         {    
  115.       
  116.         }    
  117.         /// <summary>    
  118.         ///    
  119.         /// </summary>    
  120.         public void CommonMethod_CreateProduct()    
  121.         {    
  122.     
  123.         }    
  124.         /// <summary>    
  125.         ///    
  126.         /// </summary>    
  127.         public void CommonMethod_AddProductToStore()    
  128.         {    
  129.     
  130.         }    
  131.     }    
  132. }

Answers (1)