From ee3dc9ebd57c4c3170ba65351cc70a7f5fbc2a58 Mon Sep 17 00:00:00 2001 From: SmartBear <471110230@qq.com> Date: Thu, 12 Oct 2023 04:05:12 -0500 Subject: [PATCH] refactor: support es6 & fix lint (#117) * refactor: support es6 & fix lint --- .eslintignore | 1 - .eslintrc | 166 ------------ .eslintrc.js | 41 +++ lib/helper/assert.js | 8 +- lib/helper/coverage.js | 6 +- lib/helper/element.js | 38 ++- lib/helper/index.js | 8 +- lib/helper/macaca-datahub.js | 6 +- lib/helper/reporter.js | 2 +- lib/next/index.js | 16 +- lib/web/react-router-helper.js | 2 +- package.json | 8 +- test/alert.test.js | 17 +- test/assert.test.js | 23 +- test/browser.test.js | 11 +- test/cookie.test.js | 17 +- test/excecute.test.js | 9 +- test/helper.js | 4 +- test/screenshot.test.js | 7 +- test/session.test.js | 13 +- test/source.test.js | 7 +- test/title.test.js | 7 +- test/url.test.js | 7 +- test/utility.test.js | 33 +-- test/window.test.js | 9 +- wd/lib/actions.js | 45 ++-- wd/lib/asserters.js | 29 ++- wd/lib/bin.js | 9 +- wd/lib/callbacks.js | 38 +-- wd/lib/commands.js | 452 +++++++++++++++++++-------------- wd/lib/config.js | 29 ++- wd/lib/deprecated-chain.js | 23 +- wd/lib/element-commands.js | 200 ++++++++++----- wd/lib/element.js | 8 +- wd/lib/http-utils.js | 6 +- wd/lib/jsonwire-errors.js | 46 ++-- wd/lib/lodash.js | 4 +- wd/lib/main.js | 61 +++-- wd/lib/promise-webdriver.js | 33 ++- wd/lib/tmp.js | 4 +- wd/lib/utils.js | 20 +- wd/lib/webdriver.js | 33 ++- 42 files changed, 788 insertions(+), 718 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.js diff --git a/.eslintignore b/.eslintignore index b1e34c20..12620cff 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,6 @@ **/.* **/node_modules **/build -**/test **/wd/doc **/logs **/theme diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 23c6cced..00000000 --- a/.eslintrc +++ /dev/null @@ -1,166 +0,0 @@ -{ - "env": { - "browser": true, - "node": true, - "es6": true, - "mocha": true - }, - "plugins": [ - "mocha" - ], - "parserOptions": { - "ecmaVersion": 8 - }, - // https://github.com/feross/eslint-config-standard - "rules": { - "accessor-pairs": 2, - "block-scoped-var": 0, - "brace-style": [2, "1tbs", { "allowSingleLine": true }], - "camelcase": 0, - "comma-dangle": [2, "never"], - "comma-spacing": [2, { "before": false, "after": true }], - "comma-style": [2, "last"], - "complexity": 0, - "consistent-return": 0, - "consistent-this": 0, - "curly": [2, "multi-line"], - "default-case": 0, - "dot-location": [2, "property"], - "dot-notation": 0, - "eol-last": 2, - "eqeqeq": [2, "allow-null"], - "func-names": 0, - "func-style": 0, - "generator-star-spacing": [2, "both"], - "guard-for-in": 0, - "handle-callback-err": [2, "^(err|error|anySpecificError)$" ], - "indent": [2, 2], - "key-spacing": [2, { "beforeColon": false, "afterColon": true }], - "linebreak-style": 0, - "max-depth": 0, - "max-len": 0, - "max-nested-callbacks": 0, - "max-params": 0, - "max-statements": 0, - "new-cap": [2, { "newIsCap": true, "capIsNew": false }], - "new-parens": 2, - "no-alert": 0, - "no-array-constructor": 2, - "no-bitwise": 0, - "no-caller": 2, - "no-catch-shadow": 0, - "no-cond-assign": 2, - "no-console": 0, - "no-constant-condition": 0, - "no-continue": 0, - "no-control-regex": 2, - "no-debugger": 2, - "no-delete-var": 2, - "no-div-regex": 0, - "no-dupe-args": 2, - "no-dupe-keys": 2, - "no-duplicate-case": 2, - "no-else-return": 0, - "no-empty": 0, - "no-empty-character-class": 2, - "no-eq-null": 0, - "no-eval": 2, - "no-ex-assign": 2, - "no-extend-native": 2, - "no-extra-bind": 2, - "no-extra-boolean-cast": 2, - "no-extra-semi": 0, - "no-extra-strict": 0, - "no-fallthrough": 2, - "no-floating-decimal": 2, - "no-func-assign": 2, - "no-implied-eval": 2, - "no-inline-comments": 0, - "no-inner-declarations": [2, "functions"], - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-iterator": 2, - "no-label-var": 2, - "no-labels": 2, - "no-lone-blocks": 2, - "no-lonely-if": 0, - "no-loop-func": 0, - "no-mixed-requires": 0, - "no-mixed-spaces-and-tabs": [2, false], - "no-multi-spaces": 2, - "no-multi-str": 2, - "no-multiple-empty-lines": [2, { "max": 1 }], - "no-native-reassign": 2, - "no-negated-in-lhs": 2, - "no-nested-ternary": 0, - "no-new": 0, - "no-new-func": 2, - "no-new-object": 2, - "no-new-require": 2, - "no-new-wrappers": 2, - "no-obj-calls": 2, - "no-octal": 2, - "no-octal-escape": 2, - "no-path-concat": 0, - "no-plusplus": 0, - "no-process-env": 0, - "no-process-exit": 0, - "no-proto": 2, - "no-redeclare": 2, - "no-regex-spaces": 2, - "no-reserved-keys": 0, - "no-restricted-modules": 0, - "no-return-assign": 2, - "no-script-url": 0, - "no-self-compare": 2, - "no-sequences": 2, - "no-shadow": 0, - "no-shadow-restricted-names": 2, - "no-spaced-func": 2, - "no-sparse-arrays": 2, - "no-sync": 0, - "no-ternary": 0, - "no-throw-literal": 2, - "no-trailing-spaces": 2, - "no-undef": 2, - "no-undef-init": 2, - "no-undefined": 0, - "no-underscore-dangle": 0, - "no-unneeded-ternary": 2, - "no-unreachable": 2, - "no-unused-expressions": 0, - "no-unused-vars": 0, - "no-use-before-define": 0, - "no-var": 0, - "no-void": 0, - "no-warning-comments": 0, - "no-with": 2, - "no-extra-parens": 0, - "object-curly-spacing": 0, - "one-var": [2, { "initialized": "never" }], - "operator-assignment": 0, - "operator-linebreak": [2, "after"], - "padded-blocks": 0, - "quote-props": 0, - "quotes": [1, "single", "avoid-escape"], - "radix": 2, - "semi": [2, "always"], - "semi-spacing": 0, - "sort-vars": 0, - "keyword-spacing": [2], - "space-before-blocks": [2, "always"], - "space-before-function-paren": 0, - "space-in-parens": [2, "never"], - "space-infix-ops": 2, - "space-unary-ops": [2, { "words": true, "nonwords": false }], - "spaced-comment": [2, "always"], - "strict": 0, - "use-isnan": 2, - "valid-jsdoc": 0, - "valid-typeof": 2, - "vars-on-top": 0, - "wrap-iife": [2, "any"], - "wrap-regex": 0, - "yoda": [2, "never"] - } -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..edea8f4a --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,41 @@ +'use strict'; + +/* eslint-env node */ +const eslintConfig = { + extends: 'eslint-config-egg', + env: { + browser: true, + es6: true, + node: true, + }, + settings: { + 'import/resolver': { + alias: { + map: [ + [ '@', `${__dirname}/src` ], + ], + extensions: [ '.js', '.jsx', '.json' ], + }, + }, + }, + parserOptions: { + ecmaVersion: 2020, + ecmaFeatures: { + experimentalObjectRestSpread: true, + }, + }, + plugins: [ + 'import' + ], + ignorePatterns: [ '*.d.ts' ], + rules: { + 'import/extensions': 0, + 'jsdoc/require-param-type': 0, + 'jsdoc/require-param-description': 0, + 'jsdoc/check-tag-names': 0, + 'jsdoc/require-returns-description': 0, + }, + overrides: [], +}; + +module.exports = eslintConfig; diff --git a/lib/helper/assert.js b/lib/helper/assert.js index 32d8606d..7c217d56 100644 --- a/lib/helper/assert.js +++ b/lib/helper/assert.js @@ -13,7 +13,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {string} text content. * @type assert - * @returns {Promise.} + * @return {Promise.} */ wd.addElementPromiseChainMethod('hasText', function(...texts) { return this.text().then(shouldContains(...texts)); @@ -25,7 +25,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {string} text content. * @type assert - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('hasElementByCss', function(cssSelector) { return this.elementByCssIfExists(cssSelector).then(d => { @@ -41,7 +41,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {string} title - title of the web page. * @type assert - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('assertTitle', function(title) { return this.title().then(realTitle => { @@ -59,7 +59,7 @@ module.exports = wd => { * @param {string} attribute - attribute's name. * @param {string} value - expected value. * @type assert - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('assertAttribute', function(attribute, value) { return this.execute( diff --git a/lib/helper/coverage.js b/lib/helper/coverage.js index 5468e665..32ae7103 100644 --- a/lib/helper/coverage.js +++ b/lib/helper/coverage.js @@ -13,7 +13,7 @@ program const xlogger = require('xlogger'); const logger = xlogger.Logger({ - closeFile: true + closeFile: true, }); const cwd = process.cwd(); @@ -24,9 +24,9 @@ module.exports = wd => { * @function coverage * @summary Support: Web(WebView) * @type utility - * @returns {Promise.} + * @return {Promise.} */ - wd.addPromiseChainMethod('coverage', function(context) { + wd.addPromiseChainMethod('coverage', function() { const tempDir = path.join(cwd, 'coverage', '.temp'); _.mkdir(tempDir); return this.execute('return window.__coverage__') diff --git a/lib/helper/element.js b/lib/helper/element.js index 6b724625..79b73d59 100644 --- a/lib/helper/element.js +++ b/lib/helper/element.js @@ -22,19 +22,15 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {object} browser options. * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('initWindow', function(options = {}) { - return this.init( - Object.assign( - { - platformName: 'playwright', - browserName: 'chromium', - deviceScaleFactor: 2 - }, - options - ) - ).setWindowSize(options.width, options.height); + return this.init({ + platformName: 'playwright', + browserName: 'chromium', + deviceScaleFactor: 2, + ...options, + }).setWindowSize(options.width, options.height); }); /** @@ -43,21 +39,23 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {string} the pointed url. * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('getUrl', function(url) { return this .get(url) .execute('return location.protocol') .then(protocol => { - if (!~['http:', 'https:'].indexOf(protocol)) { + // eslint-disable-next-line no-bitwise + if (!~[ 'http:', 'https:' ].indexOf(protocol)) { return new Promise(resolve => { const handle = () => { setTimeout(() => { this.get(url) .execute('return location.protocol') .then(protocol => { - if (~['http:', 'https:'].indexOf(protocol)) { + // eslint-disable-next-line no-bitwise + if (~[ 'http:', 'https:' ].indexOf(protocol)) { setTimeout(resolve, 3000); } else { handle(); @@ -76,7 +74,7 @@ module.exports = wd => { * @function saveScreenshots * @summary Support: Web(WebView) * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('saveScreenshots', function(context, params) { const filepath = path.join(reportspath, 'screenshots', `${uuid()}.png`); @@ -92,11 +90,11 @@ module.exports = wd => { * @function saveVideos * @summary Support: Web(WebView) * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('saveVideos', function(context, params = {}) { params.video = true; - return this.saveScreenshot(null, params).then((filepath) => { + return this.saveScreenshot(null, params).then(filepath => { appendToContext(context, `${path.relative(reportspath, filepath)}`); }); }); @@ -107,7 +105,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {string} content of type. * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('formInput', function(string) { const list = Array.prototype.slice.call(string); @@ -143,7 +141,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {string} content of type. * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('elementInput', function(string) { const list = Array.prototype.slice.call(string); @@ -181,7 +179,7 @@ module.exports = wd => { * @param {object} options - options of the event. * @see https://github.com/macacajs/dom-event-simulate#support-events * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('domEvent', function(eventName, options) { const uuid = Date.now(); diff --git a/lib/helper/index.js b/lib/helper/index.js index c4066622..a9adb37e 100644 --- a/lib/helper/index.js +++ b/lib/helper/index.js @@ -15,13 +15,13 @@ function initDriverServer(wd, options = {}) { const driver = wd.promiseChainRemote({ host: 'localhost', - port: options.macacaServerPort || process.env.MACACA_SERVER_PORT || 3456 + port: options.macacaServerPort || process.env.MACACA_SERVER_PORT || 3456, }); driver.configureHttp({ timeout: 20E3, retries: 5, - retryDelay: 5 + retryDelay: 5, }); const webpackDevServerPort = options.port || 8080; @@ -31,9 +31,9 @@ function initDriverServer(wd, options = {}) { return { driver, BASE_URL, - webpackDevServerPort + webpackDevServerPort, }; -}; +} module.exports = initDriverServer; module.exports.extendsMixIn = extendsMixIn; diff --git a/lib/helper/macaca-datahub.js b/lib/helper/macaca-datahub.js index c240a481..7c8a5cbf 100644 --- a/lib/helper/macaca-datahub.js +++ b/lib/helper/macaca-datahub.js @@ -11,7 +11,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {object} options. * @type datahub - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('switchScene', function(args) { return datahubClient.switchScene(args); @@ -22,7 +22,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {array} the scene list. * @type datahub - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('switchMultiScenes', function(args) { return datahubClient.switchMultiScenes(args); @@ -33,7 +33,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {object} options. * @type datahub - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('switchAllScenes', function(args) { return datahubClient.switchAllScenes(args); diff --git a/lib/helper/reporter.js b/lib/helper/reporter.js index c5e80ee2..0f09c982 100644 --- a/lib/helper/reporter.js +++ b/lib/helper/reporter.js @@ -14,7 +14,7 @@ module.exports = wd => { * @summary Support: Web(WebView) * @param {boolean} if open. * @type utility - * @returns {Promise.} + * @return {Promise.} */ wd.addPromiseChainMethod('openReporter', function(open) { if (!open || !platform.isOSX) { diff --git a/lib/next/index.js b/lib/next/index.js index 6cf2194f..a5333862 100644 --- a/lib/next/index.js +++ b/lib/next/index.js @@ -4,18 +4,18 @@ module.exports = wd => { [ 'page', 'pagePopup', - 'browser' - ].map(method => { + 'browser', + ].forEach(method => { wd.addPromiseChainMethod(method, function(...params) { const [ func, ...args ] = params; - return this.next(method, [ { func, args } ]); + return this.next(method, [{ func, args }]); }); }); [ 'fileChooser', - 'elementStatus' - ].map(method => { + 'elementStatus', + ].forEach(method => { wd.addPromiseChainMethod(method, function(...params) { return this.next(method, params); }); @@ -23,11 +23,11 @@ module.exports = wd => { [ 'mouse', - 'keyboard' - ].map(method => { + 'keyboard', + ].forEach(method => { wd.addPromiseChainMethod(method, function(...params) { const [ type, ...args ] = params; - return this.next(method, [ { type, args } ]); + return this.next(method, [{ type, args }]); }); }); }; diff --git a/lib/web/react-router-helper.js b/lib/web/react-router-helper.js index bd1d9934..955f0c18 100644 --- a/lib/web/react-router-helper.js +++ b/lib/web/react-router-helper.js @@ -74,7 +74,7 @@ exports.getRouter = (data, options = {}) => { isMatched = matchPath(pathname, currentRoute) || isMatched; } }, { - extname: '.js' + extname: '.js', }); }); currentRoute.path = currentRoute._path || currentRoute.path; diff --git a/package.json b/package.json index f294b8f0..8b1f7334 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "macaca-wd", - "version": "4.2.3", + "version": "4.3.0", "description": "Macaca webdirver API for Node.js", "keywords": [ "macaca", @@ -40,8 +40,8 @@ "xutil": "1" }, "devDependencies": { - "eslint": "^4.18.2", - "eslint-plugin-mocha": "^4.12.1", + "eslint": "8", + "eslint-config-egg": "^12.2.1", "git-contributor": "1", "husky": "^1.3.1", "jsdom": "^11.10.0", @@ -57,7 +57,7 @@ "docs:dev": "vuepress dev docs", "docs:build": "vuepress build docs", "test": "mocha", - "lint": "eslint --fix lib test", + "lint": "eslint --fix --ext js,ts lib test wd/lib", "contributor": "git-contributor" }, "husky": { diff --git a/test/alert.test.js b/test/alert.test.js index 155cfc16..cd5f75f7 100644 --- a/test/alert.test.js +++ b/test/alert.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/alert.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -31,7 +32,7 @@ describe('test/alert.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); @@ -47,7 +48,7 @@ describe('test/alert.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -64,7 +65,7 @@ describe('test/alert.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -80,7 +81,7 @@ describe('test/alert.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -97,7 +98,7 @@ describe('test/alert.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); diff --git a/test/assert.test.js b/test/assert.test.js index c31f1ed4..69ce93c7 100644 --- a/test/assert.test.js +++ b/test/assert.test.js @@ -8,7 +8,8 @@ const { elFuncFullType, elFuncSuffix } = require('../wd/lib/utils'); const wd = require('../lib/macaca-wd'); describe('test/asserter.test.js', function() { - let driver, server; + let driver, + server; const mockServer = async (mockKey, mockValue) => { server = new Server(); @@ -16,13 +17,13 @@ describe('test/asserter.test.js', function() { server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }; @@ -34,7 +35,7 @@ describe('test/asserter.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); @@ -46,7 +47,7 @@ describe('test/asserter.test.js', function() { mockServer('ctx.body', { sessionId: 'sessionId', status: 0, - value: 'someClass' + value: 'someClass', }); }); @@ -71,7 +72,7 @@ describe('test/asserter.test.js', function() { await mockServer('ctx.body', { sessionId: 'sessionId', status: 0, - value: 'My Title' + value: 'My Title', }); }); @@ -90,7 +91,7 @@ describe('test/asserter.test.js', function() { await mockServer('ctx.body', { sessionId: 'sessionId', status: 0, - value: [{ ELEMENT: 1 }, { ELEMENT: 2 }] + value: [{ ELEMENT: 1 }, { ELEMENT: 2 }], }); }); @@ -123,11 +124,11 @@ describe('test/asserter.test.js', function() { await mockServer('ctx.body', { sessionId: 'sessionId', status: 0, - value: [{ ELEMENT: 1 }, { ELEMENT: 2 }] + value: [{ ELEMENT: 1 }, { ELEMENT: 2 }], }); await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); @@ -139,11 +140,11 @@ describe('test/asserter.test.js', function() { 'name', 'partial link text', 'tag name', - 'xpath' + 'xpath', ].map(type => { return { functionSuffix: `hasElement${elFuncSuffix(type)}`, - fullType: elFuncFullType(type) + fullType: elFuncFullType(type), }; }); diff --git a/test/browser.test.js b/test/browser.test.js index 385fe251..b63b95c4 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/browser.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -31,7 +32,7 @@ describe('test/browser.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); @@ -100,7 +101,7 @@ describe('test/browser.test.js', function() { }); }); - /** + /** * https://macacajs.github.io/macaca-wd/#maximize */ describe('refresh', async () => { diff --git a/test/cookie.test.js b/test/cookie.test.js index d597136c..c8db9a27 100644 --- a/test/cookie.test.js +++ b/test/cookie.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/cookie.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -31,7 +32,7 @@ describe('test/cookie.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); @@ -58,7 +59,7 @@ describe('test/cookie.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -78,7 +79,7 @@ describe('test/cookie.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -92,12 +93,12 @@ describe('test/cookie.test.js', function() { assert.equal(server.ctx.url, '/wd/hub/session/sessionId/cookie'); assert.equal(server.ctx.method, 'POST'); assert.deepEqual(server.ctx.request.body, { - cookie: 'test_cookie' + cookie: 'test_cookie', }); assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); diff --git a/test/excecute.test.js b/test/excecute.test.js index 095314f3..5bda83f9 100644 --- a/test/excecute.test.js +++ b/test/excecute.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/execute.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -38,7 +39,7 @@ describe('test/execute.test.js', function() { assert.equal(server.ctx.url, '/wd/hub/session/execute'); assert.deepEqual(server.ctx.request.body, { args: [], - script: 'return window' + script: 'return window', }); assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', diff --git a/test/helper.js b/test/helper.js index ac078496..e0da69fe 100644 --- a/test/helper.js +++ b/test/helper.js @@ -10,7 +10,7 @@ class Server { constructor(options) { this.options = Object.assign( { - port: 3456 + port: 3456, }, options || {} ); @@ -35,7 +35,7 @@ class Server { this.ctx.body = { sessionId: 'sessionId', status: 0, - value: '' + value: '', }; }); } diff --git a/test/screenshot.test.js b/test/screenshot.test.js index 045c41ed..c72ddfaf 100644 --- a/test/screenshot.test.js +++ b/test/screenshot.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/screenshot.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); diff --git a/test/session.test.js b/test/session.test.js index af9d6787..442a94b1 100644 --- a/test/session.test.js +++ b/test/session.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/session.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -35,7 +36,7 @@ describe('test/session.test.js', function() { it('should work', async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); assert.equal(server.ctx.method, 'POST'); assert.equal(server.ctx.url, '/wd/hub/session'); @@ -63,7 +64,7 @@ describe('test/session.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); it('should work', async () => { @@ -85,7 +86,7 @@ describe('test/session.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); it('should work', async () => { diff --git a/test/source.test.js b/test/source.test.js index 0568d12c..a4caaf8d 100644 --- a/test/source.test.js +++ b/test/source.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/source.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); diff --git a/test/title.test.js b/test/title.test.js index 8f795817..c698a10b 100644 --- a/test/title.test.js +++ b/test/title.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/title.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); diff --git a/test/url.test.js b/test/url.test.js index 311e4b5e..e98ed490 100644 --- a/test/url.test.js +++ b/test/url.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/url.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); diff --git a/test/utility.test.js b/test/utility.test.js index d4052291..30519c2e 100644 --- a/test/utility.test.js +++ b/test/utility.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/utility.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -31,7 +32,7 @@ describe('test/utility.test.js', function() { beforeEach(async () => { await driver.init({ platformName: 'desktop', - browserName: 'chrome' + browserName: 'chrome', }); }); @@ -46,7 +47,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -63,7 +64,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -80,7 +81,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -97,7 +98,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -114,7 +115,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -126,7 +127,7 @@ describe('test/utility.test.js', function() { it('should work', async () => { await driver.initWindow({ width: 800, - height: 600 + height: 600, }); assert.equal( server.ctx.url, @@ -135,12 +136,12 @@ describe('test/utility.test.js', function() { assert.equal(server.ctx.method, 'POST'); assert.deepEqual(server.ctx.request.body, { width: 800, - height: 600 + height: 600, }); assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -177,7 +178,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -193,7 +194,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -209,7 +210,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); @@ -224,7 +225,7 @@ describe('test/utility.test.js', function() { assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', status: 0, - value: '' + value: '', }); }); }); diff --git a/test/window.test.js b/test/window.test.js index 2b5db561..bffbdf65 100644 --- a/test/window.test.js +++ b/test/window.test.js @@ -7,20 +7,21 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); describe('test/window.test.js', function() { - let driver, server; + let driver, + server; before(() => { server = new Server(); server.start(); const remoteConfig = { host: 'localhost', - port: 3456 + port: 3456, }; driver = wd.promiseChainRemote(remoteConfig); driver.configureHttp({ timeout: 20 * 1000, retries: 5, - retryDelay: 5 + retryDelay: 5, }); }); @@ -72,7 +73,7 @@ describe('test/window.test.js', function() { assert.equal(server.ctx.url, '/wd/hub/session/window/current/size'); assert.deepEqual(server.ctx.request.body, { width: 800, - height: 600 + height: 600, }); assert.deepEqual(server.ctx.response.body, { sessionId: 'sessionId', diff --git a/wd/lib/actions.js b/wd/lib/actions.js index 3ef41148..967c7934 100644 --- a/wd/lib/actions.js +++ b/wd/lib/actions.js @@ -1,3 +1,5 @@ +'use strict'; + const _ = require('lodash'); const __slice = Array.prototype.slice; const Webdriver = require('./webdriver'); @@ -7,9 +9,10 @@ const Element = require('./element'); * new wd.TouchAction() * TouchAction constructor * + * @param driver * @actions */ -const TouchAction = function (driver) { +const TouchAction = function(driver) { this.driver = driver; this.gestures = []; }; @@ -39,8 +42,8 @@ TouchAction.prototype.addGesture = function(action, opts) { // adding action this.gestures.push({ - action: action, - options: finalOpts + action, + options: finalOpts, }); }; @@ -52,9 +55,10 @@ TouchAction.prototype.toJSON = function() { * touchAction.longPress({el, x, y}) * pass el or (x,y) or both * + * @param opts * @actions */ -TouchAction.prototype.longPress = function (opts) { +TouchAction.prototype.longPress = function(opts) { this.addGesture('longPress', opts); return this; }; @@ -63,9 +67,10 @@ TouchAction.prototype.longPress = function (opts) { * touchAction.moveTo({el, x, y}) * pass el or (x,y) or both * + * @param opts * @actions */ -TouchAction.prototype.moveTo = function (opts) { +TouchAction.prototype.moveTo = function(opts) { this.addGesture('moveTo', opts); return this; }; @@ -74,9 +79,10 @@ TouchAction.prototype.moveTo = function (opts) { * touchAction.press({el, x, y}) * pass el or (x,y) or both * + * @param opts * @actions */ -TouchAction.prototype.press = function (opts) { +TouchAction.prototype.press = function(opts) { this.addGesture('press', opts); return this; }; @@ -86,7 +92,7 @@ TouchAction.prototype.press = function (opts) { * * @actions */ -TouchAction.prototype.release = function () { +TouchAction.prototype.release = function() { this.addGesture('release', {}); return this; }; @@ -96,9 +102,10 @@ TouchAction.prototype.release = function () { * pass el or (x,y) or both * count is optional * + * @param opts * @actions */ -TouchAction.prototype.tap = function (opts) { +TouchAction.prototype.tap = function(opts) { this.addGesture('tap', opts); return this; }; @@ -108,10 +115,11 @@ TouchAction.prototype.tap = function (opts) { * touchAction.wait(ms) * ms is optional * + * @param opts * @actions */ -TouchAction.prototype.wait = function (opts) { - if (_.isNumber(opts)) { opts = {ms: opts}; } +TouchAction.prototype.wait = function(opts) { + if (_.isNumber(opts)) { opts = { ms: opts }; } this.addGesture('wait', opts); return this; }; @@ -121,13 +129,14 @@ TouchAction.prototype.wait = function (opts) { * * @actions */ -TouchAction.prototype.cancel = function () { +TouchAction.prototype.cancel = function() { this.gestures = []; }; /** * perform the action * + * @param cb * @actions */ TouchAction.prototype.perform = function(cb) { @@ -142,9 +151,10 @@ TouchAction.prototype.perform = function(cb) { * new wd.MultiAction() * MultiAction constructor * + * @param browserOrElement * @actions */ -const MultiAction = function (browserOrElement) { +const MultiAction = function(browserOrElement) { if (browserOrElement instanceof Element) { this.element = browserOrElement; this.browser = this.element.browser; @@ -168,7 +178,7 @@ MultiAction.prototype.toJSON = function() { * * @actions */ -MultiAction.prototype.add = function () { +MultiAction.prototype.add = function() { const actions = __slice.call(arguments, 0); this.actions = this.actions.concat(actions); return this; @@ -186,6 +196,7 @@ MultiAction.prototype.cancel = function() { /** * multiAction.perform() * + * @param cb * @actions */ MultiAction.prototype.perform = function(cb) { @@ -198,13 +209,13 @@ MultiAction.prototype.perform = function(cb) { } else { if (this.element) { return this.element.performMultiAction(this); - } else { - return this.browser.performMultiAction(this); } + return this.browser.performMultiAction(this); + } }; module.exports = { - TouchAction: TouchAction, - MultiAction: MultiAction + TouchAction, + MultiAction, }; diff --git a/wd/lib/asserters.js b/wd/lib/asserters.js index 4ec04187..5db535e9 100644 --- a/wd/lib/asserters.js +++ b/wd/lib/asserters.js @@ -1,3 +1,5 @@ +'use strict'; + const _ = require('./lodash'); const __slice = Array.prototype.slice; const utils = require('./utils'); @@ -13,7 +15,7 @@ function Asserter(_assert) { * @asserter */ const nonEmptyText = new Asserter( - function (target, cb) { + function(target, cb) { target.text(function(err, text) { if (err) { return cb(err); } const satisfied = text && _(text).trim().value().length > 0; @@ -25,6 +27,7 @@ const nonEmptyText = new Asserter( /** * asserters.textInclude(content) -> Asserter * + * @param content * @asserter */ function textInclude(content) { @@ -85,6 +88,8 @@ const isHidden = new Asserter( * asserters.jsCondition(jsConditionExpr) -> Asserter * jsConditionExpr: js script expression, should evaluate as boolean. * + * @param jsConditionExpr + * @param safe * @asserter */ function jsCondition(jsConditionExpr, safe) { @@ -93,22 +98,22 @@ function jsCondition(jsConditionExpr, safe) { return new Asserter( function(browser, cb) { const _eval = safe ? browser.safeEval : browser.eval; - _eval.apply(browser, [jsConditionExpr, function(err, res) { - if (err) {return cb(err);} + _eval.apply(browser, [ jsConditionExpr, function(err, res) { + if (err) { return cb(err); } cb(null, res, res); - }]); + } ]); } ); } module.exports = { - Asserter: Asserter, - nonEmptyText: nonEmptyText, - isDisplayed: isDisplayed, - isNotDisplayed: isNotDisplayed, - textInclude: textInclude, - jsCondition: jsCondition, + Asserter, + nonEmptyText, + isDisplayed, + isNotDisplayed, + textInclude, + jsCondition, // deprecated - isVisible: isVisible, - isHidden: isHidden + isVisible, + isHidden, }; diff --git a/wd/lib/bin.js b/wd/lib/bin.js index 2b166bf8..aa4c7a5e 100755 --- a/wd/lib/bin.js +++ b/wd/lib/bin.js @@ -1,12 +1,12 @@ #!/usr/bin/env node +'use strict'; + const net = require('net'); const repl = require('repl'); const assert = require('assert'); const wd = require('./main'); -let connections = 0; - const startRepl = function() { const r = repl.start('(wd): '); r.context.assert = assert; @@ -16,8 +16,7 @@ const startRepl = function() { console.log("Access the webdriver object via the object: 'wd'"); }; - const server = net.createServer(function (socket) { - connections += 1; + const server = net.createServer(function(socket) { socket.setTimeout(5 * 60 * 1000, function() { socket.destroy(); }); @@ -26,7 +25,7 @@ const startRepl = function() { '\\\\.\\pipe\\node-repl-sock-' + process.pid : '/tmp/node-repl-sock-' + process.pid); - r.on('exit', function () { + r.on('exit', function() { server.close(); process.exit(); }); diff --git a/wd/lib/callbacks.js b/wd/lib/callbacks.js index 44c362ca..ad6c4b1c 100644 --- a/wd/lib/callbacks.js +++ b/wd/lib/callbacks.js @@ -1,9 +1,13 @@ +'use strict'; + const utils = require('./utils'); const newError = utils.newError; const getJsonwireError = utils.getJsonwireError; const isWebDriverException = utils.isWebDriverException; -const cbStub = function() {}; +const cbStub = function() { + // none +}; // just calls the callback when there is no result exports.simpleCallback = function(cb) { @@ -16,7 +20,11 @@ exports.simpleCallback = function(cb) { } else { // looking for JsonWire response let jsonWireRes; - try {jsonWireRes = JSON.parse(data);} catch (ign) {} + try { + jsonWireRes = JSON.parse(data); + } catch (ign) { + // none + } if (jsonWireRes && (jsonWireRes.status !== undefined)) { // valid JsonWire response if (jsonWireRes.status === 0) { @@ -40,7 +48,7 @@ exports.simpleCallback = function(cb) { } else { // something wrong cb(newError( - {message: 'Unexpected data in simpleCallback.', data: jsonWireRes || data})); + { message: 'Unexpected data in simpleCallback.', data: jsonWireRes || data })); } } }; @@ -56,7 +64,7 @@ const callbackWithDataBase = function(cb) { try { obj = JSON.parse(data); } catch (e) { - return cb(newError({message: 'Not JSON response', data: data})); + return cb(newError({ message: 'Not JSON response', data })); } try { alertText = obj.value.alert.text; @@ -88,10 +96,10 @@ const callbackWithDataBase = function(cb) { exports.callbackWithData = function(cb, browser) { cb = cb || cbStub; return callbackWithDataBase(function(err, obj) { - if (err) {return cb(err);} + if (err) { return cb(err); } if (isWebDriverException(obj.value)) { return cb(newError( - {message: obj.value.message, cause: obj.value})); + { message: obj.value.message, cause: obj.value })); } // we might get a WebElement back as part of executeScript, so let's // check to make sure we convert if necessary to element objects @@ -112,14 +120,14 @@ exports.callbackWithData = function(cb, browser) { exports.elementCallback = function(cb, browser) { cb = cb || cbStub; return callbackWithDataBase(function(err, obj) { - if (err) {return cb(err);} + if (err) { return cb(err); } if (isWebDriverException(obj.value)) { return cb(newError( - {message: obj.value.message, cause: obj.value})); + { message: obj.value.message, cause: obj.value })); } if (!obj.value.ELEMENT) { cb(newError( - {message: 'no ELEMENT in response value field.', cause: obj})); + { message: 'no ELEMENT in response value field.', cause: obj })); } else { const el = browser.newElement(obj.value.ELEMENT); cb(null, el); @@ -131,14 +139,14 @@ exports.elementCallback = function(cb, browser) { exports.elementsCallback = function(cb, browser) { cb = cb || cbStub; return callbackWithDataBase(function(err, obj) { - if (err) {return cb(err);} + if (err) { return cb(err); } if (isWebDriverException(obj.value)) { return cb(newError( - {message: obj.value.message, cause: obj.value})); + { message: obj.value.message, cause: obj.value })); } if (!(obj.value instanceof Array)) { return cb(newError( - {message: 'Response value field is not an Array.', cause: obj.value})); + { message: 'Response value field is not an Array.', cause: obj.value })); } let i; const elements = []; @@ -154,10 +162,10 @@ exports.elementsCallback = function(cb, browser) { exports.elementOrElementsCallback = function(cb, browser) { cb = cb || cbStub; return callbackWithDataBase(function(err, obj) { - if (err) {return cb(err);} + if (err) { return cb(err); } if (isWebDriverException(obj.value)) { return cb(newError( - {message: obj.value.message, cause: obj.value})); + { message: obj.value.message, cause: obj.value })); } let el; if (obj.value.ELEMENT) { @@ -173,7 +181,7 @@ exports.elementOrElementsCallback = function(cb, browser) { cb(null, elements); } else { cb(newError( - {message: 'no element or element array in response value field.', cause: obj})); + { message: 'no element or element array in response value field.', cause: obj })); } }); }; diff --git a/wd/lib/commands.js b/wd/lib/commands.js index e28d7076..5f13c095 100644 --- a/wd/lib/commands.js +++ b/wd/lib/commands.js @@ -1,3 +1,5 @@ +'use strict'; + const fs = require('fs'); const url = require('url'); const path = require('path'); @@ -45,7 +47,7 @@ commands.status = function() { this._jsonWireCall({ method: 'GET', absPath: 'status', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -59,7 +61,7 @@ commands.sessions = function() { this._jsonWireCall({ method: 'GET', absPath: 'sessions', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -79,8 +81,8 @@ commands.next = function() { cb: callbackWithData(cb, this), data: { method, - args - } + args, + }, }); }; @@ -117,7 +119,7 @@ commands.execute = function() { method: 'POST', relPath: '/execute', cb: callbackWithData(cb, this), - data: { script: code, args: args } + data: { script: code, args }, }); }; @@ -145,7 +147,7 @@ commands.safeExecute = function() { method: 'POST', relPath: '/execute', cb: callbackWithData(cb, this), - data: { script: safeExecuteJsScript, args: [ code, args ] } + data: { script: safeExecuteJsScript, args: [ code, args ] }, }); }; @@ -174,6 +176,7 @@ commands.safeExecute = function() { * Safely evaluate expression, always returning (using safeExecute): * safeEval(code, cb) -> cb(err, value) * + * @param code * @jsonWire POST /session/:sessionId/execute */ commands.safeEval = function(code) { @@ -197,7 +200,7 @@ commands.safeEval = function(code) { commands.executeAsync = function() { const fargs = utils.varargs(arguments); const cb = fargs.callback; - const code = fargs.all[0]; + let code = fargs.all[0]; const args = fargs.all[1] || []; code = codeToString(code); @@ -205,7 +208,7 @@ commands.executeAsync = function() { method: 'POST', relPath: '/execute_async', cb: callbackWithData(cb, this), - data: { script: code, args: args } + data: { script: code, args }, }); }; @@ -232,7 +235,7 @@ commands.safeExecuteAsync = function() { method: 'POST', relPath: '/execute_async', cb: callbackWithData(cb, this), - data: { script: safeExecuteAsyncJsScript, args: [ code, args ] } + data: { script: safeExecuteAsyncJsScript, args: [ code, args ] }, }); }; @@ -268,7 +271,7 @@ commands.sessionCapabilities = function() { this._jsonWireCall({ method: 'GET', // default url - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -301,7 +304,7 @@ commands.close = function() { this._jsonWireCall({ method: 'DELETE', relPath: '/window', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -315,13 +318,14 @@ commands.currentContext = function() { this._jsonWireCall({ method: 'GET', relPath: '/context', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * context(contextRef, cb) -> cb(err, context) * + * @param contextRef * @jsonWire POST /session/:sessionId/context */ commands.context = function(contextRef) { @@ -330,7 +334,7 @@ commands.context = function(contextRef) { method: 'POST', relPath: '/context', cb: simpleCallback(cb), - data: { name: contextRef } + data: { name: contextRef }, }); }; @@ -344,13 +348,14 @@ commands.contexts = function() { this._jsonWireCall({ method: 'GET', relPath: '/contexts', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * window(name, cb) -> cb(err) * + * @param windowRef * @jsonWire POST /session/:sessionId/window */ commands.window = function(windowRef) { @@ -359,13 +364,14 @@ commands.window = function(windowRef) { method: 'POST', relPath: '/window', cb: simpleCallback(cb), - data: { name: windowRef } + data: { name: windowRef }, }); }; /** * frame(frameRef, cb) -> cb(err) * + * @param frameRef * @jsonWire POST /session/:sessionId/frame */ commands.frame = function(frameRef) { @@ -383,7 +389,7 @@ commands.frame = function(frameRef) { method: 'POST', relPath: '/frame', cb: simpleCallback(cb), - data: { id: frameRef } + data: { id: frameRef }, }); }; @@ -406,7 +412,7 @@ commands.windowHandle = function() { this._jsonWireCall({ method: 'GET', relPath: '/window_handle', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -420,7 +426,7 @@ commands.windowHandles = function() { this._jsonWireCall({ method: 'GET', relPath: '/window_handles', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -434,13 +440,16 @@ commands.getGeoLocation = function() { this._jsonWireCall({ method: 'GET', relPath: '/location', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * setGeoLocation(lat, lon, alt, cb) -> cb(err) * + * @param lat + * @param lon + * @param alt * @jsonWire POST /session/:sessionId/location */ commands.setGeoLocation = function(lat, lon, alt) { @@ -452,13 +461,15 @@ commands.setGeoLocation = function(lat, lon, alt) { method: 'POST', relPath: '/location', cb: simpleCallback(cb), - data: { location: { latitude: lat, longitude: lon, altitude: alt } } + data: { location: { latitude: lat, longitude: lon, altitude: alt } }, }); }; /** * scroll(xOffset, yOffset, cb) -> cb(err) * + * @param xOffset + * @param yOffset * @jsonWire POST /session/:sessionId/touch/scroll */ commands.scroll = function(xOffset, yOffset) { @@ -467,7 +478,7 @@ commands.scroll = function(xOffset, yOffset) { method: 'POST', relPath: '/touch/scroll', cb: simpleCallback(cb, this), - data: { xoffset: xOffset, yoffset: yOffset } + data: { xoffset: xOffset, yoffset: yOffset }, }); }; @@ -481,13 +492,14 @@ commands.logTypes = function() { this._jsonWireCall({ method: 'GET', relPath: '/log/types', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * log(logType, cb) -> cb(err, arrayOfLogs) * + * @param logType * @jsonWire POST /session/:sessionId/log */ commands.log = function(logType) { @@ -496,7 +508,7 @@ commands.log = function(logType) { method: 'POST', relPath: '/log', cb: callbackWithData(cb, this), - data: { type: logType } + data: { type: logType }, }); }; @@ -512,7 +524,7 @@ commands.quit = function() { method: 'DELETE', // default url emit: { event: 'status', message: '\nEnding your web drivage..\n' }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -520,6 +532,7 @@ commands.quit = function() { * get(url,cb) -> cb(err) * Get a new url. * + * @param _url * @jsonWire POST /session/:sessionId/url */ commands.get = function(_url) { @@ -530,8 +543,8 @@ commands.get = function(_url) { this._jsonWireCall({ method: 'POST', relPath: '/url', - data: { 'url': _url }, - cb: simpleCallback(cb) + data: { url: _url }, + cb: simpleCallback(cb), }); }; @@ -545,13 +558,14 @@ commands.refresh = function() { this._jsonWireCall({ method: 'POST', relPath: '/refresh', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** * maximize(handle, cb) -> cb(err) * + * @param win * @jsonWire POST /session/:sessionId/window/:windowHandle/maximize */ commands.maximize = function(win) { @@ -562,13 +576,16 @@ commands.maximize = function(win) { this._jsonWireCall({ method: 'POST', relPath: '/window/' + win + '/maximize', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** * windowSize(handle, width, height, cb) -> cb(err) * + * @param win + * @param width + * @param height * @jsonWire POST /session/:sessionId/window/:windowHandle/size */ commands.windowSize = function(win, width, height) { @@ -576,8 +593,8 @@ commands.windowSize = function(win, width, height) { this._jsonWireCall({ method: 'POST', relPath: '/window/' + win + '/size', - data: { 'width': width, 'height': height }, - cb: simpleCallback(cb) + data: { width, height }, + cb: simpleCallback(cb), }); }; @@ -595,7 +612,7 @@ commands.getWindowSize = function() { this._jsonWireCall({ method: 'GET', relPath: '/window/' + win + '/size', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -617,7 +634,7 @@ commands.setWindowSize = function() { method: 'POST', relPath: '/window/' + win + '/size', cb: simpleCallback(cb), - data: { width: width, height: height } + data: { width, height }, }); }; @@ -635,7 +652,7 @@ commands.getWindowPosition = function() { this._jsonWireCall({ method: 'GET', relPath: '/window/' + win + '/position', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -657,7 +674,7 @@ commands.setWindowPosition = function() { method: 'POST', relPath: '/window/' + win + '/position', cb: simpleCallback(cb), - data: { x: x, y: y } + data: { x, y }, }); }; @@ -671,7 +688,7 @@ commands.forward = function() { this._jsonWireCall({ method: 'POST', relPath: '/forward', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -685,7 +702,7 @@ commands.back = function() { this._jsonWireCall({ method: 'POST', relPath: '/back', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -721,6 +738,7 @@ commands.configureHttp = function() { /** * setImplicitWaitTimeout(ms, cb) -> cb(err) * + * @param ms * @jsonWire POST /session/:sessionId/timeouts/implicit_wait */ commands.setImplicitWaitTimeout = function(ms) { @@ -728,8 +746,8 @@ commands.setImplicitWaitTimeout = function(ms) { this._jsonWireCall({ method: 'POST', relPath: '/timeouts/implicit_wait', - data: { ms: ms }, - cb: simpleCallback(cb) + data: { ms }, + cb: simpleCallback(cb), }); }; @@ -739,6 +757,7 @@ commands.setWaitTimeout = commands.setImplicitWaitTimeout; /** * setAsyncScriptTimeout(ms, cb) -> cb(err) * + * @param ms * @jsonWire POST /session/:sessionId/timeouts/async_script */ commands.setAsyncScriptTimeout = function(ms) { @@ -746,8 +765,8 @@ commands.setAsyncScriptTimeout = function(ms) { this._jsonWireCall({ method: 'POST', relPath: '/timeouts/async_script', - data: { ms: ms }, - cb: simpleCallback(cb) + data: { ms }, + cb: simpleCallback(cb), }); }; @@ -755,6 +774,7 @@ commands.setAsyncScriptTimeout = function(ms) { * setPageLoadTimeout(ms, cb) -> cb(err) * (use setImplicitWaitTimeout and setAsyncScriptTimeout to set the other timeouts) * + * @param ms * @jsonWire POST /session/:sessionId/timeouts */ commands.setPageLoadTimeout = function(ms) { @@ -762,14 +782,15 @@ commands.setPageLoadTimeout = function(ms) { this._jsonWireCall({ method: 'POST', relPath: '/timeouts', - data: { type: 'page load', ms: ms }, - cb: simpleCallback(cb) + data: { type: 'page load', ms }, + cb: simpleCallback(cb), }); }; /** * setCommandTimeout(ms, cb) -> cb(err) * (this is for Appium only) + * @param ms * @jsonWire POST /session/:sessionId/timeouts */ commands.setCommandTimeout = function(ms) { @@ -777,14 +798,16 @@ commands.setCommandTimeout = function(ms) { this._jsonWireCall({ method: 'POST', relPath: '/timeouts', - data: { type: 'command', ms: ms }, - cb: simpleCallback(cb) + data: { type: 'command', ms }, + cb: simpleCallback(cb), }); }; /** * element(using, value, cb) -> cb(err, element) * + * @param using + * @param value * @jsonWire POST /session/:sessionId/element */ commands.element = function(using, value) { @@ -792,8 +815,8 @@ commands.element = function(using, value) { this._jsonWireCall({ method: 'POST', relPath: '/element', - data: { using: using, value: value }, - cb: elementCallback(cb, this) + data: { using, value }, + cb: elementCallback(cb, this), }); }; @@ -801,6 +824,8 @@ commands.element = function(using, value) { * Retrieve an element avoiding not found exception and returning null instead: * elementOrNull(using, value, cb) -> cb(err, element) * + * @param using + * @param value * @jsonWire POST /session/:sessionId/elements * @docOrder 3 */ @@ -817,7 +842,7 @@ commands.elementOrNull = function(using, value) { } else { cb(err); } - } + }, ]); }; @@ -825,6 +850,8 @@ commands.elementOrNull = function(using, value) { * Retrieve an element avoiding not found exception and returning undefined instead: * elementIfExists(using, value, cb) -> cb(err, element) * + * @param using + * @param value * @jsonWire POST /session/:sessionId/elements * @docOrder 5 */ @@ -841,13 +868,15 @@ commands.elementIfExists = function(using, value) { } else { cb(err); } - } + }, ]); }; /** * elements(using, value, cb) -> cb(err, elements) * + * @param using + * @param value * @jsonWire POST /session/:sessionId/elements * @docOrder 1 */ @@ -856,8 +885,8 @@ commands.elements = function(using, value) { this._jsonWireCall({ method: 'POST', relPath: '/elements', - data: { using: using, value: value }, - cb: elementsCallback(cb, this) + data: { using, value }, + cb: elementsCallback(cb, this), }); }; @@ -865,6 +894,8 @@ commands.elements = function(using, value) { * Check if element exists: * hasElement(using, value, cb) -> cb(err, boolean) * + * @param using + * @param value * @jsonWire POST /session/:sessionId/elements * @docOrder 7 */ @@ -897,13 +928,13 @@ commands.waitFor = function() { opts = { asserter: fargs.all[0], timeout: fargs.all[1], - pollFreq: fargs.all[2] + pollFreq: fargs.all[2], }; } const { MACACA_WD_CLIENT_WAITFOR_TIMEOUT, - MACACA_WD_CLIENT_WAITFOR_POLL_FREQ + MACACA_WD_CLIENT_WAITFOR_POLL_FREQ, } = process.env; // default opts.timeout = opts.timeout || parseInt(MACACA_WD_CLIENT_WAITFOR_TIMEOUT, 10) || 10 * 1000; @@ -968,7 +999,6 @@ commands.waitFor = function() { * asserter like: function(element , cb) -> cb(err, satisfied, el) */ commands.waitForElement = function() { - const cb = findCallback(arguments); const fargs = utils.varargs(arguments); const using = fargs.all[0]; @@ -982,12 +1012,12 @@ commands.waitForElement = function() { opts = { asserter: fargs.all[2], timeout: fargs.all[3], - pollFreq: fargs.all[4] + pollFreq: fargs.all[4], }; } else { opts = { timeout: fargs.all[2], - pollFreq: fargs.all[3] + pollFreq: fargs.all[3], }; } @@ -1054,7 +1084,7 @@ commands.waitForElement = function() { { asserter: wrappedAsserter, timeout: opts.timeout, - pollFreq: opts.pollFreq + pollFreq: opts.pollFreq, }, function(err, value) { if (err && err.message && err.message.match(/Condition/)) { cb(new Error("Element condition wasn't satisfied!")); @@ -1086,12 +1116,12 @@ commands.waitForElements = function() { opts = { asserter: fargs.all[2], timeout: fargs.all[3], - pollFreq: fargs.all[4] + pollFreq: fargs.all[4], }; } else { opts = { timeout: fargs.all[2], - pollFreq: fargs.all[3] + pollFreq: fargs.all[3], }; } @@ -1155,7 +1185,7 @@ commands.waitForElements = function() { { asserter: wrappedAsserter, timeout: opts.timeout, - pollFreq: opts.pollFreq + pollFreq: opts.pollFreq, }, function(err, value) { if (err && err.message && err.message.match(/Condition/)) { cb(new Error("Element condition wasn't satisfied!")); @@ -1191,7 +1221,7 @@ commands.takeScreenshot = function() { this._jsonWireCall({ method: 'GET', relPath: `/screenshot${url.format({ query: params })}`, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1248,6 +1278,7 @@ commands.saveScreenshot = function() { if (_params && _params.video) { cb(null, base64Data); } + // eslint-disable-next-line node/prefer-promises/fs require('fs').writeFile(filePath, base64Data, 'base64', function(err) { if (err) { return cb(err); @@ -1467,6 +1498,7 @@ _.each(utils.elementFuncTypes, function(suffix) { /** * getTagName(element, cb) -> cb(err, name) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/name */ commands.getTagName = function(element) { @@ -1474,7 +1506,7 @@ commands.getTagName = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/name', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1498,7 +1530,7 @@ commands.getAttribute = function() { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/attribute/' + attrName, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1522,7 +1554,7 @@ commands.getProperty = function() { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/property/' + propertyName, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1542,13 +1574,14 @@ commands.getRect = function() { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/rect', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * isDisplayed(element, cb) -> cb(err, displayed) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/displayed */ commands.isDisplayed = function(element) { @@ -1556,7 +1589,7 @@ commands.isDisplayed = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/displayed', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1565,6 +1598,7 @@ commands.displayed = commands.isDisplayed; /** * isEnabled(element, cb) -> cb(err, enabled) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/enabled */ commands.isEnabled = function(element) { @@ -1572,7 +1606,7 @@ commands.isEnabled = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/enabled', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1581,6 +1615,7 @@ commands.enabled = commands.isEnabled; /** * isSelected(element, cb) -> cb(err, selected) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/selected */ commands.isSelected = function(element) { @@ -1588,7 +1623,7 @@ commands.isSelected = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/selected', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1625,7 +1660,7 @@ commands.clickElement = function() { method: 'POST', relPath: '/element/' + element + '/click', data: { clickOpts: params }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1642,13 +1677,15 @@ commands.takeElementScreenshot = function() { this._jsonWireCall({ method: 'GET', relPath: `/element/${element}/screenshot${url.format({ query: params })}`, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * getComputedCss(element, cssProperty , cb) -> cb(err, value) * + * @param element + * @param cssProperty * @jsonWire GET /session/:sessionId/element/:id/css/:propertyName */ commands.getComputedCss = function(element, cssProperty) { @@ -1656,7 +1693,7 @@ commands.getComputedCss = function(element, cssProperty) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/css/' + cssProperty, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1665,6 +1702,8 @@ commands.getComputedCSS = commands.getComputedCss; /** * equalsElement(element, other , cb) -> cb(err, value) * + * @param element + * @param other * @jsonWire GET /session/:sessionId/element/:id/equals/:other */ commands.equalsElement = function(element, other) { @@ -1672,7 +1711,7 @@ commands.equalsElement = function(element, other) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/equals/' + other, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -1683,7 +1722,7 @@ const _flick1 = function() { const yspeed = fargs.all[1]; const swipe = fargs.all[2]; - const data = { xspeed: xspeed, yspeed: yspeed }; + const data = { xspeed, yspeed }; if (swipe) { data.swipe = swipe; } @@ -1691,8 +1730,8 @@ const _flick1 = function() { this._jsonWireCall({ method: 'POST', relPath: '/touch/flick', - data: data, - cb: simpleCallback(cb) + data, + cb: simpleCallback(cb), }); }; @@ -1707,8 +1746,8 @@ const _flick2 = function() { this._jsonWireCall({ method: 'POST', relPath: '/touch/flick', - data: { element: element, xoffset: xoffset, yoffset: yoffset, speed: speed }, - cb: simpleCallback(cb) + data: { element, xoffset, yoffset, speed }, + cb: simpleCallback(cb), }); }; @@ -1734,6 +1773,8 @@ commands.flick = function() { * tapElement(element) -> cb(err) * Taps element * + * @param element + * @param cb * @jsonWire POST /session/:sessionId/touch/click */ commands.tapElement = function(element, cb) { @@ -1741,7 +1782,7 @@ commands.tapElement = function(element, cb) { method: 'POST', relPath: '/touch/click', data: { element: element.value.toString() }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1761,7 +1802,7 @@ commands.performTouchAction = function() { method: 'POST', relPath: '/touch/perform', data: { actions: touchAction.toJSON() }, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); } catch (err) { return cb(err); @@ -1777,7 +1818,7 @@ commands.performTouchAction = function() { commands.performMultiAction = function() { const _this = this; const fargs = utils.varargs(arguments); - let cb = fargs.callback; + const cb = fargs.callback; let element = fargs.all[0]; let multiTouchAction = fargs.all[1]; if (!multiTouchAction) { @@ -1793,8 +1834,8 @@ commands.performMultiAction = function() { _this._jsonWireCall({ method: 'POST', relPath: '/touch/multi/perform', - data: data, - cb: callbackWithData(cb, this) + data, + cb: callbackWithData(cb, this), }); } catch (err) { return cb(err); @@ -1821,10 +1862,10 @@ commands.moveTo = function() { data: { element: element ? element.toString() : null, - xoffset: xoffset, - yoffset: yoffset + xoffset, + yoffset, }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1843,8 +1884,8 @@ commands.buttonDown = function() { this._jsonWireCall({ method: 'POST', relPath: '/buttondown', - data: { button: button }, - cb: simpleCallback(cb) + data: { button }, + cb: simpleCallback(cb), }); }; @@ -1863,8 +1904,8 @@ commands.buttonUp = function() { this._jsonWireCall({ method: 'POST', relPath: '/buttonup', - data: { button: button }, - cb: simpleCallback(cb) + data: { button }, + cb: simpleCallback(cb), }); }; @@ -1884,8 +1925,8 @@ commands.click = function() { this._jsonWireCall({ method: 'POST', relPath: '/click', - data: { button: button }, - cb: simpleCallback(cb) + data: { button }, + cb: simpleCallback(cb), }); }; @@ -1906,13 +1947,13 @@ commands.swipe = function() { method: 'POST', relPath: `/element/${startX}/swipe`, data: { - startX: startX, - startY: startY, - endX: endX, - endY: endY, - duration: duration + startX, + startY, + endX, + endY, + duration, }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1926,7 +1967,7 @@ commands.doubleclick = function() { this._jsonWireCall({ method: 'POST', relPath: '/doubleclick', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1935,6 +1976,8 @@ commands.doubleclick = function() { * Type keys (all keys are up at the end of command). * special key map: wd.SPECIAL_KEYS (see lib/special-keys.js) * + * @param element + * @param keys * @jsonWire POST /session/:sessionId/element/:id/value */ commands.type = function(element, keys) { @@ -1952,7 +1995,7 @@ commands.type = function(element, keys) { method: 'POST', relPath: '/element/' + element + '/value', data: { value: keys }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1971,7 +2014,7 @@ commands.replace = function(element, keys) { method: 'POST', relPath: '/appium/element/' + element + '/replace_value', data: { value: keys }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1979,6 +2022,7 @@ commands.replace = function(element, keys) { * submit(element, cb) -> cb(err) * Submit a `FORM` element. * + * @param element * @jsonWire POST /session/:sessionId/element/:id/submit */ commands.submit = function(element) { @@ -1986,7 +2030,7 @@ commands.submit = function(element) { this._jsonWireCall({ method: 'POST', relPath: '/element/' + element + '/submit', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -1995,6 +2039,7 @@ commands.submit = function(element) { * Press keys (keys may still be down at the end of command). * special key map: wd.SPECIAL_KEYS (see lib/special-keys.js) * + * @param keys * @jsonWire POST /session/:sessionId/keys */ commands.keys = function(keys) { @@ -2012,13 +2057,14 @@ commands.keys = function(keys) { method: 'POST', relPath: '/keys', data: { value: keys }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** * clear(element, cb) -> cb(err) * + * @param element * @jsonWire POST /session/:sessionId/element/:id/clear */ commands.clear = function(element) { @@ -2026,7 +2072,7 @@ commands.clear = function(element) { this._jsonWireCall({ method: 'POST', relPath: '/element/' + element + '/clear', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -2040,7 +2086,7 @@ commands.title = function() { this._jsonWireCall({ method: 'GET', relPath: '/title', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2054,7 +2100,7 @@ commands.source = function() { this._jsonWireCall({ method: 'GET', relPath: '/source', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2064,7 +2110,7 @@ const _rawText = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/text', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2098,6 +2144,8 @@ commands.text = function() { * textPresent(searchText, element, cb) -> cb(err, boolean) * element: specific element, 'body', or undefined * + * @param searchText + * @param element * @jsonWire GET /session/:sessionId/element/:id/text * @docOrder 3 */ @@ -2122,13 +2170,14 @@ commands.alertText = function() { this._jsonWireCall({ method: 'GET', relPath: '/alert_text', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * alertKeys(keys, cb) -> cb(err) * + * @param keys * @jsonWire POST /session/:sessionId/alert_text */ commands.alertKeys = function(keys) { @@ -2137,7 +2186,7 @@ commands.alertKeys = function(keys) { method: 'POST', relPath: '/alert_text', data: { text: keys }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -2151,7 +2200,7 @@ commands.acceptAlert = function() { this._jsonWireCall({ method: 'POST', relPath: '/accept_alert', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -2165,7 +2214,7 @@ commands.dismissAlert = function() { this._jsonWireCall({ method: 'POST', relPath: '/dismiss_alert', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -2179,7 +2228,7 @@ commands.active = function() { this._jsonWireCall({ method: 'POST', relPath: '/element/active', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2193,7 +2242,7 @@ commands.url = function() { this._jsonWireCall({ method: 'GET', relPath: '/url', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2207,7 +2256,7 @@ commands.allCookies = function() { this._jsonWireCall({ method: 'GET', relPath: '/cookie', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2218,20 +2267,21 @@ commands.allCookies = function() { * Optional cookie fields: * path, domain, secure, expiry * + * @param cookie * @jsonWire POST /session/:sessionId/cookie */ commands.setCookie = function(cookie) { const cb = findCallback(arguments); // setting secure otherwise selenium server throws - if (cookie) { + if (cookie && typeof cookie === 'object') { cookie.secure = cookie.secure || false; } this._jsonWireCall({ method: 'POST', relPath: '/cookie', - data: { cookie: cookie }, - cb: simpleCallback(cb) + data: { cookie }, + cb: simpleCallback(cb), }); }; @@ -2245,13 +2295,14 @@ commands.deleteAllCookies = function() { this._jsonWireCall({ method: 'DELETE', relPath: '/cookie', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** * deleteCookie(name, cb) -> cb(err) * + * @param name * @jsonWire DELETE /session/:sessionId/cookie/:name */ commands.deleteCookie = function(name) { @@ -2259,7 +2310,7 @@ commands.deleteCookie = function(name) { this._jsonWireCall({ method: 'DELETE', relPath: '/cookie/' + encodeURIComponent(name), - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -2273,13 +2324,14 @@ commands.getOrientation = function() { this._jsonWireCall({ method: 'GET', relPath: '/orientation', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * setOrientation(cb) -> cb(err, orientation) * + * @param orientation * @jsonWire POST /session/:sessionId/orientation */ commands.setOrientation = function(orientation) { @@ -2287,8 +2339,8 @@ commands.setOrientation = function(orientation) { this._jsonWireCall({ method: 'POST', relPath: '/orientation', - data: { orientation: orientation }, - cb: simpleCallback(cb) + data: { orientation }, + cb: simpleCallback(cb), }); }; @@ -2407,19 +2459,21 @@ commands.isVisible = function() { /** * Retrieves the pageIndex element (added for Appium): * getPageIndex(element, cb) -> cb(err, pageIndex) + * @param element */ commands.getPageIndex = function(element) { const cb = findCallback(arguments); this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/pageIndex', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * getLocation(element, cb) -> cb(err, location) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/location */ commands.getLocation = function(element) { @@ -2427,13 +2481,14 @@ commands.getLocation = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/location', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * getLocationInView(element, cb) -> cb(err, location) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/location_in_view */ commands.getLocationInView = function(element) { @@ -2441,13 +2496,14 @@ commands.getLocationInView = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/location_in_view', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * getSize(element, cb) -> cb(err, size) * + * @param element * @jsonWire GET /session/:sessionId/element/:id/size */ commands.getSize = function(element) { @@ -2455,7 +2511,7 @@ commands.getSize = function(element) { this._jsonWireCall({ method: 'GET', relPath: '/element/' + element + '/size', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2463,6 +2519,7 @@ commands.getSize = function(element) { * Uploads a local file using undocumented * POST /session/:sessionId/file * uploadFile(filepath, cb) -> cb(err, filepath) + * @param filepath */ commands.uploadFile = function(filepath) { const cb = findCallback(arguments); @@ -2484,7 +2541,7 @@ commands.uploadFile = function(filepath) { method: 'POST', relPath: '/file', data: { file: Buffer.concat(dataList).toString('base64') }, - cb: callbackWithData(cb, _this) + cb: callbackWithData(cb, _this), }); }); @@ -2513,8 +2570,8 @@ commands.waitForJsCondition = function() { commands.waitFor.apply(this, [ { asserter: asserters.jsCondition(jsConditionExpr, true), - timeout: timeout, - pollFreq: pollFreq + timeout, + pollFreq, }, function(err, value) { if (err && err.message && err.message.match(/Condition/)) { cb(new Error("Element condition wasn't satisfied!")); @@ -2555,21 +2612,25 @@ commands.waitForConditionInBrowser = function() { return cb('waitForConditionInBrowser failure for: ' + conditionExpr); } cb(null, res); - } + }, ]); }; /** * sleep(ms, cb) -> cb(err) + * @param ms + * @param cb */ commands.sleep = function(ms, cb) { cb = cb || function() { + // none }; setTimeout(cb, ms); }; /** * noop(cb) -> cb(err) + * @param cb */ commands.noop = function(cb) { if (cb) { @@ -2587,7 +2648,7 @@ commands.shakeDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/shake', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -2609,8 +2670,8 @@ commands.lockDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/lock', - data: { seconds: seconds }, - cb: simpleCallback(cb) + data: { seconds }, + cb: simpleCallback(cb), }); }; /** @@ -2631,7 +2692,7 @@ commands.unlockDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/unlock', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -2652,7 +2713,7 @@ commands.isLocked = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/is_locked', - cb: callbackWithData(cb) + cb: callbackWithData(cb), }); }; @@ -2667,15 +2728,15 @@ commands.deviceKeyEvent = function() { const cb = fargs.callback; const keycode = fargs.all[0]; const metastate = fargs.all[1]; - const data = { keycode: keycode }; + const data = { keycode }; if (metastate) { data.metastate = metastate; } this._jsonWireCall({ method: 'POST', relPath: '/appium/device/keyevent', - data: data, - cb: simpleCallback(cb) + data, + cb: simpleCallback(cb), }); }; /** @@ -2697,8 +2758,8 @@ commands.pressDeviceKey = commands.deviceKeyEvent; commands.rotateDevice = function() { const fargs = utils.varargs(arguments); const cb = fargs.callback; - const element = fargs.all[0]; - const opts = fargs.all[1]; + let element = fargs.all[0]; + let opts = fargs.all[1]; if (!(element && element.value)) { opts = element; element = null; @@ -2710,8 +2771,8 @@ commands.rotateDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/rotate', - data: data, - cb: simpleCallback(cb) + data, + cb: simpleCallback(cb), }); }; /** @@ -2734,7 +2795,7 @@ commands.getCurrentDeviceActivity = function() { this._jsonWireCall({ method: 'GET', relPath: '/appium/device/current_activity', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** @@ -2756,8 +2817,8 @@ commands.installAppOnDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/install_app', - data: { appPath: appPath }, - cb: simpleCallback(cb) + data: { appPath }, + cb: simpleCallback(cb), }); }; /** @@ -2779,8 +2840,8 @@ commands.removeAppFromDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/remove_app', - data: { appId: appId }, - cb: simpleCallback(cb) + data: { appId }, + cb: simpleCallback(cb), }); }; /** @@ -2802,8 +2863,8 @@ commands.isAppInstalledOnDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/app_installed', - data: { bundleId: bundleId }, - cb: callbackWithData(cb, this) + data: { bundleId }, + cb: callbackWithData(cb, this), }); }; /** @@ -2826,20 +2887,20 @@ commands.hideDeviceKeyboard = function() { const cb = fargs.callback; let data = {}; switch (typeof fargs.all[0]) { - case 'string': - data = { keyName: fargs.all[0] }; - break; - case 'object': - data = fargs.all[0]; - break; - default: - data = null; + case 'string': + data = { keyName: fargs.all[0] }; + break; + case 'object': + data = fargs.all[0]; + break; + default: + data = null; } this._jsonWireCall({ method: 'POST', relPath: '/appium/device/hide_keyboard', - data: data, - cb: simpleCallback(cb) + data, + cb: simpleCallback(cb), }); }; commands.hideKeyboard = commands.hideDeviceKeyboard; @@ -2858,7 +2919,7 @@ commands.pushFileToDevice = function() { method: 'POST', relPath: '/appium/device/push_file', data: { path: pathOnDevice, data: base64Data }, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -2881,7 +2942,7 @@ commands.pullFileFromDevice = function() { method: 'POST', relPath: '/appium/device/pull_file', data: { path: pathOnDevice }, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** @@ -2904,7 +2965,7 @@ commands.pullFolderFromDevice = function() { method: 'POST', relPath: '/appium/device/pull_folder', data: { path: pathOnDevice }, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -2925,7 +2986,7 @@ commands.toggleAirplaneModeOnDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/toggle_airplane_mode', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -2951,7 +3012,7 @@ commands.toggleWiFiOnDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/toggle_wifi', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -2971,7 +3032,7 @@ commands.toggleLocationServicesOnDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/toggle_location_services', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -2991,7 +3052,7 @@ commands.toggleDataOnDevice = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/toggle_data', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; /** @@ -3011,7 +3072,7 @@ commands.launchApp = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/launch', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -3025,7 +3086,7 @@ commands.closeApp = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/close', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -3039,7 +3100,7 @@ commands.resetApp = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/reset', - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -3055,8 +3116,8 @@ commands.backgroundApp = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/background', - data: { seconds: seconds }, - cb: simpleCallback(cb) + data: { seconds }, + cb: simpleCallback(cb), }); }; @@ -3073,8 +3134,8 @@ commands.endTestCoverageForApp = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/end_test_coverage', - data: { intent: intent, path: path }, - cb: callbackWithData(cb, this) + data: { intent, path }, + cb: callbackWithData(cb, this), }); }; /** @@ -3104,8 +3165,8 @@ commands.complexFindInApp = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/complex_find', - data: { selector: selector }, - cb: elementOrElementsCallback(cb, this) + data: { selector }, + cb: elementOrElementsCallback(cb, this), }); }; @@ -3130,14 +3191,16 @@ commands.getAppStrings = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/app/strings', - data: { language: language }, - cb: callbackWithData(cb, this) + data: { language }, + cb: callbackWithData(cb, this), }); }; /** * setImmediateValueInApp(element, value, cb) -> cb(err) * + * @param element + * @param value * @jsonWire POST /session/:sessionId/appium/element/:elementId?/value */ commands.setImmediateValueInApp = function(element, value) { @@ -3145,8 +3208,8 @@ commands.setImmediateValueInApp = function(element, value) { this._jsonWireCall({ method: 'POST', relPath: '/appium/element/' + element.value.toString() + '/value', - data: { value: value }, - cb: simpleCallback(cb) + data: { value }, + cb: simpleCallback(cb), }); }; @@ -3165,7 +3228,7 @@ commands.startActivity = function() { method: 'POST', relPath: '/appium/device/start_activity', data: options, - cb: simpleCallback(cb) + cb: simpleCallback(cb), }); }; @@ -3188,7 +3251,7 @@ commands.setNetworkConnection = function() { method: 'POST', relPath: '/network_connection', data: { parameters: { type: fargs.all[0] } }, - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -3202,7 +3265,7 @@ commands.getNetworkConnection = function() { this._jsonWireCall({ method: 'GET', relPath: '/network_connection', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -3216,7 +3279,7 @@ commands.openNotifications = function() { this._jsonWireCall({ method: 'POST', relPath: '/appium/device/open_notifications', - cb: simpleCallback(cb, this) + cb: simpleCallback(cb, this), }); }; @@ -3230,7 +3293,7 @@ commands.settings = function() { this._jsonWireCall({ method: 'GET', relPath: '/appium/settings', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -3246,7 +3309,7 @@ commands.updateSettings = function() { method: 'POST', relPath: '/appium/settings', data: { settings: fargs.all[0] }, - cb: simpleCallback(cb, this) + cb: simpleCallback(cb, this), }); }; @@ -3260,13 +3323,14 @@ commands.availableIMEEngines = function() { this._jsonWireCall({ method: 'GET', relPath: '/ime/available_engines', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; /** * activateIMEEngine(cb, engine) -> cb(err) * + * @param engine * @jsonWire POST /session/:sessionId/ime/activate */ commands.activateIMEEngine = function(engine) { @@ -3274,8 +3338,8 @@ commands.activateIMEEngine = function(engine) { this._jsonWireCall({ method: 'POST', relPath: '/ime/activate', - data: { engine: engine }, - cb: simpleCallback(cb, this) + data: { engine }, + cb: simpleCallback(cb, this), }); }; @@ -3289,7 +3353,7 @@ commands.deactivateIMEEngine = function() { this._jsonWireCall({ method: 'POST', relPath: '/ime/deactivate', - cb: simpleCallback(cb, this) + cb: simpleCallback(cb, this), }); }; @@ -3303,7 +3367,7 @@ commands.isIMEActive = function() { this._jsonWireCall({ method: 'GET', relPath: '/ime/activated', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -3317,7 +3381,7 @@ commands.activeIMEEngine = function() { this._jsonWireCall({ method: 'GET', relPath: '/ime/active_engine', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -3331,7 +3395,7 @@ commands.getDeviceTime = function() { this._jsonWireCall({ method: 'GET', relPath: '/appium/device/system_time', - cb: callbackWithData(cb, this) + cb: callbackWithData(cb, this), }); }; @@ -3340,7 +3404,7 @@ commands.touch = function() { const fargs = utils.varargs(arguments); const code = fargs.all[0]; const args = fargs.all[1] || {}; - const actions = []; + let actions = []; if (Array.isArray(code)) { for (let i = 0, len = code.length; i < len; i++) { if (i > 0) { @@ -3353,7 +3417,7 @@ commands.touch = function() { actions[i] = code[i]; } } else if (typeof code === 'string') { - args['type'] = code; + args.type = code; actions = [ args ]; } else { cb(new Error('Touch function only accept a action name or a list of actions.')); @@ -3362,8 +3426,8 @@ commands.touch = function() { this._jsonWireCall({ method: 'POST', relPath: '/actions', - data: { actions: actions }, - cb: simpleCallback(cb) + data: { actions }, + cb: simpleCallback(cb), }); }; diff --git a/wd/lib/config.js b/wd/lib/config.js index 6fe5a22a..a773ffd3 100644 --- a/wd/lib/config.js +++ b/wd/lib/config.js @@ -1,3 +1,5 @@ +'use strict'; + const _ = require('./lodash'); const httpConfig = { @@ -5,22 +7,25 @@ const httpConfig = { retries: 3, retryDelay: 15, baseUrl: undefined, - proxy: undefined + proxy: undefined, }; function _configureHttp(httpConfig, opts) { _(_.keys(httpConfig)).intersection(_.keys(opts)).each(function(key) { switch (key) { - case 'timeout': - if (opts[key] === 'default') { opts[key] = undefined; } - break; - case 'retries': - if (opts[key] === 'always') { opts[key] = 0; } - if (opts[key] === 'never') { opts[key] = -1; } - break; + case 'timeout': + if (opts[key] === 'default') { opts[key] = undefined; } + break; + case 'retries': + if (opts[key] === 'always') { opts[key] = 0; } + if (opts[key] === 'never') { opts[key] = -1; } + break; + default: + break; } httpConfig[key] = opts[key]; - }, this).value(); + }, this) + .value(); } function configureHttp(opts) { @@ -28,7 +33,7 @@ function configureHttp(opts) { } module.exports = { - httpConfig: httpConfig, - _configureHttp: _configureHttp, - configureHttp: configureHttp + httpConfig, + _configureHttp, + configureHttp, }; diff --git a/wd/lib/deprecated-chain.js b/wd/lib/deprecated-chain.js index b32e19fa..d70d892a 100644 --- a/wd/lib/deprecated-chain.js +++ b/wd/lib/deprecated-chain.js @@ -1,3 +1,5 @@ +'use strict'; + const async = require('async'); const _ = require('./lodash'); @@ -19,7 +21,7 @@ deprecatedChain.chain = function(obj) { // Add queue if not already here if (!_this._queue) { - _this._queue = async.queue(function (task, callback) { + _this._queue = async.queue(function(task, callback) { if (task.args.length > 0 && typeof task.args[task.args.length - 1] === 'function') { // wrap the existing callback // if this is queueAddAsync, we instead create a callback that will be @@ -50,22 +52,22 @@ deprecatedChain.chain = function(obj) { // add unshift method if we need to add sth to the queue _this._queue = _.extend(_this._queue, { - unshift: function (data, callback) { + unshift(data, callback) { const _this = this; if (data.constructor !== Array) { - data = [data]; + data = [ data ]; } data.forEach(function(task) { _this.tasks.unshift({ data: task, - callback: typeof callback === 'function' ? callback : null + callback: typeof callback === 'function' ? callback : null, }); if (_this.saturated && _this.tasks.length === _this.concurrency) { _this.saturated(); } async.nextTick(_this.process); }); - } + }, }); } @@ -74,7 +76,7 @@ deprecatedChain.chain = function(obj) { // builds a placeHolder functions const buildPlaceholder = function(name) { return function() { - _this._queue.push({name: name, args: Array.prototype.slice.call(arguments, 0)}); + _this._queue.push({ name, args: Array.prototype.slice.call(arguments, 0) }); return chain; }; }; @@ -103,7 +105,7 @@ deprecatedChain.pauseChain = function(timeoutMs, cb) { }; deprecatedChain.next = function() { - this._queue.unshift({name: arguments[0], args: _.rest(arguments)}); + this._queue.unshift({ name: arguments[0], args: _.rest(arguments) }); }; deprecatedChain.queueAdd = function(func) { @@ -117,9 +119,10 @@ deprecatedChain.queueAddAsync = function(func, cb) { }; module.exports = { - patch: function(browser) { + patch(browser) { _(deprecatedChain).methods().each(function(methodName) { browser[methodName] = deprecatedChain[methodName].bind(browser); - }).value(); - } + }) + .value(); + }, }; diff --git a/wd/lib/element-commands.js b/wd/lib/element-commands.js index 95718a1c..b4dd5124 100644 --- a/wd/lib/element-commands.js +++ b/wd/lib/element-commands.js @@ -1,8 +1,10 @@ +'use strict'; + // Element object // Wrapper around browser methods const _ = require('./lodash'); const utils = require('./utils.js'); -const deprecator = utils.deprecator; +const { deprecator } = utils; const fs = require('fs'); const callbacks = require('./callbacks'); const elementCallback = callbacks.elementCallback; @@ -15,25 +17,30 @@ const elementCommands = {}; /** * element.type(keys, cb) -> cb(err) * + * @param keys + * @param cb * @jsonWire POST /session/:sessionId/element/:id/value */ -elementCommands.type = function (keys, cb) { - commands.type.apply(this.browser, [this, keys, cb]); +elementCommands.type = function(keys, cb) { + commands.type.apply(this.browser, [ this, keys, cb ]); }; /** * element.keys(keys, cb) -> cb(err) * + * @param keys + * @param cb * @jsonWire POST /session/:sessionId/element/:id/value */ -elementCommands.keys = function (keys, cb) { - commands.keys.apply(this.browser, [keys, cb]); +elementCommands.keys = function(keys, cb) { + commands.keys.apply(this.browser, [ keys, cb ]); }; function _isLocalFile(path, cb) { - fs.exists(path, function (exists) { + fs.exists(path, function(exists) { if (exists) { - fs.lstat(path, function (err, stats) { + // eslint-disable-next-line node/prefer-promises/fs + fs.lstat(path, function(err, stats) { cb(err, stats.isFile()); }); } else { cb(null, false); } @@ -44,10 +51,12 @@ function _isLocalFile(path, cb) { * Equivalent to the python sendKeys binding. Upload file if * a local file is detected, otherwise behaves like type. * element.sendKeys(keys, cb) -> cb(err) + * @param keys + * @param cb */ -elementCommands.sendKeys = function (keys, cb) { +elementCommands.sendKeys = function(keys, cb) { const _this = this; - if (!(keys instanceof Array)) {keys = [keys];} + if (!(keys instanceof Array)) { keys = [ keys ]; } // ensure all keystrokes are strings to conform to JSONWP _.each(keys, function(key, idx) { @@ -57,15 +66,15 @@ elementCommands.sendKeys = function (keys, cb) { }); const path = keys.join(''); - _isLocalFile(path, function (err, isLocalFile) { + _isLocalFile(path, function(err, isLocalFile) { if (err) { return cb(err); } if (isLocalFile) { - commands.uploadFile.apply(_this.browser, [path, function (err, distantFilePath) { + commands.uploadFile.apply(_this.browser, [ path, function(err, distantFilePath) { if (err) { return cb(err); } - return commands.type.apply(_this.browser, [_this, distantFilePath, cb]); - }]); + return commands.type.apply(_this.browser, [ _this, distantFilePath, cb ]); + } ]); } else { - commands.type.apply(_this.browser, [_this, keys, cb]); + commands.type.apply(_this.browser, [ _this, keys, cb ]); } }); }; @@ -74,10 +83,12 @@ elementCommands.sendKeys = function (keys, cb) { * Equivalent to the python sendKeys binding, but replaces texts instead of keeping original. Upload file if * a local file is detected, otherwise behaves like type. * element.setText(keys, cb) -> cb(err) + * @param keys + * @param cb */ -elementCommands.setText = function (keys, cb) { +elementCommands.setText = function(keys, cb) { const _this = this; - if (!(keys instanceof Array)) {keys = [keys];} + if (!(keys instanceof Array)) { keys = [ keys ]; } // ensure all keystrokes are strings to conform to JSONWP _.each(keys, function(key, idx) { @@ -85,10 +96,10 @@ elementCommands.setText = function (keys, cb) { keys[idx] = key.toString(); } }); - commands.replace.apply(_this.browser, [_this, keys, cb]); + commands.replace.apply(_this.browser, [ _this, keys, cb ]); }; -elementCommands.replaceKeys = function (keys, cb) { +elementCommands.replaceKeys = function(keys, cb) { deprecator.warn('element.replaceKeys', 'element.replaceKeys has been deprecated, use element.setText instead.'); elementCommands.setText.call(this, keys, cb); }; @@ -98,41 +109,44 @@ elementCommands.replaceKeys = function (keys, cb) { * * @jsonWire POST /session/:sessionId/element/:id/click */ -elementCommands.click = function () { +elementCommands.click = function() { const fargs = utils.varargs(arguments); const cb = fargs.callback; const clickOpts = fargs.all[0] || {}; - commands.clickElement.apply(this.browser, [this, clickOpts, cb]); + commands.clickElement.apply(this.browser, [ this, clickOpts, cb ]); }; /** * element.takeElementScreenshot(cb) -> cb(err) * + * @param cb * @jsonWire POST /session/:sessionId/element/:id/screenshot */ -elementCommands.screenshot = function (cb) { - commands.takeElementScreenshot.apply(this.browser, [this, cb]); +elementCommands.screenshot = function(cb) { + commands.takeElementScreenshot.apply(this.browser, [ this, cb ]); }; /** * element.tap(cb) -> cb(err) * + * @param cb * @jsonWire POST /session/:sessionId/touch/click */ -elementCommands.tap = function (cb) { - commands.tapElement.apply(this.browser, [this, cb]); +elementCommands.tap = function(cb) { + commands.tapElement.apply(this.browser, [ this, cb ]); }; /** * element.doubleClick(cb) -> cb(err) * + * @param cb * @jsonWire POST /session/:sessionId/doubleclick */ elementCommands.doubleclick = function(cb) { - return commands.moveTo.apply(this.browser, [this, function(err) { + return commands.moveTo.apply(this.browser, [ this, function(err) { if (err) { return cb(err); } - commands.doubleclick.apply(this.browser, [cb]); - }.bind(this)]); + commands.doubleclick.apply(this.browser, [ cb ]); + }.bind(this) ]); }; elementCommands.doubleClick = elementCommands.doubleclick; @@ -148,84 +162,98 @@ elementCommands.moveTo = function() { const cb = fargs.callback; const xoffset = fargs.all[0]; const yoffset = fargs.all[1]; - commands.moveTo.apply(this.browser, [this, xoffset, yoffset, cb]); + commands.moveTo.apply(this.browser, [ this, xoffset, yoffset, cb ]); }; /** * element.flick(xoffset, yoffset, speed, cb) -> cb(err) * + * @param xoffset + * @param yoffset + * @param speed + * @param cb * @jsonWire POST /session/:sessionId/touch/flick */ -elementCommands.flick = function (xoffset, yoffset, speed, cb) { - commands.flick.apply(this.browser, [this.value, xoffset, yoffset, speed, cb]); +elementCommands.flick = function(xoffset, yoffset, speed, cb) { + commands.flick.apply(this.browser, [ this.value, xoffset, yoffset, speed, cb ]); }; /** * element.text(cb) -> cb(err, text) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/text * @docOrder 2 */ -elementCommands.text = function (cb) { - commands.text.apply(this.browser, [this, cb]); +elementCommands.text = function(cb) { + commands.text.apply(this.browser, [ this, cb ]); }; /** * element.textPresent(searchText, cb) -> cb(err, boolean) * + * @param searchText + * @param cb * @jsonWire GET /session/:sessionId/element/:id/text * @docOrder 4 */ elementCommands.textPresent = function(searchText, cb) { - commands.textPresent.apply(this.browser, [searchText, this, cb]); + commands.textPresent.apply(this.browser, [ searchText, this, cb ]); }; /** * element.getAttribute(attrName, cb) -> cb(err, value) * + * @param name + * @param cb * @jsonWire GET /session/:sessionId/element/:id/attribute/:name * @docOrder 2 */ elementCommands.getAttribute = function(name, cb) { - commands.getAttribute.apply(this.browser, [this, name, cb]); + commands.getAttribute.apply(this.browser, [ this, name, cb ]); }; /** * element.getProperty(propertyName, cb) -> cb(err, value) * + * @param name + * @param cb * @jsonWire GET /session/:sessionId/element/:id/property/:name * @docOrder 2 */ elementCommands.getProperty = function(name, cb) { - commands.getProperty.apply(this.browser, [this, name, cb]); + commands.getProperty.apply(this.browser, [ this, name, cb ]); }; /** * element.getRect(cb) -> cb(err, value) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/rect * @docOrder 2 */ elementCommands.getRect = function(cb) { - commands.getRect.apply(this.browser, [this, cb]); + commands.getRect.apply(this.browser, [ this, cb ]); }; /** * element.getTagName(cb) -> cb(err, name) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/name */ elementCommands.getTagName = function(cb) { - commands.getTagName.apply(this.browser, [this, cb]); + commands.getTagName.apply(this.browser, [ this, cb ]); }; /** * element.isDisplayed(cb) -> cb(err, displayed) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/displayed */ elementCommands.isDisplayed = function(cb) { - commands.isDisplayed.apply(this.browser, [this, cb]); + commands.isDisplayed.apply(this.browser, [ this, cb ]); }; elementCommands.displayed = elementCommands.isDisplayed; @@ -233,10 +261,11 @@ elementCommands.displayed = elementCommands.isDisplayed; /** * element.isSelected(cb) -> cb(err, selected) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/selected */ elementCommands.isSelected = function(cb) { - commands.isSelected.apply(this.browser, [this, cb]); + commands.isSelected.apply(this.browser, [ this, cb ]); }; elementCommands.selected = elementCommands.isSelected; @@ -244,66 +273,74 @@ elementCommands.selected = elementCommands.isSelected; /** * element.isEnabled(cb) -> cb(err, enabled) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/enabled */ elementCommands.isEnabled = function(cb) { - commands.isEnabled.apply(this.browser, [this, cb]); + commands.isEnabled.apply(this.browser, [ this, cb ]); }; elementCommands.enabled = elementCommands.isEnabled; /** * isVisible(cb) -> cb(err, boolean) + * @param cb */ elementCommands.isVisible = function(cb) { deprecator.warn('element.isVisible', 'element.isVisible has been deprecated, use element.isDisplayed instead.'); - commands.isVisible.apply(this.browser, [this, cb]); + commands.isVisible.apply(this.browser, [ this, cb ]); }; /** * element.getLocation(cb) -> cb(err, location) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/location */ -elementCommands.getLocation = function (cb) { - commands.getLocation.apply(this.browser, [this, cb]); +elementCommands.getLocation = function(cb) { + commands.getLocation.apply(this.browser, [ this, cb ]); }; /** * element.getLocationInView(cb) -> cb(err, location) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/location */ -elementCommands.getLocationInView = function (cb) { - commands.getLocationInView.apply(this.browser, [this, cb]); +elementCommands.getLocationInView = function(cb) { + commands.getLocationInView.apply(this.browser, [ this, cb ]); }; /** * element.getSize(cb) -> cb(err, size) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/size */ -elementCommands.getSize = function (cb) { - commands.getSize.apply(this.browser, [this, cb]); +elementCommands.getSize = function(cb) { + commands.getSize.apply(this.browser, [ this, cb ]); }; /** * element.getValue(cb) -> cb(err, value) * + * @param cb * @jsonWire GET /session/:sessionId/element/:id/attribute/:name * @docOrder 4 */ elementCommands.getValue = function(cb) { - commands.getValue.apply(this.browser, [this, cb]); + commands.getValue.apply(this.browser, [ this, cb ]); }; /** * element.getComputedCss(cssProperty , cb) -> cb(err, value) * + * @param styleName + * @param cb * @jsonWire GET /session/:sessionId/element/:id/css/:propertyName */ elementCommands.getComputedCss = function(styleName, cb) { - commands.getComputedCss.apply(this.browser, [this, styleName, cb]); + commands.getComputedCss.apply(this.browser, [ this, styleName, cb ]); }; elementCommands.getComputedCSS = elementCommands.getComputedCss; @@ -311,19 +348,21 @@ elementCommands.getComputedCSS = elementCommands.getComputedCss; /** * element.clear(cb) -> cb(err) * + * @param cb * @jsonWire POST /session/:sessionId/element/:id/clear */ elementCommands.clear = function(cb) { - commands.clear.apply(this.browser, [this, cb]); + commands.clear.apply(this.browser, [ this, cb ]); }; /** * element.submit(cb) -> cb(err) * + * @param cb * @jsonWire POST /session/:sessionId/element/:id/submit */ elementCommands.submit = function(cb) { - commands.submit.apply(this.browser, [this, cb]); + commands.submit.apply(this.browser, [ this, cb ]); }; _.each(utils.elementFuncTypes, function(type) { @@ -341,11 +380,13 @@ _.each(utils.elementFuncTypes, function(type) { * element.elementByAndroidUIAutomator(value, cb) -> cb(err, element) * element.elementByAccessibilityId(value, cb) -> cb(err, element) * + * @param value + * @param cb * @jsonWire POST /session/:sessionId/element/:id/element * @docOrder 2 */ elementCommands['element' + utils.elFuncSuffix(type)] = function(value, cb) { - elementCommands.element.apply(this, [utils.elFuncFullType(type), value, cb]); + elementCommands.element.apply(this, [ utils.elFuncFullType(type), value, cb ]); }; /** @@ -362,17 +403,22 @@ _.each(utils.elementFuncTypes, function(type) { * element.elementsByAndroidUIAutomator(value, cb) -> cb(err, elements) * element.elementsByAccessibilityId(value, cb) -> cb(err, elements) * + * @param value + * @param cb * @jsonWire POST /session/:sessionId/element/:id/elements * @docOrder 2 */ elementCommands['elements' + utils.elFuncSuffix(type)] = function(value, cb) { - elementCommands.elements.apply(this, [utils.elFuncFullType(type), value, cb]); + elementCommands.elements.apply(this, [ utils.elFuncFullType(type), value, cb ]); }; }); /** * element.element(using, value, cb) -> cb(err, element) * + * @param using + * @param value + * @param cb * @jsonWire POST /session/:sessionId/element/:id/element * @docOrder 1 */ @@ -381,14 +427,17 @@ elementCommands.element = function(using, value, cb) { this.browser._jsonWireCall({ method: 'POST', relPath: '/element/' + _this.value + '/element', - data: {using: using, value: value}, - cb: elementCallback(cb, this.browser) + data: { using, value }, + cb: elementCallback(cb, this.browser), }); }; /** * element.elements(using, value, cb) -> cb(err, elements) * + * @param using + * @param value + * @param cb * @jsonWire POST /session/:sessionId/element/:id/elements * @docOrder 1 */ @@ -397,31 +446,38 @@ elementCommands.elements = function(using, value, cb) { this.browser._jsonWireCall({ method: 'POST', relPath: '/element/' + _this.value + '/elements', - data: {using: using, value: value}, - cb: elementsCallback(cb, this.browser) + data: { using, value }, + cb: elementsCallback(cb, this.browser), }); }; /** * element.equals(other, cb) -> cb(err, value) * + * @param other + * @param cb * @jsonWire GET /session/:sessionId/element/:id/equals/:other * @docOrder 1 */ elementCommands.equals = function(other, cb) { - commands.equalsElement.apply(this.browser, [this, other, cb]); + commands.equalsElement.apply(this.browser, [ this, other, cb ]); }; /** * element.sleep(ms, cb) -> cb(err) + * @param ms + * @param cb */ elementCommands.sleep = function(ms, cb) { - cb = cb || function() {}; + cb = cb || function() { + // none + }; setTimeout(cb, ms); }; /** * element.noop(cb) -> cb(err) + * @param cb */ elementCommands.noop = function(cb) { if (cb) { cb(); } @@ -430,10 +486,12 @@ elementCommands.noop = function(cb) { /** * element.performMultiAction(actions) -> cb(err, touchStateObjects) * + * @param actions + * @param cb * @jsonWire POST /session/:sessionId/touch/multi/perform */ -elementCommands.performMultiAction = function (actions, cb) { - commands.performMultiAction.apply(this.browser, [this, actions, cb]); +elementCommands.performMultiAction = function(actions, cb) { + commands.performMultiAction.apply(this.browser, [ this, actions, cb ]); }; /** @@ -441,10 +499,12 @@ elementCommands.performMultiAction = function (actions, cb) { * opts is like the following: * {x: 114, y: 198, duration: 5, radius: 3, rotation: 220, touchCount: 2} * + * @param opts + * @param cb * @jsonWire POST /session/:sessionId/appium/device/rotate */ elementCommands.rotate = function(opts, cb) { - commands.rotateDevice.apply(this.browser, [this, opts, cb]); + commands.rotateDevice.apply(this.browser, [ this, opts, cb ]); }; elementCommands.touch = function() { @@ -456,13 +516,13 @@ elementCommands.touch = function() { let actions = []; if (Array.isArray(code)) { actions = code.map(function(el) { - el['element'] = _this.value; + el.element = _this.value; return el; }); } else if (typeof code === 'string') { - args['type'] = code; - args['element'] = _this.value; - actions = [args]; + args.type = code; + args.element = _this.value; + actions = [ args ]; } else { cb(new Error('Touch function only accept a action name or a list of actions.')); } @@ -470,18 +530,20 @@ elementCommands.touch = function() { this.browser._jsonWireCall({ method: 'POST', relPath: '/actions', - data: {actions: actions}, - cb: simpleCallback(cb) + data: { actions }, + cb: simpleCallback(cb), }); }; /** * element.setImmediateValueInApp(value, cb) -> cb(err) * + * @param value + * @param cb * @jsonWire POST /session/:sessionId/appium/element/:elementId?/value */ elementCommands.setImmediateValueInApp = function(value, cb) { - commands.setImmediateValueInApp.apply(this.browser, [this, value, cb]); + commands.setImmediateValueInApp.apply(this.browser, [ this, value, cb ]); }; /** * element.setImmediateValue(value, cb) -> cb(err) diff --git a/wd/lib/element.js b/wd/lib/element.js index 6fe8edb5..7841b3aa 100644 --- a/wd/lib/element.js +++ b/wd/lib/element.js @@ -1,3 +1,5 @@ +'use strict'; + // Element object // Wrapper around browser methods const __slice = Array.prototype.slice; @@ -24,11 +26,11 @@ Element.prototype.emit = function() { this.browser.emit.apply(this.browser, __slice.call(arguments, 0)); }; -Element.prototype.toString = function () { +Element.prototype.toString = function() { return String(this.value); }; -Element.prototype.toJSON = function () { +Element.prototype.toJSON = function() { return { ELEMENT: this.value }; }; @@ -48,7 +50,7 @@ _(elementCommands).each(function(fn, name) { fargs.callback.apply(null, cbArgs); } }; - const args = fargs.all.concat([cb]); + const args = fargs.all.concat([ cb ]); return fn.apply(this, args); }; }).value(); diff --git a/wd/lib/http-utils.js b/wd/lib/http-utils.js index 418e8a48..da86e33c 100644 --- a/wd/lib/http-utils.js +++ b/wd/lib/http-utils.js @@ -1,3 +1,5 @@ +'use strict'; + const request = require('request'); const utils = require('./utils'); const urllib = require('url'); @@ -19,10 +21,10 @@ exports.emit = function(browser, method, url, data) { }; exports.buildJsonCallUrl = function(baseUrl, sessionID, relPath, absPath) { - let path = ['session']; + let path = [ 'session' ]; if (sessionID) { path.push('/', sessionID); } if (relPath) { path.push(relPath); } - if (absPath) { path = [absPath]; } + if (absPath) { path = [ absPath ]; } path = path.join(''); return utils.resolveUrl(baseUrl, path); diff --git a/wd/lib/jsonwire-errors.js b/wd/lib/jsonwire-errors.js index fc6cf00f..f919184d 100644 --- a/wd/lib/jsonwire-errors.js +++ b/wd/lib/jsonwire-errors.js @@ -1,92 +1,94 @@ +'use strict'; + const JSONWIRE_ERRORS = [ { status: 0, summary: 'Success', - detail: 'The command executed successfully.'}, + detail: 'The command executed successfully.' }, { status: 7, summary: 'NoSuchElement', - detail: 'An element could not be located on the page using the given search parameters.'}, + detail: 'An element could not be located on the page using the given search parameters.' }, { status: 8, summary: 'NoSuchFrame', - detail: 'A request to switch to a frame could not be satisfied because the frame could not be found.'}, + detail: 'A request to switch to a frame could not be satisfied because the frame could not be found.' }, { status: 9, summary: 'UnknownCommand', - detail: 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.'}, + detail: 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.' }, { status: 10, summary: 'StaleElementReference', - detail: 'An element command failed because the referenced element is no longer attached to the DOM.'}, + detail: 'An element command failed because the referenced element is no longer attached to the DOM.' }, { status: 11, summary: 'ElementNotVisible', - detail: 'An element command could not be completed because the element is not visible on the page.'}, + detail: 'An element command could not be completed because the element is not visible on the page.' }, { status: 12, summary: 'InvalidElementState', - detail: 'An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).'}, + detail: 'An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).' }, { status: 13, summary: 'UnknownError', - detail: 'An unknown server-side error occurred while processing the command.'}, + detail: 'An unknown server-side error occurred while processing the command.' }, { status: 15, summary: 'ElementIsNotSelectable', - detail: 'An attempt was made to select an element that cannot be selected.'}, + detail: 'An attempt was made to select an element that cannot be selected.' }, { status: 17, summary: 'JavaScriptError', - detail: 'An error occurred while executing user supplied JavaScript.'}, + detail: 'An error occurred while executing user supplied JavaScript.' }, { status: 19, summary: 'XPathLookupError', - detail: 'An error occurred while searching for an element by XPath.'}, + detail: 'An error occurred while searching for an element by XPath.' }, { status: 21, summary: 'Timeout', - detail: 'An operation did not complete before its timeout expired.'}, + detail: 'An operation did not complete before its timeout expired.' }, { status: 23, summary: 'NoSuchWindow', - detail: 'A request to switch to a different window could not be satisfied because the window could not be found.'}, + detail: 'A request to switch to a different window could not be satisfied because the window could not be found.' }, { status: 24, summary: 'InvalidCookieDomain', - detail: 'An illegal attempt was made to set a cookie under a different domain than the current page.'}, + detail: 'An illegal attempt was made to set a cookie under a different domain than the current page.' }, { status: 25, summary: 'UnableToSetCookie', - detail: 'A request to set a cookie\'s value could not be satisfied.'}, + detail: 'A request to set a cookie\'s value could not be satisfied.' }, { status: 26, summary: 'UnexpectedAlertOpen', - detail: 'A modal dialog was open, blocking this operation'}, + detail: 'A modal dialog was open, blocking this operation' }, { status: 27, summary: 'NoAlertOpenError', - detail: 'An attempt was made to operate on a modal dialog when one was not open.'}, + detail: 'An attempt was made to operate on a modal dialog when one was not open.' }, { status: 28, summary: 'ScriptTimeout', - detail: 'A script did not complete before its timeout expired.'}, + detail: 'A script did not complete before its timeout expired.' }, { status: 29, summary: 'InvalidElementCoordinates', - detail: 'The coordinates provided to an interactions operation are invalid.'}, + detail: 'The coordinates provided to an interactions operation are invalid.' }, { status: 30, summary: 'IMENotAvailable', - detail: 'IME was not available.'}, + detail: 'IME was not available.' }, { status: 31, summary: 'IMEEngineActivationFailed', - detail: 'An IME engine could not be started.'}, + detail: 'An IME engine could not be started.' }, { status: 32, summary: 'InvalidSelector', - detail: 'Argument was an invalid selector (e.g. XPath/CSS).'} + detail: 'Argument was an invalid selector (e.g. XPath/CSS).' }, ]; module.exports = JSONWIRE_ERRORS; diff --git a/wd/lib/lodash.js b/wd/lib/lodash.js index 1f4c4e74..3248d02f 100644 --- a/wd/lib/lodash.js +++ b/wd/lib/lodash.js @@ -1,10 +1,12 @@ +'use strict'; + const _ = require('lodash'); _.str = require('underscore.string'); _.mixin(_.str.exports()); _.mixin({ includeString: _.str.include, - reverseString: _.str.reverse + reverseString: _.str.reverse, }); module.exports = _; diff --git a/wd/lib/main.js b/wd/lib/main.js index 83a216bb..9cb910c7 100644 --- a/wd/lib/main.js +++ b/wd/lib/main.js @@ -1,3 +1,5 @@ +'use strict'; + const __slice = Array.prototype.slice; const url = require('url'); const SPECIAL_KEYS = require('webdriver-keycode'); @@ -54,7 +56,7 @@ function buildConfigUrl(remoteWdConfig) { protocol: 'http:', hostname: '127.0.0.1', port: '4444', - pathname: '/wd/hub' + pathname: '/wd/hub', }); // strip any trailing slashes from pathname @@ -82,14 +84,17 @@ const parseRemoteWdConfig = function(args) { hostname: args[0], port: args[1], user: args[2], - pwd: args[3] + pwd: args[3], }); } return config; }; -let PromiseWebdriver, PromiseElement, PromiseChainWebdriver, PromiseChainElement; +let PromiseWebdriver, + PromiseElement, + PromiseChainWebdriver, + PromiseChainElement; // Creates the Webdriver object // server parameters can be passed in 4 ways @@ -103,9 +108,9 @@ let PromiseWebdriver, PromiseElement, PromiseChainWebdriver, PromiseChainElement function remote() { const args = arguments.length >= 1 ? __slice.call(arguments, 0) : []; const driverProtos = { - 'async': Webdriver, - 'promise': PromiseWebdriver, - 'promiseChain': PromiseChainWebdriver + async: Webdriver, + promise: PromiseWebdriver, + promiseChain: PromiseChainWebdriver, }; const driverTypes = _(driverProtos).keys().value(); const driverType = driverTypes.indexOf(_(args).last()) > 0 ? args.pop() : 'async'; @@ -207,24 +212,24 @@ wrap(); module.exports = { // Retrieves browser - remote: remote, - asyncRemote: asyncRemote, + remote, + asyncRemote, // Retrieves wrap browser - promiseRemote: promiseRemote, - promiseChainRemote: promiseChainRemote, + promiseRemote, + promiseChainRemote, // Webdriver and Wrapper base classes - Webdriver: Webdriver, + Webdriver, webdriver: Webdriver, // for backward compatibility - Element: Element, - PromiseChainWebdriver: PromiseChainWebdriver, - PromiseWebdriver: PromiseWebdriver, + Element, + PromiseChainWebdriver, + PromiseWebdriver, TouchAction: actions.TouchAction, MultiAction: actions.MultiAction, // Actualizes promise wrappers - rewrap: function() { + rewrap() { deprecator.warn('rewrap', 'rewrap has been deprecated, use addAsyncMethod instead.'); wrap(); @@ -241,7 +246,7 @@ module.exports = { * @wd */ configureHttp: config.configureHttp, - getHttpConfig: function() { return _(config.httpConfig).clone(); }, + getHttpConfig() { return _(config.httpConfig).clone(); }, // deprecation /** @@ -257,60 +262,60 @@ module.exports = { * * @wd */ - addAsyncMethod: addAsyncMethod, + addAsyncMethod, /** * wd.addElementAsyncMethod(name, func) * * @wd */ - addElementAsyncMethod: addElementAsyncMethod, + addElementAsyncMethod, /** * wd.addPromiseMethod(name, func) * * @wd */ - addPromiseMethod: addPromiseMethod, + addPromiseMethod, /** * wd.addElementPromiseMethod(name, func) * * @wd */ - addElementPromiseMethod: addElementPromiseMethod, + addElementPromiseMethod, /** * wd.addPromiseChainMethod(name, func) * * @wd */ - addPromiseChainMethod: addPromiseChainMethod, + addPromiseChainMethod, /** * wd.addElementPromiseChainMethod(name, func) * * @wd */ - addElementPromiseChainMethod: addElementPromiseChainMethod, + addElementPromiseChainMethod, /** * wd.removeMethod(name, func) * * @wd */ - removeMethod: removeMethod, + removeMethod, // Useful stuff Asserter: require('./asserters').Asserter, asserters: require('./asserters'), - SPECIAL_KEYS: SPECIAL_KEYS, - Q: Q, + SPECIAL_KEYS, + Q, findCallback: utils.findCallback, varargs: utils.varargs, transferPromiseness: utils.transferPromiseness, // This is for people who write wrapper // todo: That should not be needed. - utils: utils, + utils, - setBaseClasses: function(_Webdriver, _Element) { + setBaseClasses(_Webdriver, _Element) { Webdriver = _Webdriver; Element = _Element; wrap(); - } + }, }; diff --git a/wd/lib/promise-webdriver.js b/wd/lib/promise-webdriver.js index 4b78f4c6..cb767a7c 100644 --- a/wd/lib/promise-webdriver.js +++ b/wd/lib/promise-webdriver.js @@ -1,3 +1,5 @@ +'use strict'; + const __slice = Array.prototype.slice; const Q = require('q'); const _ = require('./lodash'); @@ -21,7 +23,7 @@ const elementChainableMethods = [ 'keys', 'moveTo', 'sleep', - 'noop' + 'noop', ]; // gets the list of methods to be promisified. @@ -29,7 +31,8 @@ function filterPromisedMethods(Obj) { return _(Obj).functions().filter(function(fname) { return !fname.match('^newElement$|^toJSON$|^toString$|^_') && !EventEmitter.prototype[fname]; - }).value(); + }) + .value(); } module.exports = function(WebDriver, Element, chainable) { @@ -72,9 +75,9 @@ module.exports = function(WebDriver, Element, chainable) { if (chainable) { return this._enrich(deferred.promise); - } else { - return deferred.promise; } + return deferred.promise; + }; } @@ -131,7 +134,8 @@ module.exports = function(WebDriver, Element, chainable) { return this._enrich( _orig.apply(this, __slice.call(arguments, 0)), currentEl); }; - }).value(); + }) + .value(); // we get the list of methods dynamically. const promisedMethods = filterPromisedMethods(Object.getPrototypeOf(_this)); @@ -197,14 +201,14 @@ module.exports = function(WebDriver, Element, chainable) { // method like click, where no result is expected, we return // the element to make it chainable return el; - } else { - return res; // we have no choice but loosing the scope } + return res; // we have no choice but loosing the scope + }); - } else { - // browser case. - return _this[fname].apply(_this, args); } + // browser case. + return _this[fname].apply(_this, args); + }); }; }).value(); @@ -279,6 +283,7 @@ module.exports = function(WebDriver, Element, chainable) { * Resolves the promise (promised driver only) * browser.resolve(promise) * element.resolve(promise) + * @param promise */ PromiseWebdriver.prototype.resolve = function(promise) { const qPromise = new Q(promise); @@ -316,16 +321,16 @@ module.exports = function(WebDriver, Element, chainable) { return arg.toString(); } else if (typeof arg === 'object') { return JSON.stringify(arg); - } else { - return arg; } + return arg; + }).join(', ') + ' )'; console.log(' --> ' + status + context + ' ' + method + args); }); }; return { - PromiseWebdriver: PromiseWebdriver, - PromiseElement: PromiseElement + PromiseWebdriver, + PromiseElement, }; }; diff --git a/wd/lib/tmp.js b/wd/lib/tmp.js index f08eff18..56e90a47 100644 --- a/wd/lib/tmp.js +++ b/wd/lib/tmp.js @@ -1,3 +1,5 @@ +'use strict'; + // inspired by https://github.com/raszi/node-tmp, but only // provides tmp paths. @@ -69,7 +71,7 @@ function _getTmpName(options, callback) { (_isUndefined(opts.prefix)) ? 'tmp-' : opts.prefix, process.pid, (Math.random() * 0x1000000000).toString(36), - opts.postfix + opts.postfix, ].join(''); return path.join(opts.dir || _TMP, name); diff --git a/wd/lib/utils.js b/wd/lib/utils.js index 4a05feba..01317fad 100644 --- a/wd/lib/utils.js +++ b/wd/lib/utils.js @@ -1,3 +1,5 @@ +'use strict'; + const Args = require('vargs').Constructor; const _ = require('./lodash'); const url = require('url'); @@ -20,13 +22,13 @@ exports.findCallback = function(_arguments) { // convert to type to something like ById, ByCssSelector, etc... const STRAT_MAPPING = { '-ios uiautomation': 'ByIosUIAutomation', - '-android uiautomator': 'ByAndroidUIAutomator' + '-android uiautomator': 'ByAndroidUIAutomator', }; exports.elFuncSuffix = function(type) { let suffix = STRAT_MAPPING[type]; if (!suffix) { suffix = (' by ' + type).replace(/(\s[a-z])/g, - function($1) {return $1.toUpperCase().replace(' ', '');}) + function($1) { return $1.toUpperCase().replace(' ', ''); }) .replace('Xpath', 'XPath'); } return suffix; @@ -34,13 +36,13 @@ exports.elFuncSuffix = function(type) { // return correct jsonwire type exports.elFuncFullType = function(type) { - if (type === 'css') {return 'css selector'; } // shortcut for css + if (type === 'css') { return 'css selector'; } // shortcut for css return type; }; // from JsonWire spec + shortcuts + mobile JsonWire spec -exports.elementFuncTypes = ['class name', 'css selector', 'id', 'name', 'link text', - 'partial link text', 'tag name', 'xpath', 'css', '-ios uiautomation', '-android uiautomator', 'accessibility id']; +exports.elementFuncTypes = [ 'class name', 'css selector', 'id', 'name', 'link text', + 'partial link text', 'tag name', 'xpath', 'css', '-ios uiautomation', '-android uiautomator', 'accessibility id' ]; // chai-as-promised promisifier // just adding the core method for the sake of safety.\ @@ -48,7 +50,7 @@ exports.elementFuncTypes = ['class name', 'css selector', 'id', 'name', 'link te const Q_CORE_METHODS = [ // core methods: 'then', 'catch', 'fail', 'progress', 'finally', 'fin', 'done', - 'thenResolve', 'thenReject', 'nodeify' + 'thenResolve', 'thenReject', 'nodeify', ]; exports.transferPromiseness = function(target, promise) { @@ -70,15 +72,15 @@ exports.isPromise = function(x) { exports.deprecator = { deprecationMessageShown: {}, warnDeprecated: true, - showHideDeprecation: function(status) { + showHideDeprecation(status) { if (status !== undefined) { this.warnDeprecated = status; } else { this.warnDeprecated = !this.warnDeprecated; } }, - warn: function(cat, message) { + warn(cat, message) { if (this.warnDeprecated && !this.deprecationMessageShown[cat]) { this.deprecationMessageShown[cat] = 1; console.warn(message); } - } + }, }; // Android doesn't like cariage return diff --git a/wd/lib/webdriver.js b/wd/lib/webdriver.js index 0fc56ea1..019f2616 100644 --- a/wd/lib/webdriver.js +++ b/wd/lib/webdriver.js @@ -1,3 +1,5 @@ +'use strict'; + const EventEmitter = require('events').EventEmitter; const _ = require('./lodash'); const util = require('util'); @@ -28,7 +30,7 @@ const Webdriver = module.exports = function(configUrl) { browserName: 'firefox', version: '', javascriptEnabled: true, - platform: 'ANY' + platform: 'ANY', }; this._httpConfig = _.clone(config.httpConfig); @@ -45,6 +47,7 @@ Webdriver.prototype.newElement = function(jsonWireElement) { /** * attach(sessionID, cb) -> cb(err) * Connect to an already-active session. + * @param sessionID */ Webdriver.prototype.attach = function(sessionID) { const cb = findCallback(arguments); @@ -72,8 +75,8 @@ Webdriver.prototype._init = function() { delete this.sessionID; const _this = this; const fargs = utils.varargs(arguments); - let cb = fargs.callback; - let desired = fargs.all[0] || {}; + const cb = fargs.callback; + const desired = fargs.all[0] || {}; const _desired = _.clone(desired); @@ -93,7 +96,7 @@ Webdriver.prototype._init = function() { const url = httpUtils.buildInitUrl(this.configUrl); // building request - const data = {desiredCapabilities: _desired}; + const data = { desiredCapabilities: _desired }; httpUtils.emit(this, httpOpts.method, url, data); @@ -110,13 +113,17 @@ Webdriver.prototype._init = function() { _this.sessionID = jsonData.sessionId; resData = jsonData.value; } - } catch (ignore) {} + } catch (ignore) { + // none + } if (!_this.sessionID) { // attempting to retrieve the session the old way try { const locationArr = res.headers.location.replace(/\/$/, '').split('/'); _this.sessionID = locationArr[locationArr.length - 1]; - } catch (ignore) {} + } catch (ignore) { + // none + } } if (_this.sessionID) { @@ -128,13 +135,13 @@ Webdriver.prototype._init = function() { err = new Error('The environment you requested was unavailable.'); err.data = data; return cb(err); - } else { - console.error('\x1b[31mError\x1b[0m: The environment you requested was unavailable.\n'); - console.error('\x1b[33mReason\x1b[0m:\n'); - console.error(data); - console.error('\nFor the available values please consult the WebDriver JSONWireProtocol,'); - console.error('located at: \x1b[33mhttp://code.google.com/p/selenium/wiki/JsonWireProtocol#/session\x1b[0m'); } + console.error('\x1b[31mError\x1b[0m: The environment you requested was unavailable.\n'); + console.error('\x1b[33mReason\x1b[0m:\n'); + console.error(data); + console.error('\nFor the available values please consult the WebDriver JSONWireProtocol,'); + console.error('located at: \x1b[33mhttp://code.google.com/p/selenium/wiki/JsonWireProtocol#/session\x1b[0m'); + } }); }; @@ -190,7 +197,7 @@ _(commands).each(function(fn, name) { if (fargs.callback) { fargs.callback.apply(null, cbArgs); } } }; - const args = fargs.all.concat([cb]); + const args = fargs.all.concat([ cb ]); return fn.apply(this, args); }; }).value();