How to prevent Gradle job running in background on TFS agent - selenium

I have configured a Windows 7 VM as an agent to my TFS2015 setup.
I have created a Gradle (invoking the gradlew.bat) job to run my selenium scripts from the TFS build definition as
gradlew.bat clean test aggregate
This works fine (I can see IE being invoked) when I run it MANUALLY from the VM directly, BUT when the same is triggered as a job, it runs only in the background. Here are my observations:
The processes - Java, iexplorer, IEDriver.exe are all getting invoked in the Process manager.
When I kill iexplorer process, I can see the UnreachableBrowserException on the TFS console and the next test case runs.
The job with 2 test cases (approx 3-4 mins) fail after running for 10 mins and I see the error logs in TFS console
The scripts ran on UI the very first time I set this up but has never run after that.
I am using Gradle 3.0 and have disabled the Gradle Daemon by adding org.gradle.daemon=false in gradle.properties. This has been bugging me for a couple of days so badly.
Any help would be great.

For your tests to interact with the desktop they will need to be running interactively on a machine that is logged on and not locked (no screensaver active).
See: https://www.visualstudio.com/en-us/docs/build/admin/agents/v2-windows#interactive
You can configure the machine to start-up automatically and authenticate on start-up, disable the scren locking policy and screensavers and add the run.cmd to the windows start-up section in the star-menu.
See: http://donovanbrown.com/post/2015/08/28/auto-start-build-agent-in-interactive-mode
Press Windows Key + R to open the Run dialog
Type in the following and press enter:
control userpasswords2
Uncheck the box for User must enter a user name and password to use this computer.
Click the Apply button
You will be prompted by an Automatically sign in dialog
Enter the password for the user
Click OK
Click OK on the Users Accounts dialog
And
Right-click the desktop
Select New / Shortcut
Enter cmd
Click Next
Change the name to Start Agent
Click Finish
Right-click on the new shortcut
Select Properties
Append /c {pathTo\run.cmd} to the target
If you installed your agent to C:\Agent, your target should look like this: C:\Windows\System32\cmd.exe /c c:\agent\agent\run.cmd
Click OK
Note: updated for the 2.0 build agent, which is started using run.cmd instead of vsoagent.exe
Press Windows Key + R to open the Run dialog
Type in the following
shell:startup
Click OK
This will open the Startup folder in Windows Explorer.
Drag and drop the shortcut to this folder

Related

'npm' is not recognized as internal or external command, in windows 11

when I'm typing commands which starts with npm, it shows the massage of ,
"'npm' is not recognized as internal or external command"
Download node.js
First of all Download and install node.js from here Nodejs.org
In windows 11
There are two ways to do this
the short way is,
1. Go to settings
2. Now you are on System window, click About
3. Next, Click on Advanced system settings button
4. Then, Click Environment Variable on the dialogue box
5. From Environment Variable, Select Path6. And then click Edit
7. click New
8. At the text box, add ; C:\Program Files\node.js\
9. Click Ok all the open dialogue box
Reference: Fix ~ npm not recognized as internal or external command (Note: this is my own blog[include images also)

Unable to add External Tool to run Before Configuration Launch IntelliJ

Introduction
I've looked around and haven't seen anyone else having my issue.
Basically, I am wanting to run a start.bat file to start up my server before I start up my debugging session. I currently have my debugging inside of an IntelliJ Configuration and it works well. The problem is that in the options for my configuration I can't seem to add an "External Tools" task to the Before Launch section. I was able to add a maven task here previously. However, when I follow the following steps, the "start.bat" is not added.
First I go into Settings->Tools->External Tools to add my Spigot-Server tool which basically calls the start.bat file inside of a test-server directory.
Snippet of External Tools
Second, I go into my "Debug Spigot" configuration and at the bottom, I see a "Before Launch" Section.
Snippet of Spigot Debug options
I click on the + inside of that section to add a new task, and I click on "External Tools"
Snippet of adding External Tools Task
And then I make sure my Spigot-Server task is selected.
Snippet of select external tool
And then once I hit okay, the window closes but I don't see a new task added to the before launch section. It looks the same it did before I clicked on anything. I also don't see any status message at the bottom of IntelliJ
I basically expect the task "Spigot-Server" to show under the Before Launch section. This would basically start up the server and once the server was completely started, it would then launch the debugging configuration.
I think it may be an issue with IntelliJ's UI. I searched IntelliJ's issue tracker But couldn't find any that matched.
I'm wanting to know if there are any work arounds to get this setup in IntelliJ>
I was able to achieve my goal by doing some workarounds that I discovered with the help of CrazyCoder. I found this stackoverflow question that told me about the batch plugin.
I was able to create a Batch run configuration for a wrapper batch file that gets around the limitation CrazyCoder mentioned. He said that even if I did get my setup where my server runs before my debugging is launched, my debugging would never launch. This is because the terminal process needs to exit before the next task starts.
To get around this this is the wrapper batch file I created.
#echo OFF
START "Spigot-Server" /D C:\Users\rocke\Documents\Programming\Minecraft\Spigot\capture-the-carrot\test-server "start.bat"
ping -n 3 127.0.0.1 >nul
It basically uses the "START" command to run the task asynchronously and then waits 2 seconds. This is because all I need to do is wait for the start.bat command to run the very first part so that it establishes remote debugging. And then the wrapper ends after 2 seconds (the 3 represents the number of seconds I want to wait +1). And this allows the Debugging process to start while also ensuring that the server has setup remote debugging!
I'll just share screenshots of my configuration if anyone wants to do the same.
Maven Build Configuration
Spigot Server Start Configuration
Remote Debugging Configuration
The way this is setup is once I run the Remote Debugging Configuration, it has a "Before Launch" Task of Spigot Server. Spigot Server also has a "Before Launch" Task of Maven Build Project.
So my Maven Build Project runs, then my Spigot Server wrapper runs and after 2 seconds terminates, and then my Debugging Configuration runs!
If you have any questions regarding remote debugging with spigot, use this resource: https://www.spigotmc.org/wiki/intellij-debug-your-plugin/

CMD window Close automatically after Jenkins build is over

I trying to run Selenium grid and node using Jenkins but the CMD windows always closes after executing the steps
i am running the below code in Jenkins Window Batch Command
cd "C:\TapsiumACSS\Grid3.9"
start Hub.bat
I need the CMD window to be opened
You can create a shortcut of the bat file and under properties in the target section you have to add &PAUSE
This will pause the command prompt until an user input is done.
Just a opinion, Not a good idea to use Jenkins and ask the user to do something as that defeats the whole automation aspect... Instead copy the selenium results into a html or text file which can be viewed later :)
P.S. you will have to refer to this bat file location in Jenkins i.e. the shortcut location
Hope it helps :)

Run interactive batch in Visual Studio post build events

I have a program written in vb.net. After I build, I want to launch an interactive batch file that executes a psexec command remotely. How can I do that?
this is my post build event:
call "$(ProjectDir)ExecOnGw.bat"
And this is my batch that if it runs in a normal command prompt, execution is ok.
c:\Sysinternal\psexec.exe \\gateway "C:\Remotepath\mybatch.bat" -u mydomain\myuser -p ******
pause
This batch calls another batch on a remote machine that does something, then if I want to exit, I have to press a "q" and "Enter". In a normal command prompt, it works fine. But in a Visual Studio post build event it goes down.
Help me!
I've done this before using the start command. I created a simple pause.bat file to demonstrate:
#echo off
pause Press Any Key
exit
If I put this in the post build event, I see a console that just closes.
call pause.bat
If I use this instead, I get a second console window that takes my input before closing.
start "My Process" /D c:\batch /WAIT pause.bat
Here is info about our technical development environment :
Microsoft Visual Studio Enterprise 2019
.NET Core 3.1
Just to add to #dsway good answer, I used Visual Studio 2019’s macros so that I could keep the directory path as relative:
start "My Process" /D "$(SolutionDir)Scripts" /WAIT blahblah.bat
Right-click on the Project in question
A context menu will show up
Select the Properties option
Select “Build Events”
Click on “Edit Post-build…”
Enter the aforementioned command that I posted above, and tailor it to your needs before pressing OK.

RestartManager fails to restart application during update

I'm using c#, .net 4, WIX 3.5, Windows Vista.
I have made my application compatible with RestartManager by p/invoking the RegisterApplicationRestart method and by handling the WM_QUERYENDSESSION and WM_ENDSESSION window messages (I return new IntPtr(1);).
If I try to update my application manually, then everything works as it should:
Launch application;
Launch msi file containing new app version;
During the installation/update, I'm prompted to close the running application;
Upon continuing the running app is closed, install completes, and the app is restarted;
If I try to update my application from the application itself, then I run into problems:
1) Launch application;
2) Download the new msi file;
3) Launch msi file with:
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i \"" + downloadPath + "\" /passive";
p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = securePassword;
p.Start();
}
4) Because I'm using passive mode, the application is closed automatically;
5) After the installation, my application is not restarted and under Event Viewer I have an
Event 10007 - Application or service 'MyApp' could not be restarted.
I have tried:
Not to use passive mode for msiexec;
Launch msiexec via cmd.exe (cmd.exe /C "msiexec /i ....") - in the hopes that launching msiexec from another process would solve the problem;
Wait for 60+ seconds before launching the msi update (shouldn't be relevant in my scenario, but MSDN documentation has something about it...)
But none of the above has worked (always the same result).
Having to launch the setup with elevated permissions might have something to do with the issue, because during the manual update I get a warning in the Event Viewer - Application MyApp (pid 3220) cannot be restarted - Application SID does not match Conductor SID.
Despite this, restarting the app still works. Googleing the warning yields no good/specific results, only that this warning is probably caused by running the msi in an elevated prompt.
How do I fix (or workaround) this issue, so that I can update my application from the application itself and restart my application afterwards?
Edit - extra testing:
There doesn't seem to be a need to respond to WM_QUERYENDSESSION and WM_ENDSESSION messages, because application restart during a manual upgrade works without them, so we can rule them out;
If I don't provide administrator credentials to the application initiated upgrade and instead I type them in during the upgrade, then app restarting works;
If I run an elevated command prompt and initiate an application upgrade from there (manually), then app restarting still works;
In order for application upgrade to work at all under Standard user accounts (so far I tested under an Administrator account with UAC), then I also have to set p.StartInfo.LoadUserProfile = true;. Otherwise nothing happens. (application restart still doesn't work though);
I tried all other process StartInfo parameters that I could set - WorkingDirectory, Redirect, Verb
(= "runas") - no change in results;
I installed Vista SP2 onto the virtual machine that I have been testing on (so far ran SP1), but no change;
I performed an "automatic" application upgrade with verbose logging. In the end there was an error message - RESTART MANAGER: Failed while restarting applications. Error: 352. That error code is very generic (http://msdn.microsoft.com/cs-cz/library/aa373665), inorder to get more detailed info I would have to write my own installer that would call RmGetList after the error, then I might get more details (this though is something I'm not willing to do);
Edit 2 - msi log file:
http://mommi.planet.ee/muu/log.txt
Assuming that the manual process indeed works without any problem it seems that your need for Administrator privileges in combination with the "updating itself" leads to these problems. I see the following options:
create a batch file to execute the update
When you want to update call this batch file (with elevated privileges), make the app close itself... the batch file should wait some seconds, then check whether the app is still running (and close it in case) and then run the commandline you need to run msiexec - don't restart the app from within msiexec but after a successfull run of msiexec from the batch file.
create a batch file which is always used to start the app
When the time comes to update you just end the app. Either the batch file check for an available update and applies it, starting the app after successfull update OR the app set some environment variable which is then accordingly processed by the rest of the batch file.