Best JavaScript code snippet using appium
client.js
Source:client.js
...8 }9 getRandomPages(limit) {10 const _this = this;11 return new Promise(async (resolve, reject) => {12 const args = _this._util.getDefaultArgs("GET");13 args.list = 'random';14 args.action = 'query';15 args.rnlimit = limit;16 const response = JSON.parse(await _this._get(args));17 response.query.search = _this._util.rawPageArrayTo(response.query.random, _this)18 resolve(response);19 })20 }21 search(term) {22 const _this = this;23 return new Promise(async (resolve, reject) => {24 const args = _this._util.getDefaultArgs("GET");25 args.list = 'search';26 args.action = 'query';27 args.srsearch = term;28 const response = JSON.parse(await _this._get(args));29 response.query.search = _this._util.rawPageArrayTo(response.query.search, _this)30 resolve(response);31 })32 }33 getPage(pageTitle) {34 const _this = this;35 return new Promise(async (resolve, reject) => {36 const info = await getPageInfo(pageTitle);37 _this.pageHandler.add(info);38 // REMOVE IF SLOW39 await _this.pageHandler.get(raw.pageid).refreshAll();40 resolve();41 })42 }43 getPageInfo(pageTitle) {44 const _this = this;45 return new Promise(async (resolve, reject) => {46 const args = _this._util.getDefaultArgs("GET");47 args.action = 'query';48 args.titles = pageTitle;49 args.prop = 'info';50 const response = JSON.parse(await _this._get(args));51 resolve(response.query.pages[pageID]);52 })53 }54 getPageText(pageTitle, format) {55 const _this = this;56 return new Promise(async (resolve, reject) => {57 const args = _this._util.getDefaultArgs("GET");58 args.action = 'parse';59 args.formatversion = 2;60 if (format.toLowerCase() == "html") {61 args.prop = 'text';62 } else if (format.toLowerCase() == "wikitext") {63 args.prop = 'wikitext';64 }65 args.page = pageTitle;66 const response = JSON.parse(await _this._get(args));67 resolve(response.parse);68 })69 }70 getPageCategories(pageTitle, pageID) {71 const _this = this;72 return new Promise(async (resolve, reject) => {73 const args = _this._util.getDefaultArgs("GET");74 args.action = 'query';75 args.titles = pageTitle;76 args.prop = 'categories';77 const response = JSON.parse(await _this._get(args));78 resolve(response.query.pages[pageID]);79 })80 }81 _get(args) {82 const _this = this;83 return new Promise((resolve, reject) => {84 if ((typeof args).toLowerCase() == 'object') {85 args = _this.util.stringifyArgs("GET", args);86 }87 fetch(`${_this.baseURL}?${args}`)...
redux.spec.js
Source:redux.spec.js
...33 statePath,34 statePathFetch,35 statePathUpdate36 });37 const args = getDefaultArgs({});38 describe("fetchData()", () => {39 it("should return new data if request hasn't been made", async (done) => {40 const argsDefault = getDefaultArgs({});41 const data = await fetchData(argsDefault);42 expect(argsDefault.dispatch.calls.count()).toEqual(2);43 expect(data).toEqual(args.newData);44 done();45 });46 it("should return existing data if request has been made", async (done) => {47 const argsLoading = getDefaultArgs({requestState: args.requestStateLoading});48 const dataLoading = await fetchData(argsLoading);49 expect(argsLoading.dispatch.calls.count()).toEqual(0);50 expect(dataLoading).toEqual(args.existingData);51 const argsLoaded = getDefaultArgs({requestState: args.requestStateLoaded});52 const dataLoaded = await fetchData(argsLoaded);53 expect(argsLoaded.dispatch.calls.count()).toEqual(0);54 expect(dataLoaded).toEqual(args.existingData);55 done();56 });57 it("should return new data if previous request ended in error", async (done) => {58 const argsError = getDefaultArgs({requestState: args.requestStateError});59 const dataError = await fetchData(argsError);60 expect(argsError.dispatch.calls.count()).toEqual(2);61 expect(dataError).toEqual(args.newData);62 done();63 });64 // FIXME: this seems to make jasmine ignore the rest of the tests65 // is an exception bubbling up from fetchData? why?66 // how else to test return value in the catch case?67 xit("should return existing data if request fails", async (done) => {68 const argsFail = getDefaultArgs({getData: () => Promise.reject('error')});69 try{70 const dataFail = await fetchData(argsFail).catch((error) => console.log(error));71 expect(argsFail.dispatch.calls.count()).toEqual(2);72 expect(dataFail).toEqual(args.existingData);73 }74 catch(error) {75 return;76 }77 done();78 });79 });80 describe("updateData()", () => {81 it("should return new data regardless of previous request state", async (done) => {82 const argsDefault = getDefaultArgs({});83 const data = await updateData(argsDefault);84 expect(argsDefault.dispatch.calls.count()).toEqual(2);85 expect(data).toEqual(args.newData);86 const argsLoading = getDefaultArgs({requestState: args.requestStateLoading});87 const dataLoading = await updateData(argsLoading);88 expect(argsLoading.dispatch.calls.count()).toEqual(2);89 expect(dataLoading).toEqual(args.newData);90 const argsLoaded = getDefaultArgs({requestState: args.requestStateLoaded});91 const dataLoaded = await updateData(argsLoaded);92 expect(argsLoaded.dispatch.calls.count()).toEqual(2);93 expect(dataLoaded).toEqual(args.newData);94 const argsError = getDefaultArgs({requestState: args.requestStateError});95 const dataError = await updateData(argsError);96 expect(argsError.dispatch.calls.count()).toEqual(2);97 expect(dataError).toEqual(args.newData);98 done();99 });100 // FIXME: same problem as fetchData() case101 xit("should return existing data if request fails", async (done) => {102 const argsFail = getDefaultArgs({putData: () => {throw new Error('test')}});103 const data = await fetchData(argsFail);104 expect(argsFail.dispatch.calls.count()).toEqual(2);105 expect(data).toEqual(args.existingData);106 done();107 });108 });...
redux.unit.spec.js
Source:redux.unit.spec.js
...41 statePath,42 statePathFetch,43 statePathUpdate,44 });45 const args = getDefaultArgs({});46 describe("fetchData()", () => {47 it("should return new data if request hasn't been made", async () => {48 const argsDefault = getDefaultArgs({});49 const data = await fetchData(argsDefault);50 await delay(10);51 expect(argsDefault.dispatch.calls.count()).toEqual(2);52 expect(data).toEqual(args.newData);53 });54 it("should return existing data if request has been made", async () => {55 const argsLoading = getDefaultArgs({56 requestState: args.requestStateLoading,57 });58 const dataLoading = await fetchData(argsLoading);59 expect(argsLoading.dispatch.calls.count()).toEqual(0);60 expect(dataLoading).toEqual(args.existingData);61 const argsLoaded = getDefaultArgs({62 requestState: args.requestStateLoaded,63 });64 const dataLoaded = await fetchData(argsLoaded);65 expect(argsLoaded.dispatch.calls.count()).toEqual(0);66 expect(dataLoaded).toEqual(args.existingData);67 });68 it("should return new data if previous request ended in error", async () => {69 const argsError = getDefaultArgs({70 requestState: args.requestStateError,71 });72 const dataError = await fetchData(argsError);73 await delay(10);74 expect(argsError.dispatch.calls.count()).toEqual(2);75 expect(dataError).toEqual(args.newData);76 });77 // FIXME: this seems to make jasmine ignore the rest of the tests78 // is an exception bubbling up from fetchData? why?79 // how else to test return value in the catch case?80 it("should return existing data if request fails", async () => {81 const argsFail = getDefaultArgs({82 getData: () => Promise.reject("error"),83 });84 try {85 const dataFail = await fetchData(argsFail).catch(error =>86 console.log(error),87 );88 expect(argsFail.dispatch.calls.count()).toEqual(2);89 expect(dataFail).toEqual(args.existingData);90 } catch (error) {91 return;92 }93 });94 });95 describe("updateData()", () => {96 it("should return new data regardless of previous request state", async () => {97 const argsDefault = getDefaultArgs({});98 const data = await updateData(argsDefault);99 expect(argsDefault.dispatch.calls.count()).toEqual(2);100 expect(data).toEqual(args.newData);101 const argsLoading = getDefaultArgs({102 requestState: args.requestStateLoading,103 });104 const dataLoading = await updateData(argsLoading);105 expect(argsLoading.dispatch.calls.count()).toEqual(2);106 expect(dataLoading).toEqual(args.newData);107 const argsLoaded = getDefaultArgs({108 requestState: args.requestStateLoaded,109 });110 const dataLoaded = await updateData(argsLoaded);111 expect(argsLoaded.dispatch.calls.count()).toEqual(2);112 expect(dataLoaded).toEqual(args.newData);113 const argsError = getDefaultArgs({114 requestState: args.requestStateError,115 });116 const dataError = await updateData(argsError);117 expect(argsError.dispatch.calls.count()).toEqual(2);118 expect(dataError).toEqual(args.newData);119 });120 it("should return existing data if request fails", async () => {121 const argsFail = getDefaultArgs({122 putData: () => {123 throw new Error("test");124 },125 });126 const data = await updateData(argsFail);127 await delay(10);128 expect(argsFail.dispatch.calls.count()).toEqual(2);129 expect(data).toEqual(args.existingData);130 });131 });...
routerHelper.spec.js
Source:routerHelper.spec.js
...14 limitations under the License.15*/16import sinon from 'sinon';17import { routerHook } from '../routerHelper';18function getDefaultArgs() {19 return {20 prevProps: {21 currentUser: {22 username: '',23 },24 },25 nextProps: {26 currentUser: {27 username: '',28 },29 currentSite: {30 name: '',31 },32 menus: [33 { url: '/dataset/list' },34 ],35 history: {36 push: sinon.spy(),37 },38 },39 nextStates: {40 isSystemInited: true,41 isDataInited: true,42 },43 redirectToLogin: sinon.spy(),44 };45}46describe('è·¯ç±é©ååè½æµè¯', () => {47 describe('æªç»å½çç¨æ·', () => {48 it('è¿å
¥ç»å½é¡µé¢', () => {49 const { prevProps, prevState, nextProps, nextStates, redirectToLogin } = getDefaultArgs();50 prevProps.currentUser.username = '';51 nextProps.currentUser.username = '';52 nextProps.currentSite.name = 'login';53 routerHook({ prevProps, prevState }, { nextProps, nextStates, redirectToLogin });54 expect(nextProps.history.push.called).toBeFalsy();55 expect(redirectToLogin.called).toBeFalsy();56 });57 it('è¿å
¥ä¸å¯è¿å
¥ç页é¢', () => {58 const { prevProps, prevState, nextProps, nextStates, redirectToLogin } = getDefaultArgs();59 prevProps.currentUser.username = '';60 nextProps.currentUser.username = '';61 nextProps.currentSite = null;62 routerHook({ prevProps, prevState }, { nextProps, nextStates, redirectToLogin });63 expect(redirectToLogin.called).toBeTruthy();64 });65 it('ç³»ç»è¿å
¥ç»å½ç¨æ·', () => {66 const { prevProps, prevState, nextProps, nextStates, redirectToLogin } = getDefaultArgs();67 prevProps.currentUser.username = '';68 nextProps.currentUser.username = 'ADMIN';69 nextProps.currentSite.name = 'login';70 routerHook({ prevProps, prevState }, { nextProps, nextStates, redirectToLogin });71 expect(nextProps.history.push.args[0][0]).toBe('/dataset/list');72 });73 });74 describe('å·²ç»å½çç¨æ·', () => {75 it('è¿å
¥ç»å½é¡µé¢', () => {76 const { prevProps, prevState, nextProps, nextStates, redirectToLogin } = getDefaultArgs();77 prevProps.currentUser.username = 'ADMIN';78 nextProps.currentUser.username = 'ADMIN';79 nextProps.currentSite.name = 'login';80 routerHook({ prevProps, prevState }, { nextProps, nextStates, redirectToLogin });81 expect(nextProps.history.push.args[0][0]).toBe('/dataset/list');82 });83 it('è¿å
¥ä¸åå¨ç页é¢', () => {84 const { prevProps, prevState, nextProps, nextStates, redirectToLogin } = getDefaultArgs();85 prevProps.currentUser.username = 'ADMIN';86 nextProps.currentUser.username = 'ADMIN';87 nextProps.currentSite = null;88 routerHook({ prevProps, prevState }, { nextProps, nextStates, redirectToLogin });89 expect(nextProps.history.push.args[0][0]).toBe('/dataset/list');90 });91 it('ç³»ç»éåºç»å½ç¨æ·', () => {92 const { prevProps, prevState, nextProps, nextStates, redirectToLogin } = getDefaultArgs();93 prevProps.currentUser.username = 'ADMIN';94 nextProps.currentUser.username = '';95 nextProps.currentSite = 'datasetList';96 routerHook({ prevProps, prevState }, { nextProps, nextStates, redirectToLogin });97 expect(redirectToLogin.called).toBeTruthy();98 });99 });...
EntryModel.js
Source:EntryModel.js
...10 overrides.constructor = function (context) {11 var me = this;12 // fix context with defaultArgs13 var newContext = _.chain(context)14 .defaults(me.getDefaultArgs())15 .extend({16 context: require('./context').dump()17 })18 .value();19 // call super20 me.$super([newContext]);21 };22 overrides.resolveQuery = function (data) {23 var url = this.get('url');24 var query = url.getQuery();25 // è¿æ»¤æ没åçé»è®¤åæ°26 query = _.chain(query)27 .extend(data)28 .extend(this.getExtraQuery())29 .purify(this.getDefaultArgs())30 .value();31 var path = url.getPath();32 return require('er/URL').withQuery(path, query).toString();33 };34 overrides.loadingData = {35 loading: '<span class="view-loading">å è½½ä¸ï¼è¯·ç¨å...</span>'36 };37 overrides.defaultArgs = {};38 overrides.getDefaultArgs = function () {39 return this.defaultArgs || {};40 };41 /**42 * è·åéå ç请æ±åæ°43 *...
request.js
Source:request.js
...19export default class Request {20 static get(path, query = {}) {21 if(path[path.length - 1] !== "/")22 path += "/"23 let args = merge({}, getDefaultArgs(), { method: 'GET' });24 let qstring = Object.keys(query).reduce((acc, key) => {25 acc = acc + key + '=' + query[key] + '&';26 return acc;27 }, '');28 if(qstring.endsWith('&'))29 qstring = qstring.slice(0, qstring.length - 1);30 if(qstring != '')31 path = path + '?' + qstring;32 return _fetch(path, args);33 }34 static postForm(path, data) {35 if(path[path.length - 1] !== "/")36 path += "/"37 let args = cloneDeep(getDefaultArgs());38 args.method = 'POST';39 delete args.headers['Content-Type'];40 let formData = new FormData();41 Object.keys(data).reduce((acc, key) => {42 acc.append(key, data[key]);43 return acc;44 }, formData);45 args.body = formData;46 return _fetch(path, args);47 }48 static post(path, data) {49 if(path[path.length - 1] !== "/")50 path += "/"51 let args = cloneDeep(getDefaultArgs());52 args.method = 'POST';53 args.body = JSON.stringify(data);54 return _fetch(path, args);55 }56 static delete(path) {57 if(path[path.length - 1] !== "/")58 path += "/"59 let args = merge({}, getDefaultArgs(), { method: 'DELETE' });60 return _fetch(path, args);61 }...
test.js
Source:test.js
1#! /usr/bin/env node2const jest = require('jest');3function getDefaultArgs() {4 return '--config jest.config.js';5}6function main(args) {7 const [ process, file, ...jestArgs ] = args;8 jest.run([getDefaultArgs(), ...jestArgs].join(' '));9}...
Using AI Code Generation
1var args = driver.getDefaultArgs();2driver.setDefaultArgs(args);3var settings = driver.getSettings();4driver.updateSettings(settings);5var types = driver.getSupportedPerformanceDataTypes();6var data = driver.getPerformanceData("com.example.android.apis", types[0], 10000);7var types = driver.getPerformanceDataTypes();8var data = driver.getPerformanceData("com.example.android.apis", types[0], 10000);9var types = driver.getPerformanceDataTypes();10var data = driver.getPerformanceData("com.example.android.apis", types[0], 10000);11var types = driver.getPerformanceDataTypes();12var data = driver.getPerformanceData("com.example.android.apis", types[0], 10000);13var types = driver.getPerformanceDataTypes();14var data = driver.getPerformanceData("com.example.android.apis", types[0], 10000);15var types = driver.getPerformanceDataTypes();16var data = driver.getPerformanceData("com.example.android.apis", types[0], 10000);
Using AI Code Generation
1var args = driver.getDefaultArgs();2driver.setDefaultArgs(args);3var args = driver.getDefaultArgs();4driver.setDefaultArgs(args);5var args = driver.getDefaultArgs();6driver.setDefaultArgs(args);7var args = driver.getDefaultArgs();8driver.setDefaultArgs(args);9var args = driver.getDefaultArgs();10driver.setDefaultArgs(args);11var args = driver.getDefaultArgs();12driver.setDefaultArgs(args);13var args = driver.getDefaultArgs();14driver.setDefaultArgs(args);15var args = driver.getDefaultArgs();16driver.setDefaultArgs(args);17var args = driver.getDefaultArgs();18driver.setDefaultArgs(args);19var args = driver.getDefaultArgs();20driver.setDefaultArgs(args);21var args = driver.getDefaultArgs();22driver.setDefaultArgs(args);
Using AI Code Generation
1var driver = new AppiumDriver();2var defaultArgs = driver.getDefaultArgs();3console.log(defaultArgs);4var driver = new AppiumDriver();5var devices = driver.getDeviceList();6console.log(devices);7var driver = new AppiumDriver();8var devices = driver.getDeviceList();9console.log(devices);10var driver = new AppiumDriver();11var devices = driver.getDeviceList();12console.log(devices);13var driver = new AppiumDriver();14var devices = driver.getDeviceList();15console.log(devices);16var driver = new AppiumDriver();17var devices = driver.getDeviceList();18console.log(devices);19var driver = new AppiumDriver();20var devices = driver.getDeviceList();21console.log(devices);22var driver = new AppiumDriver();23var devices = driver.getDeviceList();24console.log(devices);25var driver = new AppiumDriver();26var devices = driver.getDeviceList();27console.log(devices);28var driver = new AppiumDriver();29var devices = driver.getDeviceList();30console.log(devices);31var driver = new AppiumDriver();32var devices = driver.getDeviceList();33console.log(devices);34var driver = new AppiumDriver();35var devices = driver.getDeviceList();36console.log(devices);37var driver = new AppiumDriver();38var devices = driver.getDeviceList();39console.log(devices);40var driver = new AppiumDriver();41var devices = driver.getDeviceList();42console.log(devices);
Using AI Code Generation
1var wd = require('wd');2var driver = wd.promiseChainRemote();3driver.init({4}).then(function() {5 return driver.getDefaultArgs();6}).then(function(args) {7 console.log(args);8}).fin(function() { return driver.quit(); })9.done();10{ appPackage: 'com.example.android.contactmanager',11 deviceName: 'Android Emulator' }
Using AI Code Generation
1var wd = require('wd');2var driver = wd.promiseChainRemote();3driver.init(getDefaultArgs()).then(function() {4});5var getDefaultArgs = function() {6 var defaultArgs = {7 };8 return defaultArgs;9};10driver.waitForElementByAccessibilityId('Accessibility', wd.asserters.isDisplayed, 5000)11 .click()12 .waitForElementByAccessibilityId('Accessibility Node Provider', wd.asserters.isDisplayed, 5000)13 .click()14 .waitForElementByAccessibilityId('Accessibility Node Querying', wd.asserters.isDisplayed, 5000)15 .click()16 .nodeify(done);17driver.quit();
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!!