Best JavaScript code snippet using devicefarmer-stf
ExchangeController.js
Source:ExchangeController.js
1/**2 * ExchangeController3 *4 * @description :: Server-side logic for managing exchanges5 * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers6 */7var http = require('http');8var CryptoJS = require("crypto-js");9var querystring = require('querystring');10var loda = require('lodash');11var key = '5Df8$&@S';12var iv = CryptoJS.enc.Utf8.parse(key);13var key = CryptoJS.enc.Utf8.parse(key);14module.exports = {15 // å
å§ ååæ¥å£16 autologin: function(request, response, callback) {17 GlobalMethods.httpPost(request, response, callback, GlobalVal.apiHost, '/ppmiao-coin/duiba/autologin');18 },19 autologinbg: function(request, response, callback) {20 var data = querystring.stringify({21 token: this.des(request.body.token),22 productId: request.body.productId23 });24 GlobalMethods.httpPost(request, response, callback, GlobalVal.apiHost, '/ppmiao-coin/duiba/autologinbg',data);25 },26 queryForFrontItem: function(request, response, callback) {27 GlobalMethods.httpPost(request, response, callback, GlobalVal.apiHost, '/ppmiao-coin/duiba/queryForFrontItem');28 },29 getUserVipInfo: function(request, response, callback) {30 var data = querystring.stringify({31 token: this.des(request.body.token)32 });33 var options = {34 hostname: 'api.ppmiao.com',35 path: '/user/getUserVipInfo.json',36 method: 'POST',37 agent: false,38 headers: {39 'Content-Type': 'application/x-www-form-urlencoded',40 'Content-Length': data.length,41 }42 };43 let body = '';44 var req = http.request(options, (res) => {45 var responseTimer = setTimeout(function() {46 res.destroy();47 debug('......Response Timeout......');48 }, 5000);49 res.setEncoding('utf8');50 // loda.replace()51 res.on('data', (chunk) => {52 body += chunk;53 }).on('end', (chunk) => {54 clearTimeout(responseTimer);55 if (res.statusCode == 200) {56 let resp = JSON.parse(body); 57 if (resp.isEnc == 'Y') {58 let data = resp.resText;59 data = data.replace(/[\r\n]/g, "");60 var ciphertext = CryptoJS.DES.decrypt(data, key, {61 iv: iv,62 mode: CryptoJS.mode.CBC,63 padding: CryptoJS.pad.Pkcs764 });65 ciphertext = CryptoJS.enc.Utf8.stringify(ciphertext);66 response.send(ciphertext);67 } else {68 response.send(resp.resText);69 }70 }71 });72 });73 req.on('error', function(e) {74 if (callback) {75 callback(e, null);76 }77 console.log('problem with request: ' + e.message);78 });79 req.write(data);80 req.end();81 },82 getExchangeList: function(request, response, callback) {83 var data = querystring.stringify({84 token: this.des(request.body.token)85 });86 var options = {87 hostname: 'api.ppmiao.com',88 path: '/user/getExchangeList.json',89 method: 'POST',90 agent: false,91 headers: {92 'Content-Type': 'application/x-www-form-urlencoded',93 'Content-Length': data.length,94 }95 };96 let body = '';97 var req = http.request(options, (res) => {98 var responseTimer = setTimeout(function() {99 res.destroy();100 debug('......Response Timeout......');101 }, 5000);102 res.setEncoding('utf8');103 res.on('data', (chunk) => {104 body += chunk;105 }).on('end', (chunk) => {106 clearTimeout(responseTimer);107 if (res.statusCode == 200) {108 let resp = JSON.parse(body); 109 if (resp.isEnc == 'Y') {110 let data = resp.resText;111 data = data.replace(/[\r\n]/g, "");112 var ciphertext = CryptoJS.DES.decrypt(data, key, {113 iv: iv,114 mode: CryptoJS.mode.CBC,115 padding: CryptoJS.pad.Pkcs7116 });117 ciphertext = CryptoJS.enc.Utf8.stringify(ciphertext);118 response.send(ciphertext);119 } else {120 response.send(resp.resText);121 }122 }123 });124 });125 req.on('error', function(e) {126 if (callback) {127 callback(e, null);128 }129 console.log('problem with request: ' + e.message);130 });131 req.write(data);132 req.end();133 },134 claimExchange: function(request, response, callback) {135 var data = querystring.stringify({136 token: this.des(request.body.token),137 id: request.body.id138 });139 var options = {140 hostname: 'api.ppmiao.com',141 path: '/user/claimExchange.json',142 method: 'POST',143 agent: false,144 headers: {145 'Content-Type': 'application/x-www-form-urlencoded',146 'Content-Length': data.length,147 }148 };149 let body = '';150 var req = http.request(options, (res) => {151 var responseTimer = setTimeout(function() {152 res.destroy();153 debug('......Response Timeout......');154 }, 5000);155 res.setEncoding('utf8');156 res.on('data', (chunk) => {157 body += chunk;158 }).on('end', (chunk) => {159 clearTimeout(responseTimer);160 if (res.statusCode == 200) {161 let resp = JSON.parse(body); 162 if (resp.isEnc == 'Y') {163 let data = resp.resText;164 data = data.replace(/[\r\n]/g, "");165 var ciphertext = CryptoJS.DES.decrypt(data, key, {166 iv: iv,167 mode: CryptoJS.mode.CBC,168 padding: CryptoJS.pad.Pkcs7169 });170 ciphertext = CryptoJS.enc.Utf8.stringify(ciphertext);171 response.send(ciphertext);172 } else {173 response.send(resp.resText);174 }175 }176 });177 });178 req.on('error', function(e) {179 if (callback) {180 callback(e, null);181 }182 console.log('problem with request: ' + e.message);183 });184 req.write(data);185 req.end();186 },187 getWeeklyAward: function(request, response, callback) {188 var data = querystring.stringify({189 token: this.des(request.body.token)190 });191 var options = {192 hostname: 'api.ppmiao.com',193 path: '/user/getWeeklyAward.json',194 method: 'POST',195 agent: false,196 headers: {197 'Content-Type': 'application/x-www-form-urlencoded',198 'Content-Length': data.length,199 }200 };201 let body = '';202 var req = http.request(options, (res) => {203 var responseTimer = setTimeout(function() {204 res.destroy();205 debug('......Response Timeout......');206 }, 5000);207 res.setEncoding('utf8');208 res.on('data', (chunk) => {209 body += chunk;210 }).on('end', (chunk) => {211 clearTimeout(responseTimer);212 if (res.statusCode == 200) {213 let resp = JSON.parse(body); 214 if (resp.isEnc == 'Y') {215 let data = resp.resText;216 data = data.replace(/[\r\n]/g, "");217 var ciphertext = CryptoJS.DES.decrypt(data, key, {218 iv: iv,219 mode: CryptoJS.mode.CBC,220 padding: CryptoJS.pad.Pkcs7221 });222 ciphertext = CryptoJS.enc.Utf8.stringify(ciphertext);223 response.send(ciphertext);224 } else {225 response.send(resp.resText);226 }227 }228 });229 });230 req.on('error', function(e) {231 if (callback) {232 callback(e, null);233 }234 console.log('problem with request ' + e.message);235 });236 req.write(data);237 req.end();238 },239 claimWeeklyAward: function(request, response, callback) {240 var data = querystring.stringify({241 token: this.des(request.body.token),242 id: request.body.id243 });244 var options = {245 hostname: 'api.ppmiao.com',246 path: '/user/claimWeeklyAward.json',247 method: 'POST',248 agent: false,249 headers: {250 'Content-Type': 'application/x-www-form-urlencoded',251 'Content-Length': data.length,252 }253 };254 let body = '';255 var req = http.request(options, (res) => {256 var responseTimer = setTimeout(function() {257 res.destroy();258 debug('......Response Timeout......');259 }, 5000);260 res.setEncoding('utf8');261 res.on('data', (chunk) => {262 body += chunk;263 }).on('end', (chunk) => {264 clearTimeout(responseTimer);265 if (res.statusCode == 200) {266 let resp = JSON.parse(body); 267 if (resp.isEnc == 'Y') {268 let data = resp.resText;269 data = data.replace(/[\r\n]/g, "");270 var ciphertext = CryptoJS.DES.decrypt(data, key, {271 iv: iv,272 mode: CryptoJS.mode.CBC,273 padding: CryptoJS.pad.Pkcs7274 });275 ciphertext = CryptoJS.enc.Utf8.stringify(ciphertext);276 response.send(ciphertext);277 } else {278 response.send(resp.resText);279 }280 }281 });282 });283 req.on('error', function(e) {284 if (callback) {285 callback(e, null);286 }287 console.log('problem with request: ' + e.message);288 });289 req.write(data);290 req.end();291 },292 des: function(token) {293 var key = '5Df8$&@S';294 var iv = CryptoJS.enc.Utf8.parse(key);295 var key = CryptoJS.enc.Utf8.parse(key);296 var decrypted = CryptoJS.TripleDES.decrypt(token, key, {297 iv: iv,298 mode: CryptoJS.mode.CBC,299 padding: CryptoJS.pad.Pkcs7300 });301 // 转æ¢ä¸º utf8 å符串302 decrypted = CryptoJS.enc.Utf8.stringify(decrypted);303 return decrypted;304 }...
index.js
Source:index.js
1import axios from "axios";2import originJsonp from "jsonp";3import { BASIC } from "./config";4import { message } from "antd";5import NProgress from "nprogress";6import "nprogress/nprogress.css";7import Cookies from "js-cookie";8import { ENTRANCE_MODE_IFRAME } from "../globalSet/config";9const instance = axios.create({10 method: "GET",11 baseURL: BASIC.API_URL12});13NProgress.inc(0.3);14NProgress.configure({ easing: "ease", speed: 500, showSpinner: false });15let requestTimer = null,16 responseTimer = null;17instance.interceptors.request.use(config => {18 let token = Cookies.get("Authorization");19 if (token) {20 config.headers["Authorization"] = token;21 NProgress.start();22 } else {23 clearTimeout(requestTimer);24 if (BASIC.getUrlParam.isMobile === "1") return {};25 requestTimer = setTimeout(() => {26 // message.error("缺å°æéï¼æ æ³è¯ç¨å°å¾");27 if (!ENTRANCE_MODE_IFRAME) {28 redirectToLogin();29 }30 }, 1000);31 return {};32 }33 return config;34});35instance.interceptors.response.use(36 config => {37 let { data } = config;38 NProgress.done();39 if (data.code === BASIC.TOKEN_AUTH_ERROR) {40 clearTimeout(responseTimer);41 if (BASIC.getUrlParam.isMobile === "1") return {};42 responseTimer = setTimeout(() => {43 message.error("æéä¸è¶³ï¼è¯·éæ°ç»å½");44 // è°ç¨çµç45 try {46 if (window.parent) {47 window.parent.postMessage("token_invalid", "*");48 }49 } catch (err) {50 console.log(err);51 }52 }, 1000);53 return config;54 } else return config;55 },56 err => {57 NProgress.done();58 if (err && err.response) {59 if (err.response.status === BASIC.SERVER_ERROR) {60 clearTimeout(responseTimer);61 if (BASIC.getUrlParam.isMobile === "1") return {};62 responseTimer = setTimeout(() => {63 message.error("ç³»ç»ç¹å¿,请ç¨ååè¯");64 }, 1000);65 }66 // eslint-disable-next-line eqeqeq67 if (err.response.status == BASIC.TOKEN_AUTH_ERROR) {68 clearTimeout(responseTimer);69 if (BASIC.getUrlParam.isMobile === "1") return {};70 responseTimer = setTimeout(() => {71 message.error("æéä¸è¶³ï¼è¯·éæ°ç»å½");72 if (!ENTRANCE_MODE_IFRAME) {73 //å¦ææ¯ç¬ç«åºç¨å
¥å£74 redirectToLogin();75 } else {76 let url = "";77 try {78 url = window.top.document.referrer;79 } catch (M) {80 if (window.parent) {81 try {82 url = window.parent.document.referrer;83 } catch (L) {84 url = "";85 }86 }87 }88 if (url === "") {89 url = document.referrer;90 }91 window.parent.location.href =92 url ||93 "https://lingxi.di-an.com/" +94 "#/login?redirect=/technological/simplemode/home";95 }96 }, 1000);97 }98 return err.response;99 }100 return err && err.response;101 }102);103//éå®åè·¯ç±104export function redirectToLogin() {105 const { origin, hash } = window.location;106 const hashname = !!hash ? hash.replace("#", "") : hash;107 window.location.href = `${origin}/#/login?redirect=${hashname}`;108}109// å
¬ç¨çajax请æ±æ¹æ³ã110let request = (method, url, data, header) => {111 let obj = {};112 method === "GET" ? (obj.params = data) : (obj.data = data);113 return instance({114 method,115 url,116 ...obj,117 headers: {118 ...header119 }120 });121};122const strParam = data => {123 let url = "";124 for (var k in data) {125 let value = data[k] !== undefined ? data[k] : "";126 url += "&" + k + "=" + encodeURIComponent(value);127 }128 return url ? url.substring(1) : "";129};130// geoserver wfsæå¡è·åæ¹æ³131const getFeature = (url, options) => {132 const myOptions = {133 service: "WFS",134 version: "1.0.0",135 request: "GetFeature",136 outputFormat: "text/javascript",137 format_options: "callback:cb"138 };139 const myUrl =140 url +141 (url.indexOf("?") < 0 ? "?" : "&") +142 strParam({ ...myOptions, ...options });143 const opts = {144 param: "callback",145 name: "cb"146 };147 return new Promise((resolve, reject) => {148 originJsonp(myUrl, opts, (err, data) => {149 if (!err) {150 resolve(data);151 } else {152 reject(err);153 }154 });155 });156};...
responseTimer.js
Source:responseTimer.js
1var expect = require("chai").expect;2var ResponseTimer = require('./../../src/models/responseTimer');3describe('responseTimer', function(){4 describe('constructor', function(){5 it('it sets the startingtime', function(){6 var timer = new ResponseTimer(getDate());7 expect(timer.start).to.equal(10);8 });9 it('sets the default time', function(){10 var timer = new ResponseTimer();11 expect(timer.start).not.to.equal(null);12 })13 });14 describe('setConnection',function(){15 it('can set connectionTime', function (){16 var timer = new ResponseTimer(getDate(10));17 timer.setConnection(getDate(20));18 expect(timer.connection).to.equal(20)19 });20 it('sets the default time', function(){21 var timer = new ResponseTimer();22 timer.setConnection();23 expect(timer.connection).not.to.equal(null);24 })25 })26 describe('setDocuments',function(){27 it('can set documentTime', function (){28 var timer = new ResponseTimer(getDate(10));29 timer.setDocuments(getDate(20));30 expect(timer.documents).to.equal(20)31 });32 it('sets the default time', function(){33 var timer = new ResponseTimer();34 timer.setDocuments();35 expect(timer.documents).not.to.equal(null);36 })37 })38 describe('setResponse',function(){39 it('can set responseTime', function (){40 var timer = new ResponseTimer(getDate(10));41 timer.setResponse(getDate(20));42 expect(timer.response).to.equal(20)43 });44 it('sets the response time', function(){45 var timer = new ResponseTimer();46 timer.setResponse();47 expect(timer.response).not.to.equal(null);48 })49 })50 describe('connectTime',function(){51 it('can calculate connectionTime', function (){52 var timer = new ResponseTimer(getDate(10));53 timer.setConnection(getDate(20));54 expect(timer.connectTime).to.equal(10)55 });56 })57 describe('documentTime',function(){58 it('can calculate documenTime', function (){59 var timer = new ResponseTimer(getDate(10));60 timer.setDocuments(getDate(20));61 expect(timer.documentTime).to.equal(10);62 });63 })64 describe('responseTime',function(){65 it('can calculate responseTime', function (){66 var timer = new ResponseTimer(getDate(10));67 timer.setResponse(getDate(20));68 expect(timer.responseTime).to.equal(10)69 });70 })71});72function getDate(delay = 10){73 var date = new Date();74 date.setTime(delay);75 return date;...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2 if (err) {3 console.log("Error: " + err);4 } else {5 console.log("Response Time: " + time);6 }7});
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var responseTimer = devicefarmer.responseTimer;3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var devicefarmer = require('devicefarmer-stf');10var responseTimer = devicefarmer.responseTimer;11 if(err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var devicefarmer = require('devicefarmer-stf');18var responseTimer = devicefarmer.responseTimer;19 if(err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var devicefarmer = require('devicefarmer-stf');26var responseTimer = devicefarmer.responseTimer;27 if(err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var devicefarmer = require('devicefarmer-stf');34var responseTimer = devicefarmer.responseTimer;35 if(err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var devicefarmer = require('devicefarmer-stf');42var responseTimer = devicefarmer.responseTimer;43 if(err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var devicefarmer = require('devicefarmer-st
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2client.listDevices().then(function (devices) {3 return devices[0].responseTime();4}).then(function (responseTime) {5 console.log(responseTime);6});7This is a Node.js client library for STF (
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = client.getDevice('emulator-5554');3device.responseTimer(1000, function(err, res) {4 console.log(res);5});6var stf = require('devicefarmer-stf');7var device = client.getDevice('emulator-5554');8device.responseTimer(1000, function(err, res) {9 console.log(res);10});11var stf = require('devicefarmer-stf');12var device = client.getDevice('emulator-5554');13device.responseTimer(1000, function(err, res) {14 console.log(res);15});16var stf = require('devicefarmer-stf');17var device = client.getDevice('emulator-5554');18device.responseTimer(1000, function(err, res) {19 console.log(res);20});21var stf = require('devicefarmer-stf');22var device = client.getDevice('emulator-5554');23device.responseTimer(1000, function(err, res) {24 console.log(res);25});26var stf = require('devicefarmer-stf');27var device = client.getDevice('emulator-5554');28device.responseTimer(1000, function(err, res) {29 console.log(res);30});
Using AI Code Generation
1var responseTimer = require('devicefarmer-stf').responseTimer;2var timer = responseTimer(url, function(err, time) {3 console.log(time);4});5var responseTimer = require('devicefarmer-stf').responseTimer;6var timer = responseTimer(url, function(err, time) {7 console.log(time);8});9var responseTimer = require('devicefarmer-stf').responseTimer;10var timer = responseTimer(url, function(err, time) {11 console.log(time);12});13var responseTimer = require('devicefarmer-stf').responseTimer;14var timer = responseTimer(url, function(err, time) {15 console.log(time);16});17var responseTimer = require('devicefarmer-stf').responseTimer;18var timer = responseTimer(url, function(err, time) {19 console.log(time);20});21var responseTimer = require('devicefarmer-stf').responseTimer;22var timer = responseTimer(url, function(err, time) {23 console.log(time);24});25var responseTimer = require('devicefarmer-stf').responseTimer;26var timer = responseTimer(url, function(err, time) {27 console.log(time);28});29var responseTimer = require('devicefarmer-stf').responseTimer;30var timer = responseTimer(url, function(err, time) {31 console.log(time);32});33var responseTimer = require('devicefarmer-stf').responseTimer;34var timer = responseTimer(url, function(err
Using AI Code Generation
1const responseTimer = require('devicefarmer-stf-utils').responseTimer;2responseTimer(1000, function (err, result) {3 if (err) {4 console.log("Error: " + err);5 } else {6 console.log("Result: " + result);7 }8});9const responseTimer = require('devicefarmer-stf-utils').responseTimer;10responseTimer(1000, function (err, result) {11 if (err) {12 console.log("Error: " + err);13 } else {14 console.log("Result: " + result);15 }16});17var responseTimer = require('devicefarmer-stf-utils').responseTimer;18responseTimer(1000, function (err, result) {19 if (err) {20 console.log("Error: " + err);21 } else {22 console.log("Result: " + result);23 }24});25var responseTimer = require('devicefarmer-stf-utils').responseTimer;26responseTimer(1000, function (err, result) {27 if (err) {28 console.log("Error: " + err);29 } else {30 console.log("Result: " + result);31 }32});33var responseTimer = require('devicefarmer-stf-utils').responseTimer;34responseTimer(1000, function (err, result) {35 if (err) {36 console.log("Error: " + err);37 } else {38 console.log("Result: " + result);39 }40});41var responseTimer = require('devicefarmer-stf-utils').responseTimer;42responseTimer(1000, function (err, result) {
Using AI Code Generation
1var responseTimer = require('devicefarmer-stf').responseTimer;2responseTimer(url, 1000, function(error, response) {3 if (error) {4 console.log('error: ' + error);5 } else {6 console.log('response: ' + response);7 }8});9responseTimer(url, 100, function(error, response) {10 if (error) {11 console.log('error: ' + error);12 } else {13 console.log('response: ' + response);14 }15});16responseTimer(url, 1000, function(error, response) {17 if (error) {18 console.log('error: ' + error);19 } else {20 console.log('response: ' + response);21 }22});23responseTimer(url, 100, function(error, response) {24 if (error) {25 console.log('error: ' + error);26 } else {27 console.log('response: ' + response);28 }29});30responseTimer(url, 1000, function(error, response) {31 if (error) {32 console.log('error: ' + error);33 } else {34 console.log('response: ' + response);35 }36});37responseTimer(url, 100, function(error, response) {38 if (error) {39 console.log('error: ' + error);40 } else {41 console.log('response: ' + response);42 }43});44responseTimer(url, 1000, function(error, response) {45 if (error) {46 console.log('error: ' + error);47 } else {48 console.log('response: ' + response);49 }50});51responseTimer(url, 100,
Using AI Code Generation
1var stf = require('devicefarmer-stf');2device.responseTimer(function (err, res) {3 if (err) {4 console.log(err);5 } else {6 console.log(res);7 }8});9var stf = require('devicefarmer-stf');10device.battery(function (err, res) {11 if (err) {12 console.log(err);13 } else {14 console.log(res);15 }16});17var stf = require('devicefarmer-stf');18device.screen(function (err, res) {19 if (err) {20 console.log(err);21 } else {22 console.log(res);23 }24});25var stf = require('devicefarmer-stf');26device.setScreen(true, function (err, res) {27 if (err) {28 console.log(err);29 } else {30 console.log(res);31 }32});33var stf = require('devicefarmer-stf');34device.setScreen(false, function (err, res) {35 if (err) {36 console.log(err
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!!