StackOverflowException on a context menu strip item (Tool strip menu item) - c#

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.

Related

Android Menu Text Stops Updating

We have a Xamarin Android app, with a navigation drawer.
Based on actions in the app, ... changing user name, changing mode, scanning items, we update some the text of various menu items in the navigation drawer to reflect the current state of the application and data, for easy viewing by the user.
The menu texts are updated with code along these lines... just with different actual IDs and text based upon the scenario.
private void BindThatMenuText() {
IMenuItem menu = navigationView.Menu.FindItem(Resource.Id.nav_someitem);
menu.SetTitle($"Some Text ({State Indicator})");
}
It works perfect. You click things, or scan things, and the menu items update their text appropriately. It's all peaches.
But then after a while (could be 30mins, or an hour, or a day), the menus just stop reflecting the new text. ... It doesn't throw any errors, like if navigationView were null or anything. The code runs fine, but the menus just don't actually update anymore.
I've found two ways to make it start working again...
Reinstall the application
Under App Info delete the app's data
Doing either of those will make the menus start reflecting text-updates again as they are supposed to, until they stop again. Of course, we can't very well tell the user to just keep going and doing that.
Any ideas why the text updates would work for a while, and then just stop working, ... and start again if the app's data is cleared?

C# Selenium - Can't Get Elements in New Tab

I have a bit of code that clicks on a link from a webpage which opens a new tab and automatically shifts my view to the new tab. When I try to select elements from that new webpage, I get errors saying the elements do no exist even though they do. Most of the times before the test crashes, the tab actually changes back to the original making me to believe that it is actually searching for the elements on the old tab. I try to use _driver.SwitchTo().Window(_driver.WindowHandles.Last()); in the hopes that it does something but it just closes out of the window entirely and opens a new blank window. How do I get it so I can get elements from the new webpage and no longer reference the old tab?
Use this helper function to switch to your tab of choice. The index is determined by the order they have been created. So your your default tabIndex is 0, if you open a new tab/window it will have tabIndex 1 and so forth..
internal void SwitchToTab(int tabIndex) {
WebDriver.Instance.Wait(2);
var newTab = WebDriver.Instance.Driver().WindowHandles[tabIndex];
Instance.Driver().SwitchTo().Window(newTab);
WebDriver.Instance.Wait(2);
}
The waits are just for letting the new tab load. These waits are not good practice, so you should look for other methods for waiting for whatever element/state you are waiting for.

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

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);

Changing text of a combobox in a different tab

I have a combo box which I need to mirror in another tab page in a C# winforms based application.
I have perfectly working code for when you select a different item from the drop down list. Unfortunately, however, when I change the Text of a tab that has not been clicked on yet nothing actually happens.
If I first click each tab then everything works as expected.
Now I'm putting this down to some form of lack of initialisation happening first. So I've tried to select each tab in my constructor.
tabControlDataSource.SelectedIndex = 0;
tabControlDataSource.SelectedIndex = 1;
// etc
But this doesn't work.
I've also tried calling tabControlDataSource.SelectTab( 1 ) and still it doesn't work.
Does anyone know how I can force the tab to "initialise"?
Ok, typically I post the question after struggling for an hour and shortly afterwards find the solution.
TabPages are lazily initialised. So they don't fully initialise until they are made visible for the first time.
So i added this code to my constructor:
tabControlDataSource.TabPages[0].Show();
tabControlDataSource.TabPages[1].Show();
tabControlDataSource.TabPages[2].Show();
but this didn't work :(
It occurred to me, however, that the constructor might not be the best place. So I created an event handler for Shown as follows:
private void MainForm_Shown( object sender, EventArgs e )
{
tabControlDataSource.TabPages[0].Show();
tabControlDataSource.TabPages[1].Show();
tabControlDataSource.TabPages[2].Show();
}
And now everything is working!
Perhaps you could also use sort of a "lazy" synchronization (initialization) in this case. Quick robust ideas: polling timer to update content (which will update it once you see tab page), no dependses within second tab (no Changed events for combobox to update second tab content, use original combobox from first tab or rather have it's content underlying in accessable for both comboboxes class, etc), "reinitialization" when tab become visible (at which moment you also init your second combobox)...
Can't be a hour, no way =D

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