Skip to content

Commit 6d0134f

Browse files
committed
[js] Removed the WebDriver.prototype.call() method. This was used to inject
custom function calls into the control flow. Now that the promise manager is no longer used, this method is no longer necessary. Users are now responsible for coordinating actions (ideally with async functions) and can just call functions directly instead of through `driver.call()`.
1 parent aa27e7a commit 6d0134f

File tree

4 files changed

+8
-164
lines changed

4 files changed

+8
-164
lines changed

javascript/node/selenium-webdriver/CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ mode.
3535
* Removed the 'opera' module
3636
* Removed the `WebDriver.attachToSession()` factory method. Users can just use
3737
use the `WebDriver` constructor directly instead.
38+
* Removed the `WebDriver.prototype.call()` method. This was used to inject
39+
custom function calls into the control flow. Now that the promise manager is
40+
no longer used, this method is no longer necessary. Users are now responsible
41+
for coordinating actions (ideally with async functions) and can just call
42+
functions directly instead of through `driver.call()`.
3843
* Removed the `WebDriver.prototype.touchActions()` method. Action sequences
3944
are now defined from a single origin: `WebDriver.prototype.actions()`.
4045
* Removed the promise manager from `lib/promise`, which includes the removal

javascript/node/selenium-webdriver/lib/webdriver.js

-19
Original file line numberDiff line numberDiff line change
@@ -382,18 +382,6 @@ class IWebDriver {
382382
*/
383383
executeAsyncScript(script, ...args) {}
384384

385-
/**
386-
* Executes a custom function.
387-
*
388-
* @param {function(...): (T|IThenable<T>)} fn The function to execute.
389-
* @param {Object=} scope The object in whose scope to execute the function.
390-
* @param {...*} args Any arguments to pass to the function.
391-
* @return {!IThenable<T>} A promise that will be resolved' with the
392-
* function's result.
393-
* @template T
394-
*/
395-
call(fn, scope = undefined, ...args) {}
396-
397385
/**
398386
* Waits for a condition to evaluate to a "truthy" value. The condition may be
399387
* specified by a {@link Condition}, as a custom function, or as any
@@ -758,13 +746,6 @@ class WebDriver {
758746
setParameter('args', args));
759747
}
760748

761-
/** @override */
762-
call(fn, scope = undefined, ...args) {
763-
return promise.fullyResolved(args).then(function(args) {
764-
return fn.apply(scope, args);
765-
});
766-
}
767-
768749
/** @override */
769750
wait(condition, timeout = 0, message = undefined) {
770751
if (typeof timeout !== 'number' || timeout < 0) {

javascript/node/selenium-webdriver/test/lib/webdriver_test.js

-140
Original file line numberDiff line numberDiff line change
@@ -398,146 +398,6 @@ describe('WebDriver', function() {
398398
});
399399
});
400400

401-
describe('customFunctions', function() {
402-
it('returnsANonPromiseValue', function() {
403-
var driver = new FakeExecutor().createDriver();
404-
return driver.call(() => 'abc123').then(function(value) {
405-
assert.equal('abc123', value);
406-
});
407-
});
408-
409-
it('passingArgumentsToACustomFunction', function() {
410-
var add = function(a, b) {
411-
return a + b;
412-
};
413-
var driver = new FakeExecutor().createDriver();
414-
return driver.call(add, null, 1, 2).then(function(value) {
415-
assert.equal(3, value);
416-
});
417-
});
418-
419-
it('passingPromisedArgumentsToACustomFunction', function() {
420-
var promisedArg = Promise.resolve(2);
421-
var add = function(a, b) {
422-
return a + b;
423-
};
424-
var driver = new FakeExecutor().createDriver();
425-
return driver.call(add, null, 1, promisedArg).then(function(value) {
426-
assert.equal(3, value);
427-
});
428-
});
429-
430-
it('passingArgumentsAndScopeToACustomFunction', function() {
431-
function Foo(name) {
432-
this.name = name;
433-
}
434-
Foo.prototype.getName = function() {
435-
return this.name;
436-
};
437-
var foo = new Foo('foo');
438-
439-
var driver = new FakeExecutor().createDriver();
440-
return driver.call(foo.getName, foo).then(function(value) {
441-
assert.equal('foo', value);
442-
});
443-
});
444-
445-
it('customFunctionThrowsAnError', function() {
446-
var driver = new FakeExecutor().createDriver();
447-
return driver.call(throwStubError).then(fail, assertIsStubError);
448-
});
449-
450-
it('returnsATaskResultAfterSchedulingAnother', function() {
451-
let executor = new FakeExecutor().
452-
expect(CName.GET_TITLE).
453-
andReturnSuccess('Google Search').
454-
expect(CName.CLOSE).
455-
end();
456-
457-
var driver = executor.createDriver();
458-
return driver.call(function() {
459-
var title = driver.getTitle();
460-
driver.close();
461-
return title;
462-
}).then(function(title) {
463-
assert.equal('Google Search', title);
464-
});
465-
});
466-
467-
it('hasANestedCommandThatFails', function() {
468-
let executor = new FakeExecutor().
469-
expect(CName.SWITCH_TO_WINDOW, {
470-
'name': 'foo',
471-
'handle': 'foo'
472-
}).
473-
andReturnError(new StubError()).
474-
end();
475-
476-
var driver = executor.createDriver();
477-
return driver.call(function() {
478-
return driver.switchTo().window('foo');
479-
}).then(fail, assertIsStubError);
480-
});
481-
482-
it('returnsADeferredAction', function() {
483-
let executor = new FakeExecutor().
484-
expect(CName.GET_TITLE).andReturnSuccess('Google').
485-
end();
486-
487-
var driver = executor.createDriver();
488-
driver.call(function() {
489-
return driver.getTitle();
490-
}).then(function(title) {
491-
assert.equal('Google', title);
492-
});
493-
});
494-
});
495-
496-
describe('nestedCommands', function() {
497-
it('canReturnValueFromNestedFunction', function() {
498-
var driver = new FakeExecutor().createDriver();
499-
return driver.call(function() {
500-
return driver.call(function() {
501-
return driver.call(() => 'foobar');
502-
});
503-
}).then(function(value) {
504-
assert.equal('foobar', value);
505-
});
506-
});
507-
508-
it('errorsBubbleUp_caught', function() {
509-
var driver = new FakeExecutor().createDriver();
510-
return driver.call(function() {
511-
return driver.call(function() {
512-
return driver.call(throwStubError);
513-
});
514-
}).then(fail, assertIsStubError);
515-
});
516-
517-
it('errorsBubbleUp_uncaught', function() {
518-
var driver = new FakeExecutor().createDriver();
519-
return driver.call(function() {
520-
return driver.call(function() {
521-
return driver.call(throwStubError);
522-
});
523-
})
524-
.then(_ => assert.fail('should have failed'), assertIsStubError);
525-
});
526-
527-
it('canScheduleCommands', function() {
528-
let executor = new FakeExecutor().
529-
expect(CName.GET_TITLE).
530-
expect(CName.CLOSE).
531-
end();
532-
533-
var driver = executor.createDriver();
534-
return driver.call(function() {
535-
return driver.call(() => driver.getTitle())
536-
.then(() => driver.close());
537-
});
538-
});
539-
});
540-
541401
describe('WebElementPromise', function() {
542402
let driver = new FakeExecutor().createDriver();
543403

javascript/node/selenium-webdriver/test/upload_test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ test.suite(function(env) {
6363

6464
await driver.get(Pages.uploadPage);
6565

66-
var fp = await driver.call(function() {
67-
return io.tmpFile().then(function(fp) {
68-
fs.writeFileSync(fp, FILE_HTML);
69-
return fp;
70-
});
66+
var fp = await io.tmpFile().then(function(fp) {
67+
fs.writeFileSync(fp, FILE_HTML);
68+
return fp;
7169
});
7270

7371
await driver.findElement(By.id('upload')).sendKeys(fp);

0 commit comments

Comments
 (0)