Пример #1
0
        public bool click(By locator, string locatorName)
        {
            bool flag = true;

            try
            {
                /*Highlight element*/
                WebElement         webElement = driver.FindElement(locator);
                JavascriptExecutor js         = driver as JavascriptExecutor;
                js.ExecuteScript("arguments[0].style.border='2px solid yellow'", webElement);
                js.ExecuteScript("arguments[0].click();", webElement);
                /*Highlight code ends*/
                //Thread.Sleep(500);
                // driver.FindElement(locator).Click();
                //js.ExecuteScript("arguments[0].click();", webElement);
                //flag = true;
            }
            catch (Exception)
            {
                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), ScreenshotImageFormat.Jpeg);
                return(flag);
            }
            return(flag);
        }
Пример #2
0
        internal IWebElement waitForElementIsPresent(By lookupBy, int maxWaitTime = 60)
        {
            IWebElement element = null;

            try
            {
                element = new WebDriverWait(driver, TimeSpan.FromSeconds(maxWaitTime)).Until(ExpectedConditions.ElementExists(lookupBy));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            if (element != null)
            {
                try
                {
                    string             script     = String.Format(@"arguments[0].style.cssText = ""border-width: 4px; border-style: solid; border-color: {0}"";", "orange");
                    JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
                    jsExecutor.ExecuteScript(script, new object[] { element });
                    jsExecutor.ExecuteScript(String.Format(@"$(arguments[0].scrollIntoView(true));"), new object[] { element });
                }
                catch { }
            }
            return(element);
        }
Пример #3
0
        public bool click(By locator, string locatorName)
        {
            bool flag = true;

            try
            {
                /*Highlight element*/
                WebElement         webElement = driver.FindElement(locator);
                JavascriptExecutor js         = driver as JavascriptExecutor;
                js.ExecuteScript("arguments[0].style.border='2px solid yellow'", webElement);
                js.ExecuteScript("arguments[0].click();", webElement);
                /*Highlight code ends*/
                //Thread.Sleep(500);
                // driver.FindElement(locator).Click();
                //js.ExecuteScript("arguments[0].click();", webElement);
                //flag = true;
                ExtentReport.ReportPass("The Element <b>" + locatorName + "</b> Click Successfull");
            }
            catch (Exception ex)
            {
                //TakeScreenShot();
                ExtentReport.ReportPass("The Element <b>" + locatorName + "</b> Click Failed :" + ex.Message);
                return(flag);
            }
            return(flag);
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pixels">Maybe 600 is good, the height is 768 but we should minus other elements</param>
 /// <param name="waitTime">August 10: my suspect is if we move to uidiv then scroll immedietely
 /// after scroll the page for pin, so should wait here</param>
 public static void Scroll(int pixels, int waitSeconds)
 {
     // MessageBox.Show("before scroll");
     OpenQA.Selenium.IJavaScriptExecutor jse = (OpenQA.Selenium.IJavaScriptExecutor)driver;
     jse.ExecuteScript("window.scrollBy(0," + pixels.ToString() + ")", "");
     System.Threading.Thread.Sleep(TimeSpan.FromSeconds(waitSeconds));
 }
 public static void UIElementScroll(string scrollValue)
 {
     try {
         OpenQA.Selenium.IJavaScriptExecutor js = (OpenQA.Selenium.IJavaScriptExecutor)innerDriver;
         //Amount by which the element is to be scrolled.
         js.ExecuteScript("scroll(0," + scrollValue + ")");
     }
     catch (WebDriverTimeoutException ex) { throw ex; }
     catch (NoSuchElementException ex) { throw ex; }
 }
Пример #6
0
        public bool mouseHoverByJavaScript(By locator, string locatorName)
        {
            bool flag = false;

            try
            {
                WebElement         mo         = driver.FindElement(locator);
                string             javaScript = "var evObj = document.createEvent('MouseEvents');" + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + "arguments[0].dispatchEvent(evObj);";
                JavascriptExecutor js         = (JavascriptExecutor)driver;
                js.ExecuteScript(javaScript, mo);
                flag = true;
                return(flag);
            }

            catch (Exception)
            {
                return(flag);
            }
        }
Пример #7
0
        public bool JSClick(By locator, string locatorName)
        {
            bool flag = false;

            try
            {
                WebElement         element  = driver.FindElement(locator);
                JavascriptExecutor executor = (JavascriptExecutor)driver;
                executor.ExecuteScript("arguments[0].click();", element);
                //driver.executeAsyncScript("arguments[0].click();", element);
                flag = true;
            }
            catch (Exception ex)
            {
                TakeScreenShot();
                throw new Exception(ex.Message);
            }

            return(flag);
        }
Пример #8
0
        public bool JSClick(By locator, string locatorName)
        {
            bool flag = false;

            try
            {
                WebElement         element  = driver.FindElement(locator);
                JavascriptExecutor executor = (JavascriptExecutor)driver;
                executor.ExecuteScript("arguments[0].click();", element);
                //driver.executeAsyncScript("arguments[0].click();", element);
                flag = true;
            }
            catch (Exception ex)
            {
                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), ScreenshotImageFormat.Jpeg);
                throw new Exception(ex.Message);
            }

            return(flag);
        }
Пример #9
0
        public bool selectByVisibleText(By locator, string visibletext, string locatorName)
        {
            bool flag = false;

            try
            {
                /*Highlight element*/

                WebElement         webElement = driver.FindElement(locator);
                JavascriptExecutor js         = driver as JavascriptExecutor;
                js.ExecuteScript("arguments[0].style.border='4px solid yellow'", webElement);
                /*Highlight code ends*/
                Select s = new Select(driver.FindElement(locator));
                s.SelectByText(visibletext);
                flag = true;
                return(flag);
            }
            catch (Exception)
            {
                return(flag);
            }
        }
Пример #10
0
        public bool click1(By locator, string locatorName)
        {
            bool flag = true;

            try
            {
                /*Highlight element*/
                WebElement         webElement = driver.FindElement(locator);
                JavascriptExecutor js         = driver as JavascriptExecutor;
                js.ExecuteScript("arguments[0].style.border='2px solid yellow'", webElement);
                /*Highlight code ends*/
                Thread.Sleep(500);
                driver.FindElement(locator).Click();
                //js.ExecuteScript("arguments[0].click();", webElement);
                //flag = true;
            }
            catch (Exception)
            {
                return(flag);
            }
            return(flag);
        }
Пример #11
0
        public bool type(By locator, string testdata, string locatorName)
        {
            bool flag = false;

            try
            {
                /*Highlight element*/

                WebElement         webElement = driver.FindElement(locator);
                JavascriptExecutor js         = driver as JavascriptExecutor;
                js.ExecuteScript("arguments[0].style.border='4px solid yellow'", webElement);
                /*Highlight code ends*/
                driver.FindElement(locator).Clear();

                driver.FindElement(locator).SendKeys(testdata);
                flag = true;
            }
            catch (Exception)
            {
                return(flag);
            }

            return(flag);
        }
Пример #12
0
        public override void Run(TestContainer container)
        {
            try
            {
                //* add for IsExecuteCommand start
                if (!base.IsCommandContinue(container))
                {
                    this.PassTest = true;
                    this.SkipTest = true;
                    return;
                }
                //* add for IsExecuteCommand end

                string invokeMethodName;
                string invokeParameter;

                UICommandHelper cmdHelp = new UICommandHelper();
                cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter);

                By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By;

                Thread.Sleep(1000);
                IWebElement element = container.Driver.FindElement(by);
                //Console.WriteLine(element.GetAttribute("Value"));
                //Console.WriteLine(base.Parameters["Value"]);

                //edit: all the way. 38 rows of 45-49
                OpenQA.Selenium.IJavaScriptExecutor js = (OpenQA.Selenium.IJavaScriptExecutor)container.Driver;

                if (base.GetParameter("Value").Equals(element.GetAttribute("Value").Trim()))
                {
                    /// TODO: Pass
                    this.PassTest = true;
                }
                else if (base.GetParameter("Value").Equals(js.ExecuteScript("return $('#" + invokeParameter.ToString() + "').val()").ToString().Trim()))
                {
                    /// TODO: Pass
                    this.PassTest = true;
                }

                //* add for output and IsExpectedFail start
                this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest);
                //* add for output and IsExpectedFail end

                //* add for output and IsExpectedFail start
                this.PassTest = GetTestPassExpected(this.PassTest);
                //* add for output and IsExpectedFail end

                //add by zhuqianqian ScreenShot start
                if (!this.PassTest)
                {
                    CommandFailScreenShot(container);
                    Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:" + base.GetParameter("Value") + "   Actual value:" + js.ExecuteScript("return $('#" + invokeParameter.ToString() + "').val()").ToString().Trim(), ELogType.Info);
                }
                //add by zhuqianqian ScreenShot end
            }
            catch (Exception ex)
            {
                //add by zhuqianqian ScreenShot start
                CommandFailScreenShot(container);
                throw ex;
                //add by zhuqianqian ScreenShot end
            }
        }