Permalink
Browse files

fix(protractor): target.of() Dynamic selector accepts both string and…

… number arguments

affects: serenity-js

ISSUES CLOSED: #93
  • Loading branch information...
jan-molak committed Sep 25, 2017
1 parent f743361 commit a710f61ae89ccc402d455344c6e0df22b8e5764c
@@ -60,6 +60,17 @@ describe ('Target', () => {
expect(element).to.have.been.calledWith(webdriver.By.id('sign-up-button'));
});
it ('can have an XPath locator defined using numeric tokens to be resolved at a later stage', () => {
const
byLocatorTemplate = webdriver.By.xpath(`//ul[@id='items']//li[{0}]`),
element = sinon.spy(),
target = Target.the('n-th item').located(byLocatorTemplate);
target.of(3).resolveUsing(element);
expect(element).to.have.been.calledWith(webdriver.By.xpath(`//ul[@id='items']//li[3]`));
});
it ('correctly overrides the toString method of the cloned locator', () => {
const
byLocatorTemplate = webdriver.By.id('sign-up-{0}'),
@@ -8,7 +8,7 @@ export class Target {
located: (byLocator: Locator): Target => new Target(name, byLocator),
})
of(...tokenReplacements: string[]): Target {
of(...tokenReplacements: Array<string|number>): Target {
return new Target(describeAs(this.name, ...tokenReplacements), new Interpolated(this.locator).with(tokenReplacements));
}
@@ -37,7 +37,7 @@ class Interpolated {
constructor(private locator: Locator) {
}
public with(tokenReplacements: string[]) {
public with(tokenReplacements: Array<string|number>) {
const unescaped = template => template.replace(/\\{(\d+)\\}/, '{$1}');
const asString = (locator: Locator): string => unescaped(`${(locator as any).value}`);

0 comments on commit a710f61

Please sign in to comment.