Skip to content

Commit 4e99af4

Browse files
committed
allow stored variables to partially affect the locators
1 parent bdb0ab7 commit 4e99af4

File tree

6 files changed

+88
-88
lines changed

6 files changed

+88
-88
lines changed

packages/selianize/__tests__/command.spec.js

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

packages/selianize/__tests__/location.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,40 @@ describe("location code emitter", () => {
2727
it("should emit id locator", () => {
2828
const type = "id";
2929
const selector = "someId";
30-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.id("${selector}")`);
30+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.id(\`${selector}\`)`);
3131
});
3232
it("should emit link locator", () => {
3333
const type = "link";
3434
const selector = "someLink";
35-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.linkText("${selector}")`);
35+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.linkText(\`${selector}\`)`);
3636
});
3737
it("should emit css locator", () => {
3838
const type = "css";
3939
const selector = "someCss";
40-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css("${selector}")`);
40+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css(\`${selector}\`)`);
4141
});
4242
it("should emit css locator with `=` sign", () => {
4343
const type = "css";
4444
const selector = "a[title=JScript]";
45-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css("${selector}")`);
45+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css(\`${selector}\`)`);
4646
});
4747
it("should escape quotes in locator strings", () => {
4848
const type = "css";
4949
const selector = "a[title=\"escaped\"]";
50-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe("By.css(\"a[title=\\\"escaped\\\"]\")");
50+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe("By.css(`a[title=\\\"escaped\\\"]`)");
5151
});
5252
it("should emit xpath locator", () => {
5353
const type = "xpath";
5454
const selector = "someXpath";
55-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.xpath("${selector}")`);
55+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.xpath(\`${selector}\`)`);
5656
});
5757
it("should emit implicit xpath locator", () => {
5858
const selector = "//test=xpath";
59-
return expect(LocationEmitter.emit(selector)).resolves.toBe(`By.xpath("${selector}")`);
59+
return expect(LocationEmitter.emit(selector)).resolves.toBe(`By.xpath(\`${selector}\`)`);
6060
});
6161
it("should emit name locator", () => {
6262
const type = "name";
6363
const selector = "someName";
64-
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.name("${selector}")`);
64+
return expect(LocationEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.name(\`${selector}\`)`);
6565
});
6666
});

packages/selianize/__tests__/selection.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ describe("selection location code emitter", () => {
2424
it("should emit label locator", () => {
2525
const type = "label";
2626
const selector = "a label";
27-
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.xpath("//option[. = '${selector}']")`);
27+
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.xpath(\`//option[. = '${selector}']\`)`);
2828
});
2929
it("should emit id locator", () => {
3030
const type = "id";
3131
const selector = "someId";
32-
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css("*[id=${selector}]")`);
32+
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css(\`*[id=${selector}]\`)`);
3333
});
3434
it("should emit value locator", () => {
3535
const type = "value";
3636
const selector = "someValue";
37-
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css("*[value=${selector}]")`);
37+
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css(\`*[value=${selector}]\`)`);
3838
});
3939
it("should emit id locator", () => {
4040
const type = "index";
4141
const selector = "2";
42-
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css("*:nth-child(${selector})")`);
42+
return expect(SelectionEmitter.emit(`${type}=${selector}`)).resolves.toBe(`By.css(\`*:nth-child(${selector})\`)`);
4343
});
4444
});

packages/selianize/src/command.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,23 @@ async function emitVerifyElementNotPresent(locator) {
217217
}
218218

219219
async function emitVerifySelectedValue(locator, value) {
220-
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.toHaveSelectedValue("${value}");`);
220+
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.toHaveSelectedValue(\`${value}\`);`);
221221
}
222222

223223
async function emitVerifySelectedLabel(locator, labelValue) {
224-
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await driver.findElement(${await LocationEmitter.emit(locator)}).then(element => {element.getAttribute("value").then(selectedValue => {element.findElement(By.xpath('option[@value="'+selectedValue+'"]')).then(selectedOption => {selectedOption.getText().then(selectedLabel => {expect(selectedLabel).toBe("${labelValue}");});});});});`);
224+
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await driver.findElement(${await LocationEmitter.emit(locator)}).then(element => {element.getAttribute("value").then(selectedValue => {element.findElement(By.xpath('option[@value="'+selectedValue+'"]')).then(selectedOption => {selectedOption.getText().then(selectedLabel => {expect(selectedLabel).toBe(\`${labelValue}\`);});});});});`);
225225
}
226226

227227
async function emitVerifyNotSelectedValue(locator, value) {
228-
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.not.toHaveSelectedValue("${value}");`);
228+
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.not.toHaveSelectedValue(\`${value}\`);`);
229229
}
230230

231231
async function emitVerifyValue(locator, value) {
232-
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.toHaveValue("${value}");`);
232+
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.toHaveValue(\`${value}\`);`);
233233
}
234234

235235
async function emitVerifyText(locator, text) {
236-
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.toHaveText("${text}");`);
236+
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await expect(driver.findElement(${await LocationEmitter.emit(locator)})).resolves.toHaveText(\`${text}\`);`);
237237
}
238238

239239
async function emitVerifyNotText(locator, text) {
@@ -245,7 +245,7 @@ async function emitVerifyTitle(title) {
245245
}
246246

247247
async function emitStore(value, varName) {
248-
return Promise.resolve(`vars["${varName}"] = "${value}";`);
248+
return Promise.resolve(`vars["${varName}"] = \`${value}\`;`);
249249
}
250250

251251
async function emitStoreText(locator, varName) {
@@ -284,7 +284,7 @@ async function emitSelectFrame(frameLocation) {
284284

285285
function emitSelectWindow(windowLocation) {
286286
if (/^name=/.test(windowLocation)) {
287-
return Promise.resolve(`await driver.switchTo().window("${windowLocation.split("name=")[1]}");`);
287+
return Promise.resolve(`await driver.switchTo().window(\`${windowLocation.split("name=")[1]}\`);`);
288288
} else {
289289
return Promise.reject(new Error("Can only emit `select window` using name locator"));
290290
}
@@ -307,11 +307,11 @@ async function emitMouseOut(locator) {
307307
}
308308

309309
function emitAssertAlert(alertText) {
310-
return Promise.resolve(`await driver.switchTo().alert().then(alert => {alert.getText().then(text => {expect(text).toBe("${alertText}");});});`);
310+
return Promise.resolve(`await driver.switchTo().alert().then(alert => {alert.getText().then(text => {expect(text).toBe(\`${alertText}\`);});});`);
311311
}
312312

313313
function emitAssertAlertAndAccept(alertText) {
314-
return Promise.resolve(`await driver.switchTo().alert().then(alert => {alert.getText().then(text => {expect(text).toBe("${alertText}");alert.accept();});});`);
314+
return Promise.resolve(`await driver.switchTo().alert().then(alert => {alert.getText().then(text => {expect(text).toBe(\`${alertText}\`);alert.accept();});});`);
315315
}
316316

317317
function emitChooseOkOnNextConfirmation() {
@@ -323,11 +323,11 @@ function emitChooseCancelOnNextConfirmation() {
323323
}
324324

325325
function emitAnswerOnNextPrompt(textToSend) {
326-
return Promise.resolve(`await driver.switchTo().alert().then(alert => {alert.sendKeys("${textToSend}").then(() => {alert.accept();});});`);
326+
return Promise.resolve(`await driver.switchTo().alert().then(alert => {alert.sendKeys(\`${textToSend}\`).then(() => {alert.accept();});});`);
327327
}
328328

329329
async function emitEditContent(locator, content) {
330-
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await driver.findElement(${await LocationEmitter.emit(locator)}).then(element => {driver.executeScript("if(arguments[0].contentEditable === 'true') {arguments[0].innerHTML = '${content}'}", element);});`);
330+
return Promise.resolve(`await driver.wait(until.elementLocated(${await LocationEmitter.emit(locator)}));await driver.findElement(${await LocationEmitter.emit(locator)}).then(element => {driver.executeScript(\`if(arguments[0].contentEditable === 'true') {arguments[0].innerHTML = '${content}'}\`, element);});`);
331331
}
332332

333333
async function emitSubmit(locator) {

packages/selianize/src/location.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ export default {
4747
};
4848

4949
function emitId(selector) {
50-
return Promise.resolve(`By.id("${selector}")`);
50+
return Promise.resolve(`By.id(\`${selector}\`)`);
5151
}
5252

5353
function emitName(selector) {
54-
return Promise.resolve(`By.name("${selector}")`);
54+
return Promise.resolve(`By.name(\`${selector}\`)`);
5555
}
5656

5757
function emitLink(selector) {
58-
return Promise.resolve(`By.linkText("${selector}")`);
58+
return Promise.resolve(`By.linkText(\`${selector}\`)`);
5959
}
6060

6161
function emitCss(selector) {
62-
return Promise.resolve(`By.css("${selector}")`);
62+
return Promise.resolve(`By.css(\`${selector}\`)`);
6363
}
6464

6565
function emitXpath(selector) {
66-
return Promise.resolve(`By.xpath("${selector}")`);
66+
return Promise.resolve(`By.xpath(\`${selector}\`)`);
6767
}

packages/selianize/src/selection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ export default {
3939
};
4040

4141
function emitId(id) {
42-
return Promise.resolve(`By.css("*[id=${id}]")`);
42+
return Promise.resolve(`By.css(\`*[id=${id}]\`)`);
4343
}
4444

4545
function emitValue(value) {
46-
return Promise.resolve(`By.css("*[value=${value}]")`);
46+
return Promise.resolve(`By.css(\`*[value=${value}]\`)`);
4747
}
4848

4949
function emitLabel(label) {
50-
return Promise.resolve(`By.xpath("//option[. = '${label}']")`);
50+
return Promise.resolve(`By.xpath(\`//option[. = '${label}']\`)`);
5151
}
5252

5353
function emitIndex(index) {
54-
return Promise.resolve(`By.css("*:nth-child(${index})")`);
54+
return Promise.resolve(`By.css(\`*:nth-child(${index})\`)`);
5555
}

0 commit comments

Comments
 (0)