Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We have created a sample project for you. Please download greeter-sample .zipexample project, extract it and open the project in your IDE.
If you open To enable JSTestDriver assistance go to the Settings | Editor | Inspections and turn on JavaScript | JsTestDriver checkbox.

On opening GreeterTest.js for the first time, you will see error highlighting on the TestCase method call expression . Position the and tooltip asking about adding JsTestDriver assertion framework support. Press Alt+Enter/Option+Enter and press OK in the opened "Code Assistance For JsTestDriver Assertion framework" dialog.
Image Added

Or you may position the caret on the error- highlighted code, press Alt+Enter/Option+Enter and choose "Add JsTestDriver assertion framework support" from the list of available intention actions.

Image RemovedImage Added

A global JavaScript library named "JsTestDriver Assertion Framework" will be created and associated with a project. To view it, open the Settings dialog (File | Settings or IntelliJ IDEA | Preferences) and select JavaScript Libraries.

Before you can run any of your tests you need to start the test server and capture at least one slave browser. The server does not have to reside on the machine where the test runner is, and the browsers themselves can be on different machines as well.

Starting JsTestDriver server locally

To launch the JsTestDriver server, look for the tool window at the bottom of the screen.

Image Removed

Click the green arrow to the right of the address bar to start the server. The status bar turns yellow to let you know the server is running, but has no slave browsers.

Image Removed

Then, copy the capture URL and paste it in a browser. The status bar turns green, and the corresponding browser icon lights up. Now you’re ready to run tests.

Image Removed

Running tests

To run tests, right-click greeter.jstd and choose "Run “greeter.jstd”'greeter.jstd'". Tests will be run against the local JsTestDriver server.

Image Removed

, additional JSTestDriver Server tool window will be added at the IDE right bottom corner.
To capture a browser you can click on the suggested link in the Run tool window (like http://127.0.0.1:9876/capture) or copy the link and paste it into the desired browser(s).

Image Added

In our case we have one failed test "GreeterTest . test greet null". You can easily navigate from the stack trace to the source code that causes problems. You can also navigate from the test results tree to the test case/test function declaration using the F4 key.

...

In order to remove duplicated code that sets the greeter local variable, you can refactor the Greeter object creation to a special method called setUp, which is called before each test function is executed. Just invoke the Generate action by pressing Alt+Insert inside of a TestCase method call expression, and then choose "JsTestDriver Setup".

Image RemovedImage Added

Use the Shift+F10 keyboard shortcut to re-run the tests after changing code.

...