Skip to content

Commit e161448

Browse files
authored
Merge branch 'master' into rewrite-targetselector-class
2 parents 84aacac + 388b35e commit e161448

File tree

14 files changed

+106
-118
lines changed

14 files changed

+106
-118
lines changed

packages/selenium-ide/src/content/locatorBuilders.js

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { MozillaBrowserBot } from "./selenium-browserbot";
1818
import { core } from "./closure-polyfill";
19-
const exactMatchPattern = window.global.exactMatchPattern;
19+
import { exactMatchPattern } from "./targetSelector";
2020

2121
export default function LocatorBuilders(window) {
2222
this.window = window;
@@ -290,11 +290,6 @@ LocatorBuilders.prototype.preciseXPath = function(xpath, e) {
290290
* ===== builders =====
291291
*/
292292

293-
LocatorBuilders.add("ui", function(pageElement) {
294-
return UIMap.getInstance().getUISpecifierString(pageElement,
295-
this.window.document);
296-
});
297-
298293
LocatorBuilders.add("id", function(e) {
299294
if (e.id) {
300295
return "id=" + e.id;
@@ -329,58 +324,6 @@ LocatorBuilders.add("css", function(e) {
329324
return "css=" + sub_path;
330325
});
331326

332-
/*
333-
* This function is called from DOM locatorBuilders
334-
*/
335-
LocatorBuilders.prototype.findDomFormLocator = function(form) {
336-
if (form.hasAttribute("name")) {
337-
let name = form.getAttribute("name");
338-
let locator = "document." + name;
339-
if (this.findElement(locator) == form) {
340-
return locator;
341-
}
342-
locator = "document.forms['" + name + "']";
343-
if (this.findElement(locator) == form) {
344-
return locator;
345-
}
346-
}
347-
let forms = this.window.document.forms;
348-
for (let i = 0; i < forms.length; i++) {
349-
if (form == forms[i]) {
350-
return "document.forms[" + i + "]";
351-
}
352-
}
353-
return null;
354-
};
355-
356-
LocatorBuilders.add("dom:name", function(e) {
357-
if (e.form && e.name) {
358-
let formLocator = this.findDomFormLocator(e.form);
359-
if (formLocator) {
360-
let candidates = [formLocator + "." + e.name,
361-
formLocator + ".elements['" + e.name + "']"
362-
];
363-
for (let c = 0; c < candidates.length; c++) {
364-
let locator = candidates[c];
365-
let found = this.findElement(locator);
366-
if (found) {
367-
if (found == e) {
368-
return locator;
369-
} else if (found instanceof NodeList) {
370-
// multiple elements with same name
371-
for (let i = 0; i < found.length; i++) {
372-
if (found[i] == e) {
373-
return locator + "[" + i + "]";
374-
}
375-
}
376-
}
377-
}
378-
}
379-
}
380-
}
381-
return null;
382-
});
383-
384327
LocatorBuilders.add("xpath:link", function(e) {
385328
if (e.nodeName == "A") {
386329
let text = e.textContent;
@@ -477,21 +420,6 @@ LocatorBuilders.add("xpath:href", function(e) {
477420
return null;
478421
});
479422

480-
LocatorBuilders.add("dom:index", function(e) {
481-
if (e.form) {
482-
let formLocator = this.findDomFormLocator(e.form);
483-
if (formLocator) {
484-
let elements = e.form.elements;
485-
for (let i = 0; i < elements.length; i++) {
486-
if (elements[i] == e) {
487-
return formLocator + ".elements[" + i + "]";
488-
}
489-
}
490-
}
491-
}
492-
return null;
493-
});
494-
495423
LocatorBuilders.add("xpath:position", function(e, opt_contextNode) {
496424
//this.log.debug("positionXPath: e=" + e);
497425
let path = "";
@@ -515,4 +443,4 @@ LocatorBuilders.add("xpath:position", function(e, opt_contextNode) {
515443
});
516444
// Samit: Warning: The old method of setting the order using LocatorBuilders.order is now deprecated
517445
// You can change the priority of builders by setting LocatorBuilders.order.
518-
//LocatorBuilders.order = ['ui', 'id', 'link', 'name', 'css', 'dom:name', 'xpath:link', 'xpath:img', 'xpath:attributes', 'xpath:idRelative', 'xpath:href', 'dom:index', 'xpath:position'];
446+
//LocatorBuilders.order = ['id', 'link', 'name', 'css', 'xpath:link', 'xpath:img', 'xpath:attributes', 'xpath:idRelative', 'xpath:href', 'xpath:position'];

packages/selenium-ide/src/content/prompt-injector.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ if (window === window.top) {
4040
}
4141
record("assertPrompt", [[event.data.recordedMessage]], "", false, event.data.frameLocation);
4242
if (event.data.recordedResult != null) {
43-
record("webdriverAnswerOnNextPrompt", [[event.data.recordedResult]], "", false, event.data.frameLocation);
43+
record("webdriverAnswerOnVisiblePrompt", [[event.data.recordedResult]], "", false, event.data.frameLocation);
4444
} else {
45-
record("webdriverChooseCancelOnNextPrompt", [[""]], "", false, event.data.frameLocation);
45+
record("webdriverChooseCancelOnVisiblePrompt", [[""]], "", false, event.data.frameLocation);
4646
}
4747
break;
4848
case "confirm":
@@ -53,9 +53,9 @@ if (window === window.top) {
5353
}
5454
record("assertConfirmation", [[event.data.recordedMessage]], "", false, event.data.frameLocation);
5555
if (event.data.recordedResult == true) {
56-
record("webdriverChooseOkOnNextConfirmation", [[""]], "", false, event.data.frameLocation);
56+
record("webdriverChooseOkOnVisibleConfirmation", [[""]], "", false, event.data.frameLocation);
5757
} else {
58-
record("webdriverChooseCancelOnNextConfirmation", [[""]], "", false, event.data.frameLocation);
58+
record("webdriverChooseCancelOnVisibleConfirmation", [[""]], "", false, event.data.frameLocation);
5959
}
6060
break;
6161
case "alert":

packages/selenium-ide/src/content/targetSelector.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@
1717

1818
// Modified in tools.js from selenium-IDE
1919

20+
export function exactMatchPattern(string) {
21+
if (string != null && (string.match(/^\w*:/) || string.indexOf("?") >= 0 || string.indexOf("*") >= 0)) {
22+
return "exact:" + string;
23+
} else {
24+
return string;
25+
}
26+
}
27+
2028
class TargetSelector {
2129
constructor(callback, cleanupCallback) {
2230
this.callback = callback;
2331
this.cleanupCallback = cleanupCallback;
24-
2532
// This is for XPCOM/XUL addon and can't be used
2633
//var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
2734
//this.win = wm.getMostRecentWindow('navigator:browser').getBrowser().contentWindow;

packages/selenium-ide/src/neo/IO/SideeX/ext-command.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export default class ExtCommand {
212212
});
213213
}
214214

215-
doPause(ignored, milliseconds) {
215+
doPause(milliseconds) {
216216
return new Promise(function(resolve) {
217217
setTimeout(resolve, milliseconds);
218218
});

packages/selenium-ide/src/neo/IO/SideeX/playback.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function doSeleniumCommand(id, command, target, value, implicitTime, implicitCou
288288
function doPluginCommand(id, command, target, value, implicitTime, implicitCount) {
289289
return executeCommand(command, target, value, {
290290
commandId: id,
291+
isNested: !!PlaybackState.callstack.length,
291292
runId: PlaybackState.runId,
292293
testId: PlaybackState.currentRunningTest.id,
293294
frameId: extCommand.getCurrentPlayingFrameId(),

packages/selenium-ide/src/neo/models/Command.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class CommandList {
218218
name: "answer on next prompt",
219219
description: "Affects the next alert prompt. This command will send \
220220
the specified answer string to it. If the alert is already \
221-
present, then use \"webdriver answer on next prompt\" instead.",
221+
present, then use \"webdriver answer on visible prompt\" instead.",
222222
target: ArgTypes.answer
223223
}],
224224
[ "assertAlert", {
@@ -327,19 +327,19 @@ class CommandList {
327327
name: "choose cancel on next confirmation",
328328
description: "Affects the next confirmation alert. This command will \
329329
cancel it. If the alert is already present, then use \
330-
\"webdriver choose cancel on next confirmation\" instead."
330+
\"webdriver choose cancel on visible confirmation\" instead."
331331
}],
332332
[ "chooseCancelOnNextPrompt", {
333333
name: "choose cancel on next prompt",
334334
description: "Affects the next alert prompt. This command will cancel \
335335
it. If the alert is already present, then use \"webdriver \
336-
choose cancel on next prompt\" instead."
336+
choose cancel on visible prompt\" instead."
337337
}],
338338
[ "chooseOkOnNextConfirmation", {
339339
name: "choose ok on next confirmation",
340340
description: "Affects the next confirmation alert. This command will accept \
341341
it. If the alert is already present, then use \"webdriver \
342-
choose ok on next confirmation\" instead."
342+
choose ok on visible confirmation\" instead."
343343
}],
344344
[ "click", {
345345
name: "click",
@@ -687,30 +687,30 @@ class CommandList {
687687
target: ArgTypes.selectLocator,
688688
value: ArgTypes.pattern
689689
}],
690-
[ "webdriverAnswerOnNextPrompt", {
691-
name: "webdriver answer on next prompt",
690+
[ "webdriverAnswerOnVisiblePrompt", {
691+
name: "webdriver answer on visible prompt",
692692
description: "Affects a currently showing alert prompt. This command \
693693
instructs Selenium to provide the specified answer to it. \
694694
If the alert has not appeared yet then use \"answer on next \
695695
prompt\" instead.",
696696
target: ArgTypes.answer
697697
}],
698-
[ "webdriverChooseCancelOnNextConfirmation", {
699-
name: "webdriver choose cancel on next confirmation",
698+
[ "webdriverChooseCancelOnVisibleConfirmation", {
699+
name: "webdriver choose cancel on visible confirmation",
700700
description: "Affects a currently showing confirmation alert. This command \
701701
instructs Selenium to cancel it. If the alert has not \
702702
appeared yet then use \"choose cancel on next confirmation\" \
703703
instead."
704704
}],
705-
[ "webdriverChooseCancelOnNextPrompt", {
706-
name: "webdriver choose cancel on next prompt",
705+
[ "webdriverChooseCancelOnVisiblePrompt", {
706+
name: "webdriver choose cancel on visible prompt",
707707
description: "Affects a currently showing alert prompt. This command \
708708
instructs Selenium to cancel it. If the alert has not \
709709
appeared yet then use \"choose cancel on next prompt\" \
710710
instead."
711711
}],
712-
[ "webdriverChooseOkOnNextConfirmation", {
713-
name: "webdriver choose ok on next confirmation",
712+
[ "webdriverChooseOkOnVisibleConfirmation", {
713+
name: "webdriver choose ok on visible confirmation",
714714
description: "Affects a currently showing confirmation alert. This command \
715715
instructs Selenium to accept it. If the alert has not \
716716
appeared yet then use \"choose ok on next confirmation\" \

packages/selenium-side-runner/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ Running tests faster through the use of multiple workers
4949
The runner will automatically set the number of workers to the amount of cores available, for most cases this is the best result.
5050
**Note:** unless you specified that a suite is parallel, it will still run the contained tests sequentially, though the runner will run suites in parallel by default.
5151
To mark a suite's tests as parallel, set that in the suite's settings in the IDE.
52+
53+
### FAQ
54+
55+
#### I'm getting an error similar to `Unknown locator ${vars.something}`
56+
When running your projects make sure that the command is aware of the locator strategy **before** variables are evaluated.
57+
For example `click | id=${myButton}` vs `click | ${idOfMyButton}`.
58+
Always use the first one, since the strategy is hardcoded in the command, the second would yield an error.
59+
60+
>But it works in the IDE.
61+
62+
That is because the IDE calculates locator strategies differently than the runner, it is a known current issue.

packages/selianize/__tests__/command.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("command code emitter", () => {
137137
target: "some test case",
138138
value: ""
139139
};
140-
return expect(CommandEmitter.emit(command)).resolves.toBe("await tests.some_test_case(driver, vars);");
140+
return expect(CommandEmitter.emit(command)).resolves.toBe("await tests.some_test_case(driver, vars, { isNested: true });");
141141
});
142142
it("should emit `run script` command", () => {
143143
const command = {
@@ -166,10 +166,10 @@ describe("command code emitter", () => {
166166
it("should emit `pause` command", () => {
167167
const command = {
168168
command: "pause",
169-
target: "",
170-
value: "300"
169+
target: "300",
170+
value: ""
171171
};
172-
return expect(CommandEmitter.emit(command)).resolves.toBe(`await driver.sleep(${command.value});`);
172+
return expect(CommandEmitter.emit(command)).resolves.toBe(`await driver.sleep(${command.target});`);
173173
});
174174
it("should emit `verify checked` command", () => {
175175
const command = {
@@ -571,33 +571,33 @@ describe("command code emitter", () => {
571571
};
572572
return expect(CommandEmitter.emit(command)).resolves.toBe(`await driver.switchTo().alert().then(alert => {alert.getText().then(text => {expect(text).toBe(\`${command.target}\`);});});`);
573573
});
574-
it("should emit `choose ok on next confirmation` command", () => {
574+
it("should emit `choose ok on visible confirmation` command", () => {
575575
const command = {
576-
command: "webdriverChooseOkOnNextConfirmation",
576+
command: "webdriverChooseOkOnVisibleConfirmation",
577577
target: "",
578578
value: ""
579579
};
580580
return expect(CommandEmitter.emit(command)).resolves.toBe("await driver.switchTo().alert().then(alert => {alert.accept();});");
581581
});
582-
it("should emit `choose cancel on next confirmation` command", () => {
582+
it("should emit `choose cancel on visible confirmation` command", () => {
583583
const command = {
584-
command: "webdriverChooseCancelOnNextConfirmation",
584+
command: "webdriverChooseCancelOnVisibleConfirmation",
585585
target: "",
586586
value: ""
587587
};
588588
return expect(CommandEmitter.emit(command)).resolves.toBe("await driver.switchTo().alert().then(alert => {alert.dismiss();});");
589589
});
590-
it("should emit `answer on next prompt` command", () => {
590+
it("should emit `answer on visible prompt` command", () => {
591591
const command = {
592-
command: "webdriverAnswerOnNextPrompt",
592+
command: "webdriverAnswerOnVisiblePrompt",
593593
target: "an answer",
594594
value: ""
595595
};
596596
return expect(CommandEmitter.emit(command)).resolves.toBe(`await driver.switchTo().alert().then(alert => {alert.sendKeys(\`${command.target}\`).then(() => {alert.accept();});});`);
597597
});
598-
it("should emit `choose cancel on next prompt` command", () => {
598+
it("should emit `choose cancel on visible prompt` command", () => {
599599
const command = {
600-
command: "webdriverChooseCancelOnNextPrompt",
600+
command: "webdriverChooseCancelOnVisiblePrompt",
601601
target: "",
602602
value: ""
603603
};

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/__tests__/testcase.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("test case code emitter", () => {
2727
return expect(TestCaseEmitter.emit(test)).resolves.toEqual({
2828
name: "example test case",
2929
test: `it("${test.name}", async () => {await tests.example_test_case(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});`,
30-
function: "tests.example_test_case = async function example_test_case(driver, vars) {}"
30+
function: "tests.example_test_case = async function example_test_case(driver, vars, opts) {}"
3131
});
3232
});
3333
it("should emit a test with a single command", () => {
@@ -43,7 +43,7 @@ describe("test case code emitter", () => {
4343
return expect(TestCaseEmitter.emit(test)).resolves.toEqual({
4444
name: "example test case",
4545
test: `it("${test.name}", async () => {await tests.example_test_case(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});`,
46-
function: `tests.example_test_case = async function example_test_case(driver, vars) {await driver.get(BASE_URL + "${test.commands[0].target}");}`
46+
function: `tests.example_test_case = async function example_test_case(driver, vars, opts) {await driver.get(BASE_URL + "${test.commands[0].target}");}`
4747
});
4848
});
4949
it("should emit a test with multiple commands", () => {
@@ -71,7 +71,7 @@ describe("test case code emitter", () => {
7171
return expect(TestCaseEmitter.emit(test)).resolves.toEqual({
7272
name: "example test case",
7373
test: `it("${test.name}", async () => {await tests.example_test_case(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});`,
74-
function: `tests.example_test_case = async function example_test_case(driver, vars) {await driver.get(BASE_URL + "${test.commands[0].target}");await driver.get(BASE_URL + "${test.commands[1].target}");await driver.get(BASE_URL + "${test.commands[2].target}");}`
74+
function: `tests.example_test_case = async function example_test_case(driver, vars, opts) {await driver.get(BASE_URL + "${test.commands[0].target}");await driver.get(BASE_URL + "${test.commands[1].target}");await driver.get(BASE_URL + "${test.commands[2].target}");}`
7575
});
7676
});
7777
it("should reject a test with failed commands", () => {
@@ -133,7 +133,7 @@ describe("test case code emitter", () => {
133133
return expect(TestCaseEmitter.emit(test, { silenceErrors: true })).resolves.toEqual({
134134
name: "silence",
135135
test: "it(\"silence\", async () => {await tests.silence(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});",
136-
function: "tests.silence = async function silence(driver, vars) {throw new Error(\"Unknown command doesntExist\");}"
136+
function: "tests.silence = async function silence(driver, vars, opts) {throw new Error(\"Unknown command doesntExist\");}"
137137
});
138138
});
139139
});

0 commit comments

Comments
 (0)