This is a migrated thread and some comments may be shown as answers.

SyncWaitResult exception: MainWindow return null

24 Answers 245 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
p-h
Top achievements
Rank 1
p-h asked on 21 Nov 2018, 12:52 PM

Hello,

I am using testing framework. in my computer its work fine. but in another computer the test fail.

the code:

            Settings settings = new Settings();
            settings.ClientReadyTimeout = 100;
            settings.Wpf.DefaultApplicationPath = applicationPath;
            Manager manager = new Manager(settings);
            var process = Process.GetProcesses().FirstOrDefault(t => t.ProcessName.StartsWith("AAA"));
            if (process != null)
            {
                manager.Start();
                manager.ConnectToApplication(process);
            }

when I run the test with debugging:

            var window = Manager.Current.Applications[0].MainWindow;

window is null.

when I run the test without debugging the exception is:

            Exception thrown: 'System.ApplicationException' in ArtOfTest.WebAii.dll
            Additional information: Unexpected error. SyncWaitResult was null for this wait

           at ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target)
           at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType)
           at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout)
           at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Int32 timeout)
           at ArtOfTest.WebAii.Wpf.WpfApplication.get_MainWindow()

24 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 22 Nov 2018, 09:57 AM

I have another account with lisence

I logged in  with that account

Please send me an answer as quick as you can

 

Thanks

0
Elena
Telerik team
answered on 23 Nov 2018, 03:20 PM
Hello David,

Thank you for the shared details. I tried to test the provided code snippet and reproduce the reported misbehavior. Though, I am not sure if the setup I prepare is the one you use. Can you please prepare a sample project which demonstrates the issue and send it via this thread?

That way I will be able to understand how you are implementing the Testing Framework in your project along with any other details what might have gone wrong. 

If you do not have the time for a sample project, I would like to know your input on the following topics:
- is this a Test Studio project and test, or you are using a unit test
- is the sample code snippet included in a class file or it is part of a test 
- does the application under test starts at all, or the crash appear before its process is launched. 

Basically any information related to the project and how that failing code is used in it, will be of great help for the investigation. 

Thank you in advance. I am looking forward to hearing back from you. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 25 Nov 2018, 08:42 AM

- is this a Test Studio project and test, or you are using a unit test

I don't use test studio, only testing framework.
- is the sample code snippet included in a class file or it is part of a test 

The code is in the class file. The calling to the MainWindow is from any step

- does the application under test starts at all, or the crash appear before its process is launched. 

    The application started, and then failed on the MainWindow.

0
Elena
Telerik team
answered on 26 Nov 2018, 03:04 PM
Hello David,

Thank you for getting back to me with additional details. 

I wanted to share with you we managed to reproduce the same misbehavior on our end and although this is not consistently observed, we can continue the investigation. I completely understand this is not a solution yet, but wanted to let you know we are a step further in the exploration of the case. Once there is any valuable information to provide or we need any additional input on your end, I will get back to you. 

In the meantime, please, do not hesitate to contact me again in case you have any questions on the topic. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Elena
Telerik team
answered on 27 Nov 2018, 12:28 PM
Hello David,

Based on the repro of the misbehavior we had on our end, we came to the conclusion this is sort of a sync issue between the time the Manager class is initialized until the WPF application under test is being recognized to get its main window. 

Having that in mind, we included a delay in the code to handle that lack of synchronization - to avoid using a hard-coded delay this is inserted in an for cycle. That way you could change the maximum length of the delay if this depends on the application or the currently used environment. Please find below the code you shared previously updated with the for cycle I mentioned. 

            Settings settings = new Settings();
            settings.ClientReadyTimeout = 100;
            settings.Wpf.DefaultApplicationPath = applicationPath;
            Manager manager = new Manager(settings);
            var process = Process.GetProcesses().FirstOrDefault(t => t.ProcessName.StartsWith("AAA"));
            if (process != null)
            {
                manager.Start();
                manager.ConnectToApplication(process);
            }
 
                  // This is the execution delay inserted to handle the lack of syncronization
 
            for (var i = 0; Manager.Current.Applications[0].Windows.Count == 0; i++)
             {
                 Thread.Sleep(100);
 
                 if (i >= 200)
                 {
                     break;
                 }
             }
 
            var window = Manager.Current.Applications[0].MainWindow;

If you continue facing troubles you could increase the amount of iterations for the for cycle as the current 200 might not be sufficient - depending on the environment and how long it take for the WPF to be started and initialized by the Testing Framework. 

Please let me know if that works for you as well. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 19 Dec 2018, 02:43 PM
Hi,

We tried your solution but it did not help in our case.

(Code always entered break line)

The code works well only in one station. In all other stations, we were unable to run the test due to this problem.

Until now we have tried everything we can (add installations, work with the same operating system, etc.)

You have an idea?
0
Daniel Djambov
Telerik team
answered on 24 Dec 2018, 06:32 AM
Hello,

From what I understand, the code we offered you works fine on one machine and does not on others.

So my next question is what is the difference between those machines? Like if it works on your local machine, but not on a remotely connected machines?
Are those machines Virtual Machines hosted somewhere? Do you use some remote desktop connection for them?

If you have remote machines that does not have an active user session (like machine is locked or remote connection is closed), OS API can return null for any windows present there and this can cause the behavior.

Please provide some additional information about the setup and how you use the machines you observe the behavior.

We will work with you to overcome the issue,

Thank you for your cooperation,

Best Regards,
Daniel Djambov
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 24 Dec 2018, 08:36 AM

I'm sorry if I didnt explain myself well.

The code works well only in one station - I meant the code I sent you, that the main window returned null.

We have one machine that all code works fine. In all other machines, the tests don't run also with the code you suggested.

We checked the references, the installations, the machines, and there was no difference.

The machines we are working with are phisical (no vm or remote):

* OS win10, i7

* VS2017 + TestingFramework offline

Thank you

0
Daniel Djambov
Telerik team
answered on 27 Dec 2018, 07:15 AM
Hello,

Thank you for the additional details.

From the information we have so far, to me it seems the problem might be related to some timing issue. The window to be shown takes different time on different machines and when the code is called, window is still not loaded, or Windows reports it as not available.

In order to verify this assumption, can I please ask you to try increasing timeouts in your code, before trying to get the window. The code we provided you has only 2000 msec (2 seconds) waiting for the window to appear after the process is started.

Can you add a Thread.Sleep(5000) before the cycle that waits for the window (after process is found). Also inside the cycle that waits for the window, instead of Thread.Sleep(200), replace it with Thread.Sleep(500). And observe while running the test if the window is actually shown on screen.

This way we can verify if it is not a time synchronization problem and will look for another cause if it doesn't work.

Please try this out and let me know what the result is on all your test machines.

In case it doesn't work, please send us the code you have implemented, to check if there is something different or see any additional clue to investigate.

Thank you for your cooperation,

Best Regards,
Daniel Djambov
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 27 Dec 2018, 11:20 AM

I try this code but it didnt work:

Settings settings = new Settings();
settings.ClientReadyTimeout = 500;
settings.Wpf.DefaultApplicationPath = applicationPath;
Manager manager = new Manager(settings);
var process = Process.GetProcesses().FirstOrDefault(t => t.ProcessName.StartsWith("AAA"));
if (process != null)
{
    manager.Start();
    manager.ConnectToApplication(process);
}
 
      Thread.Sleep(5000);
 
for (var i = 0; Manager.Current.Applications[0].Windows.Count == 0; i++)
    {
        Thread.Sleep(500);
 
        if (i >= 200)
        {
                break;
        }
    }
 
var window = Manager.Current.Applications[0].MainWindow;
0
Daniel Djambov
Telerik team
answered on 27 Dec 2018, 11:37 AM
Hi again,

Thank you for providing the code - I just noticed that you have defined this:
settings.ClientReadyTimeout = 500;

I think this could be causing all the trouble, because this setting is by default 60000 (1 min) waiting to connect to application and 0.5 seconds is way too less.

Can you please increase this value to 30000 or 60000 and give it another try?

Waiting to hear back from you about the outcome.

Best Regards,
Daniel Djambov
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 27 Dec 2018, 12:17 PM

Thank you for your quick reply!

I tried all cases but it didnt work.

do you have another solution?

0
Daniel Djambov
Telerik team
answered on 27 Dec 2018, 01:53 PM
Hi David,

Let's summarize and start over.

From what I understand so far you have written a code that connects to already running WPF application and want to get its main window. This code works on one of your machines and does not work on other machines, all machines are similar physical machines. Is that correct?

What we have offered so far is to make time synchronization and wait for the WPF application to be running before we try to get its window.

What is unclear to me at this point is how exactly you start your WPF application prior to running the unit test? Do you start it manually or have some code to do it?

Another thing that I don't know is if your WPF application can have multiple running instances? Or multiple processes exists with same name of the application? I'm asking because your code connects to first found process and first application window, which might not always work if there is some old stuck application process that has no window in it.

Can you please send me a whole working code example/solution, could be just a sample test in it (not your whole solution) to see what exactly you do to initialize the manager, settings objects and any other additional things your solution does before it runs the test?

As you are using Telerik Testing Framework, you have to write all the code to properly initialize all settings for the test.

Please provide more details on how you start your application and the use case you have for the tests you wish to create.

More information will be needed from your side to further investigate why your code does not always work.

Thank you for your cooperation,

Best Regards,
Daniel Djambov
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 06 Jan 2019, 11:02 AM

Hello,

Sorry for the delay.

"From what I understand ... all machines are similar physical machines. Is that correct?" Yes.

I start the app with TestStack.White framework. then I connect with Telerik Testing framework, I have only one process.

The code I initialize the manager is what I sent you before. I don't have another code.

Thanks in advance

0
Elena
Telerik team
answered on 09 Jan 2019, 03:51 PM
Hi David,

Let me please step back in this discussion. Based on the investigation so far and the outcome of the proposed solutions, it seems the issue is a synchronization one. As it is quite difficult to continue troubleshooting without having an overview of the whole setup, I believe our last option is an online meeting. Would you mind joining us for a remote session in order to demonstrate the environment in use and the encountered misbehavior? 

I verified your account and it seems we are in the same time zone - GMT (+2:00) - please let me know if this information is incorrect. Otherwise, I would like to know if tomorrow, Thursday 1/10/2019, in 14:00-15:00 suits your other daily tasks? Please feel free to propose any other time between 14:00-17:00 for this Thursday. 

Once we agree for a suitable time frame, I will provide you meeting details.

I am looking forward to hearing back from you. Thanks. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 10 Jan 2019, 12:23 PM

I will call you at 15:00

Thank you!

0
David
Top achievements
Rank 1
answered on 10 Jan 2019, 01:42 PM

Hello,

Today we can't call you anymore.

We will call you on Sunday or Monday between 10:00 - 15:00.

Please send us the meeting details.

0
Elena
Telerik team
answered on 11 Jan 2019, 04:59 PM
Hello David,

Please have in mind that our official channel for online meetings is GoToMeeting. So, once we arrange a suitable time frame for both sides, I will send you the meeting details to be able to join the call. 

In addition and since this is a public forum thread, we can switch to a visible only for you support ticket communication for your further convenience. 

As of the time frames you have listed, Monday 1/14/2019 in 14:00 is the first possible option on our end to attend a meeting. Please let me know if this suits you as well, and I will send you the required meeting details. 

Thank you for your understanding. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 13 Jan 2019, 12:26 PM
Hi,

the date you suggest is ok,

we waiting for meeting details.

we try to attache video that described the problem but we can't add it (even if we compressed it).
Is there any way to send this video to you before the conversation?

Thanks
0
Elena
Telerik team
answered on 14 Jan 2019, 09:02 AM
Hello David,

Thank you for confirming the date and time for a meeting. Below are listed the meeting details.

And in addition to that, here is a shared folder you can use to upload the video you have prepared - I hope we will have the time to see it before the online session.

Looking forward to meeting you later today. 

1362261 - SyncWaitResult exception: MainWindow return null
Mon, Jan 14, 2019 2:00 PM - 3:00 PM EET

Please join my meeting from your computer, tablet or smartphone.
https://global.gotomeeting.com/join/719125421

You can also dial in using your phone.
(For supported devices, tap a one-touch number below to join instantly.)
Israel (Toll Free): 1 809 454 830
- One-touch: tel:+9721809454830,,719125421

Access Code: 719-125-421

Joining from a video-conferencing room or system?
Dial: 67.217.95.2##719125421
Cisco devices: 719125421@67.217.95.2

First GoToMeeting? Let's do a quick system check: https://link.gotomeeting.com/system-check

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Elena
Telerik team
answered on 14 Jan 2019, 12:07 PM
Hi David,

I see two persons waiting to join the meeting. Do you see any troubles in logging in the meeting? 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Elena
Telerik team
answered on 14 Jan 2019, 03:35 PM
Hello David,

Thank you for your time and cooperation during our meeting today. 

What we found out about the project and environment is that the version of the currently installed Testing framework is different than the one used to develop the tests. Thus there are references to dlls with different version than the installed one. This is probably causing some troubles and this is the first thing to sort out and fix. So we agreed to the following steps to perform on your end: 

1. Fix the references in the current solution to point to the correct and currently installed version of the Testing Framework. Then try to run the test again - you can use any of the tests which we hadn't modified and the one that we did modify during the meeting. Then please share the outcome of both tests' execution. 

2. If still the tests are failing, please install Test Studio on this machine - it is not necessary to activate it, but the installation will add the full set of components on that machine. Then using the same project with fixed references, please run the tests again and let us know if there are any errors. 

If the above two approaches do not change the behavior on that particular machine, we can explore it on our end through TeamViewer for example. For that purposes, I would like to know if it will be possible to share that machine with us for a time frame at the afternoon for example when you are not going to use it. Then prepare an account and password for TeamViewer connection. Please let us know about the options we have to cover this, if necessary. 

Since the information about connecting to a computer in your network is quite confident, I would like to remind you this is a public thread opened under the pninah@i-rox.net account. I can convert this to be a private one, but will be only visible for this account. Alternatively, I can submit a new private support ticket on your behalf, where we can continue the communication on this case. 

Thank you once again and I am looking forward to hearing back from you. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
David
Top achievements
Rank 1
answered on 15 Jan 2019, 11:02 AM

Hi,

We fixed the reference as you said - it really works !!!

Thank you very much for your support and help all along

0
Elena
Telerik team
answered on 17 Jan 2019, 03:58 PM
Hello David,

Thanks for letting me know. I am pleased to know our advice was helpful to fix the issue. 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
p-h
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Elena
Telerik team
Daniel Djambov
Telerik team
Share this question
or