I am preparing a suite of E2E tests using protractor and Jasmine. Currently I'm running these from the command line using Node. In the past I've used Jasmine tests with the SpecRunner.html setup, which shows the results in the browser as they are run, allows you to select individual tests or sub-suites of tests to run, etc.
Has anyone set up Jasmine + Protractor tests in that way - output going into one browser window, while tests run in another browser window?
Alternatively, is there a Jasmine reporter that will provide a similar output format even if I still have to run the tests from the command line?
For jasmine2, look into jasmine2-screenshot-reporter package.
For jasmine1:
I've used protractor-html-screenshot-reporter package that generates nice test reports including screenshots:
initialize a baseDirectory inside the onPrepare function:
onPrepare: function() {
// Add a screenshot reporter and store screenshots to `/tmp/screnshots`:
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/tmp/screenshots'
}));
}
and observe a nicely HTML formatted test results:
Hope this is what you were asking about.
Related
I have unit tests set up with Karma and Mocha. Karma is important here because some of the functionality I'm testing needs a web browser (even if a fake headless one). But much of the code can run either in a browser or Node.js. For debugging tests it would be much easier to skip launching Karma and use Mocha directly most of the time.
I can do that easily enough if running the whole test suite, but I'd like to be able to use the convenience of the little green play-button style arrows for individual tests. Unfortunately, even for a single unit test, these always launch Karma now.
Disabling the Karma plugin doesn't help. Instead, that makes all of the green arrows go away, with no easy access to either Karma or Mocha.
Is there a way to configure IDEA so that these convenience arrows ignore Karma, and directly run Mocha tests instead?
The logic used for determining what test runner is available for a given test file is based on dependencies declarations in package.json nearest to the current file.
Note that if you have a single package.json, with both karma and mocha included, and there is a karma config in your project, karma is preferred - see https://youtrack.jetbrains.com/issue/WEB-26070#comment=27-2088951. To force using Mocha test runner for files in a certain directory, create a Mocha run configuration with Test directory: set to this directory - when running tests from gutter in this folder, mocha will be used.
When I launch protractor conf.js and this file needs to launch multiple spec files (like below), some of them are (randomly?) skipped. It works quite well when I run each spec separately.
specs: [
'tests/test-1-*.js',
'tests/test-2-*.js',
'tests/test-3-*.js'
],
What can I do to run all tests without any being skipped?
I don't know why this is happening, but if you need to be sure to run all your tests with the same stability than when you run them separately, then you can create a bat file (if you're using Windows) like this:
CALL protractor conf.js --specs='tests/test-1-*.js'
CALL protractor conf.js --specs='tests/test-2-*.js'
CALL protractor conf.js --specs='tests/test-3-*.js'
This will solve the problem until you find the root cause.
I have a bunch of unit tests:
/tests/modules/unit-test-1.js
/tests/modules/unit-test-2.js
/tests/modules/unit-test-3.js
...
..
that I run by doing:
mocha ./tests/modules/*.js
I also have a my-ui.html file and I want to run a UI test on that file.
For this, I want to add a /tests/modules/ui-test-1.js to the above list and what I want this file to do is:
load my-ui.html in a headless chrome
use jQuery to look for some elements on the loaded file
run some Mocha assertions on the above jQuery findings
I want to still be able to run mocha ./tests/modules/*.js and have all my tests run one by one, regardless of whether some of them will be unit tests or UI tests.
There are so many tools but no clear guidelines on how to do the above using Mocha. Any suggestions will be most welcome :)
I must clarify that I do not want to run my test results in the browser using some Mocha UI (I know there are guidelines about that..) - What I want is to load some local file in a headless browser and run Mocha assertions using jQuery on the DOM of that loaded HTML. The results of all my tests will keep appearing in the terminal as is currently the case.
I have a sample project that I am using to write Unit Tests for Dojo modules before moving our to my main project. I have tests that are successfully running in node and chrome environments, but the coverage report is only reporting coverage for the tests executed in the node environment.
Below is a link to the sample project. Does anyone have any ideas why the code coverage report is not showing the metrics for TestModule_Dijit.js file specifically?
SampleProject.zip
Thanks in advance
I tried your sample project, and it appears to be working fine. At least, when running Intern I see coverage reports for both the browser and Node.
Note that coverage is only gathered for browser tests that are managed Intern running in Node. In other words, tests run when you call intern from the command line will collect coverage, whether they're run in Node or in a browser. Tests run using the browser client, where you manually browse to http://localhost:9000/__intern/, will not collect coverage.
Unrelated to the original question, I noticed that you're gathering coverage data for your tests rather than the source files. In general, coverage is most meaningful for the source since the point of test coverage data is to show how much of your application code is being exercised by the tests (not how much of the test code itself is running).
I wrote the Jasmine test for the javascript. I am trying to run the Jasmine tests using Phantomjs. I downloaded the Phantomjs from Phantomjs.org and tried running it using phantomjs.exe //path to phantom jasmine http://localhost/myJasmineTestRunner.html. Googling doesn't help me out. Can someone suggest me how to test jasmine tests using phantomjs.
Running the Tests
In order to run our jasmine test suite on the command line, all we need is:
PhantomJS
Installing PhantomJS from phantomjs.org is fairly trivial (at least on a mac).
A URL to our Jasmine test suite
We already covered jasmine test suites, so we have a URL to a jasmine test suite.
A script that loads our URL and parses the results
Fortunately, PhantomJS provides a working jasmine runner example – all we have to do is download it and use it.
Once we got these, all we have to do is run the following command:
phantomjs
It doesn’t take more than a few seconds(!) and we are provided with the test results.
This is it.
Now, lets run it with our build tool.
* For the purpose of this article, lets assume PhantomJS is installed on the system, our jasmine runner is located at /path/to/run-jasmine.js and our jasmine test suite is located at http://localhost/js/test/unit/
Source.