Best JavaScript code snippet using appium
App.js
Source:App.js
1import React from 'react';2import logo from './logo.svg';3import './App.css';4const DEFAULT_SESSION_TIME = 25; // In minutes5const DEFAULT_BREAK_TIME = 5; // In minutes6const TIME_LIMIT_H = 60; // In minutes7const TIME_LIMIT_L = 1; // In minutes8const BreakControl = (props) => {9 return (10 <div id="break-label">11 <h3>Break Length</h3>12 <button id="break-decrement" onClick={props.decrease} >13 <i class="fa fa-arrow-down fa-fw"></i>14 </button>15 <div id="break-length">{props.time}</div>16 <button id="break-increment" onClick={props.increase} >17 <i class="fa fa-arrow-up fa-fw"></i>18 </button>19 </div>20 );21}22const SessionControl = (props) => {23 return (24 <div id="session-label">25 <h3>Session Length</h3>26 <button id="session-decrement" onClick={props.decrease} >27 <i class="fa fa-arrow-down fa-fw"></i>28 </button>29 <div id="session-length">{props.time}</div>30 <button id="session-increment" onClick={props.increase} >31 <i class="fa fa-arrow-up fa-fw"></i>32 </button>33 </div>34 );35}36const TimerDisplay = (props) => {37 let minutes = parseInt(props.timeLeft/60).toString();38 let seconds = (props.timeLeft % 60).toString();39 if (minutes.length < 2) {40 minutes = "0"+minutes41 }42 if (seconds.length < 2) {43 seconds = "0"+seconds44 }45 return (46 <div id="timer-label">47 <h3>{props.mode}</h3>48 <h3 id="time-left">{minutes+":"+seconds}</h3>49 </div>50 );51}52const TimerControl = (props) => {53 return (54 <div id="timer-control">55 <button 56 id="start_stop"57 onClick={props.playControl}>58 <i class="fa fa-power-off fa-2x" />59 </button>60 <button id="reset" onClick={props.resetTime} >61 <i class="fas fa-redo fa-2x" />62 </button>63 </div>64 );65}66class App extends React.Component {67 constructor(props) {68 super(props);69 this.state = {70 breakTime: 3,71 time: 1500, // Unit of seconds72 initBreak: DEFAULT_BREAK_TIME, // Unit of minutes73 initSession: DEFAULT_SESSION_TIME, // Unit of minutes74 mode: "Session",75 timerId: '',76 counting: false77 };78 this.incrementBreak = this.incrementBreak.bind(this);79 this.decrementBreak = this.decrementBreak.bind(this);80 this.incrementSession = this.incrementSession.bind(this);81 this.decrementSession = this.decrementSession.bind(this);82 this.resetTime = this.resetTime.bind(this);83 this.handleCount = this.handleCount.bind(this);84 this.timer = this.timer.bind(this);85 }86 87 incrementBreak() {88 if (!this.state.counting && this.state.initBreak < TIME_LIMIT_H) {89 this.setState({90 initBreak: this.state.initBreak+191 });92 if (this.state.mode === "Break") {93 this.setState({94 time: (this.state.initBreak+1)*6095 });96 }97 }98 }99 100 decrementBreak() {101 if (!this.state.counting && this.state.initBreak > TIME_LIMIT_L) {102 this.setState({103 initBreak: this.state.initBreak-1104 });105 if (this.state.mode === "Break") {106 this.setState({107 time: (this.state.initBreak-1)*60108 });109 }110 }111 }112 113 incrementSession() {114 if (!this.state.counting && this.state.initSession < TIME_LIMIT_H) {115 this.setState({116 initSession: this.state.initSession+1117 });118 if (this.state.mode === "Session") {119 this.setState({120 time: (this.state.initSession+1)*60121 });122 }123 }124 }125 126 decrementSession() {127 if (!this.state.counting && this.state.initSession > TIME_LIMIT_L) {128 this.setState({129 initSession: this.state.initSession-1,130 time: this.state.initSession131 });132 if (this.state.mode === "Session") {133 this.setState({134 time: (this.state.initSession-1)*60135 });136 }137 }138 }139 140 resetTime() {141 const sound = document.getElementById("beep");142 sound.pause();143 sound.currentTime = 0;144 this.setState({145 mode: "Session",146 counting: false,147 time: DEFAULT_SESSION_TIME*60,148 initBreak: DEFAULT_BREAK_TIME,149 initSession: DEFAULT_SESSION_TIME150 });151 if (this.state.timerId) {152 clearInterval(this.state.timerId);153 }154 }155 156 handleCount() {157 if (!this.state.counting) {158 console.log("start/resume timer");159 this.timer();160 this.setState({161 counting: ~this.state.counting162 });163 } else {164 console.log("stop timer");165 if (this.state.timerId) {166 clearInterval(this.state.timerId);167 }168 this.setState({169 counting: ~this.state.counting170 });171 }172 }173 174 timer() {175 if (this.state.mode === "Session") {176 let currentTimer = setInterval(() => {177 if (this.state.time > 0) {178 this.setState({179 time: this.state.time-1180 });181 } else {182 this.setState({183 mode: "Break",184 time: this.state.initBreak*60185 });186 let sound = document.getElementById("beep");187 sound.play();188 clearInterval(this.state.timerId);189 this.timer();190 }191 }, 1000);192 this.setState({193 timerId: currentTimer194 });195 } else {196 let currentTimer = setInterval(() => {197 if (this.state.time > 0) {198 this.setState({199 time: this.state.time-1200 });201 } else {202 clearInterval(this.state.timerId);203 this.setState({204 mode: "Session",205 time: this.state.initSession*60206 });207 let sound = document.getElementById("beep");208 sound.play();209 this.timer();210 }211 }, 1000);212 this.setState({213 timerId: currentTimer214 });215 }216 }217 218 render() {219 return (220 <div id="container">221 <div id="main-title">25+5 Clock</div>222 <BreakControl time={this.state.initBreak} increase={this.incrementBreak} decrease={this.decrementBreak} />223 <SessionControl time={this.state.initSession} increase={this.incrementSession} decrease={this.decrementSession} />224 <TimerDisplay timeLeft={this.state.time} mode={this.state.mode} />225 <TimerControl playControl={this.handleCount} resetTime={this.resetTime} />226 <audio id="beep" preload="auto" src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/audio/BeepSound.wav"></audio>227 </div>228 );229 }230}...
Principal.js
Source:Principal.js
...46 47 };48 const handleLogout = function (){49 axios.get('/login/endSession').then(()=>{50 initSession();51 //console.log(logged);52 }); 53 };54 useEffect(()=>{55 initSession();56 },[]);57 //<h1>hola {online?'online':'offline'}</h1>58 return (59 60 <div>61 62 63 {!logged? 64 <Router>65 <Switch>66 <Route exact path = "/register" >67 <Registro initSession = {initSession}/>68 </Route>69 <Route>...
index.js
Source:index.js
...5 url = null;6 qq = null;7 verifyKey = null;8 session = null;9 initSession({url, verifyKey, qq = null}) {10 return fetch(`${url}/verify`, {11 method: "POST",12 body: JSON.stringify({verifyKey: verifyKey}),13 headers: {14 "Content-Type": "application/json"15 }16 })17 .then(head => head.json())18 .then(res => {19 if (res.code === 0) {20 this.url = url;21 this.verifyKey = verifyKey;22 this.session = res.session;23 if (qq && !qq /*qq*/) { // TODO Miraiæ°çæ¬ä¸æ¯æç»å®QQ24 this.qq = qq;25 return fetch(`${url}/bind`, {26 method: "POST",27 body: JSON.stringify({28 verifyKey: verifyKey,29 qq: qq30 }),31 headers: {32 "Content-Type": "application/json"33 }34 })35 .then(head => head.json())36 .then(res => {37 if (res.code === 0) {38 log("Seele.Session.initSession", "è¿æ¥Miraiæå");39 log("Seele.Session.initSession", `session:${res.session}`)40 return true;41 } else {42 error("Seele.Session.initSession", "Miraiç»å®QQ失败");43 return this.unbindSession().then(res => {44 throw new Error("Miraiç»å®QQ失败\n" + JSON.stringify(res));45 });46 }47 })48 .catch(e => {49 error("Seele.Session.initSession", "Miraiè¿æ¥å¤±è´¥");50 console.error(e);51 throw new Error("Miraiè¿æ¥å¤±è´¥");52 })53 } else {54 log("Seele.Session.initSession", "è¿æ¥Miraiæå");55 log("Seele.Session.initSession", `session:${res.session}`)56 return true;57 }58 } else {59 error("Seele.Session.initSession", "Mirai认è¯å¤±è´¥");60 throw new Error("Mirai认è¯å¤±è´¥");61 }62 })63 .catch(e => {64 error("Seele.Session.initSession", "Miraiè¿æ¥å¤±è´¥");65 console.error(e);66 throw new Error("Miraiè¿æ¥å¤±è´¥");67 })68 }69 async updateSession() {70 if (this.url && this.verifyKey) {71 await this.initSession({url: this.url, verifyKey: this.verifyKey, qq: this.qq});72 } else {73 error("Seele.Session.updateSession", "请å
åå§åsession");74 throw new Error("请å
åå§åsession");75 }76 }77 unbindSession() {78 if (this.url && this.session) {79 if (this.qq) {80 return fetch(`${this.url}/release`, {81 method: "POST",82 body: JSON.stringify({sessionKey: this.session, qq: this.qq}),83 headers: {84 "Content-Type": "application/json"85 }...
unit-test-min.spec.js
Source:unit-test-min.spec.js
...41 chai.expect(event.numEventsTotal).to.be.equal(eventCount);42 chai.expect(event.events).to.eql(expectedEvent);43 }44 it('should getCurrentAnalyticsEvent succeed after init', function () {45 initSession("unitTestAcc1", "core-analytics-client-lib");46 const event = getCurrentAnalyticsEvent();47 _validateCurrentEvent(event);48 });49 it('should fail analyticsEvent on invalid arguments', function () {50 initSession("unitTestAcc1", "core-analytics-client-lib");51 chai.expect(analyticsEvent).to.throw();52 chai.expect(()=>analyticsEvent('ev1', 'cat1', 'sub1', -1)).to.throw();53 chai.expect(()=>analyticsEvent('ev1', 'cat1', 'sub1', "10")).to.throw();54 chai.expect(()=>analyticsEvent('ev1', 'cat1', 'sub1', 1, "1"))55 .to.throw();56 });57 it('should analyticsEvent api succeed', async function () {58 initSession("unitTestAcc1", "core-analytics-client-lib", 10, .1);59 analyticsEvent('ev1', 'cat1', 'sub1');60 analyticsEvent('ev1', 'cat2', 'sub1', 5);61 await sleep(200);62 analyticsEvent('ev1', 'cat2', 'sub1', 2);63 const event = getCurrentAnalyticsEvent();64 _validateCurrentEvent(event, 3, {65 "ev1": {66 "cat1": {67 "sub1": {68 "time": [0],69 "valueCount": [1]70 }71 },72 "cat2": {73 "sub1": {74 "time": [0, 0.2],75 "valueCount": [5, 2]76 }77 }78 }79 }, .1);80 });81 it('should analyticsEvent api succeed if count and value is given subsequently', async function () {82 initSession("unitTestAcc1", "core-analytics-client-lib", 10, .1);83 analyticsEvent('ev1', 'cat1', 'sub1');84 analyticsEvent('ev1', 'cat2', 'sub1', 5);85 analyticsEvent('ev1', 'cat2', 'sub1', 5, 1);86 analyticsEvent('ev1', 'cat2', 'sub1', 2, 1);87 await sleep(200);88 analyticsEvent('ev1', 'cat2', 'sub1', 2);89 const event = getCurrentAnalyticsEvent();90 _validateCurrentEvent(event, 5, {91 "ev1": {92 "cat1": {93 "sub1": {94 "time": [0.2],95 "valueCount": [1]96 }...
unit-test.spec.js
Source:unit-test.spec.js
...41 chai.expect(event.numEventsTotal).to.be.equal(eventCount);42 chai.expect(event.events).to.eql(expectedEvent);43 }44 it('should getCurrentAnalyticsEvent succeed after init', function () {45 initSession("unitTestAcc1", "core-analytics-client-lib");46 const event = getCurrentAnalyticsEvent();47 _validateCurrentEvent(event);48 });49 it('should fail analyticsEvent on invalid arguments', function () {50 initSession("unitTestAcc1", "core-analytics-client-lib");51 chai.expect(analyticsEvent).to.throw();52 chai.expect(()=>analyticsEvent('ev1', 'cat1', 'sub1', -1)).to.throw();53 chai.expect(()=>analyticsEvent('ev1', 'cat1', 'sub1', "10")).to.throw();54 chai.expect(()=>analyticsEvent('ev1', 'cat1', 'sub1', 1, "1"))55 .to.throw();56 });57 it('should analyticsEvent api succeed', async function () {58 initSession("unitTestAcc1", "core-analytics-client-lib", 10, .1);59 analyticsEvent('ev1', 'cat1', 'sub1');60 analyticsEvent('ev1', 'cat2', 'sub1', 5);61 await sleep(200);62 analyticsEvent('ev1', 'cat2', 'sub1', 2);63 const event = getCurrentAnalyticsEvent();64 _validateCurrentEvent(event, 3, {65 "ev1": {66 "cat1": {67 "sub1": {68 "time": [0],69 "valueCount": [1]70 }71 },72 "cat2": {73 "sub1": {74 "time": [0, 0.2],75 "valueCount": [5, 2]76 }77 }78 }79 }, .1);80 });81 it('should analyticsEvent api succeed if count and value is given subsequently', async function () {82 initSession("unitTestAcc1", "core-analytics-client-lib", 10, .1);83 analyticsEvent('ev1', 'cat1', 'sub1');84 analyticsEvent('ev1', 'cat2', 'sub1', 5);85 analyticsEvent('ev1', 'cat2', 'sub1', 5, 1);86 analyticsEvent('ev1', 'cat2', 'sub1', 2, 1);87 await sleep(200);88 analyticsEvent('ev1', 'cat2', 'sub1', 2);89 const event = getCurrentAnalyticsEvent();90 _validateCurrentEvent(event, 5, {91 "ev1": {92 "cat1": {93 "sub1": {94 "time": [0.2],95 "valueCount": [1]96 }...
routes.js
Source:routes.js
1const cookieParser = require('cookie-parser');2const bodyParser = require('body-parser');3const express = require('express');4const BaseController = require('../controllers/BaseController');5const UserController = require('../controllers/UserController');6const TeamController = require('../controllers/TeamController');7const TaskController = require('../controllers/TaskController');8const TokenController = require('../controllers/TokenController');9module.exports = function(app) {10 app.use(cookieParser());11 //app.use(bodyParser());12 app.use(express.urlencoded({extended: true}));13 app.use(express.json())14 app.post('/api/user/register',BaseController.InitSession,UserController.UserRegister,BaseController.EndSession);15 app.post('/api/user/login', BaseController.InitSession, UserController.UserLogin, BaseController.EndSession);16 app.get('/api/user/logout',UserController.UserLogout); 17 app.delete('/api/user/deleteUser', BaseController.InitSession, UserController.deleteUser, BaseController.EndSession);18 app.get('/api/user/listUser', BaseController.InitSession, UserController.getAllUser, BaseController.EndSession);19 20 app.post('/api/team/addTeam',TokenController.tokenControl, BaseController.InitSession, TeamController.AddTeams, BaseController.EndSession);21 app.post('/api/team/deleteMember/:team_id',TokenController.tokenControl, BaseController.InitSession, TeamController.DeleteMember, BaseController.EndSession);22 app.get('/api/team/listTeam',TokenController.tokenControl, BaseController.InitSession, TeamController.ListTeam, BaseController.EndSession);23 app.post('/api/task/addTask',TokenController.tokenControl, BaseController.InitSession,TaskController.AddTask, BaseController.EndSession);24 app.get('/api/task/ListTask',TokenController.tokenControl, BaseController.InitSession,TaskController.ListTask, BaseController.EndSession);25 app.post('/api/task/updateTask/:task_id',TokenController.tokenControl, BaseController.InitSession, TaskController.UpdateTask, BaseController.EndSession);26 app.delete('/api/task/deleteTask/:task_id',TokenController.tokenControl, BaseController.InitSession, TaskController.DeleteTask, BaseController.EndSession);27 app.post('/api/task/checkedTask/:task_id',TokenController.tokenControl, BaseController.InitSession, TaskController.CheckedTask, BaseController.EndSession);28 app.get('/api/task/userTaskFilter',BaseController.InitSession, TaskController.UserTaskFilter, BaseController.EndSession);29 app.get('/tokenControl', TokenController.tokenControl);30 var errorHandler = function(err, req, res, next) {31 if (res.locals.connection) {32 res.locals.connection.release();33 }34 res.json({35 data: null,36 error: err37 });38 };39 app.use(errorHandler);...
clientparser.js
Source:clientparser.js
1var hexdump = require('hexdump-nodejs'),2 util = require('util'),3 Reader = require('../reader'),4 SetTarget = require('./settarget'),5 VariableHeader = require('../variableheader'),6 SendNick = require('./sendnick'),7 Split = require('./split'),8 InitSession = require('./initsession'),9 EventEmitter = require('events').EventEmitter;10var ClientParser = function() {};11ClientParser.prototype.parse = function(message)12{13 try14 {15 var reader = new Reader(message);16 //console.log("client");17 //console.log(hexdump(message));18 var header = new VariableHeader(reader, true);19 if (header.messageType)20 {21 switch (header.messageType)22 {23 case 0x10:24 var setTarget = new SetTarget(reader);25 //console.log(setTarget);26 return setTarget;27 break;28 case 0x11:29 return { type:'shoot' };30 break;31 case 0x21: // ping 32 return { type:'ping' };33 break;34 case 0x31: // geo request?35 // 6 byte payload sent on connection36 // gets GEO IP estimation response37 return false;38 break;39 case 0xFD:40 var sendNick = new SendNick(reader);41 console.log(sendNick);42 return sendNick;43 break;44 case 0xFE:45 var initSession = new InitSession(reader);46 console.log(initSession);47 return initSession;48 49 break;50 case 0x19:51 var split = new Split(reader);52 console.log(split);53 54 return split;55 break;56 default:57 console.log('C: %s unparsed\n' + hexdump(message), header.messageType);58 return false;59 }60 }61 else62 {63 // control packets? 64 return false;65 }66 }67 catch (e)68 {69 console.log('exception: ' + e);70 console.log( e.stack );71 console.log('offending packet');72 console.log(hexdump(message));73 }74 75}...
application.js
Source:application.js
...22 // console.debug('session has been invalidated!');23 // });24 // },25 initSession: function () {26 let p = this.get('session').initSession();27 p.then(28 () => {29 console.debug('initSession resolved');30 },31 // TODO: translations32 () => {33 this.get('messageBox').open({34 type: 'error',35 allowClose: false,36 title: 'Session initialization error',37 message: 'Fatal error: session cannot be initialized'38 });39 }40 );41 return p;42 }.on('init'),43 resetController(controller, isExiting /*, transition*/ ) {44 if (isExiting) {45 controller.resetQueryParams();46 }47 },48 // TODO: initialization of initSession in model causes the application to hang...49 // model() {50 // return this.initSession();51 // },...
Using AI Code Generation
1var wd = require('wd');2var asserters = wd.asserters;3var serverConfig = {4};5var desiredCaps = {6};7var driver = wd.remote(serverConfig);8driver.init(desiredCaps, function() {9 driver.findElement('name', 'button', function(err, el) {10 el.click(function() {11 driver.findElement('name', 'text', function(err, el) {12 el.text(function(err, text) {13 console.log(text);14 driver.quit();15 });16 });17 });18 });19});
Using AI Code Generation
1driver.initSession();2driver.initSession();3driver.initSession();4driver.initSession();5driver.initSession();6driver.initSession();7driver.initSession();8driver.initSession();9driver.initSession();10driver.initSession();11driver.initSession();12driver.initSession();13driver.initSession();14driver.initSession();15driver.initSession();16driver.initSession();17driver.initSession();18driver.initSession();19driver.initSession();20driver.initSession();21driver.initSession();22driver.initSession();23driver.initSession();24driver.initSession();25driver.initSession();26driver.initSession();27driver.initSession();
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6driver.init(desiredCaps).then(function () {7 console.log('App launched successfully!');8 return driver.initSession(desiredCaps);9}).then(function () {10 console.log('App launched successfully!');11 return driver.initSession(desiredCaps);12}).then(function () {13 console.log('App launched successfully!');14}).catch(function (err) {15 console.log('App launch failed!');16 console.log(err);17});18Your name to display (optional):19Your name to display (optional):
Using AI Code Generation
1var wd = require('wd');2var driver = wd.remote("localhost", 4723);3driver.initSession({4}, function() {5 driver.elementById('com.android.calculator2:id/digit_5', function(err, el) {6 el.click();7 driver.elementById('com.android.calculator2:id/op_add', function(err, el) {8 el.click();9 driver.elementById('com.android.calculator2:id/digit_9', function(err, el) {10 el.click();11 driver.elementById('com.android.calculator2:id/eq', function(err, el) {12 el.click();13 driver.elementById('com.android.calculator2:id/formula', function(err, el) {14 el.text(function(err, text) {15 console.log('Result is: ' + text);16 });17 });18 });19 });20 });21 });22});23{24 "dependencies": {25 }26}27set PATH=%PATH%;C:\Program Files\nodejs28set PATH=%PATH%;C:\Users\username\AppData\Roaming\npm29set PATH=%PATH%;C:\Users\username\AppData\Local\Programs\Appium\resources\app\node_modules\appium\build\android_bootstrap30set PATH=%PATH%;C:\Users\username\AppData\Local\Programs\Appium\resources\app\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar31set PATH=%PATH%;C:\Users\username\AppData\Local\Programs\Appium\resources\app\node_modules\appium\build\android_bootstrap\bin32set PATH=%PATH%;C:\Users\username\AppData\Local\Programs\Appium\resources\app\node_modules\appium
Using AI Code Generation
1var AppiumDriver = require('appiumdriver');2var driver = new AppiumDriver();3driver.initSession({4}, function(err, sessionID) {5 if (err) {6 console.log(err);7 } else {8 console.log("Session ID: " + sessionID);9 }10});11var request = require('request');12function AppiumDriver() {13}14AppiumDriver.prototype.initSession = function(desiredCaps, callback) {15 var that = this;16 request.post({17 json: {18 }19 }, function(err, res, body) {20 if (err) {21 callback(err, null);22 } else {23 callback(null, body.sessionId);24 }25 });26};27module.exports = AppiumDriver;
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!!