* [ui-tests] python is back! * [minor] remove old test * [test] dont test test_runner * [tests] try firefox * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] try chrome 1 * [tests] try chrome 2 * [tests] try chrome 3 * [tests] try phantomJS * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] try chrome * [tests] login click button * [tests] login click button * [tests] show log * [test] test with start_maximized * [test] test only login * [travis] test another port for selenium * [travis] try running ui tests after unittests are done * [travis] pring body_div if fails * [tests] complete setup wizard for frappe * [minor] move ui tests to frappe/ui/tests * [tests] ui tests in public and codacy fixes * [fix] tests + eslint * [minor] move tests to tests/ui folder and print console after print * [fix] linting * [tests] added documentation and better integration testing * [promise] form triggering is now promise based * [test] * [test] * [test] * [test] * [test] print output * [minor] default empty in select and print console * [cleanup] more minor fixes * [enhance] first-cut done! * [minor] frappe.run_serially to pass arguments while chaining
46 lines
2 KiB
Markdown
46 lines
2 KiB
Markdown
# UI Testing with Frappe API
|
|
|
|
You can either write integration tests, or directly write tests in Javascript using [QUnit](http://api.qunitjs.com/)
|
|
|
|
QUnit helps you write UI tests using the UQuit framework and native frappe API. As you might have guessed, this is a much faster way of writing tests.
|
|
|
|
### Test Runner
|
|
|
|
To write QUnit based tests, add your tests in the `tests/ui` folder of your application. Your test files must begin with `test_` and end with `.js` extension.
|
|
|
|
To run your files, you can use the **Test Runner**. The **Test Runner** gives a user interface to load all your QUnit tests and run them in the browser.
|
|
|
|
In the CI, all QUnit tests are run by the **Test Runner** using `frappe/tests/test_test_runner.py`
|
|
|
|
<img src="{{docs_base_url}}/assets/img/app-development/test-runner.png" class="screenshot">
|
|
|
|
### Example QUnit Test
|
|
|
|
Here is the example of the To Do test in QUnit
|
|
|
|
QUnit.test("test quick entry", function(assert) {
|
|
assert.expect(2);
|
|
let done = assert.async();
|
|
let random = frappe.utils.get_random(10);
|
|
|
|
frappe.set_route('List', 'ToDo')
|
|
.then(() => {
|
|
return frappe.new_doc('ToDo');
|
|
})
|
|
.then(() => {
|
|
frappe.quick_entry.dialog.set_value('description', random);
|
|
return frappe.quick_entry.insert();
|
|
})
|
|
.then((doc) => {
|
|
assert.ok(doc && !doc.__islocal);
|
|
return frappe.set_route('Form', 'ToDo', doc.name);
|
|
})
|
|
.then(() => {
|
|
assert.ok(cur_frm.doc.description.includes(random));
|
|
done();
|
|
});
|
|
});
|
|
|
|
### Writing Test Friendly Code with Promises
|
|
|
|
Promises are a great way to write test-friendly code. If your method calls an aysnchronous call (ajax), then you should return an `Promise` object. While writing tests, if you encounter a function that does not return a `Promise` object, you should update the code to return a `Promise` object.
|