How to use msValidator method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

validate.js

Source:validate.js Github

copy

Full Screen

1import { avalon, isObject, platform } from '../seed/core'2var valiDir = avalon.directive('validate', {3 diff: function(validator) {4 var vdom = this.node5 if (vdom.validator) {6 return7 }8 if (isObject(validator)) {9 //注意,这个Form标签的虚拟DOM有两个验证对象10 //一个是vmValidator,它是用户VM上的那个原始子对象,也是一个VM11 //一个是validator,它是vmValidator.$model, 这是为了防止IE6-8添加子属性时添加的hack12 //也可以称之为safeValidate13 vdom.validator = validator14 validator = platform.toJson(validator)15 validator.vdom = vdom16 validator.dom = vdom.dom17 for (var name in valiDir.defaults) {18 if (!validator.hasOwnProperty(name)) {19 validator[name] = valiDir.defaults[name]20 }21 }22 validator.fields = validator.fields || []23 vdom.vmValidator = validator24 return true25 }26 },27 update: function(vdom) {28 var vmValidator = vdom.vmValidator29 var validator = vdom.validator30 var dom = vdom.dom31 dom._ms_validate_ = vmValidator32 collectFeild(vdom.children, vmValidator.fields, vmValidator)33 var type = window.netscape ? 'keypress' : 'focusin'34 avalon.bind(document, type, findValidator)35 //为了方便用户手动执行验证,我们需要为原始vmValidate上添加一个onManual方法36 function onManual() {37 var v = this38 v && valiDir.validateAll.call(v, v.onValidateAll)39 }40 try {41 var fn = vmValidator.onManual = onManual.bind(vmValidator)42 validator.onManual = fn43 } catch (e) {44 avalon.warn('要想使用onManual方法,必须在validate对象预定义一个空的onManual函数')45 }46 delete vdom.vmValidator47 dom.setAttribute('novalidate', 'novalidate')48 /* istanbul ignore if */49 if (vmValidator.validateAllInSubmit) {50 avalon.bind(dom, 'submit', validateAllInSubmitFn)51 }52 },53 validateAll: function(callback) {54 var validator = this55 var vdom = this.vdom56 var fields = validator.fields = []57 collectFeild(vdom.children, fields, validator)58 var fn = typeof callback === 'function' ? callback : validator.onValidateAll59 var promises = validator.fields.filter(function(field) {60 var el = field.dom61 return el && !el.disabled && validator.dom.contains(el)62 }).map(function(field) {63 return valiDir.validate(field, true)64 })65 var uniq = {}66 return Promise.all(promises).then(function(array) {67 var reasons = array.concat.apply([], array)68 if (validator.deduplicateInValidateAll) {69 reasons = reasons.filter(function(reason) {70 var el = reason.element71 var uuid = el.uniqueID || (el.uniqueID = setTimeout('1'))72 if (uniq[uuid]) {73 return false74 } else {75 return uniq[uuid] = true76 }77 })78 }79 fn.call(vdom.dom, reasons) //这里只放置未通过验证的组件80 })81 },82 validate: function(field, isValidateAll, event) {83 var promises = []84 var value = field.value85 var elem = field.dom86 /* istanbul ignore if */87 if (typeof Promise !== 'function') { //avalon-promise不支持phantomjs88 avalon.warn('浏览器不支持原生Promise,请下载并<script src=url>引入\nhttps://github.com/RubyLouvre/avalon/blob/master/test/promise.js')89 }90 /* istanbul ignore if */91 if (elem.disabled)92 return93 var rules = field.vdom.rules94 var ngs = [],95 isOk = true96 if (!(rules.norequired && value === '')) {97 for (var ruleName in rules) {98 var ruleValue = rules[ruleName]99 if (ruleValue === false)100 continue101 var hook = avalon.validators[ruleName]102 var resolve103 promises.push(new Promise(function(a, b) {104 resolve = a105 }))106 var next = function(a) {107 var reason = {108 element: elem,109 data: field.data,110 message: elem.getAttribute('data-' + ruleName + '-message') || elem.getAttribute('data-message') || hook.message,111 validateRule: ruleName,112 getMessage: getMessage113 }114 if (a) {115 resolve(true)116 } else {117 isOk = false118 ngs.push(reason)119 resolve(false)120 }121 }122 field.data = {}123 field.data[ruleName] = ruleValue124 hook.get(value, field, next)125 }126 }127 //如果promises不为空,说明经过验证拦截器128 return Promise.all(promises).then(function(array) {129 if (!isValidateAll) {130 var validator = field.validator131 if (isOk) {132 validator.onSuccess.call(elem, [{133 data: field.data,134 element: elem135 }], event)136 } else {137 validator.onError.call(elem, ngs, event)138 }139 validator.onComplete.call(elem, ngs, event)140 }141 return ngs142 })143 }144});145//https://github.com/RubyLouvre/avalon/issues/1977146function getValidate(dom) {147 while (dom.tagName !== 'FORM') {148 dom = dom.parentNode149 }150 return dom._ms_validate_151}152function validateAllInSubmitFn(e) {153 e.preventDefault()154 var v = getValidate(e.target)155 if (v && v.onManual) {156 v.onManual()157 }158}159function collectFeild(nodes, fields, validator) {160 for (var i = 0, vdom; vdom = nodes[i++];) {161 var duplex = vdom.rules && vdom.duplex162 if (duplex) {163 fields.push(duplex)164 bindValidateEvent(duplex, validator)165 } else if (vdom.children) {166 collectFeild(vdom.children, fields, validator)167 } else if (Array.isArray(vdom)) {168 collectFeild(vdom, fields, validator)169 }170 }171}172function findValidator(e) {173 var dom = e.target174 var duplex = dom._ms_duplex_175 var vdom = (duplex || {}).vdom176 if (duplex && vdom.rules && !duplex.validator) {177 var msValidator = getValidate(dom)178 if (msValidator && avalon.Array.ensure(msValidator.fields, duplex)) {179 bindValidateEvent(duplex, msValidator)180 }181 }182}183function singleValidate(e) {184 var dom = e.target185 var duplex = dom._ms_duplex_186 var msValidator = getValidate(e.target)187 msValidator && msValidator.validate(duplex, 0, e)188}189function bindValidateEvent(field, validator) {190 var node = field.dom191 if (field.validator) {192 return193 }194 field.validator = validator195 /* istanbul ignore if */196 if (validator.validateInKeyup && (!field.isChanged && !field.debounceTime)) {197 avalon.bind(node, 'keyup', singleValidate)198 }199 /* istanbul ignore if */200 if (validator.validateInBlur) {201 avalon.bind(node, 'blur', singleValidate)202 }203 /* istanbul ignore if */204 if (validator.resetInFocus) {205 avalon.bind(node, 'focus', function(e) {206 var dom = e.target207 var field = dom._ms_duplex_208 var validator = getValidate(e.target)209 validator && validator.onReset.call(dom, e, field)210 })211 }212}213var rformat = /\\?{{([^{}]+)\}}/gm214function getMessage() {215 var data = this.data || {}216 return this.message.replace(rformat, function(_, name) {217 return data[name] == null ? '' : data[name]218 })219}220valiDir.defaults = {221 validate: valiDir.validate,222 onError: avalon.noop,223 onSuccess: avalon.noop,224 onComplete: avalon.noop,225 onManual: avalon.noop,226 onReset: avalon.noop,227 onValidateAll: avalon.noop,228 validateInBlur: true, //@config {Boolean} true,在blur事件中进行验证,触发onSuccess, onError, onComplete回调229 validateInKeyup: true, //@config {Boolean} true,在keyup事件中进行验证,触发onSuccess, onError, onComplete回调230 validateAllInSubmit: true, //@config {Boolean} true,在submit事件中执行onValidateAll回调231 resetInFocus: true, //@config {Boolean} true,在focus事件中执行onReset回调,232 deduplicateInValidateAll: false //@config {Boolean} false,在validateAll回调中对reason数组根据元素节点进行去重...

Full Screen

Full Screen

EditStatusPageMonitorDialog.jsx

Source:EditStatusPageMonitorDialog.jsx Github

copy

Full Screen

...19 return false;20 }21 return (floatValue >= 0 && floatValue <= 100);22}23function msValidator(value) {24 const normalizedValue = '' + value;25 if (!normalizedValue.match(RegexPatterns.integer)) {26 return false;27 }28 const intValue = parseInt(normalizedValue);29 if (isNaN(intValue)) {30 return false;31 }32 return (intValue >= 0 && intValue <= 30*1000);33}34function getFloat(value) {35 return parseFloat(('' + value).replace(',', '.'));36}37export default function EditStatusPageMonitorDialog({ monitor, onClose }) {38 const onCloseHook = useRef(onClose, []);39 const { t } = useTranslation();40 const { enqueueSnackbar } = useSnackbar();41 const [ isLoading, setIsLoading ] = useState(false);42 const [ title, setTitle ] = useState(monitor.monitorTitle);43 const [ monitorEnabled, setMonitorEnabled ] = useState(monitor.enabled);44 const [ thresholdUptimeWarning, setThresholdUptimeWarning ] = useState(monitor.thresholdUptimeWarning * 100.0);45 const [ thresholdUptimeError, setThresholdUptimeError ] = useState(monitor.thresholdUptimeError * 100.0);46 const [ thresholdLatencyWarning, setThresholdLatencyWarning ] = useState(monitor.thresholdLatencyWarning);47 const [ thresholdLatencyError, setThresholdLatencyError ] = useState(monitor.thresholdLatencyError);48 const [ percentile, setPercentile ] = useState(monitor.percentile);49 function doSaveMonitor() {50 if (!title.match(RegexPatterns.title)) {51 return;52 }53 setIsLoading(true);54 updateStatusPageMonitor(monitor.monitorId, {55 monitorTitle: title,56 enabled: monitorEnabled,57 thresholdUptimeWarning: getFloat(thresholdUptimeWarning) / 100.0,58 thresholdUptimeError: getFloat(thresholdUptimeError) / 100.0,59 thresholdLatencyWarning: getFloat(thresholdLatencyWarning),60 thresholdLatencyError: getFloat(thresholdLatencyError),61 percentile62 })63 .then(() => {64 enqueueSnackbar(t('statuspages.monitorUpdated'), { variant: 'success' });65 onCloseHook.current(true);66 })67 .catch(() => {68 enqueueSnackbar(t('statuspages.monitorUpdateFailed'), { variant: 'error' });69 })70 .finally(() => setIsLoading(false));71 }72 const PERCENTILE_MARKS = [73 {74 value: 0.50,75 label: 'p50'76 },77 {78 value: 0.90,79 label: 'p90'80 },81 {82 value: 0.95,83 label: 'p95'84 },85 {86 value: 0.99,87 label: 'p99'88 }89 ]90 return <Dialog open={true} onClose={() => onCloseHook.current()} fullWidth maxWidth='sm'>91 <DialogTitle>{t('statuspages.editMonitor', { title: monitor.monitorTitle })}</DialogTitle>92 <DialogContent>93 <Grid container spacing={1}>94 <Grid item xs={12}>95 <FormControl fullWidth>96 <ValidatingTextField97 label={t('statuspages.title')}98 defaultValue={title}99 onChange={({target}) => setTitle(target.value)}100 InputLabelProps={{ shrink: true }}101 pattern={RegexPatterns.title}102 patternErrorText={t('common.checkInput')}103 fullWidth104 autoFocus105 />106 </FormControl>107 </Grid>108 <Grid item xs={6}>109 <ValidatingTextField110 label={t('statuspages.thresholdUptimeWarning')}111 defaultValue={thresholdUptimeWarning}112 onChange={({target}) => setThresholdUptimeWarning(target.value)}113 InputLabelProps={{shrink: true}}114 InputProps={{115 startAdornment: <InputAdornment position='start'>116 <StatusPageConfigIcon icon={UptimeIcon} color='orange' />117 </InputAdornment>118 }}119 patternErrorText={t('statuspages.checkUptimeThresholdInput')}120 validator={percentValidator}121 fullWidth122 />123 </Grid>124 <Grid item xs={6}>125 <ValidatingTextField126 label={t('statuspages.thresholdUptimeError')}127 defaultValue={thresholdUptimeError}128 onChange={({target}) => setThresholdUptimeError(target.value)}129 InputLabelProps={{ shrink: true }}130 InputProps={{131 startAdornment: <InputAdornment position='start'>132 <StatusPageConfigIcon icon={UptimeIcon} color='red' />133 </InputAdornment>134 }}135 patternErrorText={t('statuspages.checkUptimeThresholdInput')}136 validator={percentValidator}137 fullWidth138 />139 </Grid>140 <Grid item xs={6}>141 <ValidatingTextField142 label={t('statuspages.thresholdLatencyWarning')}143 defaultValue={thresholdLatencyWarning}144 onChange={({target}) => setThresholdLatencyWarning(target.value)}145 InputLabelProps={{ shrink: true }}146 InputProps={{147 startAdornment: <InputAdornment position='start'>148 <StatusPageConfigIcon icon={LatencyIcon} color='orange' />149 </InputAdornment>150 }}151 patternErrorText={t('statuspages.checkLatencyThresholdInput')}152 validator={msValidator}153 fullWidth154 />155 </Grid>156 <Grid item xs={6}>157 <ValidatingTextField158 label={t('statuspages.thresholdLatencyError')}159 defaultValue={thresholdLatencyError}160 onChange={({target}) => setThresholdLatencyError(target.value)}161 InputLabelProps={{ shrink: true }}162 InputProps={{163 startAdornment: <InputAdornment position='start'>164 <StatusPageConfigIcon icon={LatencyIcon} color='red' />165 </InputAdornment>166 }}167 patternErrorText={t('statuspages.checkLatencyThresholdInput')}168 validator={msValidator}169 fullWidth170 />171 </Grid>172 <Grid item xs={12}>173 <FormControl fullWidth>174 <Typography variant='caption' color='textSecondary'>{t('statuspages.percentile')}</Typography>175 <Box pl={1.5} pr={1.5}>176 <Slider177 value={percentile}178 marks={PERCENTILE_MARKS}179 min={0.5}180 max={0.99}181 step={null}182 valueLabelDisplay='auto'183 valueLabelFormat={formatPercentile}184 onChange={(event, value) => setPercentile(value)}185 />186 </Box>187 </FormControl>188 </Grid>189 <Grid item xs={12}>190 <FormControlLabel191 control={<Switch192 checked={monitorEnabled}193 onChange={({target}) => setMonitorEnabled(target.checked)}194 />}195 label={t('statuspages.enableMonitor')}196 />197 </Grid>198 </Grid>199 </DialogContent>200 <DialogActions>201 <Button autoFocus onClick={() => onCloseHook.current()} disabled={isLoading}>202 {t('common.cancel')}203 </Button>204 <Button color='primary' onClick={() => doSaveMonitor()} disabled={205 isLoading ||206 title.length<3 ||207 !msValidator(thresholdLatencyError) || !msValidator(thresholdLatencyWarning) ||208 !percentValidator(thresholdUptimeError || !percentValidator(thresholdUptimeWarning))}>209 {t('common.save')}210 </Button>211 </DialogActions>212 </Dialog>;...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

1const fs = require('fs');2const path = require('path');3const uuidv4 = require('uuid');4const appDir = path.dirname(require.main.filename);5const SITE_JSON_PATH = appDir + '/data/siteinfo.json';6const AUTH_JSON_PATH = appDir + '/data/auth.json';7class CMS {8 constructor(data = {}) {9 data = Object.assign({}, CMS.defaults(), data);10 this.id = data.id;11 this.sitename = data.sitename;12 this.frontendurl = data.frontendurl;13 this.apiurl = data.apiurl;14 this.haswww = data.haswww;15 this.isHttps = data.isHttps;16 this.authkey = data.authkey;17 this.googleAdClient = data.googleAdClient;18 this.googleAnalytics = data.googleAnalytics;19 this.msValidator = data.msValidator;20 this.defMetaDesc = data.defMetaDesc;21 this.defMetaKey = data.defMetaKey;22 this.lang = data.lang;23 }24 validate() {25 if (!this.sitename || !this.frontendurl || !this.apiurl) {26 return false;27 }28 return true;29 }30 /**31 * Returns new object with current data.32 * @param {{needAuthKey:boolean;}} data Optional, has props like authkey flag33 */34 toJSON(data = {}) {35 if (data.needAuthKey == void 0) { data.needAuthKey = false; }36 const json = {};37 json.id = this.id;38 json.sitename = this.sitename;39 json.frontendurl = this.frontendurl;40 json.apiurl = this.apiurl;41 json.haswww = this.haswww;42 json.isHttps = this.isHttps;43 if (data.needAuthKey) {44 json.authkey = this.authkey;45 }46 json.googleAdClient = this.googleAdClient;47 json.googleAnalytics = this.googleAnalytics;48 json.msValidator = this.msValidator;49 json.defMetaDesc = this.defMetaDesc;50 json.defMetaKey = this.defMetaKey;51 json.lang = this.lang;52 return json;53 }54 clean() {55 for (let key in this) {56 if (this.hasOwnProperty(key)) {57 delete this[key];58 }59 }60 }61 set(data) {62 this.clean();63 Object.assign(this, {}, data);64 }65 getFrontendURL() {66 let www = '';67 if (this.haswww) {68 www = 'www.';69 }70 let https = 'http://';71 if (this.isHttps) {72 https = 'https://';73 }74 return https + www + this.frontendurl;75 }76 getAPIURL() {77 let https = 'http://';78 if (this.isHttps) {79 https = 'https://';80 }81 return https + this.apiurl;82 }83}84CMS.SCHEMA = {85 properties: [{86 name: 'id',87 isPrimaryKey: true,88 type: 'uuid'89 }, {90 name: 'sitename',91 type: 'string'92 }, {93 name: 'frontendurl',94 type: 'string'95 }, {96 name: 'apiurl',97 type: 'uuid'98 }, {99 name: 'haswww',100 type: 'boolean'101 }, {102 name: 'isHttps',103 type: 'boolean'104 }, {105 name: 'authkey',106 type: 'string'107 }, {108 name: 'googleAdClient',109 type: 'string'110 }, {111 name: 'googleAnalytics',112 type: 'string'113 }, {114 name: 'msValidator',115 type: 'string'116 }, {117 name: 'defMetaDesc',118 type: 'string'119 }, {120 name: 'defMetaKey',121 type: 'string'122 }, {123 name: 'lang',124 type: 'string'125 }]126};127CMS.defaults = () => {128 return {129 id: uuidv4.v4(),130 haswww: true,131 isHttps: false,132 googleAdClient: '',133 googleAnalytics: '',134 msValidator: '',135 defMetaDesc: '',136 defMetaKey: '',137 lang: ''138 };139};140CMS.isConfigured = false;141/**142 * Returns promise containing JSON object.143 * @param {string} path path of the json to read from144 */145CMS.readJSON = (path) => {146 return new Promise((res, rej) => {147 fs.readFile(path, 'utf8', (err, data) => {148 if (err) {149 rej(err);150 } else {151 res(JSON.parse(data));152 }153 });154 });155};156/**157 * Writes json by stringifying it158 * Returns promise containing JSON object.159 * @param {string} path path of the json to write to160 * @param {Object} json JSON object to write161 */162CMS.writeJSON = (path, json) => {163 return new Promise((res, rej) => {164 fs.writeFile(path, JSON.stringify(json), (err) => {165 if (err) {166 rej(err);167 } else {168 res(json);169 }170 });171 });172};173CMS.readConfigJSONFIle = () => CMS.readJSON(SITE_JSON_PATH);174/**175 * Automatically configures site incase of memory failure.176 */177CMS.autoConfigure = () => {178 return new Promise((res, rej) => {179 CMS.readConfigJSONFIle().then((data) => {180 CMS._instance.set(data);181 CMS.isConfigured = true;182 res({ message: 'configured', siteinfo: CMS._instance.toJSON() });183 return data;184 }, (err) => {185 if (err.code == 'ENOENT') {186 res({ message: 'jsonfilenotpresent' });187 CMS.isConfigured = false;188 console.log('Site is not configured yet, needs to be configured');189 } else {190 CMS.isConfigured = false;191 rej(err);192 }193 });194 });195};196CMS._instance = new CMS();197CMS.getInstance = () => CMS._instance;...

Full Screen

Full Screen

file_service.js

Source:file_service.js Github

copy

Full Screen

1/**2 * Created by bustamante on 6/24/15.3 */4angular.module('magicSurface').factory('FileApi',["MSValidator", "FileRestApi", "$timeout", function(MSValidator, FileRestApi, $timeout){5 function save(file, data){6 var promise = {7 success: function(_func){promise._success = _func},8 error: function(_func){promise._error = _func},9 finally: function(_func){promise._finally = _func},10 progress: function(_func){promise._progress = _func}11 };12 $timeout(function(){13 data.layer = data.layer || data.layerId;14 var _rules = {15 hasId: [data.layer]16 };17 var status = MSValidator.validate(undefined, _rules);18 if(status.isValid)19 {20 data.layerId = isNaN(data.layer)? data.layer.id : data.layer;21 delete data.layer;22 var p = FileRestApi.save(file, data);23 p.success(function(result){24 if(promise._success)promise._success(result);25 if(promise._finally)promise._finally();26 });27 p.error(function(result){28 if(promise._error)promise._error(result);29 if(promise._finally)promise._finally();30 });31 p.progress(promise._progress);32 } else {33 if(promise._error) promise._error(status);34 if(promise._finally) promise._finally('');35 }36 });37 return promise;38 }39 function get(file){40 var promise = {41 success: function(_func){promise._success = _func},42 error: function(_func){promise._error = _func},43 finally: function(_func){promise._finally = _func}44 };45 $timeout(function(){46 var status = MSValidator.validate(file, {hasId: [file]});47 if(status.isValid){48 var params = {fileId: isNaN(file)? file.id : file};49 FileRestApi.get(params)50 .success(promise._success)51 .error(promise._error)52 .finally(promise._finally);53 } else {54 if(promise._error) promise._error(status);55 if(promise._finally) promise._finally('');56 }57 });58 return promise59 }60 function list(form){61 var promise = {62 success: function(_func){promise._success = _func},63 error: function(_func){promise._error = _func},64 finally: function(_func){promise._finally = _func}65 };66 $timeout(function(){67 var _rules = {68 hasId: [form.layerId]69 };70 if(!form.filters) form.filters = {};71 var status = MSValidator.validate(undefined, _rules);72 if(status.isValid)73 {74 form.layerId = isNaN(form.layerId)? form.layerId.id : form.layerId;75 FileRestApi.list(form)76 .success(promise._success)77 .error(promise._error)78 .finally(promise._finally);79 } else {80 if(promise._error) promise._error(status);81 if(promise._finally) promise._finally('');82 }83 });84 return promise;85 }86 function del(file){87 var promise = {88 success: function(_func){promise._success = _func},89 error: function(_func){promise._error = _func},90 finally: function(_func){promise._finally = _func}91 };92 $timeout(function(){93 var is_file_object = angular.isObject(file) && angular.isUndefined(file.id);94 if(is_file_object || !isNaN(file)){95 var params = {FileId: isNaN(file)? file.id : file};96 FileRestApi.del(params)97 .success(promise._success)98 .error(promise._error)99 .finally(promise._finally);100 } else {101 if(promise._error) promise._error({msg: 'fileId inválido'});102 if(promise._finally) promise._finally('');103 }104 });105 return promise106 }107 return {108 save: save,109 get: get,110 list: list,111 del: del112 }...

Full Screen

Full Screen

layer_service.js

Source:layer_service.js Github

copy

Full Screen

1/**2 * Created by bustamante on 6/21/15.3 */4angular.module('magicSurface').factory('LayerApi', ["LayerRestApi", "MSValidator", "$timeout", function(LayerRestApi, MSValidator, $timeout){5 var _rules = {6 notEmpty: ['name', 'latitude', 'longitude'],7 };8 function save(form){9 var promise = {10 success: function(_func){promise._success = _func},11 error: function(_func){promise._error = _func},12 finally: function(_func){promise._finally = _func}13 };14 $timeout(function(){15 var status = MSValidator.validate(form, _rules);16 if(status.isValid) {17 LayerRestApi.save(form)18 .success(promise._success)19 .error(promise._error)20 .finally(promise._finally);21 } else {22 if(promise._error) promise._error(status);23 if(promise._finally) promise._finally('');24 }25 });26 return promise;27 }28 function get(form){29 var promise = {30 success: function(_func){promise._success = _func},31 error: function(_func){promise._error = _func},32 finally: function(_func){promise._finally = _func}33 };34 $timeout(function(){35 if (form === undefined) form = {};36 if (!isNaN(form)) form = {'layerId': form};37 var status = MSValidator.validate(form.layerId, {hasId: [form.layerId]});38 if(status.isValid){39 form.layerId = isNaN(form.layerId)? form.layerId.id : form.layerId;40 form.options = form.options === undefined ? {} : form.options;41 LayerRestApi.get(form)42 .success(promise._success)43 .error(promise._error)44 .finally(promise._finally);45 } else {46 if(promise._error) promise._error(status);47 if(promise._finally) promise._finally('');48 }49 });50 return promise51 }52 function list(form){53 var promise = {54 success: function(_func){promise._success = _func},55 error: function(_func){promise._error = _func},56 finally: function(_func){promise._finally = _func}57 };58 $timeout(function(){59 if (form === undefined) form = {};60 if (form.filters === undefined) form.filters = {};61 if (form.options === undefined) form.options = {};62 LayerRestApi.list(form)63 .success(promise._success)64 .error(promise._error)65 .finally(promise._finally);66 });67 return promise;68 }69 function del(form){70 var promise = {71 success: function(_func){promise._success = _func},72 error: function(_func){promise._error = _func},73 finally: function(_func){promise._finally = _func}74 };75 $timeout(function(){76 if(form === undefined) form = {};77 var is_layer_object = angular.isObject(form.layerId) && angular.isUndefined(form.layerId.id);78 if(is_layer_object || !isNaN(form.layerId)){79 if(form.options === undefined) form.options = {};80 form.layerId = isNaN(form.layerId)? form.layerId.id : form.layerId;81 LayerRestApi.del(form)82 .success(promise._success)83 .error(promise._error)84 .finally(promise._finally);85 } else {86 if(promise._error) promise._error({msg: 'LayerId inválido'});87 if(promise._finally) promise._finally('');88 }89 });90 return promise91 }92 return {93 save: save,94 list: list,95 get: get,96 del: del97 }...

Full Screen

Full Screen

validator.js

Source:validator.js Github

copy

Full Screen

1/**2 * Created by bustamante on 6/21/15.3 */4angular.module('msvalidator', []);5angular.module('msvalidator').factory('MSValidator', function(){6 var _form = undefined;7 var _status = undefined;8 var _functionsRoles = {9 'notEmpty': function (fields) {10 var _fieldsWrong = [];11 for(var i = 0; i < fields.length; ++i){12 if(!_form[fields[i]]){13 _fieldsWrong.push(fields[i]);14 }15 }16 if(!angular.equals(_fieldsWrong, [])){17 return {18 msg: 'Campos obrigatorios!',19 fields: _fieldsWrong20 }21 }22 },23 'existOnly': function (fields) {24 var _fieldsWrong = [];25 for(var field in _form){26 if(fields.indexOf(field) === -1){27 _fieldsWrong.push(field);28 }29 }30 if(!angular.equals(_fieldsWrong, [])){31 return {32 msg: 'Ha campos que nao deveriam existir no objeto!',33 fields: _fieldsWrong34 }35 }36 },37 'isNumber': function (fields) {38 var _fieldsWrong = [];39 for(var i = 0; i < fields.length; ++i){40 if(_form[fields[i]] !== undefined && isNaN(_form[fields[i]])){41 _fieldsWrong.push(fields[i]);42 }43 }44 if(!angular.equals(_fieldsWrong, [])){45 return {46 msg: 'Ha campos que deveriam ser números!',47 fields: _fieldsWrong48 }49 }50 },51 'hasId': function(layer){52 var isLayerObj = angular.isObject(layer) && angular.isUndefined(layer.id);53 if(!isLayerObj && isNaN(layer)){54 return {55 msg: 'Obejot não possui um id!'56 }57 }58 },59 'isFile': function(file){60 if(angular.isArray(file))61 file = file[0];62 var isFile = angular.isObject(file) && (file instanceof File);63 if(!isFile){64 return {65 msg: 'File inválido, verifique se ele é do tipo File'66 }67 }68 }69 };70 function validate(form, rules){71 _form = form;72 _status = {isValid: true};73 for(var rule in rules){74 var array = rules[rule];75 if(_functionsRoles[rule] !== undefined){76 var error = _functionsRoles[rule](array);77 if ( error !== undefined){78 _status = error;79 _status.isValid = false;80 break;81 }82 } else {83 console.error("Ops a rule " + rule + " não existe!!");84 }85 }86 return _status;87 }88 return {89 validate: validate90 }...

Full Screen

Full Screen

validators.js

Source:validators.js Github

copy

Full Screen

...14 throw new Error('Url or Uri must start with <scheme>://');15 }16 },17 implicitWait: (ms) => {18 msValidator(ms);19 },20 asyncScriptTimeout: (ms) => {21 msValidator(ms);22 },23 timeouts: (type, ms) => {24 msValidator(ms);25 if (!_.contains(['script', 'implicit', 'page load', 'command'], type)) {26 throw new Error(`'${type}' is not a valid timeout type`);27 }28 },29 clickCurrent: (button) => {30 if (!(isNumber(button) || _.isUndefined(button)) || (button < 0 || button > 2)) {31 throw new Error('Click button must be 0, 1, or 2');32 }33 },34 setNetworkConnection: (type) => {35 if (!isNumber(type) || [0, 1, 2, 4, 6].indexOf(type) === -1) {36 throw new Error('Network type must be one of 0, 1, 2, 4, 6');37 }38 }...

Full Screen

Full Screen

magicSurface.js

Source:magicSurface.js Github

copy

Full Screen

1angular.module('magicSurface', ['msajax', 'msvalidator', 'ngFileUpload']);2angular.module('magicSurface').factory('MagicSurface', function(){3 var _token;4 var _username;5 var _host = 'http://magicsurfacebr.appspot.com/';6 //var _host = 'http://localhost:8080/';7 function configApp(token, username){8 _token = token;9 _username = username;10 }11 function getToken(){12 return _token;13 }14 function getUsername(){15 return _username;16 }17 function getHost(){18 return _host19 }20 return {21 getHost: getHost,22 getToken: getToken,23 getUsername: getUsername,24 configApp: configApp25 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .msValidator('test')9 .end();10[HTTP] {"desiredCapabilities":{"platformName":"Android","platformVersion":"7.0","deviceName":"emulator-5554","automationName":"UiAutomator2","app":"C:\\Users\\<User>\\Desktop\\ApiDemos-debug.apk"},"capabilities":{"firstMatch":[{"platformName":"android"}]}}11[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","platformVersion":"7.0","deviceName":"emulator-5554","automationName":"UiAutomator2","app":"C:\\Users\\<User>\\Desktop\\ApiDemos-debug.apk"},null,{"firstMatch":[{"platformName":"android"}]}]12[debug] [BaseDriver] Event 'newSessionRequested' logged at 1537999258773 (11:20:58 GMT+0530 (India Standard Time))13[Appium] Appium v1.9.1 creating new AndroidUiautomator2Driver (v1.28.1) session

Full Screen

Using AI Code Generation

copy

Full Screen

1const msValidator = require('appium-base-driver').msValidator;2const msValidator = require('appium-base-driver').msValidator;3const msValidator = require('appium-base-driver').msValidator;4const msValidator = require('appium-base-driver').msValidator;5const msValidator = require('appium-base-driver').msValidator;6const msValidator = require('appium-base-driver').msValidator;7const msValidator = require('appium-base-driver').msValidator;8const msValidator = require('appium-base-driver').msValidator;9const msValidator = require('appium-base-driver').msValidator;10const msValidator = require('appium-base-driver').msValidator;11const msValidator = require('appium-base-driver').msValidator;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { msValidator } from 'appium-base-driver';2const ms = 1000;3const isValid = msValidator(ms);4import { msToSec } from 'appium-base-driver';5const ms = 1000;6const sec = msToSec(ms);7import { msToSec } from 'appium-base-driver';8const ms = 1000;9const sec = msToSec(ms);10import { errorFromMJSONWPStatusCode } from 'appium-base-driver';11const status = 6;12const err = errorFromMJSONWPStatusCode(status);13import { errorFromW3CJsonCode } from 'appium-base-driver';14const status = 6;15const err = errorFromW3CJsonCode(status);16import { errorFromCode } from 'appium-base-driver';17const status = 6;18const err = errorFromCode(status);19import { isErrorType } from 'appium-base-driver';20const err = new Error('A session is either terminated or not started');21const isType = isErrorType(err, 'A session is either terminated or not started');22import { isSessionCommand } from 'appium-base-driver';23const cmd = 'createSession';24const isCmd = isSessionCommand(cmd);25import { isSessionCommand } from

Full Screen

Using AI Code Generation

copy

Full Screen

1it('should validate ms app', async () => {2 await driver.validateApp('path/to/ms/app');3});4it('should validate ms app', async () => {5 await driver.validateMSApp('path/to/ms/app');6});7it('should validate ms app', async () => {8 await driver.validateMSApp('path/to/ms/app');9});10it('should validate ms app', async () => {11 await driver.validateMSApp('path/to/ms/app');12});13it('should validate ms app', async () => {14 await driver.validateMSApp('path/to/ms/app');15});16it('should validate ms app', async () => {17 await driver.validateMSApp('path/to/ms/app');18});19it('should validate ms app', async () => {20 await driver.validateMSApp('path/to/ms/app');21});22it('should validate ms app', async () => {23 await driver.validateMSApp('path/to/ms/app');24});25it('should validate ms app', async () => {26 await driver.validateMSApp('path/to/ms/app');27});28it('should validate ms app', async () => {29 await driver.validateMSApp('path/to/ms/app');30});31it('should validate ms app', async () => {32 await driver.validateMSApp('path/to/ms/app');33});34it('should validate ms app', async () => {35 await driver.validateMSApp('path/to/ms/app');36});37it('should validate ms app', async () => {38 await driver.validateMSApp('path/to/ms/app');39});40it('should validate ms app', async () => {41 await driver.validateMSApp('

Full Screen

Using AI Code Generation

copy

Full Screen

1var msValidator = driver.msValidator;2var msValidator = driver.msValidator;3var msValidator = driver.msValidator;4var msValidator = driver.msValidator;5var msValidator = driver.msValidator;6var msValidator = driver.msValidator;7var msValidator = driver.msValidator;8var msValidator = driver.msValidator;

Full Screen

Using AI Code Generation

copy

Full Screen

1var msValidator = require('appium-base-driver').msValidator;2var ms = 10000;3var valid = msValidator(ms);4console.log(valid);5var msValidator = require('appium-base-driver').msValidator;6var ms = 1000;7var valid = msValidator(ms);8console.log(valid);9var msValidator = require('appium-base-driver').msValidator;10var ms = 0;11var valid = msValidator(ms);12console.log(valid);13var msValidator = require('appium-base-driver').msValidator;14var ms = -1;15var valid = msValidator(ms);16console.log(valid);17var msValidator = require('appium-base-driver').msValidator;18var ms = -1000;19var valid = msValidator(ms);20console.log(valid);21var msValidator = require('appium-base-driver').msValidator;22var ms = '1000';23var valid = msValidator(ms);24console.log(valid);25var msValidator = require('appium-base-driver').msValidator;26var ms = '-1000';27var valid = msValidator(ms);28console.log(valid);29var msValidator = require('appium-base-driver').msValidator;30var ms = 'test';31var valid = msValidator(ms

Full Screen

Using AI Code Generation

copy

Full Screen

1var baseDriver = require('appium-base-driver');2var driver = new baseDriver();3var screenName = 'test';4var validation = driver.msValidator(screenName);5if(validation == true)6{7console.log("The screen is validated");8}9{10console.log("The screen is not validated");11}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful