This is an assertion modifier. It returns the test instance itself, but the next added assertion is specialized in a certain way.
This modifier "inverts" the assertion, so it obtains a negative semantic.
For example, there's a equal assertion which passes, when provided objects are the structurally the same. Inverted assertion will pass when provided objects are structurally different:
t.equal(1, 1) // passes
t.not.equal(1, 2) // passes
t.not.equal(1, 1) // fails
Any assertion can be negated in this way, except the ones related to waiting, like waitFor.
This is an assertion modifier. It returns the test instance itself, but the next added assertion is specialized in a certain way.
This modifier makes the assertion "silent" - it will only appear in the test log if it fails.
Note, that by default, the console output already hides passed assertions. The dashboard interface however shows them.
This modifier causes the passed assertion to be physically excluded from the log, so it won't appear in any kind of user interface or report.
For example:
t.silent.equal(1, 1) // passes, assertion excluded from the log
t.silent.equal(1, 2) // fails, assertion will be included in the log as usual
Any assertion can be modified in this way.
This method returns an "expectation" instance, which can be used to check various assertions about the passed value.
Every expectation has a special property not
, that contains another expectation, but with the negated meaning.
For example:
t.expect(1).toBe(1)
t.expect(1).not.toBe(2)
t.expect('Foo').toContain('oo')
t.expect('Foo').not.toContain('bar')
Please refer to the documentation of the Expectation class for the list of available methods.
Normally, to test the asynchronous code, you just make your test function async
and await
on any asynchronous
method call inside of it:
import { it } from "@bryntum/siesta/index.js"
import { MyClass } from "my-lib"
it('Testing asynchronous code should work', async t => {
const myClass = new MyClass()
await myClass.asyncMethod('do something')
})
However, for example if code is using callbacks, you might not have a Promise
instance to await
for.
In such case, use this method to indicate the beginning of the "asynchronous gap" in the code flow. Each gap should be finalized
with the endAsync call within the timeout
milliseconds, otherwise a failed assertion will be reported.
The test will wait for all asynchronous gaps to complete before it will finalize.
For example:
import { it } from "@bryntum/siesta/index.js"
import { MyClass } from "my-lib"
it('Testing asynchronous code should work', t => {
const myClass = new MyClass()
// indicate async gap starts
const async = t.beginAsync()
myClass.asyncMethodWithCallback(() => {
// indicate async gap completes
t.endAsync(async)
})
})
The "gap id" opaque object, which should be passed to the endAsync call.
This method finalizes the "asynchronous gap" started with beginAsync.
The gap id to finalize (returned by the beginAsync method)
This assertion passes, if waiting for some condition has completed successfully, within the expected timeout.
The condition to wait for should be specified as a checker
function. It can be async
if needed (return a Promise
).
For the waiting to complete, the condition checker should return some "truthy" value, like true
, 1
, 'some_string'
, etc.
That value (wrapped in a Promise
) will be returned from the waitFor
method itself.
Alternatively, this method can just await for certain time.
This method has 3 overloads:
timeout
.Note, this method is async
. Don't forget to await
on it. .
For example:
await t.waitFor(() => /Special/.test(document.title))
await t.waitFor({
condition : () => document.readyState === 'complete'),
timeout : 30000,
interval : 1000
})
const elements = await t.waitFor(() => {
const els = document.querySelectorAll('.some_class')
return els.length > 0 ? els : null
})
IMPORTANT: To avoid race conditions, always start waiting for certain event, before triggering it. See the trigger option in the WaitForOptions object for more details.
This assertion passes if provided value is "falsy" - false
, 0
, ''
etc.
Backward compatibility alias for false
Backward compatibility alias for true
This assertion passes if provided value is "truthy" - true
, 1
, 'non_empty_string'
etc
This assertion passes if the given offset
point of the target
element is directly reachable by the user, i.e.
it is not covered with some other element. If the offset
is not provided, the center of the element is tested.
The test is performed using the document.getElementFromPoint() method.
Usually it is fine if the element is covered with one of its children - it is still considered reachable.
This behaviour is controlled with the allowChildren
option, by default it is set to true
.
This method has 2 overloads, one simplified and one with options.
This assertion passes, if the value
property of the target
element is strictly equal to the given value
argument. No assumption is made about what is the target element, but usually it should be <input>
or
<textarea>
.
For example:
t.elementValuesIs('#input1', 'Need this text', 'Correct text in the input field')
This assertion passes if the given CSS / ActionTarget selector is found in the DOM.
A CSS or ActionTarget selector
The description for the assertion
This assertions passes if waiting for the given selector
completes within timeout
.
If no timeout
is given TestDescriptor.defaultTimeout is used. One can also specify
a root
element, from which the query will be starting.
This method has 2 overloads
For example:
await t.waitForSelector('.css-class', { root : '.root', timeout : 5000 })
include
include
This assertions passes if waiting for the given selector
completes within timeout
.
If no timeout
is given TestDescriptor.defaultTimeout is used. One can also specify
a root
element, from which the query will be starting.
This method has 2 overloads
For example:
await t.waitForSelector('.css-class', { root : '.root', timeout : 5000 })
include
include
Performs a query in the DOM using query method and returns the 1st element from the results.
Synonym for query.
This helper method returns an index of the caret position (0-based) in the given target
element
This helper method returns a selected text in the given target
element
This helper method moves the caret position in the given target
element by the delta
.
Performs a query in the DOM, by default it is a regular CSS query with extra capabilities.
Notably, the :contains(text)
pseudo is supported. It matches, if the text content of the element
contains the provided text
.
Also, the ->
characters split the query into segments, and each segment matches inside a "context".
Context can be either an iframe or a web component shadow DOM. Simply put, the ->
symbol marks the boundary
of the iframe/web component. Web component need to have "opened" shadow DOM for query to work.
For example:
// matches the `body` element of all iframes with `my-frame` CSS class
.my-frame -> body
// matches the `body` element of all iframes with `nested-frame` CSS class, which are in turn contained
// inside the iframes with `my-frame` class
.my-frame -> .nested-frame -> body
// matches the elements with `target-class` CSS class, which are inside the shadow DOM of the
// web component element with `my-web-comp1` class
.my-web-comp1 -> .target-class
This method uses querySingleContext to perform simple query inside a single context.
An enhanced CSS selector
The root DOM element (or a Document
) from which to start the query. Optional, by default
its the document
of the test context.
You probably don't need to use this method in your tests. Use query instead. This method can be overridden by the subclass, to provide some extra query syntax, features etc.
Performs a query in the DOM, by default it is a regular CSS query. Query is performed inside a single DOM context (single iframe or single web component). See query for cross-context querying capabilities.
This helper method selects text in the given target
element, starting from the index start
(0-based)
till the index end
This helper method sets the index of the caret position (0-based) in the given target
element.
A shorter alias for equal
This assertion passes if the received (left) and expected (right) values are "structurally" equal, the so called "deep" equality.
Map
, Set
and other native JavaScript data types are supported. Currently these objects are compared
by their content, any extra properties, set on them, will not be compared. We plan to support this
use case if there will be a demand for it.
Cyclic data structures are supported. Fuzzy matchers, like any, anyNumberApprox, etc are supported
inside the expected
data.
This assertion passes if the received (left) and expected (right) values are "structurally" equal, the so called "deep" equality.
Map
, Set
and other native JavaScript data types are supported. Currently these objects are compared
by their content, any extra properties, set on them, will not be compared. We plan to support this
use case if there will be a demand for it.
Cyclic data structures are supported. Fuzzy matchers, like any, anyNumberApprox, etc are supported
inside the expected
data.
This is Siesta 5 backward compatible assertion, which performs comparison of the 2 values, using the ==
comparison.
So, null
will be equal to undefined
, 4
to "4"
and so on. As an additional quirk, Date
instances
are compared structurally, by their time, instead of by reference.
The fuzzy matchers, like any, anyNumberApprox, etc are supported for the expected
value.
It is recommended to use the deep structural equality instead of this assertion, check equal and its shortcut alias eq.
Backward compatible alias for equal
This assertion passes if the received and expected values are equal, as defined by the ===
operator.
This assertion passes if the received (left) and expected (right) values are "structurally" not equal, the so called "deep" inequality.
See equal for details.
This assertion passes, if the provided function func
does not throw any exceptions.
import { it } from "@bryntum/siesta/index.js"
it('Test section', async t => {
t.doesNotThrow(() => {}, 'No exceptions thrown')
})
The func
function may be async
or return Promise
. In such case, do not
forget to await
on the assertion method itself:
import { it } from "@bryntum/siesta/index.js"
it('Test section', async t => {
await t.doesNotThrow(async () => {}, 'No exceptions thrown')
})
See also throws
Backward compatible alias for doesNotThrow
This assertion passes, if the provided function func
throws an exception, which
stringifies to the pattern
.
import { it } from "@bryntum/siesta/index.js"
it('Test section', async t => {
t.throws(() => throw new Error("oops"), /oop/i, 'Correct exception thrown')
})
The func
function may be async
or return Promise
. In such case, do not
forget to await
on the assertion method itself:
import { it } from "@bryntum/siesta/index.js"
it('Test section', async t => {
await t.throws(async () => throw new Error("oops"), /oop/i, 'Correct exception thrown')
})
See also doesNotThrow
The function to call. May be async
or return Promise
. In such case, do not
forget to await
on the assertion method itself:
Backward compatible alias for throws
This is a shortcut alias for isCalledNTimes, with the expected
argument hardcoded to the >= 1
.
It passes if the function property is called at least one time during the test life span.
The function itself or the name of the function property on the host object (2nd argument)
The host object
The description of the assertion
This assertion passes if the object's function property is called the expected number of times during the test life span. The expected number of calls can be either a number or a string, consisting from the comparison operator and a number. See [[FiresOkOptions.events]] for more details.
For example:
const obj = {
data : 1,
increment : function () {
return ++this.data
}
}
// exact number of calls
t.isCalledNTimes('increment', obj, 3, 'Correct number of calls to `increment`')
// expected number of calls as expression
t.isCalledNTimes('increment', obj, '<= 3', 'Correct number of calls to `increment`')
// passing property itself
t.isCalledNTimes(obj.increment, obj, 3, 'Correct number of calls to `increment`')
The function itself or the name of the function property on the host object (2nd argument)
The host object
The expected number of calls
The description of the assertion
This is a shortcut alias for isCalledNTimes, with the expected
argument hardcoded to the 1
.
It passes if the function property is called exactly once time during the test life span.
The function itself or the name of the function property on the host object (2nd argument)
The host object
The description of the assertion
This is a shortcut alias for isCalledNTimes, with the expected
argument hardcoded to the 0
.
It passes if the function property is not called during the test life span.
The function itself or the name of the function property on the host object (2nd argument)
The host object
The description of the assertion
This is a shortcut alias for methodIsCalledNTimes, with the expected
argument hardcoded to >=1
.
It passes if the method is called at least once during the test life span.
The function itself or the name of the function property on the host object (2nd argument)
The description of the assertion
This assertion passes when the supplied class method is called the expected number of times during the test life span. The expected number of calls can be either a number or a string, consisting from the comparison operator and a number. See [[FiresOkOptions.events]] for more details.
Under "class method" here we mean the function in the prototype. Note, that this assertion counts calls to the method in any class instance.
For example:
class Car {
constructor (type, version) {
this.carInfo = {
type : type,
version : version
}
}
update (type, version) {
this.setVersion(type);
this.setType(version);
}
setVersion (data) {
this.carInfo.version = data;
}
setType (data) {
this.carInfo.type = data;
}
};
t.methodIsCalled("setVersion", Car, "Checking if method 'setVersion' has been called");
t.methodIsCalled("setType", Car, "Checking if method 'setType' has been called");
const m = new Car('rover', '0.1.2');
m.update('3.2.1', 'New Rover');
This assertion is useful when you need to verify the method calls during class instantiation time, which means you need to observe the prototype method before the instantiation.
The method function itself or its name
The class
The expected number of calls.
The description of the assertion
This is a shortcut alias for methodIsCalledNTimes, with the expected
argument hardcoded to 0
.
It passes if the method is not called during the test life span.
The function itself or the name of the function property on the host object (2nd argument)
The description of the assertion
A wrapper for the any fuzzy matcher helper
A wrapper for the anyArrayContaining fuzzy matcher helper.
A wrapper for the anyNumberApprox fuzzy matcher helper.
A wrapper for the anyObjectContaining fuzzy matcher helper.
A wrapper for the anyStringLike fuzzy matcher helper.
This assertion passes, if the received value is approximately equal to the expected.
The notion of "approximate equality" is defined with the approx
attribute,
which is converted to the NumberApproximation with the NumberApproximation.fromApproximation.
The log method for the debug
log level
The log method for the error
log level
The log method for the info
log level
The log method for the log
log level
The log method for the warn
log level
This method create a standalone spy function, which tracks all calls to it. Tracking is done using the associated
spy instance, which is available as and
property. One can use the Spy class API to
verify the calls to the spy function.
For example:
const spyFunc = t.createSpy('onadd listener')
myObservable.addEventListener('add', spyFunc)
// do something that triggers the `add` event on the `myObservable`
t.expect(spyFunc).toHaveBeenCalled()
t.expect(spyFunc.calls.argsFor(1)).toEqual([ 'Arg1', 'Arg2' ])
See also: spyOn
A name of the spy for debugging purposes
Created function. The associated spy instance is assigned to it as the spy
property
This method creates an object, which properties are spy functions. Such object can later be used as a mockup.
This method can be called with one argument only, which should be an array of properties.
For example:
const mockup = t.createSpyObj('encoder-mockup', [ 'encode', 'decode' ])
// or just
const mockup = t.createSpyObj([ 'encode', 'decode' ])
mockup.encode('string')
mockup.decode('string')
t.expect(mockup.encode).toHaveBeenCalled()
See also: createSpy
An array of the property names. For each property name a spy function will be created.
A mockup object
This method installs a "spy" instead of normal function in some object. The "spy" is basically another function, which tracks its calls. With spies, one can verify that some function has been called and that it has been called with certain arguments.
By default, spy will call the original method and return a value from it. To enable different behavior, you can use one of these methods:
For example:
// spy that tracks the calls to `process`
const spy = t.spyOn(obj, 'process')
// or, if you need to also mock the method
const spy = t.spyOn(obj, 'process').callFake(() => {
// is called instead of `process` method
})
// call the method
obj.process('fast', 1)
t.expect(spy).toHaveBeenCalled();
t.expect(spy).toHaveBeenCalledWith('fast', 1);
See also createSpy, createSpyObj, toHaveBeenCalled, toHaveBeenCalledWith
See also the Spy class for additional details.
An object which property is being spied
A name of the property over which to install the spy.
spy Created spy instance
Alias for isGreaterOrEqual
This assertion passes if the received value is greater than expected, as defined by the >
operator.
It works for numbers, Dates and other values that overloads the valueOf
method.
This assertion passes if the received value is greater or equal than expected, as defined by the >=
operator.
It works for numbers, Dates and other values that overloads the valueOf
method.
Alias for isLessOrEqual
This assertion passes if the received value is less than expected, as defined by the <
operator.
It works for numbers, Dates and other values that overloads the valueOf
method.
This assertion passes if the received value is less than expected, as defined by the <=
operator.
It works for numbers, Dates and other values that overloads the valueOf
method.
This assertion passes if the provided observable
triggers the specified event(s) at least N
times times during
the rest of the test execution.
This method is a specialized form of the firesOk assertion.
The observable instance, anything that resolveObservable accepts
The name of the event(s)
The minimum number of events to be fired
Assertion description
This assertion counts the number of events, triggered by the provided observable
instance, during the
provided period and compares it with the expected numbers. The period is specified with the during
option and can be:
async
)The exact notion of what the observable
is, is defined by the resolveObservable method.
This method has several overloads. Normally it accepts a single object with various options:
await t.firesOk({
observable : document.body,
events : {
mousedown : 2,
mouseup : 2,
click : '> 1',
dblclick : '== 1'
},
during : async () {
await t.click([ 100, 100 ])
},
desc : 'Correct double click events fired'
})
This method also can be called in 2 additional shortcuts forms:
// shortcut form, multiple events
t.firesOk(observable, { event1 : 1, event2 : '>1' }, description)
// shortcut form, single event
t.firesOk(observable, eventName, 1, during?, description)
t.firesOk(observable, eventName, '>1', during?, description)
This assertion passes if the provided observable
triggers the specified event(s) exactly 1 time during
the rest of the test execution.
This method is a specialized form of the firesOk assertion.
The observable instance, anything that resolveObservable accepts
The name of the event(s)
Assertion description
Alias for wontFire method
This assertion passes, if the provided observable
, triggers the specified event
within the timeout
and fails otherwise. The timeout
can be specified using the object
argument,
if not provided the TestDescriptor.waitForTimeout is used.
This assertion passes if the provided observable
triggers the specified event(s) exactly N
times during
the rest of the test execution.
This method is a specialized form of the firesOk assertion.
The observable instance, anything that resolveObservable accepts
The name of the event(s)
Expected number of events
Assertion description
This assertion passes if the provided observable
does not trigger the specified event(s) during
the rest of the test execution.
This method is a specialized form of the firesOk assertion.
The observable instance, anything that resolveObservable accepts
The name of the event(s)
Assertion description
The current log level, the logger operates at.
This assertion passes if the provided iterable
contains the element
value.
The element comparison is performed deeply.
This method applies its 1st argument (if any) to the current instance using Object.assign()
.
Supposed to be overridden in the subclasses to customize the instance creation process.
This assertion passes if the provided iterable
does not contain the element
value.
The element comparison is performed deeply.
This is a type-safe static constructor method, accepting a single argument. If that argument is already an instance of this class - it is returned right away, otherwise the new constructor is used for instantiation.
This is a type-safe static constructor method, accepting a single argument, with the object, corresponding to the class properties. It will generate a compilation error, if unknown property is provided.
For example:
class MyClass extends Base {
prop : string
}
const instance : MyClass = MyClass.new({ prop : 'prop', wrong : 11 })
will produce:
TS2345: Argument of type '{ prop: string; wrong: number; }' is not assignable to parameter of type 'Partial<MyClass>'.
Object literal may only specify known properties, and 'wrong' does not exist in type 'Partial<MyClass>'
The only thing this constructor does is create an instance and call the initialize method on it, forwarding the first argument. The customization of instance is supposed to be performed in that method.
This assertion passes when provided string
matches the given pattern
.
The pattern
can be a RegExp
instance or string
, in the latter case the provided string
should contain the pattern
as a substring.
This assertion passes when provided string
does not matches the given pattern
.
The pattern
can be a RegExp
instance or string
, in the latter case the provided string
should not contain the pattern
as a substring.
This method allows you to execute some "cleanup" code hook after every "it" section of the current test.
It is usually used to clear some global resource, used by the tests. Sometimes it is actually more convenient,
instead of clearing the resource in the afterEach
do that in the beforeEach
, after checking that resource
has been allocated. In this way, if you'll be debugging some individual test section, the resource will still be
available after the test completion.
it
sections can be nested, and hooks can be added at every level.
afterEach
hooks are executed starting from the innermost level.
The 1st argument of the hook function is always the test instance being launched.
If the hook function is async
Siesta will await
until it completes.
This method can be called several times, providing several hook functions to execute.
import { it, beforeEach } from "@bryntum/siesta/index.js"
let file
beforeEach(async () => file = await OPEN_FILE())
afterEach(async () => await CLOSE_FILE(file))
it('Test section', async t => {
const content = await READ_FILE(file)
})
Backward compatibility. The hook function also accepts an optional second argument, which is a callback, which should be called, indicating that hook execution has complete. If it is provided, Siesta will await both for any promise returned from the hook function and for the call to callback.
This method allows you to execute some "setup" code hook before every "it" section of the current test. It is usually used to restore some global state to the predefined value.
it
sections can be nested, and hooks can be added at every level.
beforeEach
hooks are executed starting from the outermost level.
The 1st argument of the hook function is always the test instance being launched.
If the hook function is async
Siesta will await
until it completes.
This method can be called several times, providing several hook functions to execute.
import { it, beforeEach } from "@bryntum/siesta/index.js"
let sum
beforeEach(async t => sum = 0)
it('Test section #1', async t => {
sum++
t.equal(sum, 1)
})
it('Test section #2', async t => {
sum += 2
t.equal(sum, 2)
})
Backward compatibility. The hook function also accepts an optional second argument, which is a callback, which should be called, indicating that hook execution has complete. If it is provided, Siesta will await both for any promise returned from the hook function and for the call to callback.
An alias for iit
An alias for it
This is an "exclusive" version of the regular it test section. When such exclusive section is found, the other regular test sections at the same level will not be executed, only "exclusive" ones.
This method creates a "parent" node in the test file, grouping assertions together. Such node is called "test section" or "sub-test". Sub-tests can be nested arbitrarily.
The 1st argument for this method can be either a string or a configuration object for this test's descriptor.
The string value corresponds to { title : 'string_value' }
.
The configuration object of the nested test section "extends" the configuration object of the parent section.
For example if parent section sets the defaultTimeout to a certain value, the nested section will use that value too.
import { it } from "@bryntum/siesta/index.js"
it({ title : 'Test section', defaultTimeout : 1000 }, async t => {
t.it('Nested test section', async t => {
// will fail within 1s
await t.waitFor(() => false)
})
})
See also iit, xit methods to quickly isolate/exclude a test section.
To create a top-level test section, the it function or it static method should be used. These aliases can actually be used inside the test function as well, however it is recommended to use the method on the test instance.
import { it, Test } from "@bryntum/siesta/index.js"
it('Test section', async (t : Test) => {
t.it({ title : 'Nested section', isTodo : true }, async (t : Test) => {
...
})
})
// The following two lines are identical
it('Test section', async (t : Test) => { ... }) // `it` function
Test.it('Test section', async (t : Test) => { ... }) // static `Test.it` method
The configuration descriptor for the test section
The test function. Can be async
if needed or return Promise
.
This is a no-op method, allowing you to quickly ignore some test sections - just add x
("exclude") to the section call.
Alias for Test.iit.
Alias for Test.it.
Alias for Test.iit. Should be used for top-level sub-tests only.
Static alias for Test.it. Should be used for top-level sub-tests only. Can be useful if you create your own subclass of the test class.
Alias for Test.xit.
Alias for Test.xit. Should be used for top-level sub-tests only.
This assertion passes if the received value
is a Array
.
This assertion passes if the received value
is a Boolean
.
This assertion passes if the received value
is a Date
.
This assertion passes if the received value
is a Function
.
This assertion passes if the received value
is an instance of the cls
class. It works for native built-in classes
too.
For example:
t.isInstanceOf([ 1, 2, 3 ], Array)
t.isInstanceOf(1, Number)
The received value
The class constructor
This assertion passes if the received value
is a Map
.
This assertion passes if the received value
is a Number
.
This assertion passes if the received value
is a Object
.
This assertion passes if the received value
is a RegExp
.
This assertion passes if the received value
is a Set
.
This assertion passes if the received value
is a String
.
This assertion passes if the received value
is a WeakMap
.
This assertion passes if the received value
is a WeakSet
.
Simulates a click on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.
Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.
This method has 2 overloads and target
and offset
can be given either as positional arguments, or in the form
of the MouseActionOptions object.
For example:
await t.click('.css-class .another-css.class', [ 30, 40 ])
await t.click('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
await t.click({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })
A special case of
await t.click()
is equivalent to t.click([])
- clicking at the current cursor location.
Simulates a double click on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.
Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.
This method has 2 overloads and target
and offset
can be given either as positional arguments, or in the form
of the MouseActionOptions object.
For example:
await t.doubleClick('.css-class .another-css.class', [ 30, 40 ])
await t.doubleClick('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
await t.doubleClick({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })
A special case of
await t.doubleClick()
is equivalent to t.doubleClick([])
- clicking at the current cursor location.
Simulates a drag action, from the given source
element, by the given delta.
For example:
await t.dragBy('#source', [ 10, 20 ], { ctrlKey : true })
await t.dragBy([], [ 10, 20 ], { ctrlKey : true }) // drag from current cursor position
Simulates a drag action, from the source
element, to the target
element
This method has several overloads and source
and target
can be provided either as positional arguments, or
as properties of the DragActionOptions object.
For example:
await t.dragTo('#source', '#target', { ctrlKey : true })
await t.dragTo({ source : '#source', target : '#target', ctrlKey : true })
Simulates a key down action on the given target
element.
For example:
await t.keyDown('#source', 's')
Simulates a single key press on the given target
element.
For example:
await t.keyPress('#source', 's', { ctrlKey : true })
Simulates a key up action on the given target
element.
For example:
await t.keyUp('#source', 's')
Simulates a "mouse down" action on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.
Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.
This method has 2 overloads and target
and offset
can be given either as positional arguments, or in the form
of the MouseActionOptions object.
For example:
await t.mouseDown('.css-class .another-css.class', [ 30, 40 ])
await t.mouseDown('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
await t.mouseDown({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })
A special case of
await t.mouseDown()
is equivalent to t.mouseDown([])
- clicking at the current cursor location.
Simulates a "mouse up" action on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.
Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.
This method has 2 overloads and target
and offset
can be given either as positional arguments, or in the form
of the MouseActionOptions object.
For example:
await t.mouseUp('.css-class .another-css.class', [ 30, 40 ])
await t.mouseUp('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
await t.mouseUp({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })
A special case of
await t.mouseUp()
is equivalent to t.mouseUp([])
- clicking at the current cursor location.
Simulates a relative "mouse move" action, from the current position, by the given delta.
This method has several overloads and delta
can be provided either as a Point or 2 positional arguments.
For example:
await t.moveMouseBy(30, 40)
await t.moveMouseBy([ 30, 40 ], { ctrlKey : true })
Simulates "mouse move" action to the given ActionTarget at the given ActionTargetOffset point. If offset is not provided, cursor moves to the center of the visible part of the target element.
Before performing mouse move, Siesta waits for the target element to become actionable.
This method has several overloads and target
and offset
can be given either as positional arguments, or in the form
of the MouseActionOptions object.
For example:
await t.moveMouseTo(30, 40)
await t.moveMouseTo([ 30, 40 ])
await t.moveMouseTo('.css-class .another-css.class', [ 30, 40 ])
await t.moveMouseTo('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
await t.moveMouseTo({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })
Simulates a right click on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.
Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.
This method has 2 overloads and target
and offset
can be given either as positional arguments, or in the form
of the MouseActionOptions object.
For example:
await t.rightClick('.css-class .another-css.class', [ 30, 40 ])
await t.rightClick('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
await t.rightClick({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })
A special case of
await t.rightClick()
is equivalent to t.rightClick([])
- clicking at the current cursor location.
Simulates keyboard typing on the given target
element. Performs all actions that a real user would do,
including pressing and releasing a keyboard button for every character.
If target is provided as []
or null
, the typing will be performed on the currently focused element.
Otherwise, target will be resolved and focused.
Simulation of pressing the special keys is supported. You can specify them, by using their all uppercased
key name inside the square brackets: [ENTER]
, [BACKSPACE]
, [LEFT]
. To type [ENTER]
as plain text and not as
a special character - use double square brackets: [[ENTER]
]. The full list of special key names is
available here.
To specify a control key like "SHIFT / CONTROL / ALT / META" of to be pressed during typing, use the options
argument.
For example:
await t.type('#source', 'some text[ENTER]', { ctrlKey : true })
The text to type
Additional options for the action
Generated using TypeDoc
Test class for code running in the browser environment.
Please refer to the TestDescriptorBrowser documentation for the list of available config options.