C# How to get the current Page Coded UI TEST in Wpf - c#

I want to know if it's possible to get / know the current page in wpf.
In my project, I put this code and I have the correct page:
var current_page = (Window.Current.Content as Frame).Content.GetType();
Windows.Current.Content was null.
But in my UI Test project, I have the following error:
Result Message:
Test method CodedUITestProject1.CodedUiTest.CodedUITestMethod1 threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.

Related

C#/Selenium .Net conversion ro .Core error

I am currently converting C#/Selenium test suites from .NET to .NET Core
Prior to conversion this little bit of code worked fine in one suite.
public void ClearConsoleErrors()
{
IJavaScriptExecutor js = (IJavaScriptExecutor)Driver;
String script = "console.clear();";
js.ExecuteScript(script);
Driver.Manage().Logs.GetLog(LogType.Browser);
}
Now we get this error
System.NullReferenceException: 'Object reference not set to an instance of an object.'
The error happens on this line - Driver.Manage().Logs.GetLog(LogType.Browser);
And ideas folks?

Visual Studio 2017 IWizard ProjectFinishedGenerating project is null

I have the following code in my class that extends IWizard:
public void ProjectFinishedGenerating(Project project)
{
MessageBox.Show(project.Name);
}
But it gives me the error:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object.
Saying that project is null. Which is right according to my debugger. However, what on earth causes this? I would've thought the method only gets called with a non-null project. How can I fix this?

How to find out the XAML file that produces a XamlParseException

I get the following error at runtime from a C# WPF application:
A first chance exception of type
'System.Windows.Markup.XamlParseException' occurred in
PresentationFramework.dll
Additional information: 'Set property
'System.Windows.Controls.ContentControl.Content' threw an exception.'
Line number '6' and line position '6'.
How can I find which file this is associated with? The Visual Studio solution contains two XAML files, app.xaml and MainWindow.xaml.
I am using VS 2010 on Windows 7. The application targets .NET 4.0.
UPDATE:
Following up on Kasper's helpful suggestion, I displayed the exception in detail, and this is what it showed:
Based on the information in there, I was able to gather that a certain DLL was missing. Supplying the DLL fixed this problem, but I still have other XAML parse errors coming up.
In the code-behind, the XAML code is parsed in the method InitializeComponent which is automatically generated. This method is called in the Window object's constructor. So to have more details about the exception, put the call to InitializeComponent in a try/catch block. This way, you have access to the useless XamlParseException, but also to its InnerExceptions and to the StackTrace.
UPDATE!
You can call the inner exception using a MessageDialog.
public partial class Window1 : System.Windows.Window
{
public Window1()
{
try
{
InitializeComponent();
}
catch ( Exception ex )
{
// Log error (including InnerExceptions!)
// Handle exception
MessageDialog dialog = new MessageDialog(ex.InnerException);
dialog.ShowAsync();
}
}
}
Hope that helps :)
There is also another trick to this:
Open the "Exceptions" window (Debug/Exceptions) in Visual Studio.
Click "add"
Add "System.Windows.Markup.XamlParseException"
Check the box to break on throw for this exception.
Hit F5!
You'll find that the XamlParseException you catch is much more descriptive, and will give the correct position in the xaml file.
Let me know if this was easier :)

Errorcode CS1955 at every form

If I add a new Form to my C# Project it always throws the error
CS1955 "Non-invocable member 'name' cannot be used like a method.".
Even If i create a new Form and add it like
Application.Run(Form1());
in the Program.cs file in VS15 Enterprise
It still throws this error, and I have no idea why.

commit values on SelectedItems of ComboBoxes in Coded UI Tests

Is there any possibility to commit a value of a variable (declared as string) on a SelectedItem of a ComboBox in a Coded UI Test?
for instance:
private const string SALUTATION = "Mr.";
...
CommonMap.SalutationParams.LstEntriesSelectedItemsAsString = SALUTATION;
CommonMap.Salutation();
...
I am getting an error because of trying this:
Result Message:
Test method CodedUIClassicCommon.Common.CodedUITestsCommon.CodedUIClassicCommonNeuerBenutzerWeiblich threw exception:
Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: Cannot perform 'SetProperty of SelectedItemsAsString with value "A.Frau/SgF"' on the control. Additional Details:
TechnologyName: 'MSAA'
ControlType: 'List'
---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xF004F008
TestCleanup method CodedUIClassicCommon.Common.CodedUITestsCommon.MyTestCleanUp threw exception. Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException: Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException: Cannot perform 'Click' on the hidden control. Additional Details:
TechnologyName: 'MSAA'
Name: 'Neu Ctrl+N'
ControlType: 'MenuItem'
---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xF004F002.
I have searched in google for such a problem but i couldn't resolve it.
thanks for any help.
eric
Should
CommonMap.SalutationParams.LstEntriesSelectedItemsAsString = SALUTATION;
Have a dot between the LstEntries and SelectedItemsAsString?
CommonMap.SalutationParams.LstEntries.SelectedItemsAsString = SALUTATION;
Can you confirm that the object you are trying to click on is in fact visible? If you are clicking on a MenuItem that is hidden because the list needs to be expanded/scrolled/etc it will throw an error. This would be my first thought.
Also, I prefer to use the PerformSelect of the MenuItem rather than reassigning the value.

Categories