I have built a Selenium project in C# and would like to run it every day as a task in task scheduler.
I would like to know how to make the project exec file or how to do it effectively.
You can schedule the task by doing the following
Required Tools
1. NUnit3 Console. Location: https://docs.nunit.org/articles/nunit/running-tests/Console-Command-Line.html
2. Windows Task Scheduler
Download NUnit.Console-*.msi file.
Install exe file.
Create an nunit command to run your tests:
> nunit3-console testsfile.dll
More details here: https://github.com/nunit/docs/wiki/Console-Command-Line
Next, create the scheduled task
List item
1. Open Task Scheduler
2. Under Actions, Click Create a Basic Task
3. Provide a descriptive name
4. Choose the starting date and time.
5. Choose Start a Program as the type of action
6. In Program/Script add nunit3-console
7. In Arguments add testsfile.dll
7. In Start in add nunit3 console location
8. Click Finish.
Now it will run on the schedule you provided.
Related
Task scheduler says the task is completed but upon checking, my .exe didn't produce some output. there's nothing in my log as well.
I created a .BAT file to execute my C# program .exe in task scheduler.
Here's my .BAT file code -
echo #off
start "Bank" C:\Users\mySpace\Desktop\bank.exe
Here's the screenshot of my Task scheudler -
console app with a batch file which will hit my Automation testing application and runs selected test cases. I have test case with code coverage and it runs from my visual studio . and now on top of it I have to create a console app which will keep some time interval and hit my VS test case and execute it.Any links will be helpful.
I expect the test case pass and fails status
Here's the batch file I use to run my Selenium tests with multiple runsettings files.
#ECHO OFF
IF NOT EXIST Results MKDIR Results
SETLOCAL
SET PATH=%PATH%;"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform"
SET VSTEST=vstest.console.exe
SET TESTS=.\bin\Debug\something.something.Tests.dll
IF "%~1"=="" (
FOR %%J IN (*.runsettings) DO CALL :func %%J
) ELSE (
CALL :func "%~1"
)
GOTO :EOF
:func
ECHO.
ECHO %~1 **********
ECHO.
"%VSTEST%" %TESTS% /Settings:"%~1" /Logger:trx /ResultsDirectory:Results
GOTO :EOF
You could use NUNit's console runner to run tests from the command line, or on a build server. I've had great success with running my tests this way.
First, you need to install the NUnit.ConsoleRunner Nuget package onto your project.
Then, navigate to the NUnit.ConsoleRunner directory under your packages folder that exists in the project directory.
Open NUnit.ConsoleRunner > tools folder to get into the same directory as the .exe itself.
Then, you can run:
nunit3-console {Path to your project's .dll} --testlist={Path to .txt testlist}
With valid parameters, it looks something like this:
nunit3-console C:\Users\christine.harbour\Repository\AutomationTestSuite\AutomationTestSuite.dll --testlist=C:\Users\christine.harbour\Repository\AutomationTestSuite\MyTestList.txt
Your testlist should contain namespaces of the test cases you wish to run, separated by a line break. For example:
AutomationTestSuite.Tests.MyTestClass_1.MyTest
AutomationTestSuite.Tests.MyTestClass_2.MyOtherTest
After you run the tests, the results will be saved in the NUnit.ConsoleRunner > tools directory. The results are in XML format and can be programatically parsed to push your test results to another tool.
There are plenty of arguments you can pass into the ConsoleRunner, including build configuration and framework version, all which are specified on NUnit's documentation.
NUnit console runner also integrates with Cake, which is a build scripting tool for C# projects. So, you could hypothetically clean / build your project, restore missing package references, and run your tests, all from the console.
More info on NUnit console runner can be found here: https://github.com/nunit/docs/wiki/Console-Command-Line
Our coded ui tests take several hours to complete, if I launch run functional tests task from the build definition it looks like it is consuming build minutes and using build pipelines so wrote a small powershell script (and a console application in C#). the plan is to launch either ps1 or console app from the build definition and exit. the ps1 or exe takes a build name as a parameter and launches the vstestconsole with that name as one of the parameters. when I test this locally on azure VM test machine it works fine (updates the results) but when I launch the same through build definition with build name as the parameter I get build cannot be found under team project error:
Log:
[command]C:\Users\automation\Desktop\ps1\cmd\ExecuteVSconsole.exe UI_Automation_NoWait_20170621.9
Error: Build "UI_Automation_NoWait_20170621.9" cannot be found under team project "XXX"
arg list :C:\Uiautomationbinaries\UI.dll /logger:Tfspublisher;Collection=https://xxx.visualstudio.com/;BuildName=UI_Automation_NoWait_20170621.9;TeamProject="xxx"
The build task I am using is : Powershell on target machine.
The build number is unique (name of the def + day+rev)
I have tried some of the solutions I have found online.
Since running locally successful, suggest you RDP to the remote machine (the target machine of the task)with your build service account. Then manually run the powershell script to see whether it works.
Also pay attention to the permission of your build service account.
Besides, since you are using azure VM , also follow this tutorial To set up WinRM for Microsoft Azure Virtual Machines for PowerShell on Target Machines task.
Fellow coders,
I've built a WPF/ C# application (with .net 4), the app runs fine if debugging or even launching the ".exe" on its own, the app itself runs with Administrator privileges. While running with Administrator privileges I made it add itself as a Task in the "Task Scheduler".
I've made sure the "Run with highest privileges" was checked while creating the task (and verified in the Task Scheduler that everything was set like it was supposed to)
When running the task, the task fails and I see this error:
Task Scheduler failed to launch action "MYPATH\MyClient.Common.dll" in instance "{8df36ee7-0db9-4807-9b5d-d43a793f2169}" of task "\MyClient". Additional Data: Error Value: 2147942593.
I don't understand where this is coming from specially that the MyClient.Common.dll has nothing special; just some logging stuff and a few helpers.
Here are the dlls MyClient.Common.dll is referencing:
Microsoft.CSharp
System
System.Core
System.Data
System.Data.DataSetExtensions
System.Management
System.Xml
System.Xml.Linq
I've tried looking for the error value: "2147942593" but no luck.
Thank you in advance!
Error code 2147942593 (hex 0x800700C1) is the HRESULT encapsulation of Windows error code C1, or ERROR_BAD_EXE_FORMAT.
(search for 0xC1 in http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx)
In a task scheduler this often occurs in one of the following cases:
The path points to a file that isn't an EXE program. If you literally entered the path to a DLL, this could be the cause.
The path includes spaces and isn't quoted. See Why "schtasks" does not run my job?
I am using Team City as the build server, and I have a msbuild build script to build and run integration tests for my project. However, Team City when running my tests decides to ignore the WorkingDirectory attribute on the NUnit task, and as a result my tests fail to initialize:
[17:46:54]: [Project "MyProject.msbuild.xml.teamcity.patch.tcprojx" (ficc-build target(s)):] C:\dev\BuildAgent\work\30decc96a6997d21\MyProject\MyProject.msbuild.xml Value from NUnit task attribute OutputXmlFile has been ignored because TeamCity NUnit task is used
[17:46:54]: [Project "MyProject.msbuild.xml.teamcity.patch.tcprojx" (ficc-build target(s)):] C:\dev\BuildAgent\work\30decc96a6997d21\MyProject\MyProject.msbuild.xml Value from NUnit task attribute WorkingDirectory has been ignored because TeamCity NUnit task is used
[17:46:54]: [Project "MyProject.msbuild.xml.teamcity.patch.tcprojx" (ficc-build target(s)):] Value from NUnit task attribute ToolPath has been ignored because TeamCity NUnit task is used
How can I force Team City to run these tests from my working directory? I don't want to execute nunit-console directly, because I want to benefit from the built-in reporting on test failures, etc.
I can't see a way to change TeamCity's working directory using the MSBuild task, but you could take the middle road and use TeamCity's own console runner, which you could start from within the proper working directory. Another option is to run the standard NUnit console, with TeamCity's NUnit Addin loaded.