Run test cases in jenkins using java program - jenkins

I have developed a webpage.In that i have a button. I want to run test cases in jenkins after clicking the button.How do i run testng testcases in Jenkins programatically ?

You will have to configure your job to trigger on that button click and write script to be executed in job config for running test cases.
OR
You can integrate your Jenkins with SCM tool.(eg GitHub)
Push your source codes files their, configure your repo with Jenkins.
You can have .xml file with target to run test cases, and u can mention that target in commands section it will run test cases OR instead of .xml file you can write entire script needed to run test cases.
(Additionally you can use github hook feature to trigger this job after new code changes have been done, so it can be tested instantly).
I hope this will give you an idea, feel free to contact if you have any queries.

Related

Running Protractors in Jenkins

I was just wondering if it is possible to run protractor e2e tests in Jenkins with every build. Currently we trigger test cases manually and they are not part of Jenkins but somehow I need them to be run automatically and show the results (failures/pass) as part of the build.
Can anyone share their experience.
Regards
Syed Zaidy
Yes this is possible, you set this up under the Build Triggers section of your job. You have the options to build periodically, build remotely, build after another project is built, or build after a push to GitHub/BitBucket.
You can also put your tests in the pipeline, "downstream" from another job, so they are automatically triggered whenever that job completes.
Yes, it is possible to run Protractor tests from a Jenkins job. To do this, you will need a headless browser. Read about Headless browsers here:
You can follow the following instructions and install npm, protractor and chrome headless in the Jenkins box here

what did jenkins actually build?

I created a freestyle project in jenkins, in which I chose source code management as git, screenshot below
That's pretty my config. The repo you see in there is public repo. then I save the config, then I click build now.
It seems to works base on the notification on screen, which says 'success'. But I have no idea I what the heck Jenkins produced. I didn't instruct what to build and how to build. How does it know what I want? And lets say it did build something, where does it store the build? I didn't instruct it where to store the built file either. Can someone explain what is going on?
To actually build something you need to add something to your Build section in the project configuration. For a javascript configuration it might look something like:
npm install
npm run test-coverage
npm run linter
npm run complexity
where each item after run is a script in your package.json. Then you can add plugins to read the outputs of those actions, for example:
Clover test coverage publisher
TAP (Test) results publisher
HTML Publisher for publishing static analysis results
Checkstyle publisher for linting results
This allows you to pass and fail builds based on certain test criteria and where continuous integration starts to shine.
In Jenkins job you have several sections - you can define pre build actions to prepare the environment, SCM to check out from source control, Build section to run your build pipeline and post build operation to run actions after the build section.
If you defined only the SCM section all your job did is to check out your sources from the source control you provided. the status of this action is SUCCESS.
Don't forget to check the console output of the job that ran to see which steps ran.

ghostinspector(phantomjs) running from jenkins and seeing result in jenkins

I am using ghostinspector to record and run tests. I have also seen API integration.
Is there a way I can create a build and when I trigger this build, it runs test on ghostinspector. (I am able to do this using custom build command in jenkins which makes curl request)
In additional to triggering build I would like to see result in jenkins as well. does ghostinspector or phantomjs test script returns result in TAP format or any other format which jenkins can show as test results
Full disclosure: I work for Ghost Inspector.
We now offer the ability to download results from your test suite in XUnit format via our API that you should be able to use in Jenkins to report on your suite status.
Hope that helps.

Build and run unit-tests with two distinct jobs

I have a basic setup: some source files stored in GitHub that are pulled and built by a Jenkins job.
Now I'd like to run the unit-tests automatically when the build is done (I'm using NUnit if it can help).
I could add another build step to the "build" job to run nunit-console but I'd like to separate the build task from the unit-testing task, so that in the Jenkins dashboard I can directly see what is broken: the build or "only" the tests.
I could create another job that would pull the code-source too but it would duplicate the first job.
What's the simplest way to run the unit-tests directly on the binaries produced by the first job (run second job in the same workspace? copy the binaries? ...) ?
Thanks for any input.
You could use the Copy Artifact Plugin to copy the artefacts to another job and then run the unit tests but this may not work, depending on how C# handles packaging and the project is structured.
It look like you can use the NUint Plugin to publish the results of your tests so you may be able to use a single job as I don't think that the tests will run if the previous build step fails as they don't for JUnit tests

Coded UI test fails with MSTest under Jenkins

I am using Jenkins for my project CI. And several automation test cases developed by Coded UI(C# language) will be run when the new build is deployed. I created a job on the master(windows) that MSTest those test cases(note: with MSTest under cmd, test cases can be run successfully) but saw the below issue:
Error calling Initialization method for test class QuickUI.SmokeTests: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: To run tests that interact with the desktop, you must set up the test agent to run as an interactive process. For more information, see "How to: Set Up Your Test Agent to Run Tests That Interact with the Desktop" (http://go.microsoft.com/fwlink/?LinkId=159018)
Therefore,
1) Need I use Jenkins slave to run test cases?
2) If so, how to config since the dlls needs to be copied to slave firstly?
3) Is there any account or jenkins service configuration needs to be taken care?
Thanks in advance.
Sounds like you need to get mstest setup on your build machine. The easiest way is to use test agents (http://www.microsoft.com/en-us/download/details.aspx?id=38186) when installing chose test agents.
(below is copied from my answer in Coded UI build server integration process)
You going to want to put your CodedUI tests inside an orderedTest. Right Click on the solution -> add -> orderedTest.
You going to want to install https://wiki.jenkins-ci.org/display/JENKINS/MSTestRunner+Plugin it's not a requirement, but it makes working with mstest in jenkins a little easier.
At this point you just need to configure the plugin in jenkins to run your orderedTest. It will need you to point to mstest and the location of your orderedtest.
1) Recommnd to run test on slave
2) To run GUI test, don't run the slave as windows service
3) Theoratically you only need the slave agent running. However the windows account logged in should have access to all the resources that your tests need.
Some other threads you could reference, pay special attention to this if you want to run the tests in unattended way.
Jenkins on Windows and GUI Tests without RDC

Resources