How to generate mocha test case report and show using Jenkins? - testing

I am doing mocha unit testing for my JavaScript functions. I am running mocha in a browser not using Node. I am using require.js to load files.
When I do mocha.run() it shows reports in the browser.
Now I want to make a Jenkins job to display the report.
So how do I generate the report file so that I can provide it to Jenkins?

Running the command:
$ npm install mocha-junit-reporter --save-dev
Will generate an XML file that you can give to Jenkins

Run the command
$ mocha ./test.js --reporter mocha-junit-reporter --reporter-options ./test-results.xml
For docker file use below command
CMD ["mocha", "./test.js" , "--reporter", "mocha-junit-reporter", "--reporter-options","./test-results.xml"]
Both command will do the same.
test-results.xml file be generate in the folder .

I am answering my own question, I have solve this problem by using NGINX server which is open source.
I have added form tag in index.html of mocha and wrote on function on submit form to run mocha suit, this will return you output , parse that output and make file of that according to your need like total success count, failure count etc. and gave to Jenkins.

Related

How to Save Test Results in Postman

I have an API Collection in Postman, and I have saved a few examples for each request.
When I try to save the Test Results though, only the JavaScript code is saved in the examples, and not the actual results (same goes for when exporting the whole API Collection).
Is there any other way I can do this to export the Test Results too?
as far as I know, you can't save test results but you can run test collection on Newman and save the result
Try creating a report, it will include all the results of your test.
You can install newman-reporter-htmlextra with the following command:
npm install -g newman-reporter-htmlextra
Then you can execute Newman with report enabled:
newman run xxxxx.json -r htmlextra
The resulting HTML report will be saved in newman directory on the current directory.

“ERROR Unable to find the browser. “saucelabs:Chrome#83.0:Windows10” is not a browser alias or path to an executable file

I am trying to run my UI test using testcafe and saucelabs. I am facing this above error. Currently I am using testcafe v1.8.3 and testcafe-browser-provider-saucelabs v1.7.0
I have tried changing versions of browser provider also but still facing the above error. Pls help out with a solution for this as i am stuck with it for more than a week
So, it looks like the runner you are using (testcafe-browser-provider) is a very old one, there is a new runner you can use for testcafe tests called saucectl.
TLDR:
Install saucectl globally npm install -g saucectl
Set up saucectl within your project folder with saucectl init This will create a .sauce/config.yml file
Tweak the settings to run the spec files and OS/ browser of your choice
Use saucectl run
You can see an example proj here: https://github.com/saucelabs/saucectl-testcafe-example
It looks like your provider is installed locally, while you are using the global TestCafe installation. You also need to install TestCafe locally or both packages globally. After this, check your browser provider: testcafe -b saucelabs.
I am using testcafe v1.8.3 and testcafe-browser-provider-saucelabs v1.7.0
Please update your testcafe and testcafe-browser-provider-saucelabs versions to the latest ones.

How to run CI selenium side runner tests on Jenkins

I have a .side file generated by the Selenium IDE, which I need to run on CI using Jenkins.
I am running it as a build step with the following shell command:
selenium-side-runner /path/to/file.ide
The problem arises due to the fact that no matter if the selenium test fails, Jenkins always shows is as success.
In this thread it's suggested to upload the file as generic, but still, the commands to execute it are missing
How to upload a generic file into a Jenkins job?
I've found a possible solution to it on this posts, but I would appreciate having a cleaner way to solve this instead of parsing the results checking for errors.
How to mark a build unstable in Jenkins when running shell scripts
Is there a plugin able to run selenium .side files on Jenkins and this one showing the success/failures of the test?
You can generate a Junit test report file and then use the Jenkins Junit plugin after your tests execution.
selenium-side-runner --output-directory=results --output-format=junit
# Outputs results in `junit` frormat in `./results/projectName.xml'
Check the official documentation for more details.

Display selenese-runner results in Jenkins

As I am implementing an automated way to GUI test our webapplication with selenium I ran into some issues.
I am using selenese-runner to execute our Selenium test suites, created with Selenium IDE as a post build action in Jenkins.
This works perfeclty fine, as the build fails when something is wrong, and the build succeeds if all tests are passed. And the results are stored on a per build basis as HTML files, generated be selenese-runner.
My problem is however, that I seem to be unable to find a way, how to display these results in the respective jenkins build.
Does anyone have an idea how to solve this issue. Or maybe I am on the wrong path at all?
Your help is highly appreciated!
I believe the JUnit plugin should do what you want, but it doesn't work for me.
My config uses this shell script to run the tests (you can see the names of all my test suites):
/usr/bin/Xvfb &
export DISPLAY=localhost:0.0
cd ${WORKSPACE}
java -jar ./test/selenium/bin/selenese-runner.jar --baseurl http://${testenvironment} --screenshot-on-fail ./seleniumResults/ --html-result ./seleniumResults/ ./test/selenium/Search_TestSuite.html ./test/selenium/Admin_RegisteredUser_Suite.html ./test/selenium/Admin_InternalUser_Suite.html ./test/selenium/PortfolioAgency_Suite.html ./test/selenium/FOAdmin_Suite.html ./test/selenium/PublicWebsite_Suite.html ./test/selenium/SystemAdmin_Content_Suite.html ./test/selenium/SystemAdmin_MetaData_Suite.html
killall Xvfb
And I can see the result of the most recent test (you can see the name of my jenkins task folder)
http://<JENKINS.MY.COMPANY>/job/seleniumRegressionTest/ws/seleniumResults/index.html
Earlier tests are all saved on the Jenkins server, so I can view them if I need to.

Generation of Selenium reports using Hudson (now known as Jenkins) from JUnit XML format file

For Test Automation of web project we use Hudson, PHPUnit, and Selenium. The results of the build are stored in the JUnit XML format.
When I try to include generation of reports using the Hudson Publish JUnit test result report option, the build finishes with Failed status.
Below is my Hudson configuration to run the tests.
sudo -u apache phpunit - log-junit /var/lib/hudson/jobs/Work-stars-Tests/builds/${BUILD_ID}/ seleniumReports/seleniumTests.xml + path to test php files
Generation of reports is enabled through the Hudson configuration option «Publish JUnit test result report», where I specify the path to the folder with PHP tests.
The user we use to run Hudson has permission to write/read files in the folder with the reports. As for the path we've tried to specify both full and relative.
The error No test report files were found. Configuration error? is displayed in the console after the build.
How do we resolve this issue?
Found my own solution to this problem :)
In Hudson project configuration settings modified execute shell command to
> #!/bin/sh -x phpunit --log-junit ${WORKSPACE}/zf/tests/_tmp/reports/seleniumTests.xml
> ${WORKSPACE}/zf/tests/selenium/; sed
> -i '/<testsuite name=".*\/"/D;/^ <\/testsuite>$/D'
> ${WORKSPACE}/zf/tests/_tmp/reports/seleniumTests.xml
and set following path to Junit reports
**/zf/tests/_tmp/reports/*.xml
Problem is solved. Yahoo!