/// <remarks/> public System.IAsyncResult BeginExecuteCommand(BrowserCommand command, int secondsTimeout, System.AsyncCallback callback, object asyncState) { return(this.BeginInvoke("ExecuteCommand", new object[] { command, secondsTimeout }, callback, asyncState)); }
public void VerifyTimeOut() { CommandManager.CreateBrowserQueue(1); BrowserCommand c = new BrowserCommand(); UnitTestAssert.IsNull(CommandManager.ExecuteCommand(1, c, 0)); }
/// <summary> /// DispatchEvent /// </summary> public void DispatchEvent(HtmlEvent htmlEvent) { // [01/26/2009] Missing support for CanBuble and Cancelable. // They're never set as arguments for the events even though HtmlEvent exposes them. BrowserCommand command = new BrowserCommand(); command.Handler.RequiresElementFound = true; HtmlKeyEvent keyEvent = htmlEvent as HtmlKeyEvent; if (keyEvent != null) { command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.DispatchKeyEvent; command.Handler.SetArguments(keyEvent.Name, keyEvent.CtrlKey, keyEvent.AltKey, keyEvent.ShiftKey, keyEvent.MetaKey, keyEvent.KeyCode, keyEvent.CharCode); } else if (htmlEvent is HtmlMouseEvent) { command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.DispatchMouseEvent; command.Handler.SetArguments(htmlEvent.Name); } else { command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.DispatchHtmlEvent; command.Handler.SetArguments(htmlEvent.Name); } command.Target = this.BuildBrowserCommandTarget(); command.Description = "DispatchEvent:" + htmlEvent.Name; this.ParentPage.ExecuteCommand(command); }
public ArticleModel Select(ArticleCondition articleCondition = null) { Article article = _articleRepository.Select(articleCondition); UserModel userModel = _userService.SelectUser(article.Author); string content = article.Content; if (content.Contains(ConstantKey.NGINX_FILE_ROUTE_OLD)) { content = content.Replace(ConstantKey.NGINX_FILE_ROUTE_OLD, ConstantKey.NGINX_FILE_ROUTE); } ArticleModel articleModel = new ArticleModel() { Id = article.Id, Title = article.Title, ArticleType = article.ArticleType.GetEnumText(), CreateTime = article.CreateTime.Value.ToString("yyyy/MM/dd"), Content = content, Author = userModel.Username, AuthorAccount = userModel.Account, IsDraft = article.IsDraft ? "是" : "否", Comments = CommentModel.ConvertToCommentModels(article.Comments) }; BrowserCommand browserCommand = new BrowserCommand(article.Id); _eventBus.Publish(browserCommand); return(articleModel); }
internal string GetOuterHtml(bool reload) { if (reload) { BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.GetElementDom); command.Description = "GetElementDom"; command.Handler.RequiresElementFound = true; command.Target = this.BuildBrowserCommandTarget(); return(_parentPage.ExecuteCommand(this, command).Data); } else { StringBuilder htmlBuilder = new StringBuilder(); htmlBuilder.Append("<" + this.TagName); foreach (string attr in this._attributeDictionary.Keys) { htmlBuilder.Append(" " + attr + "="); htmlBuilder.Append("'" + this._attributeDictionary[attr] + "'"); } htmlBuilder.Append(">"); htmlBuilder.Append(this.CachedInnerText); foreach (HtmlElement element in this.ChildElements) { htmlBuilder.Append(element.GetOuterHtml(false)); } htmlBuilder.Append("</" + this.TagName + ">"); return(htmlBuilder.ToString()); } }
/// <summary> /// Execute a command on the target browser /// </summary> /// <param name="threadId">Id used to distinguish between multiple tests running at the same time</param> /// <param name="source">HtmlElement that initiated this command, null if none</param> /// <param name="command">Command to execute</param> /// <param name="secondsTimeout">Timeout in seconds that browser shoud wait for this command</param> /// <returns>BrowserInfo object that contains command results</returns> public BrowserInfo ExecuteCommand(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { if (source != null) { // add id to description, to make logs more informative command.Description += " id=" + source.Id; } // fire event before any command execution is started OnBrowserCommandExecuting(new BrowserCommandEventArgs(threadId, command, secondsTimeout)); BrowserInfo browserInfo = null; BrowserCommandHandler commandHandler = null; if (this._browserCommandHandlerFactory.TryGetValue(command.Handler.ClientFunctionName, out commandHandler)) { // just call a handler and if there any exceptions, let them go browserInfo = commandHandler(threadId, source, command, secondsTimeout); } else { throw new NotSupportedException(String.Format("Command '{0}' is not supported", command.Handler.ClientFunctionName)); } return(browserInfo); }
/// <summary> /// Public ctor /// </summary> public BrowserCommandEventArgs(int threadId, BrowserCommand command, int secondsTimeout) { this._threadId = threadId; this._command = command; this._secondsTimeout = secondsTimeout; this._abortCommand = false; }
public BrowserInfo ExecuteCommand(BrowserCommand command, int secondsTimeout) { object[] results = this.Invoke("ExecuteCommand", new object[] { command, secondsTimeout }); return((BrowserInfo)(results[0])); }
/// <summary> /// Returns the url of the page currently loaded /// </summary> /// <returns>Url of the page currently loaded</returns> public string GetCurrentUrl() { BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.GetCurrentUrl); command.Description = "GetCurrentUrl"; command.Handler.RequiresElementFound = false; return(this.ExecuteCommand(command).Data); }
/// <summary> /// Refresh this collection of html elements from the current Dom in the web page including the specified list of attributes /// </summary> /// <param name="attributesToLoad">Collection of attribute names to load for each element</param> internal void Refresh(ICollection <string> attributesToLoad) { if (TestPage == null) { return; } //send the command to get dom of this collection BrowserCommand command = new BrowserCommand(); if (_parentElement == null) { command.Description = "GetPageDom"; command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.GetPageDom; command.Handler.RequiresElementFound = false; } else { command.Description = "GetElementDom"; command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.GetElementDom; command.Handler.RequiresElementFound = true; command.Target = this.ParentElement.BuildBrowserCommandTarget(); } if (attributesToLoad != null && attributesToLoad.Count > 0) { StringBuilder attributesBuilder = new StringBuilder(); foreach (string attr in attributesToLoad) { attributesBuilder.Append(attr); attributesBuilder.Append("-"); } attributesBuilder.Length--; command.Handler.SetArguments(attributesBuilder.ToString().ToLowerInvariant()); } BrowserInfo browserInfo = this.TestPage.ExecuteCommand(_parentElement, command); HtmlElement newRoot = HtmlElement.Create(browserInfo.Data, this.TestPage, false); this.Items.Clear(); if (_parentElement == null) { this.Items.Add(newRoot); } else { foreach (HtmlElement childElement in newRoot.ChildElements) { childElement.ParentElement = _parentElement; this.Items.Add(childElement); } } OnRefresh(new EventArgs()); }
/// <summary> /// Recursively builds the innerText of this element and all its child elements. /// </summary> /// <returns>The innerText as exposed by the Dom at this moment.</returns> public string GetInnerTextRecursively() { BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.GetElementInnerTextRecursive); command.Description = "GetInnerTextRecursively"; command.Target = this.BuildBrowserCommandTarget(); command.Handler.RequiresElementFound = true; return((_parentPage.ExecuteCommand(this, command).Data ?? "").Trim()); }
/// <summary> /// Remove a command from the command table /// </summary> /// <param name="command">unique ID of command</param> private void RemoveCommand(BrowserCommand commandID) { // verify we aren't trying to remove a command that doesn't exist Debug.Assert(m_commands.Contains(commandID), "Attempted to remove a command that doesn't exist"); // remove the command from the table m_commands.Remove(commandID); }
/// <summary> /// Submits the form. /// </summary> public void Submit() { var command = new BrowserCommand(BrowserCommand.FunctionNames.FormSubmit); command.Target = this.BuildBrowserCommandTarget(); command.Description = "FormSubmit"; command.Handler.RequiresElementFound = true; this.ParentPage.ExecuteCommand(this, command); }
/// <summary> /// Add a command to the command table /// </summary> /// <param name="command">unique ID of command</param> /// <param name="command">command implementation</param> private void AddCommand(BrowserCommand commandID, IBrowserCommand command) { // verify we haven't already added this command Debug.Assert(!m_commands.Contains(commandID), "Added a command that is already part of the command table"); // insert the command into the table m_commands[commandID] = command; }
/// <summary> /// Execute a command on the browser /// </summary> /// <param name="threadId">Id used to distinguish between multiple tests running at the same time</param> /// <param name="source">HtmlElement that initiated this command, null if none</param> /// <param name="command">Command to execute</param> /// <param name="secondsTimeout">Timeout in seconds that executor shoud wait for this command</param> /// <returns>BrowserInfo object that contains command results</returns> public BrowserInfo ExecuteCommand(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { var browserInfo = CommandManager.ExecuteCommand(System.Threading.Thread.CurrentThread.ManagedThreadId, command, secondsTimeout); if (command.Handler.ClientFunctionName == BrowserCommand.FunctionNames.NavigateToUrl) { System.Threading.Thread.Sleep(NAVIGATE_WAIT_TO_LOAD_MILLISECONDS); } return(browserInfo); }
/// <summary> /// Method that waits until a custom script expression that is evaluated in the context of the /// page under test returns true /// </summary> /// <param name="scriptExpression">The javascript expression to evaluate</param> /// <param name="timeoutInSeconds">The timeout in seconds to keep trying the expression before fail.</param> public void WaitForScript(string scriptExpression, int timeoutInSeconds) { BrowserCommand command = new BrowserCommand(); command.Description = "WaitForScript"; command.Handler.RequiresElementFound = false; command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.WaitForScript; command.Handler.SetArguments(scriptExpression, timeoutInSeconds * 1000); this.ExecuteCommand(command); }
/// <remarks/> public void ExecuteCommandAsync(BrowserCommand command, int secondsTimeout, object userState) { if ((this.ExecuteCommandOperationCompleted == null)) { this.ExecuteCommandOperationCompleted = new System.Threading.SendOrPostCallback(this.OnExecuteCommandOperationCompleted); } this.InvokeAsync("ExecuteCommand", new object[] { command, secondsTimeout }, this.ExecuteCommandOperationCompleted, userState); }
/// <summary> /// Handler for Form Submit browser command /// </summary> private BrowserInfo ExecuteFormSubmit(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { var form = source as HtmlFormElement; if (form == null) { throw new InvalidOperationException(String.Format(EXECUTECOMMAND_REQUIRESOURCEANDTYPE_FORMATSTRING, "FormSubmit", typeof(HtmlFormElement).ToString())); } return(ExecuteFormSubmit(form)); }
/// <summary> /// Wait until an attribute of this element is set to the expected value. /// </summary> /// <param name="attributeName">The attribute name to wait upon.</param> /// <param name="expectedAttributeValue">The attribute value to wait upon.</param> /// <param name="timeoutInSeconds">Timeout in seconds for the attribute to have the expected value.</param> public void WaitForAttributeValue(string attributeName, string expectedAttributeValue, int timeoutInSeconds) { BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.WaitForDomChange); command.Description = "WaitForDomChange"; command.Target = this.BuildBrowserCommandTarget(); // even though we truly require element to be found, this command needs special logic that is implemented in the command handler. command.Handler.RequiresElementFound = false; command.Handler.SetArguments(attributeName, expectedAttributeValue, timeoutInSeconds * 1000); _parentPage.ExecuteCommand(command); }
public override bool ShowHtml(string title, string buttonText, string html) { using (var pool = new NSAutoreleasePool()) { var thread = new Thread(OpenBrowserOnThread); BrowserCommand browserCommand = new BrowserCommand(); browserCommand.Title = title; browserCommand.ButtonText = buttonText; browserCommand.Html = html; browserCommand.CheckNullsAndSetDefaults(); thread.Start(browserCommand); } return(true); }
public override bool OpenBrowser(string title, string buttonText, string url) { using (var pool = new NSAutoreleasePool()) { var thread = new Thread(OpenBrowserOnThread); BrowserCommand browserCommand = new BrowserCommand(); browserCommand.Title = title; browserCommand.ButtonText = buttonText; browserCommand.Url = Uri.EscapeUriString(url); browserCommand.CheckNullsAndSetDefaults(); thread.Start(browserCommand); } return(true); }
/// <summary> /// Execute a command /// </summary> /// <param name="command">unique ID of command</param> public void Execute(BrowserCommand command) { // verify that the command exists Debug.Assert(m_commands.Contains(command), "Attempted to Execute a command that doesn't exist"); // execute IBrowserCommand cmdExecute = (IBrowserCommand)m_commands[command]; if (cmdExecute != null) { cmdExecute.Execute(); } }
public void AndroidExpriBankTest() { LoginPage homePage = new LoginPage(AndroidContext); homePage.Login("company", "company"); BankSecondScreen bankSecondScreen = new BankSecondScreen(AndroidContext); bankSecondScreen.makePay(); BrowserCommand.Back(); bankSecondScreen.mortageReques(); BrowserCommand.Back(); bankSecondScreen.expenseReport(); BrowserCommand.Back(); bankSecondScreen.logOut(); }
/// <summary> /// Verify that LTAFService can send commands to browser and receive a response /// </summary> private void VerifyServiceCommunicationLoop() { BrowserCommand firstCommand = new BrowserCommand(BrowserCommand.FunctionNames.GetPageDom); firstCommand.Handler.RequiresElementFound = false; firstCommand.Description = "Startup"; try { this.ExecuteCommand(0, null, firstCommand, 60 * 4 /*timeout*/); } catch (Exception e) { throw new InvalidOperationException(ERROR_SERVICE_INIT_FAILED, e); } }
public void VerifyBasicCommandSetGet() { CommandManager.CreateBrowserQueue(1); BrowserInfo browserInfo = new BrowserInfo(); browserInfo.Data = "foobar"; BrowserSimulator.WaitForOneCommand(1, browserInfo); BrowserCommand c = new BrowserCommand(); UnitTestAssert.AreEqual("foobar", CommandManager.ExecuteCommand(1, c, 10).Data); browserInfo = CommandManager.GetBrowserInfo(1); UnitTestAssert.AreEqual("foobar", browserInfo.Data); }
internal void RefreshAttributesDictionary() { if (_parentPage == null) { return; } BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.GetElementAttributes); command.Description = "GetElementAttributes"; command.Target = this.BuildBrowserCommandTarget(); command.Handler.RequiresElementFound = true; string data = _parentPage.ExecuteCommand(this, command).Data; HtmlElement tempElement = HtmlElement.Create(data, _parentPage, false); this._attributeDictionary = new HtmlAttributeDictionary(tempElement._attributeDictionary); }
/// <summary> /// Set the text of this element. /// </summary> /// <param name="textValue">Value to set.</param> /// <param name="focusAndBlur">Wheter to dispatch focus and blur events to the textbox as part of setting the value.</param> public void SetText(string textValue, bool focusAndBlur) { if (CanSetText) { BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.SetTextBox); command.Target = this.BuildBrowserCommandTarget(); command.Description = "FillTextBox"; command.Handler.SetArguments(textValue, focusAndBlur); command.Handler.RequiresElementFound = true; this.ParentPage.ExecuteCommand(this, command); } else { throw new WebTestException("This HtmlElement does not support setting text."); } }
/// <summary> /// Select an item of this list. /// </summary> /// <param name="selectBoxIndex">The zero-based index to select.</param> public void SetSelectedIndex(int selectBoxIndex) { if (CanSelectIndex) { BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.SetSelectBoxIndex); command.Target = this.BuildBrowserCommandTarget(); command.Description = "SetSelectBox"; command.Handler.SetArguments(selectBoxIndex); command.Handler.RequiresElementFound = true; this.ParentPage.ExecuteCommand(this, command); } else { throw new WebTestException("This HtmlElement does not support setting the selected index."); } }
/// <summary> /// Handler for SetText browser command /// </summary> private BrowserInfo ExecuteCommandSetText(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { if (source is HtmlInputElement) { ((HtmlInputElement)source).CachedAttributes.Value = (string)command.Handler.Arguments[0]; } else if (source is HtmlTextAreaElement) { ((HtmlTextAreaElement)source).CachedInnerText = ((string)command.Handler.Arguments[0]); } else { throw new InvalidOperationException(String.Format(EXECUTECOMMAND_REQUIRESOURCEANDTYPE_FORMATSTRING, "SetText", typeof(HtmlInputElement).ToString() + " or " + typeof(HtmlTextAreaElement).ToString())); } return(new BrowserInfo()); }
/// <summary> /// Determine if a command is enabled /// </summary> /// <param name="command">unique ID of command</param> /// <returns>true if the command is enabled, otherwise false</returns> public bool IsEnabled(BrowserCommand command) { // verify that the command exists Debug.Assert(m_commands.Contains(command), "Attempted to QueryStatus on a command that doesn't exist"); // query status IBrowserCommand cmdStatus = (IBrowserCommand)m_commands[command]; if (cmdStatus != null) { return(cmdStatus.Enabled); } else { return(false); } }
/// <summary> /// Determine if a command is enabled /// </summary> /// <param name="command">unique ID of command</param> /// <returns>true if the command is enabled, otherwise false</returns> public bool IsEnabled(BrowserCommand command) { // verify that the command exists Debug.Assert(m_commands.Contains(command), "Attempted to QueryStatus on a command that doesn't exist"); // query status IBrowserCommand cmdStatus = (IBrowserCommand)m_commands[command]; if (cmdStatus != null) return cmdStatus.Enabled; else return false; }
/// <summary> /// Execute a command /// </summary> /// <param name="command">unique ID of command</param> public void Execute(BrowserCommand command) { // verify that the command exists Debug.Assert(m_commands.Contains(command), "Attempted to Execute a command that doesn't exist"); // execute IBrowserCommand cmdExecute = (IBrowserCommand)m_commands[command]; if (cmdExecute != null) cmdExecute.Execute(); }