appium-uiauto
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -14,20 +14,8 @@ // Generate a bootstrap for the UIAuto Instruments script containing | ||
function toBoolean(val) { | ||
if (typeof val === 'string') { | ||
return ['1','true'].indexOf(val.toLowerCase().trim()) >= 0; | ||
} else { | ||
return val ? true : false; | ||
} | ||
} | ||
function getEnv(opts) { | ||
opts = opts || {}; | ||
var bootstrapEnv = { | ||
USER: process.env.USER, | ||
NODE_BIN: process.execPath, | ||
CWD: process.cwd(), | ||
COMMAND_PROXY_CLIENT_PATH: path.resolve( | ||
__dirname, '../bin/command-proxy-client.js'), | ||
VERBOSE_INSTRUMENTS: opts.verboseInstruments || | ||
toBoolean(process.env.VERBOSE_INSTRUMENTS) | ||
nodePath: process.execPath, | ||
commandProxyClientPath: path.resolve( | ||
__dirname, '../bin/command-proxy-client.js') | ||
}; | ||
@@ -37,6 +25,18 @@ return bootstrapEnv; | ||
function buildCode(env, bootstrapJs) { | ||
function buildCode(opts) { | ||
if (opts.code) return opts.code; | ||
var env = getEnv(opts); | ||
logger.debug('Dynamic env:', JSON.stringify(env)); | ||
var bootstrapJs = path.resolve(__dirname,'../uiauto/bootstrap.js'); | ||
var lines = []; | ||
lines.push('// This file is automatically generated. Do not manually modify!'); | ||
lines.push(''); | ||
if (opts.imports && opts.imports.pre) { | ||
// mainly for testing | ||
_(opts.imports.pre).each(function (lib) { | ||
lines.push('#import \"' + lib + '\";'); | ||
}); | ||
} | ||
lines.push('#import \"' + bootstrapJs + '\";'); | ||
@@ -46,4 +46,6 @@ lines.push(''); | ||
_(env).each(function (value, key) { | ||
var quote = typeof value === 'string' ? '\"' : ''; | ||
lines.push(' ' + key + ': ' + quote + value + quote + ','); | ||
if (!_.isUndefined(value)){ | ||
var quote = typeof value === 'string' ? '\"' : ''; | ||
lines.push(' ' + key + ': ' + quote + value + quote + ','); | ||
} | ||
}); | ||
@@ -78,13 +80,3 @@ lines.push('});'); | ||
// building code and hash | ||
var code; | ||
if (!opts.code) { | ||
// building default | ||
var env = getEnv(opts); | ||
logger.debug('Dynamic env:', JSON.stringify(env)); | ||
var bootstrapJs = path.resolve(__dirname,'../uiauto/bootstrap.js'); | ||
code = buildCode(env, bootstrapJs); | ||
} else { | ||
code = opts.code; | ||
} | ||
var code = buildCode(opts); | ||
var hash = computeHash(code); | ||
@@ -91,0 +83,0 @@ var dynamicBootstrapPath = path.resolve(dynamicBootstrapDir, |
'use strict'; | ||
var logger = require('winston'), | ||
var winston = require('winston'), | ||
_ = require('underscore'); | ||
var logger = new (winston.Logger)({ | ||
transports: [ | ||
new (winston.transports.Console)({ level : 'info' }) | ||
] | ||
}); | ||
var loggerWrap = { | ||
@@ -19,2 +25,10 @@ init: function (_logger) { | ||
loggerWrap.setConsoleLevel = function (level) { | ||
logger.transports.console.level = level; | ||
}; | ||
loggerWrap.instance = function () { | ||
return logger; | ||
}; | ||
module.exports = loggerWrap; |
{ | ||
"name": "appium-uiauto", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "appium uiauto ios driver", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
@@ -11,3 +11,3 @@ /* globals commands, chai */ | ||
#import "<ROOT_DIR>/uiauto/lib/commands.js" | ||
"<EXTRA_IMPORTS>" | ||
"<POST_IMPORTS>" | ||
/* jshint ignore:end */ | ||
@@ -18,16 +18,5 @@ | ||
var env = {}; | ||
env.commandProxyClientPath = "<COMMAND_PROXY_CLIENT_PATH>"; | ||
env.nodePath = "<NODE_BIN>"; | ||
env.commandProxyClientPath = "<commandProxyClientPath>"; | ||
env.nodePath = "<nodePath>"; | ||
// default tuneup.js options | ||
var testCreateDefaultOptions = function () { | ||
return { | ||
logStackTrace: false, | ||
logTree: true, | ||
logTreeJSON: false, | ||
screenCapture: true, | ||
rethrow: true | ||
}; | ||
}; | ||
commands.startProcessing(); |
@@ -7,3 +7,3 @@ 'use strict'; | ||
Q = require('q'), | ||
CommandProxy = require('../../lib/command-proxy.js'), | ||
CommandProxy = require('../../lib/command-proxy'), | ||
instrumentsUtils = require('appium-instruments').utils, | ||
@@ -13,3 +13,4 @@ getEnv = require('../../lib/dynamic-bootstrap').getEnv, | ||
path = require('path'), | ||
fs = require('fs'); | ||
fs = require('fs'), | ||
logger = require('../../lib/logger'); | ||
@@ -21,22 +22,40 @@ chai.use(chaiAsPromised); | ||
if (process.env.VERBOSE) logger.setConsoleLevel('debug'); | ||
var prepareBootstrap = function (opts) { | ||
opts = opts || {}; | ||
var env = getEnv(); | ||
var rootDir = path.resolve(__dirname, '../..'); | ||
var extraImports = _(opts.extraImports || []).map(function (item) { | ||
return '#import "' + path.resolve( rootDir , item) + '"'; | ||
}); | ||
var code = fs.readFileSync(path.resolve( | ||
__dirname, '../../test/assets/base-bootstrap.js'), 'utf8'); | ||
_({ | ||
'<ROOT_DIR>': rootDir, | ||
'"<EXTRA_IMPORTS>"': extraImports.join('\n'), | ||
'<COMMAND_PROXY_CLIENT_PATH>': env.COMMAND_PROXY_CLIENT_PATH, | ||
'<NODE_BIN>': env.NODE_BIN | ||
}).each(function (value, key) { | ||
code = code.replace(new RegExp(key, 'g'), value); | ||
}); | ||
return require('../../lib/dynamic-bootstrap').prepareBootstrap({ | ||
code: code | ||
}); | ||
if (opts.bootstrap === 'basic') { | ||
var env = getEnv(); | ||
var postImports = []; | ||
if (opts.imports && opts.imports.post) { | ||
postImports = opts.imports.post; | ||
} | ||
postImports = _(postImports).map(function (item) { | ||
return '#import "' + path.resolve( rootDir , item) + '"'; | ||
}); | ||
var code = fs.readFileSync(path.resolve( | ||
__dirname, '../../test/assets/base-bootstrap.js'), 'utf8'); | ||
_({ | ||
'<ROOT_DIR>': rootDir, | ||
'"<POST_IMPORTS>"': postImports.join('\n'), | ||
'<commandProxyClientPath>': env.commandProxyClientPath, | ||
'<nodePath>': env.nodePath | ||
}).each(function (value, key) { | ||
code = code.replace(new RegExp(key, 'g'), value); | ||
}); | ||
return require('../../lib/dynamic-bootstrap').prepareBootstrap({ | ||
code: code, | ||
isVerbose: true | ||
}); | ||
} else { | ||
var bootstrapOpts = {}; | ||
if (opts.chai) { | ||
bootstrapOpts.imports = {}; | ||
bootstrapOpts.imports.pre = | ||
[path.resolve(rootDir, 'node_modules/chai/chai.js')]; | ||
} | ||
return require('../../lib/dynamic-bootstrap') | ||
.prepareBootstrap(bootstrapOpts); | ||
} | ||
}; | ||
@@ -47,3 +66,4 @@ | ||
app: path.resolve(__dirname, '../assets/UICatalog.app'), | ||
bootstrap: bootstrapFile | ||
bootstrap: bootstrapFile, | ||
logger: logger.instance() | ||
}); | ||
@@ -129,11 +149,15 @@ }; | ||
' var params = JSON.parse(\'' + JSON.stringify(params) + '\');\n' + | ||
' (' + func.toString() + ').apply(null, params);' + | ||
' return (' + func.toString() + ').apply(null, params);' + | ||
'})();'; | ||
return ctx.exec(script); | ||
}; | ||
return ctx; | ||
}) | ||
.then(function (ctx) { | ||
.then(function () { | ||
var cmd = ''; | ||
cmd += '$.isVerbose = ' + (process.env.VERBOSE ? true : false) + ';\n'; | ||
return ctx.exec(cmd); | ||
}).then(function () { | ||
return ctx.execFunc(function () { | ||
/* global $ */ | ||
$.delay(500); | ||
while (!$('tableview').isVisible()) { | ||
@@ -140,0 +164,0 @@ $.warn('waiting for page to load'); |
@@ -9,3 +9,3 @@ /* globals $ */ | ||
describe('commands', function () { | ||
base.globalInit(this); | ||
base.globalInit(this, {bootstrap: 'basic'}); | ||
@@ -12,0 +12,0 @@ describe("simple sequences", function () { |
@@ -8,7 +8,7 @@ /* globals $ */ | ||
describe('keyboard', function () { | ||
base.globalInit(this, { extraImports: [ | ||
var imports = { post: [ | ||
'uiauto/lib/mechanic-ext/gesture-ext.js', | ||
'uiauto/lib/mechanic-ext/keyboard-ext.js', | ||
]}); | ||
]}; | ||
base.globalInit(this, { imports: imports, bootstrap: 'basic'}); | ||
@@ -15,0 +15,0 @@ describe("hide keyboard", function () { |
@@ -10,4 +10,3 @@ 'use strict'; | ||
sinon = require('sinon'), | ||
sinonChai = require("sinon-chai"), | ||
_ = require('underscore'); | ||
sinonChai = require("sinon-chai"); | ||
@@ -27,18 +26,12 @@ chai.should(); | ||
function checkCode(code, opts) { | ||
function checkCode(code) { | ||
code.should.match(/#import/); | ||
/* jshint evil:true */ | ||
var env = envFromCode(code); | ||
env.USER.should.equal(process.env.USER); | ||
env.NODE_BIN.should.equal(process.execPath); | ||
env.CWD.should.equal(process.cwd()); | ||
env.COMMAND_PROXY_CLIENT_PATH.should.exist; | ||
fs.existsSync(env.COMMAND_PROXY_CLIENT_PATH).should.be.ok; | ||
env.VERBOSE_INSTRUMENTS.should.equal(opts.VERBOSE_INSTRUMENTS); | ||
env.nodePath.should.equal(process.execPath); | ||
env.commandProxyClientPath.should.exist; | ||
fs.existsSync(env.commandProxyClientPath).should.be.ok; | ||
} | ||
var origEnv = {}; | ||
before(function () { | ||
origEnv = _.clone(process.env); | ||
process.env.VERBOSE_INSTRUMENTS = false; | ||
sinon.spy(logger, "debug"); | ||
@@ -48,3 +41,2 @@ }); | ||
after(function () { | ||
process.env.VERBOSE_INSTRUMENTS = origEnv.VERBOSE_INSTRUMENTS; | ||
logger.debug.restore(); | ||
@@ -61,4 +53,5 @@ }); | ||
var code = fs.readFileSync(bootstrapFile, 'utf8'); | ||
checkCode(code, {VERBOSE_INSTRUMENTS: false}); | ||
}).then(function () { | ||
checkCode(code); | ||
}) | ||
.then(function () { | ||
logger.debug.calledWithMatch(/Creating or overwritting dynamic bootstrap/).should.be.ok; | ||
@@ -72,3 +65,3 @@ logger.debug.reset(); | ||
var code = fs.readFileSync(bootstrapFile, 'utf8'); | ||
checkCode(code, {VERBOSE_INSTRUMENTS: false}); | ||
checkCode(code); | ||
}).then(function () { | ||
@@ -78,11 +71,15 @@ logger.debug.calledWithMatch(/Reusing dynamic bootstrap/).should.be.ok; | ||
}) | ||
// third call call with different param: should create different bootstrap file | ||
.then(function () { return prepareBootstrap({verboseInstruments: true});}) | ||
.then(function (bootstrapFile) { | ||
// third call with extra imports: should create different bootstrap file | ||
.then(function () { | ||
var imports = {pre: ['dir1/alib.js'] }; | ||
return prepareBootstrap({imports: imports}); | ||
}).then(function (bootstrapFile) { | ||
bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/); | ||
var code = fs.readFileSync(bootstrapFile, 'utf8'); | ||
checkCode(code, {VERBOSE_INSTRUMENTS: true}); | ||
code.should.match(/#import "dir1\/alib.js";/); | ||
checkCode(code, {isVerbose: true, gracePeriod: 5}); | ||
}) | ||
.then(function () { | ||
logger.debug.calledWithMatch(/Creating or overwritting dynamic bootstrap/).should.be.ok; | ||
logger.debug.reset(); | ||
}) | ||
@@ -89,0 +86,0 @@ .nodeify(done); |
@@ -1,2 +0,2 @@ | ||
/* globals env, alerts, commands, $ */ | ||
/* globals env, alerts, commands */ | ||
@@ -17,3 +17,2 @@ /* jshint ignore:start */ | ||
env.init(dynamicEnv); | ||
$.isVerbose = env.isVerbose; | ||
alerts.configure(); | ||
@@ -20,0 +19,0 @@ commands.startProcessing(); |
@@ -18,3 +18,2 @@ // The message route is the following: | ||
(function () { | ||
var BOOTSTRAP_CONFIG_PREFIX = "setBootstrapConfig: "; | ||
var BIG_DATA_THRESHOLD = 50000; | ||
@@ -112,7 +111,3 @@ var MORE_COMMAND = "#more"; | ||
try { | ||
if (cmd.indexOf(BOOTSTRAP_CONFIG_PREFIX) === 0) { | ||
var configStr = cmd.slice(BOOTSTRAP_CONFIG_PREFIX.length); | ||
$.debug("Got bootstrap config: " + configStr); | ||
eval(configStr); | ||
} else if (cmd === MORE_COMMAND) { | ||
if (cmd === MORE_COMMAND) { | ||
result = { | ||
@@ -119,0 +114,0 @@ status: errors.Success.code, |
@@ -1,8 +0,3 @@ | ||
/* globals $ */ | ||
var env; | ||
// TODO: we should not need those | ||
var target, au; | ||
(function () { | ||
@@ -12,18 +7,6 @@ | ||
env.init = function (dynamicEnv) { | ||
// safe default | ||
$.target().setTimeout(1); | ||
target = $.target(); | ||
au = $; | ||
// TODO: move to dynamic env | ||
this.autoAcceptAlerts = false; | ||
this.user = dynamicEnv.USER; | ||
this.isVerbose = dynamicEnv.VERBOSE_INSTRUMENTS; | ||
this.nodePath = dynamicEnv.NODE_BIN; | ||
this.commandProxyClientPath = dynamicEnv.COMMAND_PROXY_CLIENT_PATH; | ||
this.nodePath = dynamicEnv.nodePath; | ||
this.commandProxyClientPath = dynamicEnv.commandProxyClientPath; | ||
}; | ||
})(); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
13341860
152
3304
13