Best JavaScript code snippet using appium-xcuitest-driver
createSurvey.js
Source:createSurvey.js
1var downloadImages = function(driver)2{3 driver4 .url("https://burst.shopify.com/")5 .pause(3000)6 .waitForElementVisible('body', 1000)7 .useXpath()8 //download survey badge9 .pause(2000)10 .setValue("//input[@class='marketing-input search-form__input search-form__input--jumbo']", "beach")11 .pause(1000)12 .keys(driver.Keys.ENTER)13 .pause(3000)14 .click("(//div[@class='grid '])[1]/div[2]/div[1]")15 .pause(2000)16 .click("//label[@for='photo_download_quality_standard']")17 .pause(2000)18 .click("//button[@data-ga-action='Download']")19 .pause(4000)20}21var signIn = function(driver)22 {23 driver24 .url(driver.globals.userNames.adminURL)25 .windowMaximize("current")26 //.waitForElementVisible('body', 1000)27 .useXpath()28 .click("//input[@id='admin_email']")29 .pause(500)30 .setValue("//input[@id='admin_email']", driver.globals.userNames.adminEmail)31 .pause(500)32 .click("//input[@id='admin_password']")33 .pause(500)34 .setValue("//input[@id='admin_password']", driver.globals.userNames.adminPassword)35 .pause(500)36 .click("//input[@class='btn btn-login test-login-button']")37 .pause(2000)38 .saveScreenshot('screenshots/sprint'+driver.globals.userNames.sprint+'/siginConfirmAdmin.png')39 .pause(1000)40 }41var clickAdminLinks = function(driver)42{43 driver44 .useXpath()45 //click Mission Hubs46 .click("//a[@class='test-nav-hubs']")47 .pause(2000)48 .assert.containsText("//h1[@class='pull-left']", "Mission Hubs")49 //add mission hub50 .click("//a[@class='btn btn-default btn-icon-add test-hub-new']")51 .pause(500)52 //input mission name53 .click("//div[@id='new_mission_hub']/div/div/div[2]/div/div/input")54 .pause(500)55 .setValue("//div[@id='new_mission_hub']/div/div/div[2]/div/div/input", "Survey smoke")56 .pause(1000)57 //click create button58 .click("//div[@class='modal-footer ng-scope']/button")59 .pause(1000)60 //add survey61 .click("//ul[@class='q-builder']/li[1]")62 .pause(4000)63 //click on the survey link64 .click("//a[@class='rowclick test-hub-structure-item-link ng-binding']")65 .pause(3000)66 //click survey name edit button67 .click("//button[@class='btn-edit']")68 .pause(500)69 //input survey name70 .clearValue("//input[@ng-show='isEdit']")71 .setValue("//input[@ng-show='isEdit']","survey smoke name")72 .pause(500)73 .keys(driver.Keys.ENTER)74 .pause(500)75 //add reward points76 .click("(//div[@class='q-list-link q-list-reward'])[1]")77 .click("//input[@class='form-control reward-points-field ng-pristine ng-valid']")78 .setValue("//input[@class='form-control reward-points-field ng-pristine ng-valid']", "10")79 .pause(500)80 .click("(//button[@class='btn btn-primary q-list-done'])[1]")81 //add badge82 .click("(//div[@class='q-list-link q-list-reward'])[2]")83 .setValue("//input[@class='js-badge-image-field']", driver.globals.userNames.path + "blue-beach-waves_925x.jpg")84 .pause(2000)85 .click("//textarea[@class='form-control q-list-badge-name test-activity-badge-name ng-pristine ng-valid placeholder']")86 .setValue("//textarea[@class='form-control q-list-badge-name test-activity-badge-name ng-pristine ng-valid placeholder']","survey badge name")87 .pause(500)88 .click("(//button[@class='btn btn-primary q-list-done'])[1]")89 .pause(1000)90 .saveScreenshot('screenshots/sprint'+driver.globals.userNames.sprint+'/pointsBadgeAdded.png')91 //Single answer question92 .click("//li[@class='js-draggable test-survey-new-single_answer ui-draggable']")93 .pause(500)94 .click("//textarea[@rows='1']")95 .pause(500)96 .setValue("//textarea[@rows='1']", "Q1 Single answer type")97 .click("//button[@class='btn btn-default q-list-add test-survey-item-edit ng-scope']")98 .pause(500)99 .click("//textarea[@class='q-field test-question-answer-0 placeholder']")100 .pause(500)101 .setValue("//textarea[@class='q-field test-question-answer-0 placeholder']", "answer 1")102 .pause(500)103 .keys(driver.Keys.ENTER)104 .click("//textarea[@class='q-field test-question-answer-1 placeholder']")105 .pause(500)106 .setValue("//textarea[@class='q-field test-question-answer-1 placeholder']", "answer 2")107 .pause(500)108 .keys(driver.Keys.ENTER)109 .click("//textarea[@class='q-field test-question-answer-2 placeholder']")110 .pause(500)111 .setValue("//textarea[@class='q-field test-question-answer-2 placeholder']", "answer 3")112 .pause(500)113 .click("//button[@class='btn button test-question-create']")114 .pause(1000)115 //Multi answer question116 .click("//li[@class='test-question-new test-question-new-multiple_answers']")117 .pause(1000)118 .click("//textarea[@rows='1']")119 .pause(500)120 .clearValue("//textarea[@rows='1']")121 .pause(500)122 .setValue("//textarea[@rows='1']", "Q2 Multiple answer type")123 .pause(500)124 .click("//textarea[@class='q-field test-question-answer-0 placeholder']")125 .pause(500)126 .setValue("//textarea[@class='q-field test-question-answer-0 placeholder']", "answer 1")127 .pause(500)128 .keys(driver.Keys.ENTER)129 .click("//textarea[@class='q-field test-question-answer-1 placeholder']")130 .pause(500)131 .setValue("//textarea[@class='q-field test-question-answer-1 placeholder']", "answer 2")132 .pause(500)133 .keys(driver.Keys.ENTER)134 .click("//textarea[@class='q-field test-question-answer-2 placeholder']")135 .pause(500)136 .setValue("//textarea[@class='q-field test-question-answer-2 placeholder']", "answer 3")137 .pause(500)138 .click("//button[@class='btn button test-question-create']")139 .pause(500)140 //Matrix Single answer question141 .click("//li[@class='test-question-new test-question-new-matrix_with_single_answer']")142 .pause(1000)143 .click("//textarea[@rows='1']")144 .pause(500)145 .clearValue("//textarea[@rows='1']")146 .pause(500)147 .setValue("//textarea[@rows='1']", "Q3 Matrix Single answer type")148 .pause(500)149 .click("//textarea[@class='q-field test-question-matrix-row-0 placeholder']")150 .pause(500)151 .setValue("//textarea[@class='q-field test-question-matrix-row-0 placeholder']", "row 1")152 .pause(500)153 .keys(driver.Keys.ENTER)154 .click("//textarea[@class='q-field test-question-matrix-row-1 placeholder']")155 .pause(500)156 .setValue("//textarea[@class='q-field test-question-matrix-row-1 placeholder']", "row 2")157 .pause(500)158 .keys(driver.Keys.ENTER)159 .click("//textarea[@class='q-field test-question-matrix-row-2 placeholder']")160 .pause(500)161 .setValue("//textarea[@class='q-field test-question-matrix-row-2 placeholder']", "row 3")162 .pause(500)163 .click("//textarea[@class='q-field test-question-matrix-col-0 placeholder']")164 .pause(500)165 .setValue("//textarea[@class='q-field test-question-matrix-col-0 placeholder']", "col 1")166 .pause(500)167 .keys(driver.Keys.ENTER)168 .click("//textarea[@class='q-field test-question-matrix-col-1 placeholder']")169 .pause(500)170 .setValue("//textarea[@class='q-field test-question-matrix-col-1 placeholder']", "col 2")171 .pause(500)172 .keys(driver.Keys.ENTER)173 .click("//textarea[@class='q-field test-question-matrix-col-2 placeholder']")174 .pause(500)175 .setValue("//textarea[@class='q-field test-question-matrix-col-2 placeholder']", "col 3")176 .pause(500)177 .click("//button[@class='btn button test-question-create']")178 .pause(500)179 //Matrix multiple answer question180 .click("//li[@class='test-question-new test-question-new-matrix_with_multiple_answers']")181 .pause(1000)182 .click("//textarea[@rows='1']")183 .pause(1000)184 .clearValue("//textarea[@rows='1']")185 .pause(500)186 .setValue("//textarea[@rows='1']", "Q4 Matrix Multiple answer type")187 .pause(500)188 .click("//textarea[@class='q-field test-question-matrix-row-0 placeholder']")189 .pause(500)190 .setValue("//textarea[@class='q-field test-question-matrix-row-0 placeholder']", "row 1")191 .pause(500)192 .keys(driver.Keys.ENTER)193 .click("//textarea[@class='q-field test-question-matrix-row-1 placeholder']")194 .pause(500)195 .setValue("//textarea[@class='q-field test-question-matrix-row-1 placeholder']", "row 2")196 .pause(500)197 .keys(driver.Keys.ENTER)198 .click("//textarea[@class='q-field test-question-matrix-row-2 placeholder']")199 .pause(500)200 .setValue("//textarea[@class='q-field test-question-matrix-row-2 placeholder']", "row 3")201 .pause(500)202 .click("//textarea[@class='q-field test-question-matrix-col-0 placeholder']")203 .pause(500)204 .setValue("//textarea[@class='q-field test-question-matrix-col-0 placeholder']", "col 1")205 .pause(500)206 .keys(driver.Keys.ENTER)207 .click("//textarea[@class='q-field test-question-matrix-col-1 placeholder']")208 .pause(500)209 .setValue("//textarea[@class='q-field test-question-matrix-col-1 placeholder']", "col 2")210 .pause(500)211 .keys(driver.Keys.ENTER)212 .click("//textarea[@class='q-field test-question-matrix-col-2 placeholder']")213 .pause(500)214 .setValue("//textarea[@class='q-field test-question-matrix-col-2 placeholder']", "col 3")215 .pause(500)216 .click("//button[@class='btn button test-question-create']")217 .pause(500)218 //Yes or No Type question219 .click("//li[@class='test-question-new test-question-new-yes_or_no']")220 .pause(1000)221 .click("//textarea[@rows='1']")222 .pause(500)223 .clearValue("//textarea[@rows='1']")224 .pause(500)225 .setValue("//textarea[@rows='1']", "Q5 Yes or No answer type")226 .pause(500)227 .click("//button[@class='btn button test-question-create']")228 .pause(5000)229 //Text Type question230 .click("//li[@class='test-question-new test-question-new-text']")231 .pause(1000)232 .click("//textarea[@rows='1']")233 .pause(1000)234 .clearValue("//textarea[@rows='1']")235 .pause(500)236 .setValue("//textarea[@rows='1']", "Q6 Text answer type")237 .pause(500)238 .click("//button[@class='btn button test-question-create']")239 .pause(500)240 //Number Type question241 .click("//li[@class='test-question-new test-question-new-numbers']")242 .pause(1000)243 .click("//textarea[@rows='1']")244 .pause(500)245 .clearValue("//textarea[@rows='1']")246 .pause(500)247 .setValue("//textarea[@rows='1']", "Q7 Number answer type")248 .pause(500)249 .click("//button[@class='btn button test-question-create']")250 .pause(500)251}252var missionLogic = function(driver)253 {254 driver255 .useXpath()256 //clicking to go back to mission Logic page257 .click("//div[@class='topbar']/ul/li[3]")258 .pause(1000)259 .click("//nav[@class='survey-navbar affix-top']/ul/li[3]")260 .pause(500)261 .click("//a[@class='mlogic-link test-hub-logic-item-view ng-scope']")262 .pause(500)263 .saveScreenshot('screenshots/sprint'+driver.globals.userNames.sprint+'/missionLogicPage.png')264 .pause(500)265 .click("//input[@id='date-start']")266 .pause(500)267 .click("//td[@class='active day']/preceding-sibling::td[@class='day'][1]")268 .pause(500)269 .click("//button[@class='mlogic-add-group']")270 .pause(500)271 .click("//span[text()='All Members']")272 .pause(500)273 .click("//button[@class='btn btn-primary test-hub-logic-item-group-save']")274 .pause(500)275 //.click("(//span[@class='control-checkbox control-checkbox-dark'])[1]")276 .pause(500)277 .click("(//label[@class='control-checkbox control-checkbox-primary'])[1]")278 .pause(500)279 .click("(//label[@class='control-checkbox control-checkbox-primary'])[2]")280 .pause(500)281 .click("//input[@class='form-control ng-pristine ng-valid ng-valid-number']")282 .pause(500)283 .setValue("//input[@class='form-control ng-pristine ng-valid ng-valid-number']","1")284 .pause(500)285 .click("//label[@class='switcher ng-scope']")286 .pause(500)287 .click("//button[@class='btn btn-default pull-right test-hub-logic-save']")288 .pause(500)289 .saveScreenshot('screenshots/sprint'+driver.globals.userNames.sprint+'/missionLogicSaved.png')290 .assert.visible("//button[@class='btn btn-default pull-right test-hub-logic-save']")291 .pause(2000)292 }293module.exports={294downloadImages: downloadImages,295 signIn: signIn,296 clickAdminLinks: clickAdminLinks,297 missionLogic: missionLogic298//sharing: sharing...
orders.js
Source:orders.js
1const csv = require('csv-parser');2const fs = require('fs');3const crypto = require('crypto');4const ed25519 = require('ed25519');5const axios = require('axios');6const Iota = require('@iota/core');7const Converter = require('@iota/converter');8const arduino = require('../ArduinoPackage/arduino');9const distributorSeed = fs.readFileSync('keys/distributor.pri', 'utf-8');10const iota = Iota.composeAPI({11 provider: 'https://nodes.comnet.thetangle.org:443'12});13let orderNumber = 1;14processOrder = async (data) => {15 return new Promise(async function(resolve, reject){16 try{17 console.log("Processing order...");18 let packagingBotPort = await findPackagingBot();19 let packageId = await arduino.request([20 arduino.commands.REQUESTID21 ]);22 const message = JSON.stringify({23 orderNumber: orderNumber,24 packageId: packageId25 });26 let transactionHash = await sendToIota(message, data.address);27 let driverKeys = await generateDriverKeys();28 await sendPackageToDriver({29 packageId: packageId,30 publicKey: driverKeys.publicKey.toString('hex'),31 privateKey: driverKeys.privateKey.toString('hex').substring(0, 64)32 });33 console.log("Order processed successfully!");34 resolve({35 orderNumber: orderNumber,36 packageId: packageId,37 transactionHash: transactionHash,38 driverPublicKey: driverKeys.publicKey.toString('hex')39 });40 }41 catch(err){42 console.log("An error occured while processing order!");43 reject(err);44 }45 });46};47findPackagingBot = () => {48 return new Promise(function(resolve, reject){49 try{50 let packagingBots = [];51 console.log("Finding an available packaging bot...");52 fs.createReadStream('packaging-bots.csv')53 .pipe(csv())54 .on('data', (row) => {55 if(row.available === 'true'){56 packagingBots.push(row.comport);57 }58 })59 .on('end', async () => {60 if(packagingBots.length > 0){61 let packagingBotPort = packagingBots.pop();62 console.log(`Packaging bot found on ${packagingBotPort}!`);63 resolve(packagingBotPort);64 }65 else{66 console.log("No available packaging bot found!");67 resolve(null);68 }69 });70 }71 catch(err){72 console.log("An error occured while finding an available packaging bot!");73 reject(err);74 }75 });76 77}78sendToIota = (message, address) => {79 return new Promise(function(resolve, reject){80 try{81 console.log(`Sending the following message in an IOTA transactions: ${message}`);82 const messageInTrytes = Converter.asciiToTrytes(message);83 console.log(`Message was converted to trytes: ${messageInTrytes}`);84 85 const transfers = [86 {87 value: 0,88 address: address,89 message: messageInTrytes90 }91 ];92 93 iota.prepareTransfers(distributorSeed, transfers)94 .then(trytes => {95 return iota.sendTrytes(trytes, 3, 10);96 })97 .then(bundle => {98 let transactionHash = bundle[0].hash;99 console.log(`Transaction was successfully created with the following hash: ${transactionHash}`);100 resolve(transactionHash);101 })102 .catch(err => {103 console.log("An error occured while sending transaction to IOTA...");104 reject(err);105 });106 }107 catch(err){108 console.log("An error occured while sending transaction to IOTA...");109 reject(err);110 }111 });112}113generateDriverKeys = () => {114 return new Promise(function(resolve, reject){115 try{116 console.log("Creating key pair for driver...");117 let driverSeed = crypto.randomBytes(32);118 let driverKeyPair = ed25519.MakeKeypair(driverSeed);119 console.log("Key pair created successfully!");120 resolve(driverKeyPair);121 }122 catch(err){123 console.log("An error occured while creating key pair for driver!");124 reject(err);125 }126 });127}128sendPackageToDriver = (package) => {129 return new Promise(function(resolve, reject) {130 try{131 console.log("Sending package to driver...");132 console.log(package);133 axios.post('http://localhost:3001/DistributePackage', package).then((res) => {134 console.log("Package successfully sent to driver!");135 resolve(res);136 }).catch((error) => {137 console.log(error);138 console.log("An error occured while sending package to driver!");139 reject(error);140 });141 }142 catch(err){143 console.log("An error occured while sending package to driver!");144 }145 })146}147exports.process = processOrder;...
index.js
Source:index.js
1/**2 * Standard Express Application and Handlers3 */4/**5 * Dependancy imports6 */7const EXPRESS = require('express');8const BODY_PARSER = require('body-parser');9const COMPRESSION = require('compression');10const CORS = require('cors');11const EXPRESS_STATUS_MONITOR = require('express-status-monitor');12const EXPRESS_RATE_LIMITER = require('express-rate-limit');13const HELMET = require('helmet');14const HPP = require('hpp');15const MONGO_SANITIZE = require('express-mongo-sanitize');16const XSS = require('xss-clean');17const APPLICATION = EXPRESS();18/**19 * Custom imports20 */21const DRIVERS = require('./drivers');22const ROUTES = require('./routes')(); // Imported with all Routers23const CONTROLLERS = require('./controllers')(); // Imported with all controllers24const API_VERSION = require('./configs').getConfig().apiVersion;25const { PRIVATE_ROUTES, ACTIVITY_LOGS } = require('./middlewares');26class ExpressApplication {27 async init() {28 await this.initDrivers();29 this.initExpress();30 this.initControllers();31 this.initRoutes();32 }33 // Initialize Drivers34 async initDrivers() {35 try {36 const CONNECTION = DRIVERS.open;37 const DRIVER_KEYS = Object.keys(CONNECTION);38 for (let i = 0; i < DRIVER_KEYS.length; i++) {39 // eslint-disable-next-line security/detect-object-injection40 await CONNECTION[DRIVER_KEYS[i]].createConnection();41 }42 global.logger.info(`Drivers initialized | ${global.env.toUpperCase()}`);43 return Promise.resolve();44 } catch (error) {45 global.logger.error(error);46 global.logger.error(`Drivers initialize failed | ${global.env.toUpperCase()}`);47 return Promise.reject();48 }49 }50 // Initialize Express Handlers51 initExpress() {52 // Set security HTTP headers53 APPLICATION.use(HELMET());54 // Limit request from same IP55 APPLICATION.use(56 '/',57 EXPRESS_RATE_LIMITER({58 max: 500,59 windowMs: 60 * 60 * 1000,60 message: 'Too many request from this IP, IP blocked please try later'61 })62 );63 // Express realtime server monitor64 APPLICATION.use(EXPRESS_STATUS_MONITOR()); // Check realtime server metrics for Express based node servers use ip/status65 // Payload compresser66 APPLICATION.use(COMPRESSION());67 // Cross origin controller68 APPLICATION.use(CORS());69 // Body parser70 APPLICATION.use(BODY_PARSER.json({ limit: '2MB' })); // supports upto 2MB JSON encoded payloads71 APPLICATION.use(72 BODY_PARSER.urlencoded({73 extended: true74 })75 );76 // Data sanitization against mongo query injection77 APPLICATION.use(MONGO_SANITIZE());78 // Data sanitization against XSS79 APPLICATION.use(XSS());80 // Prevent parameter pollution81 APPLICATION.use(HPP());82 // API activity log83 APPLICATION.use(ACTIVITY_LOGS);84 global.logger.info(`Express handlers initialized | ${global.env.toUpperCase()}`);85 }86 // Initialize Express Controllers87 initControllers() {88 CONTROLLERS.forEach(controller => {89 const EXPRESS_CONTROLLER = `${controller.constructor.name[0].toLowerCase()}${controller.constructor.name.slice(1)}`;90 // eslint-disable-next-line security/detect-object-injection91 this[EXPRESS_CONTROLLER] = controller;92 });93 global.logger.info(`Controllers initialized | ${global.env.toUpperCase()}`);94 }95 // Initialize Express Routes96 initRoutes() {97 // Public Routes98 ROUTES.forEach(route => {99 if (route.getMode() === 'public') APPLICATION.use(`${API_VERSION}${route.getRoutes()}`, route.getRouter());100 });101 // Private Routes Authorization Middleware102 APPLICATION.use(PRIVATE_ROUTES);103 // Private Routes104 ROUTES.forEach(route => {105 if (route.getMode() === 'private') APPLICATION.use(`${API_VERSION}${route.getRoutes()}`, route.getRouter());106 });107 // Static file Routes108 APPLICATION.use('/static', EXPRESS.static(`${__dirname}/public`, { maxAge: '28 days' }));109 // Undefined Routes Handler110 APPLICATION.use('*', (req, res, err) => {111 if (err) {112 res.status(404).json({113 code: 404,114 msg: `Cannot find ${req.originalUrl} Please try again!!!`115 });116 res.end();117 }118 });119 global.logger.info(`Routes initialized | ${global.env.toUpperCase()}`);120 }121 // Driver close handler122 closeDrivers() {123 try {124 const CONNECTION = DRIVERS.close;125 const DRIVER_KEYS = Object.keys(CONNECTION);126 DRIVER_KEYS.forEach(key => {127 // eslint-disable-next-line security/detect-object-injection128 CONNECTION[key].closeConnection();129 });130 } catch (error) {131 global.logger.error(error);132 global.logger.error(`Drivers termination failed | ${global.env.toUpperCase()}`);133 }134 }135}136module.exports = {137 ExpressApplication,138 APPLICATION...
DeviceDescriptor.js
Source:DeviceDescriptor.js
1"use strict";2const drivers = require("./drivers");3const EventEmitter = require("events");4const HID = require("node-hid");5const ListeningDevice = require("./ListeningDevice.js");6const robot = require("robotjs");7const utils = require("./utils");8module.exports = DeviceDescriptor;9let hidListener = null;10let keyMappings = {};11let state = {keys: {}};12function DeviceDescriptor (driverName) {13 this.driverName = driverName;14 this.driver = drivers[this.driverName];15 this.emitter = new EventEmitter(); // this.emitter is deprecated16 this.name = this.driver.PRODUCT_NAME||this.driver.PRODUCT_ID;17 this.vendor = this.driver.VENDOR_NAME||this.driver.VENDOR_ID;18 for (let keyName in this.driver.KEYS) {19 state.keys[keyName] = this.driver.KEYS[keyName].defaultValue;20 }21}22DeviceDescriptor.prototype.getInputs = function(){23 const driver = drivers[this.driverName];24 let inputs = {};25 for (let key in driver.KEYS) {26 inputs[key] = {27 label: driver.KEYS[key].label,28 type: driver.KEYS[key].type,29 defaultValue: driver.KEYS[key].defaultValue,30 valueRange: driver.KEYS[key].valueRange,31 };32 }33 return inputs;34};35DeviceDescriptor.prototype.listen = function(){36 return new Promise((resolve, reject) => {37 try {38 hidListener = new HID.HID(this.driver.VENDOR_ID, this.driver.PRODUCT_ID);39 const listeningDevice = new ListeningDevice(hidListener, this.driverName, this.emitter);40 hidListener.on("data", onData.bind(onData, this.driverName, this.emitter));41 hidListener.on("error", () => {42 this.emitter.emit("disconnect",`Device '${this.name}' disconnected.`);43 listeningDevice.stop();44 hidListener = null;45 });46 resolve(listeningDevice);47 } catch (err) {48 reject(`Device '${this.name}' by '${this.vendor}' not found.`);49 }50 });51};52DeviceDescriptor.prototype.map = function(deviceInputName, keyboardKeyName) {53 keyMappings[deviceInputName] = keyboardKeyName;54};55function onData (driverName, emitter, rawData) {56 const driver = drivers[driverName];57 const parsedData = driver.parseData(rawData);58 // BEGIN Deprecated. Remove by 1.0.0 release59 emitter.emit("data", parsedData);60 // END Deprecated61 let eventData = parseDeviceEventData(parsedData);62 if (Object.keys(keyMappings).length) {63 for (let deviceInputName in keyMappings) {64 let keyboardKeyName = keyMappings[deviceInputName];65 if (eventData[`up.${deviceInputName}`]) {66 logDataEvent("up", deviceInputName, keyboardKeyName);67 robot.keyToggle(keyboardKeyName, "up");68 } else if (eventData[`down.${deviceInputName}`]) {69 logDataEvent(" down", deviceInputName, keyboardKeyName);70 robot.keyToggle(keyboardKeyName, "down");71 }72 }73 }74}75function logDataEvent (dir, deviceInputName, keyboardKeyName) {76 if (utils.getConfig().debug) {77 console.log(`${utils.getFormattedUtcTime()} ${utils.rightPadSpaces(deviceInputName, 15)}${utils.rightPadSpaces(dir, 15)}${keyboardKeyName}`);78 }79}80function parseDeviceEventData (parsedData) {81 let output = {};82 for (let inputName in parsedData) {83 let inputEvent = parsedData[inputName];84 if (inputEvent.digital != state.keys[inputName]) {85 if (inputEvent.digital) {86 output[`down.${inputName}`] = inputEvent;87 } else {88 output[`up.${inputName}`] = inputEvent;89 }90 output[inputName] = inputEvent;91 state.keys[inputName] = inputEvent.digital;92 }93 }94 return output;...
sendKeys.js
Source:sendKeys.js
...25 this.helpers.assertArgument(value);26 var valArray = [];27 if (Array.isArray(value)) { // array28 // `instanceof Array` behaves strange when executed through vm.runInNewContext,29 // it returns false for arrays and `driver.keys()` tests for arrays using `instaceof Array`30 // thus we recreate the array.31 // https://github.com/felixge/node-sandboxed-module/issues/13#issuecomment-29958521332 for (var val of value) {33 valArray.push(val);34 }35 await this.driver.keys(valArray);36 return;37 } else { // string38 await this.driver.keys(value);39 }...
addDriver.js
Source:addDriver.js
1$(document).ready(function(){2 var TABLE_STR = ''3 + '<tr>'4 + '<td><input type="text" class="form-control"></td>'5 + '<td><input type="text" class="form-control"></td>'6 + '<td><button class="btn btn-xs table-remove-btn" type="button"><span class="glyphicon glyphicon-remove"></span></button></td>'7 + '</tr>';8 $('table').delegate('.table-add-btn', 'click', function(){9 $(this).parent().parent().parent().parent().children('tbody').append(TABLE_STR);10 });11 $('table').delegate('.table-remove-btn', 'click', function(){12 $(this).parent().parent().remove();13 });14 $('#submit-driver-add-btn').click(function(){15 set_driver_keys_value();16 var url = document.getElementById('driver-add-form').action;17 $.post(url, $('#driver-add-form').serialize(), function(data){18 data = eval(data);19 if(data[0] === 0){20 window.location.href = '/driver/'+data[1];21 }else{22 alert('Add driver failed!!!/nError Info:'+data[1]);23 return false;24 }25 });26 });27});28function set_driver_keys_value(){29 var params_tr_list = $('#driver-params-table').children('tbody').find('tr');30 var params = {};31 for(var i = 0; i < params_tr_list.length; i++){32 var input_list = $(params_tr_list[i]).find('input');33 var key = $(input_list[0]).val();34 var value = $(input_list[1]).val();35 params[key] = value;36 }37 $('#driver-keys-add').val(JSON.stringify(params));...
memberSignupFacebook.js
Source:memberSignupFacebook.js
1module.exports = {2 'Signing up via Facebook' : function(driver)3 {4 driver5 .url(driver.globals.userNames.memberURL)6 .windowMaximize("current")7 .waitForElementVisible('body', 2000)8 .useXpath()9 .click("(//a[contains(text(), 'Create Account')])[2]")10 .pause(1000)11 .click("//div[@class='desktop-container ng-scope']/div/div[1]/a[2]/div")12 .pause(1000)13 .click("//input[@id='email']")14 .clearValue("//input[@id='email']")15 .pause(2000)16 .setValue("//input[@id='email']", driver.globals.userNames.facebookEmail)17 .click("//input[@id='pass']")18 .clearValue("//input[@id='pass']")19 .pause(2000)20 .setValue("//input[@id='pass']", driver.globals.userNames.facebookPass)21 .pause(2000)22 .click("//button[@value='1']")23 .pause(4000)24 .keys(driver.Keys.ENTER)25 .pause(2000)26 .keys(driver.Keys.ENTER)27 .pause(2000)28 .keys(driver.Keys.ENTER)29 .pause(4000)30 .click("(//form[@id='edit_member'])[6]/div[2]/input")31 .pause(1000)32 .setValue("(//form[@id='edit_member'])[6]/div[5]/input", driver.globals.userNames.zipCode)33 .pause(1000)34 .click("(//button[@class='btn login themed-button'])[6]")35 .pause(4000)36 .saveScreenshot('screenshots/sprint'+driver.globals.userNames.sprint+'/registrationSignupSuccessfulViaFacebook.png')37 .pause(2000)38 }...
functions_9.js
Source:functions_9.js
1var searchData=2[3 ['keys',['Keys',['../classgranada_1_1cache_1_1_redis_cache_driver.html#a6f7868d6b986b81a348f4f21c4236ef1',1,'granada::cache::RedisCacheDriver::Keys()'],['../classgranada_1_1cache_1_1_shared_map_cache_driver.html#acc64ef3ec5ce6dffe8c0247fc65b2520',1,'granada::cache::SharedMapCacheDriver::Keys()']]]...
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5const expect = chai.expect;6const should = chai.should();7chai.use(chaiAsPromised);8const caps = {9};10describe('Test Appium XCUITest Driver', function() {11 this.timeout(300000);12 before(async () => {13 await driver.init(caps);14 await driver.sleep(2000);15 });16 after(async () => {17 await driver.quit();18 });19 it('should send keys to text field', async () => {20 const searchField = await driver.elementByAccessibilityId('SearchField');21 await searchField.sendKeys('Hello World');22 await driver.sleep(3000);23 });24});
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5chai.use(chaiAsPromised);6const desiredCaps = {7};8driver.init(desiredCaps).then(function () {9 return driver.keys('abc');10}).then(function() {11 return driver.quit();12}).catch(function (err) {13 console.log(err);14});
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5chai.use(chaiAsPromised);6const desired = {7};8const driver = wd.promiseChainRemote('localhost', 4723);9driver.init(desired).then(() => {10 return driver.elementByAccessibilityId('TextFields');11}).then((el) => {12 return el.click();13}).then(() => {14 return driver.elementByClassName('XCUIElementTypeTextField');15}).then((el) => {16 return el.sendKeys('Hello World!');17}).then(() => {18 return driver.quit();19}).done();20{21 "scripts": {22 },23 "dependencies": {24 }25}26at getResponseForW3CError (/Users/xxx/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:802:9)27at asyncHandler (/Users/xxx/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:316:37)28at Layer.handle [as handle_request] (/Users/xxx/node_modules/express/lib/router/layer.js:95:5)29at next (/Users/xxx/node_modules/express/lib/router/route.js:137:
Using AI Code Generation
1const wd = require('wd');2const assert = require('assert');3const chai = require('chai');4const chaiAsPromised = require('chai-as-promised');5const should = chai.should();6const {execSync} = require('child_process');7chai.use(chaiAsPromised);8const port = 4723;
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var caps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6driver.init(caps)7 .then(function () {8 driver.keys(['command', 'shift', '3']);9 })10 .then(function () {11 })12 .fin(function () { return driver.quit(); })13 .done();14var wd = require('wd');15var assert = require('assert');16var caps = {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!