示例#1
0
        public void SupportEmailAddressChromeTest()
        {
            string supportEmailAddress = "*****@*****.**";

            _webDriver.Url = _webAppBaseURL + "/Home/Contact";
            RemoteWebElement supportEmailElement = (RemoteWebElement)_webDriver.FindElementByLinkText(supportEmailAddress);

            Assert.AreEqual(supportEmailAddress, supportEmailElement.Text);
        }
        public void IndexTitleTest()
        {
            string expectedTitle = "MY ASP.NET";

            _webDriver.Url = _webAppBaseURL + "/Home/Index";
            RemoteWebElement titleElement = (RemoteWebElement)_webDriver.FindElementByTagName("H1");

            Assert.AreEqual(expectedTitle, titleElement.Text);
        }
示例#3
0
 public void Drag(RemoteWebElement webElement, int x = -1, int y = -1)
 {
     _dragdropactions.ClickAndHold(webElement);
     if (x != -1 && y != -1)
     {
         _dragdropactions.MoveByOffset(x, y);
     }
     _dragdropactions.Build().Perform();
 }
        public void MarketingEmailAddressTest()
        {
            string marketingEmailAddress = "*****@*****.**";

            _webDriver.Url = _webAppBaseURL + "/Home/Contact";
            RemoteWebElement marketingEmailElement = (RemoteWebElement)_webDriver.FindElementByLinkText(marketingEmailAddress);

            Assert.AreEqual(marketingEmailAddress, marketingEmailElement.Text);
        }
示例#5
0
        public static void ChangeSliderValue(this RemoteWebElement slider, double percentage)
        {
            var width  = slider.Size.Width;
            var driver = slider.WrappedDriver;

            Actions actions = new Actions(driver);

            actions.MoveToElement(slider, (int)((width * percentage) / 100), 0).ClickAndHold().Release().Perform();
        }
示例#6
0
        public static IWebElement MouseOver(this IWebElement e)
        {
            Console.WriteLine($"mouse over {++i}");
            RemoteWebElement e1     = e as RemoteWebElement;
            Actions          action = new Actions(e1.WrappedDriver);

            action.MoveToElement(e1).Build().Perform();
            Task.Delay(100).Wait();
            return(e);
        }
示例#7
0
 public void Drop(RemoteWebElement webElement, int x = -1, int y = -1)
 {
     _dragdropactions.MoveToElement(webElement);
     if (x != -1 && y != -1)
     {
         _dragdropactions.MoveByOffset(x, y);
     }
     _dragdropactions.Release(webElement);
     _dragdropactions.Build().Perform();
 }
        /// <summary>
        /// Extends click method with option to wait for ajax to complete after clicking.
        /// </summary>
        public static void Click(this IWebElement webElement, int timeoutInSeconds)
        {
            webElement.Click();
            RemoteWebElement remoteElement = webElement as RemoteWebElement;

            if (timeoutInSeconds > 0 && remoteElement != null)
            {
                remoteElement.WrappedDriver.WaitAjax(timeoutInSeconds);
            }
        }
示例#9
0
        public static void TearDown()
        {
            // Restore original mode before closing down
            CalculatorSession.FindElementByXPath("//Button[starts-with(@Name, \"Menu\")]").Click();
            CalculatorSession.FindElementByXPath("//ListItem[@Name=\"" + OriginalCalculatorMode + "\"]").Click();

            CalculatorResult = null;
            CalculatorSession.Dispose();
            CalculatorSession = null;
        }
示例#10
0
        private static void gotoNextPage()
        {
            string selector = "»";

            wait.Until(ExpectedConditions.ElementExists(By.LinkText(selector)));
            RemoteWebElement rweLink = (RemoteWebElement)driver.FindElement(By.LinkText(selector));
            var scroller             = rweLink.LocationOnScreenOnceScrolledIntoView;

            rweLink.Click();
        }
示例#11
0
        public void Select(string value)
        {
            PrepareRadios();
            RemoteWebElement webElement = null;

            if (_Radios.TryGetValue(value, out webElement))
            {
                webElement.Click();
            }
        }
示例#12
0
        public static Point getScreenCoordinates(RemoteWebElement webElement)
        {
            RemoteWebElement remoteWebElement = webElement as RemoteWebElement;

            if (remoteWebElement != null)
            {
                ICoordinates coordinates = remoteWebElement.Coordinates;
                return(new Point(coordinates.LocationOnScreen.X, coordinates.LocationOnScreen.Y));
            }
            return(new Point(0, 0));
        }
示例#13
0
        public void GetScreenshotTest()
        {
            var element = new RemoteWebElement(this.driver, "4D000000-0000-0000-B42A-000000000000");
            var image   = this.driver.GetScreenshot(element);

            Assert.Single(commandExecutor.Commands);

            var originalScreenshot = File.ReadAllBytes("screenshot.jpg");

            Assert.Equal(originalScreenshot, image);
        }
示例#14
0
        public static IWebElement Highlight(this IWebElement e, int seconds = 1)
        {
            if (seconds < 0)
            {
                return(e);
            }
            RemoteWebElement e1 = e as RemoteWebElement;

            (e1.WrappedDriver as IJavaScriptExecutor).ExecuteScript(highlightScript, e, seconds);
            Task.Delay(seconds * 1000).Wait();
            return(e);
        }
示例#15
0
        /*-------------------------------------------------------------------*/

        protected override void Execute(IWebDriver webDriver)
        {
            var webElement = _element?.AsWebElement() ?? webDriver.FindElementBySelector(_selector);

            if (webElement != null)
            {
                RemoteWebElement element = (RemoteWebElement)webElement;
                var viewPosition         = element.LocationOnScreenOnceScrolledIntoView;

                element.Click();
            }
        }
示例#16
0
        public void HighlightWebElement(RemoteWebElement webElement)
        {
            if (webElement == null)
            {
                return;
            }
            int       X  = webElement.Location.X + (int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.X;
            int       Y  = webElement.Location.Y + (int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.Y + (int)_toobarAutoElement.Current.BoundingRectangle.Height;
            Rectangle rc = new Rectangle(X, Y, webElement.Size.Width, webElement.Size.Height);

            UIAHighlight.HighlightRect(rc);
        }
示例#17
0
        public void TestDragAndDrop()
        {
            RemoteWebElement dragElement = _chromeDriver.FindElementById("draggable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            RemoteWebElement dropElement = _chromeDriver.FindElementById("droppable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            Actions actions = new Actions(_chromeDriver);

            actions.DragAndDrop(dragElement, dropElement).Perform();
        }
示例#18
0
        protected RemoteWebElement GetOrphanedElement(IOSDriver <IOSElement> remoteSession)
        {
            RemoteWebElement orphanedElement = null;

            // Track existing opened Edge window(s) and only manipulate newly opened windows
            var previouslyOpenedEdgeWindows = remoteSession.WindowHandles;
            var originalActiveWindowHandle  = remoteSession.CurrentWindowHandle;

            // Open a new window
            // The menu item names have changed between Windows 10 and the anniversary update
            // account for both combinations.
            try
            {
                remoteSession.FindElementByAccessibilityId("m_actionsMenuButton").Click();
                remoteSession.FindElementByAccessibilityId("m_newWindow").Click();
            }
            catch (OpenQA.Selenium.NoSuchElementException)
            {
                remoteSession.FindElementByAccessibilityId("ActionsMenuButton").Click();
                remoteSession.FindElementByAccessibilityId("ActionsMenuNewWindow").Click();
            }

            System.Threading.Thread.Sleep(3000); // Sleep for 3 second
            var multipleWindowHandles = remoteSession.WindowHandles;

            Assert.IsTrue(multipleWindowHandles.Count == previouslyOpenedEdgeWindows.Count + 1);

            // Ensure we get the newly opened window by removing other previously known windows from the list
            List <String> newlyOpenedEdgeWindows = new List <String>(multipleWindowHandles);

            foreach (var previouslyOpenedEdgeWindow in previouslyOpenedEdgeWindows)
            {
                newlyOpenedEdgeWindows.Remove(previouslyOpenedEdgeWindow);
            }
            Assert.IsTrue(newlyOpenedEdgeWindows.Count == 1);

            // Switch to new window and use the address edit box as orphaned element
            remoteSession.SwitchTo().Window(newlyOpenedEdgeWindows[0]);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            Assert.AreEqual(newlyOpenedEdgeWindows[0], remoteSession.CurrentWindowHandle);
            orphanedElement = remoteSession.FindElementByAccessibilityId("addressEditBox");
            Assert.IsNotNull(orphanedElement);

            // Close the newly opened window and return to previously active window
            remoteSession.Close();
            remoteSession.SwitchTo().Window(originalActiveWindowHandle);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second

            return(orphanedElement);
        }
示例#19
0
 private static bool isElementContentEditable(RemoteWebElement webElement)
 {
     while (null != webElement)
     {
         string Editable = webElement.GetAttribute("contentEditable");
         if (webElement.GetAttribute("nodeType") != "1" || Editable.Equals("inherit") || Editable.Equals("false"))
         {
             webElement = WebUtility.GetParentElement(webElement);
             continue;
         }
         return(!Editable.Equals("false"));
     }
     return(false);
 }
示例#20
0
        public static List <RemoteWebElement> GenerateWebElementsLine(RemoteWebElement webElement)
        {
            List <RemoteWebElement> webElementsLine = new List <RemoteWebElement>();

            webElementsLine.Add(webElement);

            while (!webElement.TagName.ToUpper().Equals("HTML"))
            {
                webElement = webElement.FindElement(By.XPath("..")) as RemoteWebElement;
                webElementsLine.Add(webElement);
            }
            webElementsLine.Reverse();
            return(webElementsLine);
        }
示例#21
0
        public bool IsElementInDomViaJsCss()
        {
            IJavaScriptExecutor js           = (IJavaScriptExecutor)webElement.GetDriver().Current;
            RemoteWebElement    foundElement = (RemoteWebElement)js.ExecuteScript($"return document.querySelector(\"{webElement.GetStrategyValue()}\")");

            if (foundElement == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#22
0
        public static Rectangle GetElementScreenRect(RemoteWebElement webElement)
        {
            if (webElement == null)
            {
                return(new Rectangle());
            }
            IWrapsDriver        wrapsDriver = webElement as IWrapsDriver;
            IJavaScriptExecutor jsExecutor  = wrapsDriver.WrappedDriver as IJavaScriptExecutor;

            Dictionary <string, object> pos =
                jsExecutor.ExecuteScript(_jsCalcScreenPos, webElement.Location.X, webElement.Location.Y) as Dictionary <string, object>;

            return(new Rectangle(new Point(Convert.ToInt32(pos["x"]), Convert.ToInt32(pos["y"])), webElement.Size));
        }
示例#23
0
        private static bool isRealLink(RemoteWebElement webElement)
        {
            if (webElement == null)
            {
                return(false);
            }
            string href = webElement.GetAttribute("href");

            if (string.IsNullOrEmpty(href))
            {
                return(false);
            }
            return(true);
        }
示例#24
0
        public void TestDragAndDrop5()
        {
            RemoteWebElement dragElement = _chromeDriver.FindElementById("draggable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            RemoteWebElement dropElement = _chromeDriver.FindElementById("droppable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            Actions actions = new Actions(_chromeDriver);

            _chromeDriver.ExecuteScript(jsDnD, dragElement, dropElement);
        }
示例#25
0
        public void MarkText(RemoteWebElement webElement, int start, int end)
        {
            //  Actions actions = new Actions(webElement.WrappedDriver);
            // make sure it has focus
            // Click(webElement);
            _actions.MoveToElement(webElement);

            _actions.SendKeys(webElement, Keys.Home);
            _actions.Build().Perform();
            System.Threading.Thread.Sleep(1000);
            _actions.SendKeys(webElement, Keys.Right);

            _actions.Build().Perform();
            //System.Threading.Thread.Sleep(1000);
            //_actions.MoveToElement(webElement);
            //_actions.SendKeys(webElement, Keys.ArrowLeft);
            //_actions.Build().Perform();

            //  _actions.SendKeys(webElement, Keys.Home);
            //_actions.Build().Perform();
            // _actions.KeyUp(webElement, Keys.Home);
            //  _actions.Build().Perform();

            /*  actions.KeyDown(webElement, Keys.ArrowLeft);
             * actions.SendKeys(webElement, Keys.ArrowLeft);
             * actions.SendKeys(webElement, Keys.ArrowLeft);
             * actions.SendKeys(webElement, Keys.ArrowLeft);
             * actions.SendKeys(webElement, Keys.ArrowLeft);
             * actions.SendKeys(webElement, Keys.ArrowLeft);
             * actions.Build().Perform();
             */

            /* for (int i = 0; i < 1; i++)
             * {
             *    _actions.SendKeys(webElement, Keys.Right);
             *   // _actions.Build().Perform();
             * }
             * _actions.Build().Perform();*/
            //_actions.Build().Perform();

            /*   _actions.KeyDown(webElement, Keys.LeftShift);
             * for (int i = start; i < end; i++)
             * {
             *     _actions.SendKeys(webElement, Keys.ArrowRight);
             * }
             * _actions.Build().Perform();
             * _actions.KeyUp(webElement, Keys.LeftShift);
             * _actions.Build().Perform();*/
        }
示例#26
0
        public virtual string GetRoProperty(string propertyname)
        {
            RemoteWebElement webElement = RelayObject.SEWebElement;

            propertyname = propertyname.ToLower();
            string returnValue = string.Empty;

            switch (propertyname)
            {
            case "x":
            {
                returnValue = webElement.Location.X.ToString();
            }
            break;

            case "y":
            {
                returnValue = webElement.Location.Y.ToString();
            }
            break;

            case "tagName":
            {
                returnValue = webElement.TagName;
            }
            break;

            case "width":
            {
                returnValue = webElement.Size.Width.ToString();
            }
            break;

            case "height":
            {
                returnValue = webElement.Size.Height.ToString();
            }
            break;

            default:
            {
                returnValue = webElement.GetAttribute(propertyname);
            }
            break;
            }


            return(returnValue);
        }
示例#27
0
        public WebElementsList GenerateWebElementsLine(RemoteWebElement webElement)
        {
            WebElementsList webElementsLine = WebUtility.GenerateWebElementsLine(webElement);

            //if the element is in a frame, need to switch to the top

            /*if (_isInFrame)
             * {
             *  _webDriver.SwitchTo().DefaultContent();
             * //  _currFrameElement.
             *
             * }*/

            return(webElementsLine);
        }
示例#28
0
        public virtual void DragAndDrop(IWebElement target)
        {
            ActionsHelper    actionsHelper = ActionsHelper.getInstance();
            RemoteWebElement webElement    = RelayObject.SEWebElement;
            string           draggable     = webElement.GetAttribute("draggable");

            if (!string.IsNullOrEmpty(draggable) && draggable.ToLower().Equals("true"))
            {
                BrowserHoster.getInstance().WebDriver.ExecuteScript(_jsDnD, RelayObject.SEWebElement, target.RelayObject.SEWebElement);
            }
            else
            {
                actionsHelper.DragAndDrop(RelayObject.SEWebElement, target.RelayObject.SEWebElement);
            }
        }
        public void BeforeAll()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

            // TODO: What about supporting AppiumServers.sauceURI ???
            CalculatorSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, Env.INIT_TIMEOUT_SEC);
            CalculatorSession.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);

            CalculatorSession.FindElementByName("Clear").Click();
            CalculatorSession.FindElementByName("Seven").Click();
            CalculatorResult = CalculatorSession.FindElementByName("Display is  7 ") as RemoteWebElement;
            Assert.IsNotNull(CalculatorResult);
        }
示例#30
0
        //public WebElementDecorator(IWebElement realWebElement)
        //public WebElementDecorator(RemoteWebElement realWebElement) // : base(realWebElement.WrappedDriver, "")
        public WebElementDecorator(RemoteWebElement realWebElement)
        {
            DecoratedWebElement = realWebElement; // as RemoteWebElement;
            Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + DecoratedWebElement.ToString());
            Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + DecoratedWebElement.GetType().Name);
            try {
//Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + this.DecoratedWebElement.TagName);
                Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + DecoratedWebElement.TagName);
            } catch (Exception eTagName) {
                Console.WriteLine(eTagName.Message);
                Console.WriteLine(eTagName.GetType().Name);
            }
            Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): OK");
            SearchHistory =
                new List <ISearchHistory>();
        }