Close webdriver when stop test execution from visual studio in specflow - visual-studio

I would like to close webdriver from task manager, when I stop test execution in visual studio. Normally I could use AfterTestRun to close the driver, but, when I click over stop button in visual studio meanwhile test execution is running AfterTestRun isn't execute, so web driver is still open.

You can't do this, as Visual Studio/Test Explorer is killing the test execution process when you stop the execution. No code is executed then and there is also no place where you could put some code that gets executed.
I have a command line script that kills all the processes when I press a shortcut.
You can kill a process via command line on Windows this way:
taskkill /f /im chromedriver.exe
This kills all processes with the name chromedriver.exe.

Related

Closing a new console window started from a batch script prompts to terminate the script

I'm trying to make a batch script for running multiple command line antivirus scans in a specific order.
I use it this way:
echo Running Sophos virus scan...
start "Sophos Scan" /wait /d "%~dp0sophos" SVRTcli.exe -yes >>%~dp0logs\sophoslog.txt
This will popup a new console window running sophos and wait till it's done.
If I close the new console window, the main window of my batch file will prompt for terminating the batch script. I want to avoid it and just automatically continue with my next command which is similar to the previous (different anti virus engine).
Is it possible? I tried with various solutions on the net. Every time it's the same result. You close the new console and it comes up on your batch cmd.

Launch long running cmd as pre-build event in Visual Studio

I'm trying to launch a grunt process that will watch for .js file changes and transpile them into one file using grunt tasks. I can run it manually all day long, but I want to make it a pre-build so when a new dev gets the solution, building will launch the watcher. The problem (as you may have guessed) is that the grunt process stays running, so as a pre-build event, it never continues the build. I thought that using start would be asynchronous and would launch it without VS waiting on it to complete to continue the build, but I was mistaken. So, currently, my pre-build event is
cmd /c start $(SolutionDir)ProjectName.Web\run-grunt.cmd $(SolutionDir)
and run-grunt.cmd looks like
cd %1ProjectName.Web
grunt
This works but hangs until I close the cmd window which defeats the whole purpose. So, two questions:
Is this the wrong way to get this watcher kicked off?
Is there a way to structure these such that VS will launch the cmd and then resume the build without waiting for a return?
Have you tried setting your pre-build event to simply run a batch file that executes your current pre-build event? It seems like it will work because the batch file that Visual Studio executes will actually complete, leaving another command window in its wake.
I tested my theory with two batch files:
test1.bat
call "cmd /C start test2.bat"
echo test1
test2.bat
echo test2
pause
If you're still needing some parts of the grunt task to execute pre-build, you can break them out into separate tasks, so your pre-build event may end up looking like this:
cd $(SolutionDir)ProjectName.Web\
grunt build
grunt-watch.bat

powershell command - wait until visual studio solution loading

I'm trying to write a powershell script that launches Visual Studio with a solution and run a macro.
devenv.exe "$PATH\TestSolution.sln" /Command Macros.MyMacros.TestMacro
However, it takes time to load the solution so that the macro doesn't run.
Is there a way to wait(sleep) for 15 second and run the macro?
Suspends the activity in a script or session for the specified period of time. use Start-sleep http://technet.microsoft.com/en-us/library/hh849939.aspx

Use Console2 for Visual Studio debugging?

Is there a way to use the popular Console2 cmd.exe replacement for Visual Studio debugging? In other words, when I debug a console app under VS, I want it to use Console2 instead of cmd.exe.
Interesting question. I looked into it, there are some options but none are pretty.
Console.exe takes arguments, so it's possible to start it with a specific tab and execute an arbitrary process. However, this process will always be run within it's own cmd.exe; for example if your program is c:\my.exe and you launch Console as console.exe -t tabname -r c:\myexe Console2 internally calls CreateProcess( ... cmd.exe c:\my.exe ... ), as a result you can't even see the output of my.exe. This is easily solved though: launch it as console.exe -t tabname -r "/k c:\myexe": the /k switch makes the cmd.exe stay active and you can see your program's standard output. (I looked through the source but couldn't find a way to 'attach' a tab to a currently running Console instance, so launching with arguments will always create a new instance, not sure this is what you are looking for?
You can easily modify the project's debugging properties to reflect the above:
Command: /path/to/console.exe
Command Arguments: -t tabname -r "/k $(TargetPath)"
When starting your exe from within VS, it will launch your exe witin a Console session. However the debugging won't work as VS will try to debug console.exe, not my.exe since that is now a different process. Putting a DebugBreak(); as first line in your exe's main() will sort of solve this, as it will present you the option to debug your exe. All in all, this may a bit too much of a hassle to achieve what you want, but i don't think there's another way: Console always spawns a new process, so the only way to get it debugged is to attach the debugger to it after that process started.
Scott Hanselman blogged about this.
He suggests using this value for Console Settings > tabs > Main > Shell :
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
Sadly for me, This does not appear to work for Visual Studio Express 2010, which lacks a vcvarsall.bat file.

Any way to run a macro (in an open VS instance) from the command line?

I typically run a script each night that updates my code from SVN, then builds it. The last few days I have a long debug run I'd like to start at night so it can go through the hour or two it takes to hit the error before I come in the next morning. The way I've done this so far is to VPN in later in the evening to start the run.
Is there any way I can have a script tell an active Visual Studio instance to execute a macro? Either that or launch a new instance that would run a macro once it's open. This way I could automate the whole thing.
To execute a macro or a command in a new session, do:
devenv /Command CommandName
To debug an executable, do:
devenv /DebugExe ExecutableFile
To run a solution using default settings:
devenv /r Solution
More info: http://msdn.microsoft.com/en-us/library/a329t4ed(VS.80).aspx

Resources