AngularJS selector extentions

September 22, 2017 · View on GitHub

AngularJSSelector contains a set of static methods to search for an HTML element by the specified binding (byModel, byBinding and etc.).

Usage

import { AngularJSSelector } from 'testcafe-angular-selectors';
import { Selector } from 'testcafe';

fixture `TestFixture`
    .page('http://todomvc.com/examples/angularjs/');

test('add new item', async t => {
    await t
        .typeText(AngularJSSelector.byModel('newTodo'), 'new item')
        .pressKey('enter')
        .expect(Selector('#todo-list').visible).ok();
});

See more examples here.

API

byBinding

Find elements by text binding. Does a partial match, so any elements bound to variables containing the input string will be returned.

AngularJSSelector.byBinding(bindingDescriptor, parentSelector)
ParameterDescription
bindingDescriptorThe JavaScript expression to which the element's textContent is bound.
parentSelector (optional)A TestCafe selector. If specified, TestCafe will search for the target element among the descendants of the element identified by this selector.

We don't support deprecated syntax AngularJSSelector.byBinding('{{person.name}}')

byExactBinding

Find elements by exact binding.

AngularJSSelector.byExactBinding(bindingDescriptor, parentSelector)
ParameterDescription
bindingDescriptorThe JavaScript expression to which the element's textContent is bound.
parentSelector (optional)A TestCafe selector. If specified, TestCafe will search for the target element among the descendants of the element identified by this selector.

byModel

Find elements by 'ng-model' expression

AngularJSSelector.byModel(model, parentSelector)
ParameterDescription
modelThe JavaScript expression used to bind a property on the scope to an input, select, textarea (or a custom form control).
parentSelector (optional)A TestCafe selector. If specified, TestCafe will search for the target element among the descendants of the element identified by this selector.

byOptions

Find elements by 'ng-options' expression.

AngularJSSelector.byOptions(optionsDescriptor, parentSelector)
ParameterDescription
optionsDescriptorThe JavaScript expression used to generate a list of
parentSelector (optional)A TestCafe selector. If specified, TestCafe will search for the target element among the descendants of the element identified by this selector.

byRepeater

Find elements by repeater. Does a partial match, so any elements bound to variables containing the input string will be returned.

AngularJSSelector.byRepeater(repeatDescriptor, parentSelector)
ParameterDescription
repeatDescriptorThe JavaScript expression used to instantiate a template.
parentSelector (optional)A TestCafe selector. If specified, TestCafe will search for the target element among the descendants of the element identified by this selector.

byExactRepeat

Find elements by exact repeater.

AngularJSSelector.byExactRepeater(repeatDescriptor, parentSelector)
ParameterDescription
repeatDescriptorThe JavaScript expression used to instantiate a template.
parentSelector (optional)A TestCafe selector. If specified, TestCafe will search for the target element among the descendants of the element identified by this selector.