2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
|
2012-04-29 04:33:52 +00:00
|
|
|
/**
|
|
|
|
|
* @fileoverview Utilities for working with WebDriver response objects.
|
2020-09-15 22:16:14 +05:30
|
|
|
* @see: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#responses
|
2012-04-29 04:33:52 +00:00
|
|
|
*/
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
|
2012-04-29 04:33:52 +00:00
|
|
|
goog.provide('bot.response');
|
|
|
|
|
goog.provide('bot.response.ResponseObject');
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
|
|
|
|
|
goog.require('bot.Error');
|
|
|
|
|
goog.require('bot.ErrorCode');
|
|
|
|
|
|
|
|
|
|
|
2012-03-05 13:18:07 +00:00
|
|
|
/**
|
2012-04-29 04:33:52 +00:00
|
|
|
* Type definition for a response object, as defined by the JSON wire protocol.
|
2012-04-25 23:46:12 +00:00
|
|
|
* @typedef {{status: bot.ErrorCode, value: (*|{message: string})}}
|
2015-03-17 19:15:20 -04:00
|
|
|
* @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#responses
|
2012-03-05 13:18:07 +00:00
|
|
|
*/
|
2012-04-29 04:33:52 +00:00
|
|
|
bot.response.ResponseObject;
|
2012-03-05 13:18:07 +00:00
|
|
|
|
|
|
|
|
|
2012-03-20 16:39:10 +00:00
|
|
|
/**
|
|
|
|
|
* @param {*} value The value to test.
|
|
|
|
|
* @return {boolean} Whether the given value is a response object.
|
|
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.response.isResponseObject = function (value) {
|
2012-03-20 16:39:10 +00:00
|
|
|
return goog.isObject(value) && goog.isNumber(value['status']);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-04-29 04:33:52 +00:00
|
|
|
/**
|
|
|
|
|
* Creates a new success response object with the provided value.
|
|
|
|
|
* @param {*} value The response value.
|
|
|
|
|
* @return {!bot.response.ResponseObject} The new response object.
|
|
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.response.createResponse = function (value) {
|
2012-04-29 04:33:52 +00:00
|
|
|
if (bot.response.isResponseObject(value)) {
|
2013-06-13 17:16:23 -07:00
|
|
|
return /** @type {!bot.response.ResponseObject} */ (value);
|
2012-04-29 04:33:52 +00:00
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
'status': bot.ErrorCode.SUCCESS,
|
|
|
|
|
'value': value
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
/**
|
|
|
|
|
* Converts an error value into its JSON representation as defined by the
|
|
|
|
|
* WebDriver wire protocol.
|
2012-04-29 04:33:52 +00:00
|
|
|
* @param {(bot.Error|Error|*)} error The error value to convert.
|
|
|
|
|
* @return {!bot.response.ResponseObject} The new response object.
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.response.createErrorResponse = function (error) {
|
2012-04-29 04:33:52 +00:00
|
|
|
if (bot.response.isResponseObject(error)) {
|
2013-06-13 17:16:23 -07:00
|
|
|
return /** @type {!bot.response.ResponseObject} */ (error);
|
2012-03-20 16:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-05 13:18:07 +00:00
|
|
|
var statusCode = error && goog.isNumber(error.code) ? error.code :
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.ErrorCode.UNKNOWN_ERROR;
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
return {
|
2013-06-13 17:16:23 -07:00
|
|
|
'status': /** @type {bot.ErrorCode} */ (statusCode),
|
2012-03-05 13:18:07 +00:00
|
|
|
'value': {
|
2012-04-29 04:33:52 +00:00
|
|
|
'message': (error && error.message || error) + ''
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-29 04:33:52 +00:00
|
|
|
* Checks that a response object does not specify an error as defined by the
|
|
|
|
|
* WebDriver wire protocol. If the response object defines an error, it will
|
|
|
|
|
* be thrown. Otherwise, the response will be returned as is.
|
|
|
|
|
* @param {!bot.response.ResponseObject} responseObj The response object to
|
2012-03-05 13:18:07 +00:00
|
|
|
* check.
|
2012-04-29 04:33:52 +00:00
|
|
|
* @return {!bot.response.ResponseObject} The checked response object.
|
2012-03-05 13:18:07 +00:00
|
|
|
* @throws {bot.Error} If the response describes an error.
|
2015-03-17 19:15:20 -04:00
|
|
|
* @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#failed-commands
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.response.checkResponse = function (responseObj) {
|
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports
Firefox, Chrome, IE, and Opera through the Java Selenium server. For the
browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is
used to communicate with the WebDriver server. For the other browsers, we have
to use JSONP. While IE technically supports CORS, it does not support sending
DELETE requests via CORS. Since there are quite a few DELETE commands in the
wire protocol, we have to use JSONP for IE too (yay, IE).
To create a deployable webdriver.js, run $./go webdriverjs
The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used
in either the browser or with node.
WebDriverJS may only be used in a browser already under WebDriver's control.
Furthermore, the WebDriver server URL and session ID must be passed to the
script via the wdurl and wdsid query parameters, respectively. To help with
debugging, this change includes a simple Node app:
$ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar
$ node javascript/webdriver-jsapi/node/demo.js --help
To manually run the browser demo tests:
$ ./go debug-server
$ node javascript/webdriver-jsapi/node/demo.js \
--browser=chrome \
--wdUrl=http://localhost:4444/wd/hub \
--url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html
There's still a lot to do:
- Fix the :webdriverjs build task
- Wiki/design documentation
- Improve the debug story (as in, write one)
- Write a pure-JS command executor using the atoms. This could theoretically
be used to replace Selenium Core
- Better Node integration
r14327
2011-10-22 01:15:11 +00:00
|
|
|
var status = responseObj['status'];
|
|
|
|
|
if (status == bot.ErrorCode.SUCCESS) {
|
|
|
|
|
return responseObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If status is not defined, assume an unknown error.
|
|
|
|
|
status = status || bot.ErrorCode.UNKNOWN_ERROR;
|
|
|
|
|
|
|
|
|
|
var value = responseObj['value'];
|
|
|
|
|
if (!value || !goog.isObject(value)) {
|
|
|
|
|
throw new bot.Error(status, value + '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new bot.Error(status, value['message'] + '');
|
2011-12-02 23:04:50 +00:00
|
|
|
};
|