Coded UI Test: The test run will not open a simple menu - c#

I am being asked to evaluate Visual Studio for our automation testing efforts.
I have chosen to create a simple Coded UI Test where I simply want to open up Minesweeper (Win7 version), play with the custom game options and then close the application.
Every time I Run the test, it will not open the 'Game' menu item.
// Click 'Game' -> 'Options F5' menu item
Mouse.Click(uIOptionsF5MenuItem, new Point(26, 6));
Now, if I myself click the menu item (basically giving the test a 'push'), the automation takes over by selecting the menu option I need and then will run without any issue. I just can't figure out why the test can not open this menu on its own. I've tried the SetFocus method already and I haven't found any other options. The MSDN documentation offers ZERO help.
Anyone have an idea how I can get this menu to open?
Result Message:
Test method Blorg.CodedUITest1.CodedUITestMethod1 threw exception: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details:
TechnologyName: 'MSAA'
ControlType: 'MenuItem'
Name: 'Options F5'

Try adding the menu item and perform the click like this,
WinMenuItem uIOptionsF5MenuItem = new WinMenuItem(Add the window where the menu is placed) {TechnologyName="MSAA" };
uIOptionsF5MenuItem.SearchProperties.Add("Name", "Options F5");
Mouse.Click(uIOptionsF5MenuItem);

Related

StackOverflowException on a context menu strip item (Tool strip menu item)

The concept:
OK, I have a context menu strip with one item (tool strip menu item), nothing special. I added a "click" event, everything worked the last time the application didn't thrown any exception, the context menu strip item BUT I forgot to mention that the item that I talk about is a child of another item. This another item is the first item you see in the context menu strip.
Exception:
So now, on the exception, the problem: I debug my application, my Form1 is working normally, I click on a button that will show the Form where is the context menu strip that I talked about earlier, the Form didn't want to open, I saw the debug diagnostic tool where you can see how much the application use in RAM, I saw it was starting to take my PC RAM (100 MB), normally it takes 30 MB of RAM but that's way too much until it reached the limit, 180 MB of RAM for my application, the StackOverflowException where the message says "". Yes, it is blank because there is no message, only the exception name in bold (StackOverflowException: ). I didn't find anything in my case of this StackOverflowException because the people that have this exception have multiple items on their context menu strip.
I tried:
Create another context menu strip, same text, same items, same click event, delete the old one, debug = same exception... Tried Google because I don't have any other idea = not my case.
More info:
The line of code where I have this exception is where it is declaring the text of the item. I don't see the matter with "StackOverflowException" and "Open in explorer" <- the text.
The code where the exception is thrown:
//FormName.Designer.cs
//
// openInExplorerTSMI
//
this.openInExplorerTSMI.CheckOnClick = false;
this.openInExplorerTSMI.Name = "openInExplorerTSMI";
this.openInExplorerTSMI.Size = new System.Drawing.Size(198, 22);
this.openInExplorerTSMI.Text = "Open in explorer"; //StackOverflowException here.
this.openInExplorerTSMI.Click += new System.EventHandler(this.openInExplorerTSMI_Click);
Thanks for help.

Revit C#: Copy existing button to my Ribbon

I want to use the Create-Wall-Button from Architecture in my Ribbon.
I've tried debugging and found the splitbutton here: Autodesk.Windows.ComponentManager.Ribbon.Tabs[0].Panels[1].Source.Items[0]
How can I copy this SplitButton to my Ribbon or what I have to call in a new Button to use this function?
Thank you.
It is posible to clone an built-in command button and add it to another tab, however you would need a couple of tricks and of course the non-supported Autodesk.Windows dll.
I think what you are looking for is the method PostCommand from the UIApplication. Just create a new command and the requested Postable Command will be executed after your own command is completed:
var app = cmdData.Application;
var cmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.StructuralWall);
app.PostCommand(cmdId);

Create parent menu in AddIn using c#

I want to add menu to visual studio in AddIn.
I found how to create submenu item in Expose an Add-In on the Tools Menu (Visual C#), but I want to create primary menu (like 'File', 'Edit', 'View' etc.)
How can I do that using c#?
I think You can use this:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];
CommandBarPopup myNewPopUpControl =
menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup) as CommandBarPopup;
myNewPopUpControl.Caption = "MyMenu";
myNewPopUpControl.Visible = true;
First line is from the OnConnection of the Add-In template.
As I experienced each element of Controls collection has a zero Id, so the arrangment might be problematic. Also you can create Buttons and PopUps with Automation (Exception will be thrown otherwise)
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.commandbars.commandbarcontrols.add.aspx
http://msdn.microsoft.com/en-us/library/office/aa190793(v=office.10).aspx
Update:
Your question seems to be a duplicate
[a question] Adding a Menu to the Visual Studio Menu Bar within an Add-In [a]

Visual Studio Package: Settings the visibility of a custom Solution Explorer context menu item

I am creating a Visual Studio Package (this is my first time) and my end goal is to create a context-menu item for the solution explorer that only works on certain file types. (I thought this would be a common thing, but didn't find any decent tutorials on it, so if you know any please let me know)
I followed a simple MSDN guide to create an item in the toolbar first (I forget where is was to link it) and this worked fine.
Then I found a way to move it to the Solution Explorer context menu. This was achieved by manipulating the .vsct file and having an element like this:
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>
That probably doesn't matter, but I am trying to set the scene.
Now, because I want to only show the item for certain file types, I need to find a way to check the file when the right-click button is pressed. Cutting a long search short, I found this and ended up with the following code:
protected override void Initialize()
{
//stuff
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
menuItem.BeforeQueryStatus += menuItem_BeforeQueryStatus;
//more stuff
}
void menuItem_BeforeQueryStatus(object sender, EventArgs e)
{
var myCommand = sender as OleMenuCommand;
myCommand.Text = "NEW NAME";
}
In the above example I am just trying to set the text to try and prove it works, I know there is a Visible property but I want this step to work first. The BeforeQueryStatus event is fired, and debugging shows the code executing as expected. However, there is no change in the context menu item, it stays with the original text.
What am I missing here? Why is it not updating?
OK, so I have finally found a solution to this problem, there are a couple of things that you need to do...
STEP 1:
We need to specify that the VSPackage should "auto-load", we do this so that the code will execute when the ContextMenu is shown, because normally the VSPackage would not initialise before the UI has been shown (i.e. the menu item has been clicked). To do this we add an attribute to the Package class, like so:
[ProvideAutoLoad("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
public sealed class MyFirstPackage : Package
You may wonder what that GUID value is, well in this case it represents the UICONTEXT_SolutionExists constant, which means the the package will auto-load when a solution exists (so when we create a new one or load one). I got this information from here, as you might be able to tell there are a number of different VSConstants that could be used.
Here are a couple more resources that list other GUID values that can be used:
GUID List 1
GUID List 2
STEP 2:
Now that the BeforeQueryStatus code is executing at the correct place, it is still confusing as to why the code doesn't actually change anything (in my question I try to change the Text). Well, the answer is, because we need to give the package permission to do so (at least that's the way I see it as being).
To do this we must edit the .vsct file. Inside there we can find a Buttons element, inside which should be our ContextMenu Button. By default there are some comments which mention the use of the CommandFlag node - this is what we want.
In order to give permission for our package to change the Text we must add the following node:
<CommandFlag>TextChanges</CommandFlag>
Now, if we run the VSPackage it should all work as expected!
If you are looking to allow permission to change the Visibility of the menu item (which was my original aim) then you can use the following CommandFlag:
<CommandFlag>DynamicVisibility</CommandFlag>
There is a full list of command flags here, with descriptions on what they do.
Instead of directly using the guid mentioned in musefan's answer, you can use:
[ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.SolutionExists)]
Refer to: UIContextGuids Class for all guid constants.

c# simulate click in context menu

So my question is:
I got an Windows Forms application in C# and an webBrowser control in this application. When you for example right-click on a video in youtube, a context menu shows up. Now, is it possible to programmatically rightclick in the webBrowser control an then, again programmatically, click a specific entry in that context menu?
Yes it is, but you always have to start from the same pixel, or better said an actual pixel range, so you can be sure that the clicked result will be the required one. Also you cant click an item by specifying its text, you must do everything programatticaly, from the graphics point of view(just work on the X - Y Axis since its only 2 dimensional). That is the way most web bots are made for various purposes.
Do you really have to simulate a click of the context menu or is just having the desired action good enough? If so than you can just get the item from the ContextMenu.Items list and assuming it a button raise its Click event. If you do need to at least show the context menu while do this you can call the ContextMenu.Show event. This all assumes that the contextmenu for your WebBrowser control is public (not some third party inherited control that hides it or something).

Categories