I am trying to find out reason why ShowDialog() is not showing the dialog box for me.
I have an application where I have a credential dialog box(A) for the user to enter credentials. And I have another dialog box(B) to display some custom msg based on the user's credential.
After the user enter's credentials in A, I am doing something with it.
when I am trying to show the msg in B, ShowDialog() is not showing dialog B.
Can you guys think of any reason?
Here is the code:
bool isInternetConnected = class.CheckInternetConnection(ref error);
if(!String.IsnUllOrEMpty(error))
{
DialogBox dialogBox = new DialogBox();
dialogBox.Title = "Credentials";
dialogBox.State = DialogBox.States.NoFooter;
dialogBox.ShowInTaskbar = false;
CredentialsContent Credentials = new CredentialsContent();
Credentials.ContentCompleted += new EventHandler<ContentCompletedEventArgs>(
dialogBox.OnContentCompleted);
dialogBox.MainContent = Credentials;
bool? result = dialogBox.ShowDialog();
hasAccess = result.HasValue ? result.Value : false;
}
UpdateDialog updateDialog = new UpdateDialog();
updateDialog.ShowModal = true;
bool? isTrue = updateDialog.ShowDialog();
I got it resolved.
What was happening is that windows was treating the first window(A) as main window.When it was getting closed the next window(B) as inconsequential.
So even with showdialog() it was not showing it.
The trick was to define UpdateDialog() at the start of the application.
The same question is answered here:
Open new window after first
Related
I have a login page in my app which uses UITextField element. I want to hide the keyboard when I click away from that TextField.
I tried using this code that I saw on a website in my ViewDidLoad function but it didn't work.
EntryTextField.ShouldReturn = (textField) =>
{
textField.ResignFirstResponder();
return true;
};
I solved the problem by adding these lines to ViewDidLoad():
View.UserInteractionEnabled = true;
UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(HideKyb);
tapGesture.NumberOfTapsRequired = 1;
View.AddGestureRecognizer(tapGesture);
and I added this line into the HideKyb function:
View.EndEditing(true);
I would like to test to Outlook application and send an email to me by using White Stack framework. I implemented code who click on 'New Item' and after that the new window appears. I want to type a my mail to TextBox 'To' but I don't know how get to access to second window 'Untitled - Message (HTML)'. Photo
[TestMethod]
public void mail()
{
var application = Application.Launch(appPatch);
Thread.Sleep(2000);
var window = application.GetWindow(appTitle, InitializeOption.NoCache);
SearchCriteria searchCriteriaNewEmail = SearchCriteria.ByText("New Email");
Button buttonNewEmail = window.Get<Button>(searchCriteriaNewEmail);
buttonNewEmail.Click();
Thread.Sleep(1000);
string windowTitle = "Untitled - Message(HTML)";
var window2 = application.GetWindow(windowTitle, InitializeOption.NoCache);
SearchCriteria searchCriteriaTo = SearchCriteria.ByText("To");
TextBox tbxTo = window2.Get<TextBox>(searchCriteriaTo);
tbxTo.BulkText = "mymail#gmail.com";
Thread.Sleep(2000);
window.Close();
}
The "second window" is in the same process id, so with that you can't simply use the .GetWindow() method.
For MDI applications you should use MdiChild(), or if it is a modal window, use .ModalWindow() on the parent window, or go back to the application then use Window() to get the window.
I would add that getting the window by it's title is not recommended, since that will change as you type the new title of the e-mail.
I'm running coded UI tests in Visual Studio Enterprise 2017.
My webpage under test has a javascript popup asking for an e-mail address to be entered. I can locate the confirmationPopup (highlight is drawn correctly), and I can click buttons within it, such as the cancel.
confirmationPopup = new WinWindow();
confirmationPopup.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Dialog");
confirmationPopup.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "#32770");
confirmationPopup.TechnologyName = "MSAA";
confirmationPopup.Find();
confirmationPopup.DrawHighlight();
var cancelButton = new WinButton(confirmationPopup);
cancelButton.SearchProperties.Add(WinButton.PropertyNames.Name, "Cancel");
Mouse.Click(cancelButton);
What I am struggling to do is enter text in the popup's input box:
var textInput = new WinEdit(confirmationPopup);
textInput.SearchProperties.Add(WinEdit.PropertyNames.ClassName, "Edit");
textInput.TechnologyName = "MSAA";
textInput.DrawHighlight();
textInput.Text = "bill#microsoft.com";
The highlight is drawn around the correct control, but the textInput.Text= line gives an error
Additional information: SetProperty of "Text" is not supported on control type: Window
Any ideas what I'm doing wrong?
Here is an example of interacting with javascript prompt window.
// go to a public site which has a prompt
var window = BrowserWindow.Launch("http://www.javascriptkit.com/javatutors/alert2.shtml");
var contentDiv = new HtmlDiv(window);
contentDiv.SearchProperties.Add(HtmlDiv.PropertyNames.Id, "contentcolumn", PropertyExpressionOperator.EqualTo);
var promptButton = new HtmlInputButton(contentDiv);
promptButton.SearchProperties.Add(HtmlInputButton.PropertyNames.ControlDefinition, "name=\"B4\"", PropertyExpressionOperator.Contains);
promptButton.SetFocus();
Keyboard.SendKeys("{ENTER}");
// now the prompt is showing, find it and set text
var promptWindow = new WinWindow();
promptWindow.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Dialog");
promptWindow.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "#32770");
promptWindow.DrawHighlight();
var middleWindow = new WinWindow(promptWindow);
middleWindow.DrawHighlight();
var inputBox = new WinEdit(middleWindow);
inputBox.DrawHighlight();
inputBox.Text = "Hello world!";
When using the inspect feature of coded ui, I see there is a middle window. Using it or not, I am able to find the edit.
If i click to button , my below code works very well.
if (Application.OpenForms["StockCardForm"] == null)
{
var stockCardForm = new StockCardForm();
stockCardForm.MdiParent = this;
stockCardForm.Show();
}
else
Application.OpenForms["StockCardForm"].Focus();
Instead of "StockCardForm" how can i give form name dynamic or how can i prevent to open same forms second time as dynamic ?
Any help will be appreciated.
Thanks.
You can check if there are any forms of some type already open and then do whatever you want.
if (!Application.OpenForms.OfType<StockCardForm>().Any())
{
var form = new StockCardForm();
form.Show();
}
else
Application.OpenForms.OfType<StockCardForm>().First().Focus();
I am creating a tool on an application that opens some windows forms to get information from users, my tool should deal with these windows forms by itself without users' interactions.
I have initiated an event to get the opened form's process when it opens by the following code:
mgmtWtch = new ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
mgmtWtch.EventArrived += WatchManagementEvent;
mgmtWtch.Start();
The shown window has OK button which i want to click, and i don't know how to make this action. while the parameter that i can get from this event is
EventArrivedEventArgs e
my question is how can i click the OK button through this event handler?
thanks in advance.
Have you looked at .Net's GUI automation API?
You'll want the UIAutomationClient and UIAutomationTypes assemblies.
I've used this API to drive installers, UIs during testing etc.
I found this link useful initially.
http://blogs.msdn.com/b/oldnewthing/archive/2013/04/08/10409196.aspx
e.g. assuming you have the parent window (i.e. the Form) for the button and you know the button's ID:
using System.Windows.Automation;
....
static AutomationElement FindById(AutomationElement root, string id, bool directChild)
{
Assert(root != null, "Invalid input: ParentWindow element 'root' is null.");
Condition conditions = new PropertyCondition(AutomationElement.AutomationIdProperty, id);
return root.FindFirst(directChild ? TreeScope.Children : TreeScope.Descendants, conditions);
}
....
AutomationElement button = FindById(containerWindow, id.ToString(), true);
InvokePattern invokePattern = null;
try
{
invokePattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
}
catch (InvalidOperationException)
{
MessageBox.Show("The UI element named " + button.GetCurrentPropertyValue(AutomationElement.NameProperty) + " is not a button");
return false;
}
invokePattern.Invoke();
If you don't know the button's ID but do know it's name i.e. the text on the button then replace AutomationElement.AutomationIdProperty with AutomationElement.NameProperty in FindById (and rename the method appropriately)
Assuming the button is in the top-level Form window and you know the title displayed in this Form window, the following code will get the button's parent window:
bool ignoreCase = true; // or false if preferred
Condition conditions = new PropertyCondition(
AutomationElement.NameProperty,
windowTitle,
ignoreCase ? PropertyConditionFlags.IgnoreCase : PropertyConditionFlags.None
);
AutomationElement myForm =
AutomationElement.RootElement.FindFirst(
TreeScope.Children,
conditions );
The Window Title can be retrieved from the process you already have via the process' MainWindowTitle property.