Start Selenium test cases using jenkins - jenkins

I have prepared a test cases using selenium webdriver and I ran locally using MSTEST and it works fine and now I would like to move my test cases to JENKINS, and when i run from JENKINS it says Starting execution... and its more than 15 mnts and still the same status so I have to stop it manually.
here is my console output:
Started by user anonymous
Started by user anonymous
Building in workspace D:\Jenkins\jobs\Selenium_Script\workspace
[workspace] $ cmd /c call C:\Users\XXXXXXX\AppData\Local\Temp\hudson4765437871038045571.bat
D:\Jenkins\jobs\SelScript\workspace>call "D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest" /testcontainer:D:\Sel\EmployeeTest\test.emp.admin.dll
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading D:\Sel\EmployeeTest\test.emp.admin.dll...
Starting execution...
Build was aborted
Finished: ABORTED
I wanted to execute the test case on Jenkins and check the result of execution
and here is my code I'm using just in case.
This is what I am using to instantiated my driver, do I have to use RemoteDriver?
public static IWebDriver GetDriver()
{
string _url = new Uri(Common.Url).DnsSafeHost.ToString();
switch (Common.BrowserSelected)
{
case "ff":
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", _url);
drv = new FirefoxDriver(profile);
break;
case "ie":
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
drv = new InternetExplorerDriver(options);
break;
case "chrome":
//_driver = new ChromeDriver();
break;
}
return drv;
}

You can run your Selenium scripts in the Build section of Jenkins.
Click on Add Build Step and select Execute Shell, over there you can directly run your commands as you would type in a Linux environment.
All of this assuming you are running your Jenkins of a Linux environment.
#Do I have to use RemoteDriver?
Depends do you have xvfb installed to run your tests in a headless mode?
If not, then yes, you can redirect your tests to run remotely on a windows/mac machine.
UPDATE
If you have a windows machine, you do not need xvfb. So forget about that.
Shell script (defaults to sh, but this is configurable) for building the project. The script will be run with the workspace as the current directory. Type in the contents of your shell script. If your shell script has no header line like #!/bin/sh —, then the shell configured system-wide will be used, but you can also use the header line to write script in another language (like #!/bin/perl) or control the options that shell uses.
By default, the shell will be invoked with the "-ex" option. So all of the commands are printed before being executed, and the build is considered a failure if any of the commands exits with a non-zero exit code. Again, add the #!/bin/... line to change this behavior.
As a best practice, try not to put a long shell script in here. Instead, consider adding the shell script in SCM and simply call that shell script from Jenkins (via bash -ex myscript.sh or something like that), so that you can track changes in your shell script.
Example -
You can run a ruby command like so
ruby testscripts.rb
or a shell script like so
./testscripts.sh

Jenkins is super easy. Just do this:
1. Allow Jenkins to check-out your code into the Jenkins workspace.
2. Navigate to that workspace on your Windows computer and manually run
the tests by executing the script that starts them.
By doing it this way Jenkins is temporarily out of the picture and is therefore no longer the cause of your problem. Then, you can focus on what the real actual problem is. Once you have resolved the problem, check your changes into your source code repo, then run the Jenkins build again and try to run manually again. If that also works, THEN finally, you are clear to setup a build task in Jenkins to run your test.

Related

PowerShell Script Runs correctly in ISE however, it fails through SCORCH Runbook Run .Net Script Activity

I am able to run Powershell script in ISE however, same script does not Run through "Run .Net Script" Activity in Orchestrator Runbook. It fails on minor errors where error action Silently continue is defined.
It is not specific to any single script. But, for all.
SCORCH Version 2019

launch a .bat in TFS2015 build

I have a problem trying to launch a server via a .bat file during a TFS build.
I usually launch the server via a cmd window and it works fine.
When I set it in the TFS build, I end up with the following message :
"'..\server_common.bat' is not recognized as an internal command or external, an executable or a command file".
I also have the following line:
"java -Dsun.lang.ClassLoader.allowArraySyntax=true -Xbootclasspath/a:..\..\..\lib\framework\serverjvm15.jar; -cp ..\..\..\lib\framework\fwtime.jar;" indicating a java syntax error (? I'm not skilled in java)
This batch calls other .bat files and sets java VM-related environment variables
From my research, it is probably a problem of rights as I don't have admin rights when I use TFS. However, all the other steps in the build work fine (installing and launching an appli through command lines, or launching a python script via command lines).
However I also tried to launch a basic script with the same kind of step and it works.
First, suggest you to follow the tutorial in Batch script. Make sure you have meet the requirements of Arguments and used correctly. Such as
Path
Specify the path to the .bat or .cmd script you want to run. The path
must be a fully qualified path or a valid path relative to
the default working directory. In Team Foundation Build, this
directory is $(Build.SourcesDirectory).
Also RDP to your build agent and use your build service account manually run the server_common.bat to narrow down if the account have enough permission.

Running a Windows batch file in Jenkins

I trying to run my Tests cases for a project in Jenkins through DOS Command line on Windows server . I am using Jenkins ver. 1.559.
I am trying to run a Windows batch file through a Jenkins job that has the java command.
Under the "Build" section >> "Execute Windows Batch command" >> Command: call E:\Jenkins\App\UnitTests\App_UnitTests.bat
Save and Build the job.
I am getting an error and here is my Console Output
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>java.exe -cp "E:\Jenkins\App\PPS\App\bin\;E:\Jenkins\App\PPS\App\lib\junit-4.10.jar;E:\Jenkins\App\PPS\App\lib\*.jar;" org.junit.runner.JUnitCore com.omnitracs.fra.junit.EventTests
'java.exe' is not recognized as an internal or external command, operable program or batch file.
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>PAUSE
Press any key to continue . . .
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>EXIT
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
The java command runs fine outside Jenkins.
I have set the JAVA_HOME for the local user and also the PATH variable to point to where java.exe is.
What am I doing wrong? Please help.
For a windows environment, there is some extra configuration needed for more advanced builds. Ultimately you have two options
From Jenkins, The Definitive Guide:
This basic installation will work fine in a simple context, but you
will often need to fine-tune your service. For example, by default,
the Jenkins service will be running under the local System account.
However, if you are using Maven, Jenkins will need an .m2 directory
and a settings.xml file in the home directory. Similarly, if you
are using Groovy, you might need a .groovy/lib directory. And so on.
To allow this, and to make testing your Jenkins install easier, make
sure you run this service under a real user account with the correct
development environment set up. Alternatively, run the application as the
system user, but use the System Information page in Jenkins to check
the /Users/johnsmart/Projects/Books/jenkins-thedefinitive- guide
directory, and place any files that must be placed in the user home
directory here....
To configure your Jenkins server to run under a service account (The suggested option), Install Jenkins as a service, and under the services properties set the log on user info.

Jenkins + CasperJS

I have a series of frontend tests written in CasperJS that I need to run in Jenkins. Here is command I run from the command line: casperjs test ./src/tests/**/ts_*.js --xunit=xunit.xml. This runs the tests and saves the xunit file. Ok. When I have Jenkins run the same command it gets through loading the first test page and spits out this error: "Process leaked file descriptors" and directs me to: https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build
It provides an explanation and a few OS specific work arounds. The environment this will be run on will eventually be linux however my development environment is Windows and I don't understand the workaround they provide. What kind of file is that and how does it fit with Jenkins?
Does anyone have experience running CasperJS tests using Jenkins?
I installed jenkins as a service and use default settings.
I solved same issue on windows.
if you are running as a service and default home directory ( c:/program files(x86)/jenkins/ )
you have to change path to other normal folder(ex.c:/jenkins/").
SET JENKINS_HOME=c:\jenkins\
What I do with jenkins and casper:
I create a job with string parameter 'tests', which takes *.js or specified test
and try to run casper tests via Build -> Execute shell
cd ~/test_directory
casperjs test ${tests}

execute shell step skipped completely in jenkins

I can't seem to run a build execute shell step in Jenkins. I've worked with Hudson in the past on windows and I was able to create shell/batch steps without a problem but I seem to be be missing something here.
It's a fresh jenkins install and I go to "add build step", "execute shell" and enter "echo hi" in the command. I run the build and when I look in the console output, nothing happens.
I've also tried executing a test.sh file which also just echoes hi. I've tested this in both a linux install and an os X installed Jenkins server.
What am I missing in the configuration to run a shell script?
The console output shows that the shell script steps were skipped completely
Started by user admin
Finished: SUCCESS
It looks like Jenkins is not being able to redirect the output from the system. What version of Java are you using? If you're using OpenJDK, could you try with Sun Java/Sun JDK?
First test to try to check if anything is executing at all: add the following to your "Execute Shell"
#!/bin/bash
echo "HELLO WORLD" > /tmp/testfile
Run this and check if there is a /tmp/testfile in on your Linux system, and if it contains the HELLO WORLD text, it means your script is in fact executing.
Which version of Jenkins do you have?
The last good version that I can attest to (last one I know works well at least for us) is 1.447. If you're not using that one, would you be able to try with it?
Also, could you add #!/bin/sh or #!/bin/bash before echo hi on your "Execute Shell" for the Linux system and see if that works.
Also, try running a script using source /path/to/script and see if that works. The script should contain #!/bin/sh or #!/bin/bash as the first line, just to see if that makes a difference.
Note: none of this should be required, but is helpful just to get more information on what's going on. Couldn't fit all this into a comment. I'll update my answer based on your answers to the above, or delete if I can't get anything..
Putting this here for posterity.
I had a Jenkins project configured with Maven running clean test and a execute shell in the pre steps. The logs from Maven where not coming through and the script was not executing. Once I unchecked Build modules in parallel under the Maven build options my logs and scripts started working.
Make sure its in a location where Jenkins can see it, check permissions.

Resources