-
Notifications
You must be signed in to change notification settings - Fork 7
Fixtures
A Fixture file is a JavaScript containing arbitrary code that will be executed at the very beginning of a test suite loading, and whose defined variables will be made available globally across all suite files.
Fixture files have to end with Fixture.js
.
It is good practice to split your data files over the type of provided data, and name them accordingly:
LoginFixture.js
,TranslationFixture.js
…
The files are parsed and executed as pure JavaScript, in the global scope.
This means all variables declared outside of a function scope will be available globally, across all scenarios and components of the suite.
No guarantee is made on the loading order of data files. They should all be independent from each other.
However, it is certain that all data files will be evaluated before any component or scenario file is loaded.
Pieces of information such as usernames, passwords, texts against which matches will be made… should all be written in data files, and the declared variables used in scenarios.
// example/DuckDuckGo/ZeroClickFixture.js
lookupTerm = "Toto"
// example/DuckDuckGo/1 - ZeroClickScenario.js
description: 'Looking up an ambiguous term should make a Zero Click Info box appear.',
steps: [
SearchBarComponent.searchFor(lookupTerm) // the data piece defined in the data file is used here
]
Simple helper functions can also be made available, either for computing values at execution time, or to factorize simple matchers. For example:
// CheckBoxesFixture.js
function checked(checkbox) {
return checkbox.getAttribute('checked').then(function(checked) {
assert(checked, 'should be checked')
});
}
function unchecked(checkbox) {
return checkbox.getAttribute('checked').then(function(checked) {
assert(! checked, 'should not be checked')
});
}
// PRISMComponent.js
spyOnEveryoneCheckbox: 'input[type=checkbox].spy'
// PrivacyScenario.js
description: 'As a citizen, I should not be spied upon by governments',
steps: [
{
PRISMComponent.spyOnEveryoneCheckbox: unchecked
}
]
Even though data files can be powerful, remember to keep helpers and injected data simple. All mapping should be done in components, including user actions mapping. If your helpers encapsulate too much logic, your tests will become unreadable and fragile.