コード例 #1
0
ファイル: Keyboard.cs プロジェクト: yclim95/SeleniumBasic
 /// <summary>
 /// Sends a sequence of key strokes to the active element.
 /// </summary>
 /// <param name="keysOrModifiers">Modifier keys (Ctrl, Shit or Alt) or keys</param>
 /// <param name="keys">Keys</param>
 /// <returns>Self</returns>
 public Keyboard SendKeys(string keysOrModifiers, string keys = null)
 {
     if (keys != null)
     {
         keysOrModifiers = string.Concat(keysOrModifiers, keys, keysOrModifiers);
     }
     _session.Send(RequestMethod.POST, "/keys", "value", new string[] { keysOrModifiers });
     //_session.Send(RequestMethod.POST, "/keys", "value", keysOrModifiers.ToCharArray() );
     return(this);
 }
コード例 #2
0
ファイル: WebDriver.cs プロジェクト: myahk/SeleniumBasic
        /// <summary>
        /// Loads a web page in the current browser session. Same as Open method.
        /// </summary>
        /// <param name="url">URL</param>
        /// <param name="timeout">Optional timeout in milliseconds. Infinite=-1</param>
        /// <param name="raise">Optional - Raise an exception after the timeout when true</param>
        /// <returns>Return true if the url was openned within the timeout, false otherwise</returns>
        public bool Get(string url, int timeout = -1, bool raise = true)
        {
            if (_session == null)
            {
                this.Start();
            }
            RemoteSession session = _session;

            if (string.IsNullOrEmpty(url))
            {
                throw new Errors.ArgumentError("Argument 'url' cannot be null.");
            }

            if (timeout > 0)
            {
                session.timeouts.PageLoad = timeout;
                session.Send(RequestMethod.POST, "/timeouts", "type", "page load", "ms", timeout);
            }

            int idx = url.IndexOf("/");

            if (idx == 0)
            {
                //relative url
                if (_baseUrl == null)
                {
                    throw new Errors.ArgumentError("Base URL not defined. Define a base URL or use a full URL.");
                }
                url = string.Concat(_baseUrl, url);
            }
            else
            {
                //absolute url
                idx = url.IndexOf('/', idx + 3);
                if (idx != -1)
                {
                    _baseUrl = url.Substring(0, idx - 1);
                }
                else
                {
                    _baseUrl = url;
                }
            }

            try {
                session.Send(RequestMethod.POST, "/url", "url", url);
                return(true);
            } catch {
                if (raise)
                {
                    throw;
                }
                return(false);
            }
        }
コード例 #3
0
ファイル: SearchContext.cs プロジェクト: us1415/SeleniumBasic
        /// <summary>
        /// Returns a web element matching the given method and value
        /// </summary>
        private void WaitAnyElementNotPresent(By byAny, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/element";
            DateTime      endTime = session.GetEndTime(timeout);

            foreach (By by in (By[])byAny.Value)
            {
                if (by == null)
                {
                    break;
                }
                try {
                    string method = By.FormatStrategy(by.Strategy);
                    string value  = by.Value.ToString();
                    session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                    while (true)
                    {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw new Errors.ElementPresentError(byAny);
                        }
                        SysWaiter.Wait();
                        session.SendAgain();
                    }
                } catch (Errors.NoSuchElementError) { }
            }
        }
コード例 #4
0
ファイル: SearchContext.cs プロジェクト: us1415/SeleniumBasic
        private WebElements FindAnyElements(By byAny, int minimum, int timeout)
        {
            RemoteSession session     = this.session;
            string        uri         = this.uri + "/elements";
            WebElements   webelements = new WebElements();
            DateTime      endTime     = session.GetEndTime(timeout);

            while (true)
            {
                foreach (By by in (By[])byAny.Value)
                {
                    if (by == null)
                    {
                        break;
                    }
                    var  method   = By.FormatStrategy(by.Strategy);
                    var  value    = (string)by.Value;
                    List elements = (List)session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                    webelements.Add(session, elements);
                }
                if (webelements.Count >= minimum)
                {
                    return(webelements);
                }
                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchElementError(byAny);
                }
                SysWaiter.Wait();
            }
        }
コード例 #5
0
ファイル: SearchContext.cs プロジェクト: us1415/SeleniumBasic
        private WebElement FindAnyElement(By byAny, int timeout)
        {
            RemoteSession session     = this.session;
            string        relativeUri = this.uri + "/element";
            Dictionary    element;
            DateTime      endTime = session.GetEndTime(timeout);

            while (true)
            {
                foreach (By by in (By[])byAny.Value)
                {
                    if (by == null)
                    {
                        break;
                    }
                    try {
                        string method = By.FormatStrategy(by.Strategy);
                        string value  = by.Value.ToString();
                        element = (Dictionary)session.Send(RequestMethod.POST, relativeUri, "using", method, "value", value);
                        return(new WebElement(session, element));
                    } catch (Errors.NoSuchElementError) { }
                }
                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchElementError(byAny);
                }
                SysWaiter.Wait();
            }
        }
コード例 #6
0
ファイル: Cookies.cs プロジェクト: yclim95/SeleniumBasic
        /// <summary>
        /// Adds a new cookie.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="path"></param>
        /// <param name="domain"></param>
        /// <param name="expiry"></param>
        /// <param name="secure"></param>
        /// <param name="httpOnly"></param>
        internal static void AddOne(RemoteSession session, string name, string value, string path, string domain, string expiry, bool secure, bool httpOnly)
        {
            var dict = new Dictionary();

            dict.Add("name", name);
            dict.Add("value", value);
            if (path != null)
            {
                dict.Add("path", path);
            }
            if (domain != null)
            {
                dict.Add("domain", domain);
            }
            if (expiry != null)
            {
                var dt = (long)(DateTime.Parse(expiry) - Cookie.BASE_TIME).TotalSeconds;
                dict.Add("expiry", dt);
            }
            if (secure == true)
            {
                dict.Add("secure", true);
            }
            if (httpOnly == true)
            {
                dict.Add("httpOnly", true);
            }
            session.Send(RequestMethod.POST, "/cookie", "cookie", dict);
        }
コード例 #7
0
ファイル: SearchContext.cs プロジェクト: us1415/SeleniumBasic
        /// <summary>
        /// Returns a web element matching the given method and value or null if no element found
        /// </summary>
        private WebElement FindFirstElement(Strategy strategy, string value, int timeout)
        {
            RemoteSession session     = this.session;
            string        relativeUri = this.uri + "/element";
            Dictionary    element;

            try {
                string method = By.FormatStrategy(strategy);
                element = (Dictionary)session.Send(RequestMethod.POST, relativeUri, "using", method, "value", value);
            } catch (Errors.NoSuchElementError) {
                if (timeout == 0)
                {
                    throw;
                }
                var endTime = session.GetEndTime(timeout);
                while (true)
                {
                    SysWaiter.Wait();
                    try {
                        element = (Dictionary)session.SendAgain();
                        break;
                    } catch (Errors.NoSuchElementError) {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw;
                        }
                    }
                }
            }
            return(new WebElement(session, element));
        }
コード例 #8
0
ファイル: Alert.cs プロジェクト: yclim95/SeleniumBasic
        internal static Alert SwitchToAlert(RemoteSession session, int timeout)
        {
            string text;

            try {
                text = (string)session.Send(RequestMethod.GET, "/alert_text");
            } catch (Errors.NoAlertPresentError) {
                if (timeout == 0)
                {
                    throw;
                }
                DateTime endTime = session.GetEndTime(timeout);
                while (true)
                {
                    SysWaiter.Wait();
                    try {
                        text = (string)session.SendAgain();
                        break;
                    } catch (Errors.NoAlertPresentError) {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw;
                        }
                    }
                }
            }
            return(new Alert(session, text));
        }
コード例 #9
0
ファイル: Storage.cs プロジェクト: yclim95/SeleniumBasic
 /// <summary>
 /// Get or set the storage item for the given key.
 /// </summary>
 /// <param name="key">The key to set.</param>
 /// <param name="value">The value to set.</param>
 /// <returns>object</returns>
 public string this[string key] {
     get {
         return((string)_session.Send(RequestMethod.GET, _uri + "/key/" + key));
     }
     set {
         this.Set(key, value);
     }
 }
コード例 #10
0
ファイル: SearchContext.cs プロジェクト: us1415/SeleniumBasic
        /// <summary>
        /// Returns all the web elements matching the given method and value
        /// </summary>
        private WebElements FindAllElements(Strategy strategy, string value, int minimum, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/elements";

            try {
                var  method   = By.FormatStrategy(strategy);
                List elements = session.SendUntil(timeout,
                                                  () => (List)session.Send(RequestMethod.POST, uri, "using", method, "value", value),
                                                  (r) => r.Count >= minimum
                                                  );
                return(new WebElements(session, elements));
            } catch (Errors.TimeoutError) {
                throw new Errors.NoSuchElementError(strategy, value);
            }
        }
コード例 #11
0
ファイル: Cookies.cs プロジェクト: thomb1/SeleniumBasic
 /// <summary>
 /// Adds a new cookie.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <param name="path"></param>
 /// <param name="domain"></param>
 /// <param name="expiry"></param>
 /// <param name="secure"></param>
 /// <param name="httpOnly"></param>
 internal static void AddOne(RemoteSession session, string name, string value, string path, string domain, string expiry, bool secure, bool httpOnly) {
     var dict = new Dictionary();
     dict.Add("name", name);
     dict.Add("value", value);
     if (path != null)
         dict.Add("path", path);
     if (domain != null)
         dict.Add("domain", domain);
     if (expiry != null) {
         var dt = (long)(DateTime.Parse(expiry) - Cookie.BASE_TIME).TotalSeconds;
         dict.Add("expiry", dt);
     }
     if (secure == true)
         dict.Add("secure", true);
     if (httpOnly == true)
         dict.Add("httpOnly", true);
     session.Send(RequestMethod.POST, "/cookie", "cookie", dict);
 }
コード例 #12
0
ファイル: SearchContext.cs プロジェクト: us1415/SeleniumBasic
        /// <summary>
        /// Returns a web element matching the given method and value
        /// </summary>
        private void WaitElementNotPresent(Strategy strategy, string value, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/element";
            string        method  = By.FormatStrategy(strategy);
            DateTime      endTime = session.GetEndTime(timeout);

            try {
                session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                while (true)
                {
                    SysWaiter.Wait();
                    session.SendAgain();
                    if (DateTime.UtcNow > endTime)
                    {
                        throw new Errors.ElementPresentError(strategy, value);
                    }
                }
            } catch (Errors.NoSuchElementError) { }
        }
コード例 #13
0
ファイル: Alert.cs プロジェクト: thomb1/SeleniumBasic
 internal static Alert SwitchToAlert(RemoteSession session, int timeout) {
     string text;
     try {
         text = (string)session.Send(RequestMethod.GET, "/alert_text");
     } catch (Errors.NoAlertPresentError) {
         if (timeout == 0)
             throw;
         DateTime endTime = session.GetEndTime(timeout);
         while (true) {
             SysWaiter.Wait();
             try {
                 text = (string)session.SendAgain();
                 break;
             } catch (Errors.NoAlertPresentError) {
                 if (DateTime.UtcNow > endTime)
                     throw;
             }
         }
     }
     return new Alert(session, text);
 }
コード例 #14
0
ファイル: WebElement.cs プロジェクト: yclim95/SeleniumBasic
        /// <summary>
        /// Returns the element with focus, or BODY if nothing has focus.
        /// </summary>
        internal static WebElement GetActiveWebElement(RemoteSession session)
        {
            var result = (Dictionary)session.Send(RequestMethod.POST, "/element/active");

            return(new WebElement(session, result));
        }
コード例 #15
0
ファイル: Window.cs プロジェクト: thomb1/SeleniumBasic
 internal static string GetWindowHandle(RemoteSession session) {
     return (string)session.Send(RequestMethod.GET, "/window_handle");
 }
コード例 #16
0
 /// <summary>
 /// Delete the cookie matching the name on the current page.
 /// </summary>
 /// <returns>object</returns>
 internal static void DeleteByName(RemoteSession session, string name)
 {
     session.Send(RequestMethod.DELETE, "/cookie/" + name);
 }
コード例 #17
0
ファイル: Cookie.cs プロジェクト: thomb1/SeleniumBasic
 /// <summary>
 /// Delete the cookie matching the name on the current page.
 /// </summary>
 /// <returns>object</returns>
 internal static void DeleteByName(RemoteSession session, string name) {
     session.Send(RequestMethod.DELETE, "/cookie/" + name);
 }
コード例 #18
0
ファイル: WindowContext.cs プロジェクト: thomb1/SeleniumBasic
 internal static List GetWindowsHandles(RemoteSession session) {
     return (List)session.Send(RequestMethod.GET, "/window_handles");
 }
コード例 #19
0
ファイル: Mouse.cs プロジェクト: yclim95/SeleniumBasic
 /// <summary>
 /// Move the mouse to the specificed element.
 /// </summary>
 /// <param name="element">Opaque ID assigned to the element to move to, as described in the WebElement JSON Object. If not specified or is null, the offset is relative to current position of the mouse.</param>
 public Mouse moveTo(WebElement element)
 {
     _session.Send(RequestMethod.POST, "/moveto", "element", element.Id);
     return(this);
 }
コード例 #20
0
ファイル: Cookies.cs プロジェクト: thomb1/SeleniumBasic
 /// <summary>
 /// Delete all cookies visible to the current page.
 /// </summary>
 internal static void DeleteAll(RemoteSession session) {
     session.Send(RequestMethod.DELETE, "/cookie");
 }
コード例 #21
0
ファイル: Alert.cs プロジェクト: yclim95/SeleniumBasic
 /// <summary>
 /// Dismisses the alert.
 /// </summary>
 public void Dismiss()
 {
     _session.Send(RequestMethod.POST, "/dismiss_alert");
 }
コード例 #22
0
ファイル: Timeouts.cs プロジェクト: florentbr/SeleniumBasic
 private static void SendTimeoutPageLoad(RemoteSession session, int timeout) {
     session.Send(RequestMethod.POST, "/timeouts", "type", "page load", "ms", timeout);
 }
コード例 #23
0
ファイル: Timeouts.cs プロジェクト: florentbr/SeleniumBasic
 private static void SendTimeoutImplicit(RemoteSession session, int timeout) {
     session.Send(RequestMethod.POST, "/timeouts", "type", "implicit", "ms", timeout);
 }
コード例 #24
0
ファイル: WindowContext.cs プロジェクト: thomb1/SeleniumBasic
 internal static string GetCurrentTitle(RemoteSession session) {
     return (string)session.Send(RequestMethod.GET, "/title");
 }
コード例 #25
0
ファイル: WindowContext.cs プロジェクト: thomb1/SeleniumBasic
 internal static string ActivateWindow(RemoteSession session, string name) {
     session.Send(RequestMethod.POST, "/window", "name", name);
     return (string)session.Send(RequestMethod.GET, "/window_handle");
 }
コード例 #26
0
ファイル: WebElement.cs プロジェクト: yclim95/SeleniumBasic
 private object Send(RequestMethod method, string relativeUri)
 {
     return(_session.Send(method, this.uri + relativeUri));
 }
コード例 #27
0
ファイル: Timeouts.cs プロジェクト: yclim95/SeleniumBasic
 private static void SendTimeoutImplicit(RemoteSession session, int timeout)
 {
     session.Send(RequestMethod.POST, "/timeouts", "type", "implicit", "ms", timeout);
 }
コード例 #28
0
ファイル: Cookies.cs プロジェクト: yclim95/SeleniumBasic
 /// <summary>
 /// Get all cookies visible to the current page.
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 internal static List GetAll(RemoteSession session)
 {
     return((List)session.Send(RequestMethod.GET, "/cookie"));
 }
コード例 #29
0
ファイル: Window.cs プロジェクト: yclim95/SeleniumBasic
        /// <summary>
        /// Gets the position of the browser window relative to the upper-left corner of the screen.
        /// </summary>
        /// <remarks>When setting this property, it should act as the JavaScript window.moveTo() method.</remarks>
        public Point Position()
        {
            var result = (Dictionary)_session.Send(RequestMethod.GET, uri() + "/position");

            return(new Point(result));
        }
コード例 #30
0
ファイル: Cookies.cs プロジェクト: yclim95/SeleniumBasic
 /// <summary>
 /// Delete all cookies visible to the current page.
 /// </summary>
 internal static void DeleteAll(RemoteSession session)
 {
     session.Send(RequestMethod.DELETE, "/cookie");
 }
コード例 #31
0
ファイル: Window.cs プロジェクト: yclim95/SeleniumBasic
 internal static string GetWindowHandle(RemoteSession session)
 {
     return((string)session.Send(RequestMethod.GET, "/window_handle"));
 }
コード例 #32
0
        /*
         * public IME IME {
         *  get {
         *      return _ime ?? (_ime = new IME(_session));
         *  }
         * }
         */


        #region Location

        /// <summary>
        /// Get the current geo location.
        /// </summary>
        /// <returns>The current geo location. {latitude: number, longitude: number, altitude: number} </returns>
        public Dictionary Location()
        {
            return((Dictionary)_session.Send(RequestMethod.GET, "/location"));
        }
コード例 #33
0
ファイル: Cookies.cs プロジェクト: thomb1/SeleniumBasic
 /// <summary>
 /// Get all cookies visible to the current page.
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 internal static List GetAll(RemoteSession session) {
     return (List)session.Send(RequestMethod.GET, "/cookie");
 }
コード例 #34
0
        /// <summary>
        /// Returns true if the screen is portrait, false otherwise.
        /// </summary>
        /// <returns></returns>
        public bool IsPortrait()
        {
            var value = (string)_session.Send(RequestMethod.GET, "/orientation");

            return("PORTRAIT".Equals(value));
        }
コード例 #35
0
ファイル: Timeouts.cs プロジェクト: yclim95/SeleniumBasic
 private static void SendTimeoutPageLoad(RemoteSession session, int timeout)
 {
     session.Send(RequestMethod.POST, "/timeouts", "type", "page load", "ms", timeout);
 }