Permalink
Browse files

fix(Target): `Target.of` works for Targets defined using the `by.id` …

…locator

`by.id` uses `by.css` under the hood. This means that the replacement token - {0} - was

double-escaped to become \{0\}, which made the Interpolator ignore it.
  • Loading branch information...
jan-molak committed Sep 12, 2016
1 parent 961cdf1 commit e462f7a41f08ab2958e508e10ceb0fb7593fc96c
@@ -31,7 +31,7 @@ describe ('Target', () => {
expect(target.called('"Sign Up" button').toString()).to.equal('the "Sign Up" button');
});
it ('can have a locator defined using tokens to be resolved at a later stage', () => {
it ('can have a CSS locator defined using tokens to be resolved at a later stage', () => {
let byLocatorTemplate = webdriver.By.css('{0}#sign-up.{1}'),
element = sinon.spy(),
target = Target.the('"Sign Up" button').located(byLocatorTemplate);
@@ -41,12 +41,31 @@ describe ('Target', () => {
expect(element).to.have.been.calledWith(webdriver.By.css('button#sign-up.active'));
});
it ('can have an ID locator defined using tokens to be resolved at a later stage', () => {
let byLocatorTemplate = webdriver.By.id('sign-up-{0}'),
element = sinon.spy(),
target = Target.the('"Sign Up" button').located(byLocatorTemplate);
target.of('button').resolveUsing(element);
expect(element).to.have.been.calledWith(webdriver.By.id('sign-up-button'));
});
it ('correctly overrides the toString method of the cloned locator', () => {
let byLocatorTemplate = webdriver.By.id('sign-up-{0}'),
target = Target.the('"Sign Up" button').located(byLocatorTemplate);
let result = (<any> target.of('button')).locator.toString();
expect(result).to.equal('By(css selector, *[id="sign-up-button"])');
});
it ('can describe a locator matching multiple elements', () => {
let byGroupLocator = webdriver.By.css('ul>li'),
element = { all: sinon.spy() },
target = Target.the('items').located(byGroupLocator);
target.of('button', 'active').resolveAllUsing(element);
target.resolveAllUsing(element);
expect(element.all).to.have.been.calledWith(webdriver.By.css('ul>li'));
});
@@ -55,7 +55,7 @@ class Interpolated {
}
private interpolated(template: string, replacements: string[]) {
let argToken = /{(\d+)}/g,
let argToken = /\\?\{(\d+)\\?\}/g,
interpolator = (token: string, field: number) => replacements[ field ];
return template.replace(argToken, interpolator);

0 comments on commit e462f7a

Please sign in to comment.