Skip to content

Commit 331eedc

Browse files
committed
add select's implicit label locator strategy
1 parent 3fdecee commit 331eedc

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

packages/selianize/__tests__/selection.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ describe("selection location code emitter", () => {
2121
it("should fail to emit unknown selection locator", () => {
2222
return expect(SelectionEmitter.emit("notExists=element")).rejects.toThrow("Unknown selection locator notExists");
2323
});
24+
it("should assume when no selector is given that it is the label locator", () => {
25+
return expect(SelectionEmitter.emit("label")).resolves.toBe("By.xpath(`//option[. = 'label']`)");
26+
});
2427
it("should emit label locator", () => {
2528
const type = "label";
2629
const selector = "a label";

packages/selianize/src/selection.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ const emitters = {
2525
export function emit(location) {
2626
return new Promise(async (res, rej) => {
2727
const [type, selector] = location.split("=");
28-
if (emitters[type]) {
28+
if (emitters[type] && selector) {
2929
let result = await emitters[type](selector);
3030
res(result);
31+
} else if (!selector) {
32+
// no selector strategy given, assuming label
33+
res(await emitters["label"](type));
3134
} else {
3235
rej(new Error(`Unknown selection locator ${type}`));
3336
}

tests/examples/select-examples.side

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,46 @@
2727
"targets": [],
2828
"value": "One"
2929
}]
30+
}, {
31+
"id": "58c35d38-9091-4f2e-a42f-c85ff8fdb30e",
32+
"name": "select strategies",
33+
"commands": [{
34+
"id": "ff2730d3-b18d-4425-9f9c-5f9364bfef1f",
35+
"comment": "",
36+
"command": "open",
37+
"target": "/select.html",
38+
"targets": [],
39+
"value": ""
40+
}, {
41+
"id": "48d4aacc-418b-4684-bfe8-cbb75356adbb",
42+
"comment": "",
43+
"command": "store",
44+
"target": "Two",
45+
"targets": [],
46+
"value": "label"
47+
}, {
48+
"id": "34c991ee-db67-4e15-be7d-9f84be17bdda",
49+
"comment": "",
50+
"command": "select",
51+
"target": "id=select",
52+
"targets": [],
53+
"value": "${label}"
54+
}, {
55+
"id": "951c9516-0dda-4d66-82b2-59ffa9837c99",
56+
"comment": "",
57+
"command": "assertSelectedLabel",
58+
"target": "id=select",
59+
"targets": [],
60+
"value": "Two"
61+
}]
3062
}],
3163
"suites": [{
3264
"id": "e7102959-f85f-4d57-9a39-846e52239b1b",
3365
"name": "select",
3466
"persistSession": false,
3567
"parallel": false,
3668
"timeout": 300,
37-
"tests": ["6acbf258-048b-4493-8478-accfc444fb3d"]
69+
"tests": ["6acbf258-048b-4493-8478-accfc444fb3d", "58c35d38-9091-4f2e-a42f-c85ff8fdb30e"]
3870
}],
3971
"urls": ["https://en.wikipedia.org/"],
4072
"plugins": [],
@@ -43,11 +75,14 @@
4375
"suites": [{
4476
"name": "select",
4577
"persistSession": false,
46-
"code": "global.BASE_URL = configuration.baseUrl || 'http://nginx:80';let vars = {};jest.setTimeout(300000);describe(\"select\", () => {it(\"select-verify-labels\", async () => {await tests.select_verify_labels(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});});"
78+
"code": "global.BASE_URL = configuration.baseUrl || 'http://nginx:80';let vars = {};jest.setTimeout(300000);describe(\"select\", () => {it(\"select-verify-labels\", async () => {await tests.select_verify_labels(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});it(\"select strategies\", async () => {await tests.select_strategies(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});});"
4779
}],
4880
"tests": [{
4981
"name": "select-verify-labels",
5082
"code": "tests.select_verify_labels = async function select_verify_labels(driver, vars) {await driver.get(BASE_URL + \"/select.html\");await driver.wait(until.elementLocated(By.id(`select`)), configuration.timeout);await driver.findElement(By.id(`select`)).then(element => {element.getAttribute(\"value\").then(selectedValue => {element.findElement(By.xpath('option[@value=\"'+selectedValue+'\"]')).then(selectedOption => {selectedOption.getText().then(selectedLabel => {expect(selectedLabel).toBe(`One`);});});});});await driver.wait(until.elementLocated(By.id(`select`)), configuration.timeout);await driver.findElement(By.id(`select`)).then(element => {element.getAttribute(\"value\").then(selectedValue => {element.findElement(By.xpath('option[@value=\"'+selectedValue+'\"]')).then(selectedOption => {selectedOption.getText().then(selectedLabel => {expect(selectedLabel).toBe(`One`);});});});});}"
83+
}, {
84+
"name": "select strategies",
85+
"code": "tests.select_strategies = async function select_strategies(driver, vars) {await driver.get(BASE_URL + \"/select.html\");vars[\"label\"] = `Two`;await driver.wait(until.elementLocated(By.id(`select`)), configuration.timeout);await driver.findElement(By.id(`select`)).then(element => {element.findElement(By.xpath(`//option[. = '${vars.label}']`)).then(option => {option.click();});});await driver.wait(until.elementLocated(By.id(`select`)), configuration.timeout);await driver.findElement(By.id(`select`)).then(element => {element.getAttribute(\"value\").then(selectedValue => {element.findElement(By.xpath('option[@value=\"'+selectedValue+'\"]')).then(selectedOption => {selectedOption.getText().then(selectedLabel => {expect(selectedLabel).toBe(`Two`);});});});});}"
5186
}]
5287
},
5388
"dependencies": {}

0 commit comments

Comments
 (0)