Best JavaScript code snippet using devicefarmer-stf
AccountManager.spec.ts
Source:AccountManager.spec.ts
...52 await writeLocalFile({})53 manager = new AccountManager(new FileStorage())54 })55 it(`reads and adds accounts`, async () => {56 const accountsBefore: AccountInfo[] = await manager.getAccounts()57 expect(accountsBefore.length, 'before').to.equal(0)58 await manager.addAccount(account1)59 const accountsAfter: AccountInfo[] = await manager.getAccounts()60 expect(accountsAfter.length, 'after').to.equal(1)61 })62 it(`overwrites an existing account`, async () => {63 const accountsBefore: AccountInfo[] = await manager.getAccounts()64 expect(accountsBefore.length, 'before').to.equal(0)65 await manager.addAccount(account1)66 const accountsAfterAdding: AccountInfo[] = await manager.getAccounts()67 expect(accountsAfterAdding.length, 'after adding').to.equal(1)68 const newAccount1: AccountInfo = { ...account1, scopes: [PermissionScope.OPERATION_REQUEST] }69 await manager.addAccount(newAccount1)70 const accountsAfterReplacing: AccountInfo[] = await manager.getAccounts()71 expect(accountsAfterReplacing.length, 'after replacing').to.equal(1)72 expect(accountsAfterReplacing[0].scopes, 'after replacing').to.deep.equal(newAccount1.scopes)73 })74 it(`reads and adds multiple accounts`, async () => {75 const accountsBefore: AccountInfo[] = await manager.getAccounts()76 expect(accountsBefore.length, 'before').to.equal(0)77 await manager.addAccount(account1)78 await manager.addAccount(account2)79 const accountsAfter: AccountInfo[] = await manager.getAccounts()80 expect(accountsAfter.length, 'after').to.equal(2)81 })82 it(`only adds an account once`, async () => {83 const accountsBefore: AccountInfo[] = await manager.getAccounts()84 expect(accountsBefore.length, 'before').to.equal(0)85 await manager.addAccount(account1)86 await manager.addAccount(account1)87 const accountsAfter: AccountInfo[] = await manager.getAccounts()88 expect(accountsAfter.length, 'after').to.equal(1)89 })90 it(`reads one account`, async () => {91 const accountsBefore: AccountInfo[] = await manager.getAccounts()92 expect(accountsBefore.length, 'before').to.equal(0)93 await manager.addAccount(account1)94 await manager.addAccount(account2)95 const account = await manager.getAccount(account1.accountIdentifier)96 expect(account, 'after').to.deep.include(account1)97 })98 it(`removes one account`, async () => {99 const accountsBefore: AccountInfo[] = await manager.getAccounts()100 expect(accountsBefore.length, 'before').to.equal(0)101 await manager.addAccount(account1)102 await manager.addAccount(account2)103 await manager.addAccount(account3)104 const accountsAfter: AccountInfo[] = await manager.getAccounts()105 expect(accountsAfter.length, 'after add').to.equal(3)106 await manager.removeAccount(account1.accountIdentifier)107 const accountsAfterRemove: AccountInfo[] = await manager.getAccounts()108 expect(accountsAfterRemove.length, 'after remove').to.equal(2)109 expect(accountsAfterRemove, 'after remove, account2').to.deep.include(account2)110 expect(accountsAfterRemove, 'after remove, account3').to.deep.include(account3)111 })112 it(`removes many accounts`, async () => {113 const accountsBefore: AccountInfo[] = await manager.getAccounts()114 expect(accountsBefore.length, 'before').to.equal(0)115 await manager.addAccount(account1)116 await manager.addAccount(account2)117 await manager.addAccount(account3)118 const accountsAfter: AccountInfo[] = await manager.getAccounts()119 expect(accountsAfter.length, 'after add').to.equal(3)120 await manager.removeAccounts([account1.accountIdentifier, account2.accountIdentifier])121 const accountsAfterRemove: AccountInfo[] = await manager.getAccounts()122 expect(accountsAfterRemove.length, 'after remove').to.equal(1)123 expect(accountsAfterRemove, 'after remove').to.deep.include(account3)124 })125 it(`removes all accounts`, async () => {126 const accountsBefore: AccountInfo[] = await manager.getAccounts()127 expect(accountsBefore.length, 'before').to.equal(0)128 await manager.addAccount(account1)129 await manager.addAccount(account2)130 await manager.addAccount(account3)131 const accountsAfter: AccountInfo[] = await manager.getAccounts()132 expect(accountsAfter.length, 'after add').to.equal(3)133 await manager.removeAllAccounts()134 const accountsAfterRemove: AccountInfo[] = await manager.getAccounts()135 expect(accountsAfterRemove.length, 'after remove').to.equal(0)136 })...
launch_multi_button.js
Source:launch_multi_button.js
1const pool = require('../helpers/mysql')2const moment = require('moment')3module.exports = async (req, res) => {4 try {5 const { users_id, type, post = '', link = '' } = req.body6 let data = {}7 let postContent = []8 const getAccounts = await pool(`SELECT id , email , fb_password , email_password , two_fa , execute_path , status FROM facebook_account WHERE users_id =?`, [users_id])9 if (!getAccounts[0]) { res.status(400).json({ message: 'Invalid users id.' }) }10 if (getAccounts[0]) {11 //console.log(getAccounts)12 const getConfig = await pool(`SELECT delay_min , delay_max FROM config WHERE id =?`, [1])13 for (let i = 0; i < getAccounts.length; i++) {14 if (getAccounts[i].status !== 'working') {15 if (type === 'like' || type === 'story') {16 data = {17 type,18 id: getAccounts[i].id,19 email: getAccounts[i].email,20 fb_password: getAccounts[i].fb_password,21 two_fa: getAccounts[i].two_fa,22 execute_path: getAccounts[i].execute_path,23 delay_min: getConfig[0].delay_min * 1000,24 delay_max: getConfig[0].delay_max * 1000,25 }26 }27 if (type === 'post') {28 if (!post) {29 const getPost = await pool(`SELECT post FROM facebook_post ORDER BY RAND() LIMIT 1`)30 postContent.push(Object.values(getPost[0]))31 postContent = postContent.toString()32 } else { postContent = post }33 data = {34 type,35 id: getAccounts[i].id,36 email: getAccounts[i].email,37 fb_password: getAccounts[i].fb_password,38 two_fa: getAccounts[i].two_fa,39 execute_path: getAccounts[i].execute_path,40 delay_min: getConfig[0].delay_min * 1000,41 delay_max: getConfig[0].delay_max * 1000,42 postContent43 }44 }45 if (type === 'share') {46 data = {47 type,48 id: getAccounts[i].id,49 email: getAccounts[i].email,50 fb_password: getAccounts[i].fb_password,51 two_fa: getAccounts[i].two_fa,52 execute_path: getAccounts[i].execute_path,53 delay_min: getConfig[0].delay_min * 1000,54 delay_max: getConfig[0].delay_max * 1000,55 link,56 post57 }58 }59 const obj = {60 work_at: moment().format('YYYY/MM/DD HH:mm:ss'),61 status: 'working'62 }63 data.send = 064 data.send_at = moment().format('YYYY/MM/DD HH:mm:ss')65 //console.log(data)66 await pool(`UPDATE facebook_account SET ? WHERE status = 'finish' AND users_id =?`, [obj, users_id])67 await pool(`INSERT INTO queues SET ?`, [data])68 console.log(`Add new queues.`)69 }70 }71 res.status(201).json({ message: 'Success' })72 }73 } catch (err) {74 console.log(err)75 res.status(400).json(err)76 }...
Locked Profile.js
Source:Locked Profile.js
1function AttachEvents() {2 let buttons = document.getElementsByTagName('button');3 4 for(var k = 0; k < buttons.length; k++){5 buttons[k].addEventListener("click", AccountsControl);6 buttons[k].setAttribute("id", k+1);7 }891011 function AccountsControl() {12 if (this.className == "") {13 this.setAttribute("class", "active");14 }1516 let getAccounts = document.querySelectorAll("div.profile");1718 for(var j = 0; j < getAccounts.length; j++){1920 let lockedOrNot = getAccounts[j].children[2];2122 if(getAccounts[j].children[10].className == "active" && getAccounts[j].children[10].id == this.id){2324 if(lockedOrNot.checked != true){25 let dataFields = getAccounts[j].children[getAccounts[j].children.length-2];26 dataFields.style.display = "block";27 this.textContent = "Hide it";28 this.className = "activated";29 }else {30 this.className = "";31 }3233 } else if (getAccounts[j].children[10].className == "activated" && getAccounts[j].children[10].id == this.id){34 if(lockedOrNot.checked != true){35 let dataFields = getAccounts[j].children[getAccounts[j].children.length-2];36 dataFields.style.display = "none";37 this.className = "";38 this.textContent = "Show more";39 }40 }41 }42 }43}44
...
Using AI Code Generation
1var Client = require('devicefarmer-stf-client');2client.getAccounts(function(err, accounts) {3 if(err) {4 console.log(err);5 } else {6 console.log(accounts);7 }8});9var Client = require('devicefarmer-stf-client');10client.getDevices(function(err, devices) {11 if(err) {12 console.log(err);13 } else {14 console.log(devices);15 }16});17var Client = require('devicefarmer-stf-client');18client.getDevice('2c4d4e5c', function(err, device) {19 if(err) {20 console.log(err);21 } else {22 console.log(device);23 }24});25var Client = require('devicefarmer-stf-client');26client.getDevice('2c4d4e5c', function(err, device) {27 if(err) {28 console.log(err);29 } else {30 console.log(device);31 }32});33var Client = require('devicefarmer-stf-client');34client.getDevice('2c4d4e5c', function(err, device) {35 if(err) {36 console.log(err);37 } else {38 console.log(device);39 }40});41var Client = require('devicefarmer-stf-client');42client.getDevice('2c4d4e5c', function(err, device) {43 if(err) {44 console.log(err);45 } else {46 console.log(device);47 }48});
Using AI Code Generation
1var stf = require('stf-client')2client.getAccounts(function(err, accounts) {3 if (err) {4 console.error(err)5 } else {6 console.log(accounts)7 }8})9getAccounts(callback)10getDevices(callback)11getDevice(serial, callback)12getDeviceProperties(serial, callback)13getDeviceProperties(serial, callback)14getDeviceLogs(serial, callback)15getDeviceLogcat(serial, callback)16getDeviceScreenshot(serial, callback)17getDeviceVideo(serial, callback)18getDeviceMinicap(serial, callback)19getDeviceMinitouch(serial, callback)20getDeviceRemoteConnect(serial, callback)21getDeviceRemoteDisconnect(serial, callback)22getDeviceRemoteForwards(serial, callback)23getDeviceRemoteForward(serial, local, remote, callback)
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var devices = client.getDevices();3devices.then(function(result) {4 console.log(result);5});6[ { serial: 'ZY322GK6N7',7 provider: { name: 'local' },
Using AI Code Generation
1var Client = require('devicefarmer-stf-client');2var client = new Client();3client.getAccounts(function(err, accounts) {4 console.log(accounts);5});6var Client = require('devicefarmer-stf-client');7var client = new Client();8client.getAccountDevices(1, function(err, devices) {9 console.log(devices);10});11var Client = require('devicefarmer-stf-client');12var client = new Client();13client.getDevices(function(err, devices) {14 console.log(devices);15});16var Client = require('devicefarmer-stf-client');17var client = new Client();18client.getDevice(1, function(err, device) {19 console.log(device);20});21var Client = require('devicefarmer-stf-client');22var client = new Client();23client.getDeviceUsage(1, function(err, usage) {24 console.log(usage);25});26var Client = require('devicefarmer-stf-client');27var client = new Client();28client.getDeviceUsage(1, function(err, usage) {29 console.log(usage);30});31var Client = require('devicefarmer-stf-client');32var client = new Client();33client.getDeviceUsage(1, function(err, usage) {34 console.log(usage);35});36var Client = require('devicefarmer-stf-client');37var client = new Client();38client.getDeviceUsage(1, function(err, usage) {39 console.log(usage);40});41var Client = require('devicefarmer-stf-client');42var client = new Client();43client.getDeviceUsage(1, function(err, usage) {
Using AI Code Generation
1var stf = require('stf-client');2client.getDevices(function(err, devices) {3 if (err) {4 console.log("Error: "+err);5 } else {6 console.log(devices);7 }8});9var stf = require('stf-client');10client.getAccounts(function(err, accounts) {11 if (err) {12 console.log("Error: "+err);13 } else {14 console.log(accounts);15 }16});17var stf = require('stf-client');18client.getDevices(function(err, devices) {19 if (err) {20 console.log("Error: "+err);21 } else {22 console.log(devices);23 }24});25var stf = require('stf-client');26client.getDevices(function(err, devices) {27 if (err) {28 console.log("Error: "+err);29 } else {30 console.log(devices);31 }32});33var stf = require('stf-client');34client.getDevices(function(err, devices) {35 if (err) {36 console.log("Error: "+err);37 } else {38 console.log(devices);39 }40});41var stf = require('stf-client');42client.getDevices(function(err, devices) {43 if (err) {44 console.log("Error: "+err);45 } else {46 console.log(devices);47 }48});49var stf = require('stf-client');50client.getDevices(function(err, devices) {51 if (err) {
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var device = client.getDevice("deviceID");3device.getAccounts().then(function (accounts) {4 console.log(accounts);5});6var stf = require('devicefarmer-stf-client');7var device = client.getDevice("deviceID");8device.getAccounts().then(function (accounts) {9 console.log(accounts);10});11var stf = require('devicefarmer-stf-client');12var device = client.getDevice("deviceID");13device.getAccounts().then(function (accounts) {14 console.log(accounts);15});16var stf = require('devicefarmer-stf-client');17var device = client.getDevice("deviceID");18device.getAccounts().then(function (accounts) {19 console.log(accounts);20});21var stf = require('devicefarmer-stf-client');22var device = client.getDevice("deviceID");23device.getAccounts().then(function (accounts) {24 console.log(accounts);25});26var stf = require('devicefarmer-stf-client');27var device = client.getDevice("deviceID");28device.getAccounts().then(function (accounts) {29 console.log(accounts);30});31var stf = require('devicefarmer-stf-client');32var device = client.getDevice("deviceID");33device.getAccounts().then(function (accounts) {34 console.log(accounts);35});36var stf = require('devicefarmer-stf-client');37var client = stf.connect("http
Using AI Code Generation
1var provider = require('devicefarmer-stf-provider')2provider.getAccounts(function(err,accounts){3 console.log(err,accounts)4})5var provider = require('devicefarmer-stf-provider')6provider.getDevices(function(err,devices){7 console.log(err,devices)8})9var provider = require('devicefarmer-stf-provider')10provider.getDevice('serialnumber',function(err,device){11 console.log(err,device)12})13var provider = require('devicefarmer-stf-provider')14provider.getDevice('serialnumber',function(err,device){15 console.log(err,device)16})17var provider = require('devicefarmer-stf-provider')18provider.getDevice('serialnumber',function(err,device){19 console.log(err,device)20})21var provider = require('devicefarmer-stf-provider')22provider.getDevice('serialnumber',function(err,device){23 console.log(err,device)24})25var provider = require('devicefarmer-stf-provider')26provider.getDevice('serialnumber',function(err,device){27 console.log(err,device)28})29var provider = require('devicefarmer-stf-provider')30provider.getDevice('serialnumber',function(err,device){31 console.log(err,device)32})33var provider = require('devicefarmer-stf-provider')34provider.getDevice('serialnumber',function(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!!