Coded UI in VS2013 closes the application automatically once test method is completed running - coded-ui-tests

In visual studio 2013, coded ui closes the application automatically once all test method completed running.
[TestInitialize]
public void TestInitialize()
{
uiCommonEE = UICommonEE.GetCommonEE();
}
[TestCleanup]
public void TestCleanup()
{
}
[TestMethod]
public void OpenWorkspaceTest()
{
uiCommonEE.SetBaseState();
uiCommonEE.OpenWorkspace("C:\Path\EE_Multmodule_AllDataTypes.eew");
}
I'm launching my application from TestInitialize() Method
once the testmethod is completed running, application gets closed automatically.
In testcleanuup() and classcleanup() method I haven't written anything.
I want application to be still running once all the test method of the codedUI are completed running.
Thanks in advance

You can use CloseOnPlayback on the ApplicationUnderTest or BrowserWindow class, but this will only keep the application open during the test run. The moment all test methods in the test class have been executed the playback engine will still cleanup any instance created during the test. So between all test methods in the test class the application will be kept open, when all tests completed everything will be cleaned up.

Run the application from the [ClassInitialize] or the [AssemblyInitialize] methods, but do not use Coded UI's methods to start it. This is because Coded UI keeps track of started applications so it can close them at the end of the test run. Instead use one of the other Windows process start methods, the ProcessStartInfo and Process classes, see here, may be suitable.
The question does not say what should happen if the tests are started when the application is already running. So perhaps the [ClassInitialize] or the [AssemblyInitialize] method should check whether the application is already active before running it, or perhaps the application should ignore or reject attempts to start it when it is already running.

Related

Memory Access Violation disposing libvlcsharp objects from a task

Link to full sample app
C# Winform application built in Visual Studio 2019 libvlcsharp runtime version v4.0.30319 version 3.4.4.0
I built a simpler application that has the same problem as one that is currently deployed.
Here's where the code gets the player started:
videoView1.MediaPlayer.Play(new Media(_libVLC, URI,FromType.FromLocation));
Here's the cleanup code snip:
videoView1.MediaPlayer.Stop();
videoView1.MediaPlayer.Dispose();
videoView1.Dispose();
//dispose glibvlc at higher level
The MediaPlayer dispose works OK no errors. However, videoview dispose causes a Memory Access Violation. I know this isn't normal because I built a simple c# application without using a task to dispose and clean up the objects and that worked just fine.
However the application I'm trying to debug has one thread per stream that is being displayed to manage setting up and shutting down each connection.
If the code just calls dispose on the mediaplayer and does not dispose the videoview object then the object that contains the libvlcsharp objects causes a Memory Access Violation when it gets disposed.
If I don't dispose of the MediaPlayer object any subsequent object dispose calls work OK.
I have verified that this leaks memory.
In UI class
Setup all the form variables.
instantiate LibVLC
StartVideo(); This ends with the Play method
Task.Run(() => Ask()); This emulates what may be happening in the
real app
The Ask function asks if the user wants to exit the program or kill the current player and build and start it again.
if user cancels it exits through the On Application Exit handler which
does executes the Dispose sequence shown above. This works as designed.
If user kills and restarts then it fails on the videoView1 dispose as
described above.
Here's the c# sample ask function.
public void Ask()
{
while (true)
{
DialogResult r = MessageBox.Show("Dispose and Start Again?", "Memory Access Violation Test", MessageBoxButtons.OKCancel);
if (r == DialogResult.OK)
{
videoView1.MediaPlayer.Stop();
videoView1.MediaPlayer.Dispose();
videoView1.Dispose();
StartVideo();
}
else
{
Invoke(new Action(() => this.Close()));
}
}
}
To fix problem upgrade to version 3.6.1.0 for both libvlcsharp and libvlcwinforms.winforms

Is there a way to know that IIS wants to shut down my web app?

I am looking at using QueueBackgroundWorkItem for background work items in my ASP.NET Web-API2 REST server. This works perfectly for my use case in that all jobs being run get completed and written to a DB before the web app is shut down. And the replacement web app takes over and can return the completed jobs.
However, when I complete a job in the background thread, I don't want to start another if IIS wants to shut the app down. Is there a way to find out if IIS is waiting on tasks to complete and will then be shutting down?
You could try to use configure in startup class. below is configure parameters:
IApplicationBuilder
IHostingEnvironment
ILoggerFactory
IApplicationLifetime
In the IApplicationLifetime interface you can register an event that is triggered when the application stops:
public class Startup
{
public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime)
{
applicationLifetime.ApplicationStopping.Register(OnShutdown);
}
private void OnShutdown()
{
//this code is called when the application stops
}
}
you could refer this below links or more detail:
How to listen to IIS shutdown event in ASP.NET

Leap Listener controller stops working after some time in VS2012

We have integrated flash game (crazytaxi.swf) inside Windows form application in VS Express 2012 for Windows Desktop.We are controlling game with the help of gestures using leapmotion controller.
What happens is when we run project in VS2012,game starts normally.We play game using gesture (left,right etc.).But after some time controller stops listening by exiting its thread.We can see that in output window.
"The thread '' (0x1b50) has exited with code 0 (0x0)." this we get in output window.
We are not getting how to overcome this challenge.
You didn't provide enough information but from what I gather, your LEAP thread ran to completion and closed. This can occur if you declare and initialize your listener and controller variables in a function and the variables go out of scope when the function is executed. This causes Garbage Collector to dispose both controller and listener at what might seemingly appear as random (non reproductable) moments. To fix this issue, create a singleton for the controller and listener - this can boil down to simply defining a static controller and listener variables in some class. This way the listener and controller objects will never go out of scope and get disposed by the GC.
"The thread '' (0x1b50) has exited with code 0 (0x0) basically says that:
The thread with the ID 6992 ran and completed the operation successfully.
System Error Codes (0-499)
The question is, does the device stop tracking?
Here are my 0x0's from my Leap Motion app (its working fine):
The thread 'vshost.NotifyLoad' (0x364) has exited with code 0 (0x0).
The thread '' (0x3348) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x37c8) has exited with code 0 (0x0).
Also, on a side note, because it has nothing to do with the error code - are you removing the listener from the controller, and then disposing of them both when the application is being closed? Not properly disposing of objects will cause problems.
A second note - onExit and onDisconnet are two different things.
onDisconnect(controller:Controller):void
Called when the Controller object disconnects from the Leap Motion software.
Listener
onExit(controller:Controller):void
Called when this Listener object is removed from the Controller or the Controller instance is destroyed.
In case somebody is having similar problems here is the reply I sent over email after having a look at the code:
I've looked at the code, since you only sent me a few files I had to comment out the the references to classes that was not included in the zip.
The code runs fine with 3 different Leap Motion devices - when I comment out from the method, what I suggest is:
Update the SDK. I used .Net 4 dll and the latest version of the SDK which today is: v.1.0.8.7665
Dispose the objects once you are done using them. Dispose Frames after using them, Remove listener from the Controller, and dispose Controller when the device isn't used anymore or the application is being closed.
I noticed some Timers and DispatcherTimers they were being created, but I couldn't find any references to where they were being used. What are these being used for? DispatcherTimer doesn't belong in a windows forms application.
My best guess - and I hate to guess - is that there is a threading problem OR that the objects aren't being disposed correctly - OR you are using an SDK version that had bugs.
I have two applications on GitHub - feel free to use the code as you want. There is one for WPF and one for Windows Forms - both need to be updated for latest SDK as some things have been deprecated (such as the Screen class) in later versions of the SDK.
WPF:
https://github.com/IrisClasson/Leap-Motion
Windows Forms:
https://github.com/IrisClasson/LeapMotion_WinForms_Demo_OLD_SDK
Disclaimer: I don't do much, if any WinForms development
I had a same issue with my WPF application and Leap Motion code but the code works fine with a console application.
In WPF when I globally declared the Leap-Listener and the controller Object, I did not face the error any more and the Listener is active all time.
Just declare the listener and controller in the class (globally) from which you call the listener
public static LeapListener listener;
public static Controller controller;
Now use this listener object, and add it to the controller and enable gesture property of the controller in a function or a constructor.
listener = new LeapListener();
controller.AddListener(listener);
controller = new Controller();
This should solve the issue. If the problem still persists (detection problem), simply initialize and add the same listener object to the controller object onExit event. Now the gesture and other properties exist as you are not creating a new instance of the controller again.

Why Unit test of WebServer project shows strange behaviour?

I am writing Unit test of my project HTTP THREADPOOLED WEB SERVER. For that I am using Junit in Maven.
In the mean while I stuck in one place, and the doubt is as follows,
There is one class named WebServer, whose task is to start the server, makes threadpool, and starts listening on the port for client request. When I make a thread for the same, in the Test class under annotation #BeforeClass, it is expected to wait for the client request , but it comes out shows Test completes.
public class WebServerTest {
#BeforeClass
public static void webserverStarter() {
System.out.println("Before Class : webserverStarter");
new Thread(new WebServer()).start();
}
#AfterClass
public static void webserverCleanup() {
System.out.println("After Class : webserverStarter");
}
}
I don't understand why this not waits for client request. Please help me in writing the unit test for testing HTTP Threadpooled WebServer.
The #Before are executed before every single Test. If you want to use one single Webserver, just make an object!
If you are sure that webserverStarter() is actually starting the server, there is no doubt that the server will work. Don't worry about the annotation #BeforeClass. It only mean that it will be called only once and the same thing apply to #AfterClass.
What I suspect is that, if your server is actually started, and you are sure about it, may be the server got shut down immediately after it starts successfully or after the test case ends successfully. In am using Embedded Tomcat server in which I have to tell my server to run continuously like this.
tomcat.start();
tomcat.getServer().await();

Intermittent IE timeouts and COMExceptions when running Watin tests with Nant and CruiseControl

We’ve been using Watin and CruiseControl.net for a few weeks now and most of the time they work together well. We have not had any problems running the tests on our developer machines. We are also able to run the tests interactively without problems when logged into the CI server.
Most of the time there are also no problems when the tests are executed under CruiseControl but this is not always the case as we’ve recently been seeing intermittent errors. The errors seem to come and go somewhat randomly but when an error does occur, it’s always one of the following:
WatiN.Core.Exceptions.TimeoutException: Timeout while Internet Explorer busy
System.Runtime.InteropServices.COMException: Creating an instance of the COM component with CLSID {0002DF01-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 800704a6
Our CI server environment is:
Windows Server 2008 R2
IIS 7.5
IE 8
Watin 2.0
CruiseControl 1.6.7981.1. This is running as a service which logs in as a user on our domain because the tests need to access resources on the domain.
The 'randomly' failing tests create their IE instances as follows:
[TestMethod]
public void SomeTest()
{
using (var browser = new IE())
{
// run tests here
}
}
I also tried creating the IE in a new process as follows:
[TestMethod]
public void SomeTest()
{
using (var browser = new IE( true))
{
// run tests here
}
}
But when I did that, all of our tests failed with a “WatiN.Core.Exceptions.BrowserNotFoundException: Could not find an IE window matching constraint: Timeout while waiting to attach to newly created instance of IE.. Search expired after '30' seconds”
So, I have two questions:
Can anyone tell me how I can stop the timeouts and com exceptions?
Can anyone explain why IE(true) didn’t work at all?
TIA,
Mike
See this answer by Carl Hörberg:
Running Watin on TeamCity
CruiseControl.Net and TeamCity have the same problem when running as a service and the work-around should work for both environments.
By default, the ccservice runs as Local System, does not have access to interact with the desktop UI, and the Local System account privileges are limited and that's most probably what is causing the TimeoutException, COMException, and BrowserNotFoundException from being thrown.

Resources