Beispiel #1
0
 public void SendKeys(By locator, string arg)
 {
     try
     {
         SetUp.GetInstance().Driver.FindElement(locator).SendKeys(arg);
     }
     catch (Exception ex)
     {
         Assert.Fail("It was not possible to send keys to the element: " + locator + "\n-----==========-----\nMessage: " + ex.Message + "\n-----==========-----");
     }
 }
Beispiel #2
0
 public void Click(By locator)
 {
     try
     {
         SetUp.GetInstance().Driver.FindElement(locator).Click();
         Thread.Sleep(500);
     }
     catch (Exception ex)
     {
         Assert.Fail("It was not possible to click on the element: " + locator + "\n-----==========-----\nMessage: " + ex.Message + "\n-----==========-----");
     }
 }
Beispiel #3
0
 public bool IsDisplayed(By locator)
 {
     try
     {
         IWebElement element = SetUp.GetInstance().Driver.FindElement(locator);
         bool        result  = element.Displayed;
         return(result);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #4
0
 public bool IsEnabled(By locator)
 {
     try
     {
         IWebElement element = SetUp.GetInstance().Driver.FindElement(locator);
         bool        result  = element.Enabled;
         this.Highlight(element, result);
         return(result);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #5
0
 public bool ElementEqualsText(By locator, string text)
 {
     try
     {
         IWebElement element = SetUp.GetInstance().Driver.FindElement(locator);
         bool        result  = element.Text.Equals(text);
         this.Highlight(element, result);
         return(result);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #6
0
        public void Highlight(IWebElement element, bool arg)
        {
            try
            {
                string _color = arg ? "outline: 4px solid #00FF00;" : "outline: 4px solid #ff0000;";
                this.ScrollToElement(element, -500);
                IJavaScriptExecutor javaScriptExecutor = (IJavaScriptExecutor)SetUp.GetInstance().Driver;
                javaScriptExecutor.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);",
                                                 element, _color);
            }

            catch (Exception)
            {
            }
        }
Beispiel #7
0
        public void ScrollToElement(IWebElement element, int space)
        {
            try
            {
                Point point = new Point();

                if (element != null)
                {
                    point = element.Location;
                    IJavaScriptExecutor js = (IJavaScriptExecutor)SetUp.GetInstance().Driver;

                    js.ExecuteScript("arguments[0].scrollIntoView(true);", element);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail("It was not possible to scroll to the element object using JS. \n-----==========-----\nMessage: " + ex.Message + "\n-----==========-----");
            }
        }
Beispiel #8
0
        public void ScrollToElement(By locator, int space)
        {
            try
            {
                IWebElement element = SetUp.GetInstance().Driver.FindElement(locator);
                Point       point   = new Point();

                if (element != null)
                {
                    point = element.Location;
                    IJavaScriptExecutor js = (IJavaScriptExecutor)SetUp.GetInstance().Driver;

                    js.ExecuteScript("javascript:window.scrollTo(0," + (point.Y + space) + ");");
                }
            }
            catch (Exception ex)
            {
                Assert.Fail("It was not possible to scroll to the element using JS: " + locator + "\n-----==========-----\nMessage: " + ex.Message + "\n-----==========-----");
            }
        }
Beispiel #9
0
 public bool ElementContainsText(By locator, string text, bool ignoreCase = false)
 {
     try
     {
         IWebElement element = SetUp.GetInstance().Driver.FindElement(locator);
         bool        result  = false;
         if (ignoreCase)
         {
             result = element.Text.ToUpper().Contains(text.ToUpper());
         }
         else
         {
             result = element.Text.Contains(text);
         }
         this.Highlight(element, result);
         return(result);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public void ClickAddToCart()
 {
     SetUp.GetInstance().PriceProduct = util.GetText(locatorPrice);
     SetUp.GetInstance().NameProduct  = util.GetText(locatorProductName);
     util.Click(locatorAddToCartButton);
 }
 public void ValidateCartSummary()
 {
     Assert.IsTrue(util.IsDisplayed(locatorCardTitle));
     Assert.IsTrue(util.ElementEqualsText(locatorProductNameSummary, SetUp.GetInstance().NameProduct));
 }
Beispiel #12
0
 public void Close()
 {
     SetUp.GetInstance().Driver.Close();
 }
Beispiel #13
0
 public void GoToUrl(string url)
 {
     SetUp.GetInstance().Driver.Navigate().GoToUrl(url);
 }
Beispiel #14
0
        public String GetText(By locator)
        {
            String text = SetUp.GetInstance().Driver.FindElement(locator).Text;

            return(text);
        }