Unable to get Window (and Controls) from Application

Mar 4, 2009 at 4:41 PM
hi,

I'll start off by sketching the situation I'm in.
I'm running a series of tests using nunit.
Each test tests an action on a form I specify using the title of this form. I separated the reading portion from the action portion of the tests.
The first part, called UIPlayer performs actions on forms. This is a console app that take parameters and executes the wanted actions accordingly.
What I do here is attach the Application to "nunit" and get the window I want from that app: Window w = Application.Attach("nunit").GetWindow("some title");
For reading purposes I wanted to create a second console app to take the same parameters but this time to read from controls and compare to a preset value.
This console app then returns 1 or 0 based on the success or failure of the comparison within the application.

Now this is the weird part.
For the UIPlayer, attaching the White core to nunit poses no problem. it executes the actions I want without any hesitation.
When I try the exact same code in the UIReader application it is unable to attach to nunit for some reason and just exits without any hassle except for a log4net error in the console window:

Log4Net not configured. Looked in file <Path>\log4net.config
Section: Bricks in SectionGroup: Bricks is not configure in Configuration file. Using RecheckDurationInMilliSeconds=100 for Bricks/Bricks


does anyone have any idea why this does not work? (especially because I'm trying the exact same thing, but only one works)

kind regards,

Jan Wilms


Coordinator
Mar 4, 2009 at 6:01 PM
This is similar to something quite few people have reported recently. In your console app have you tried using STAThread attribute on the main function.
If it still doesn't work can you provide me some sample code using which I can look at the failure.
Mar 4, 2009 at 9:12 PM
Platform: VB.NET 2005
Framework : 2.0
Console application:

I have a similiar issue which result in the following error:

System.TypeInitializationException was unhandled
  Message="The type initializer for 'Core.Configuration.CoreAppXmlConfiguration' threw an exception."
  Source="Core"
  TypeName="Core.Configuration.CoreAppXmlConfiguration"
  StackTrace:
       at Core.Configuration.CoreAppXmlConfiguration.get_Instance()
       at Core.Constants.get_BusyMessage()
       at Core.Factory.WindowFactory.FindWindowElement(Process process, String title)
       at Core.Factory.WindowFactory.CreateWindow(String title, Process process, InitializeOption option, WindowSession windowSession)
       at Core.Application.GetWindow(String title)

<STAThread()> _
   Public Sub Main(ByVal args As String())
       Dim Proc As Process = Process.GetProcessesByName("MyApp")(0)
       Dim application As Core.Application = Core.Application.Attach(Proc)
       Dim window As Core.UIItems.WindowItems.Window = application.GetWindow("MyApp")
            Assert.IsNotNull(window)
Mar 5, 2009 at 9:15 AM
Edited Mar 5, 2009 at 12:42 PM
using C#

I've tried several options now, also by adding the STAThread attribute.
I've also tried extracting the console project from the larger project I'm working in.

I'll show some code to allow you to see what I'm dealing with

I want to use a small app UIReader.exe (built from a console app and thus using parameters for execution)
This small app will give me back an exitcode depending on the success of a read on the form using the following code:

[STAThread()]
        static void Main(string[] args)
        {
                Window _window = Application.Attach("nunit").GetWindow("WindowTitle");
                TextBox tb = _window.Get<TextBox>(SearchCriteria.ByAutomationId("txtActivity"));
                string s = tb.Text;
                string expected = "test";
                if (expected == s)
                {
                    Environment.Exit(1);
                }
}

This is already slimmed down to the essential code without parameters to mimimize the area of errors, normally the main would call upon a class and method which it gets from the arguments with the executable.

the following code would be what I invoke to test.

bool result = UIReader.run("ActivityTextReader.readAndClose");
which in this case doesn't make any difference because my actions are hardcoded .

UIReader is a static class in the main project which launches the exe file with the proper parameterstring.

Whatever I do I keep having errors and exceptions on the GetWindow method.

What I tried up till now:

  • I made a seperate console app with the same code. Still resulting in the error with log4net. but it DOES produce a result in the console window when I print out the textbox' content. According to me this is a vertyawkward situation as it still fails in window retrieval.
  • When I remove all White code from the console app and just return an ExitCode the code gets passed properly when I manually close the window (which would trigger the Exit on the application)
  • When I remove all exception handling and run the program it requests a debug in a seperate Visual Studio which results in the debugger asking for the WindowFactory.cs file and an exception which tells me it could not find the wanted window.
What I also noticed is, when I run the test with the above code, the window I want to test does not load completely, it just shows me the window titlebar and the contour of the window. not the form itself.
any help would greatly be appreciated.






Coordinator
Mar 11, 2009 at 5:12 AM
would it be possible for you to attach the source code for this.
a failing test would be ideal.
Mar 11, 2009 at 9:17 AM
I'm sorry to say I can't post any source code.

Is there anything you might think could be an issue?