How to use driver.getPerformanceDataTypes method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

performance-e2e-specs.js

Source: performance-e2e-specs.js Github

copy
1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import AndroidDriver from '../../..';
4import { SUPPORTED_PERFORMANCE_DATA_TYPES, CPU_KEYS, MEMORY_KEYS, BATTERY_KEYS, NETWORK_KEYS } from '../../../lib/commands/performance';
5import _ from 'lodash';
6import DEFAULT_CAPS from '../desired';
7
8
9chai.should();
10chai.use(chaiAsPromised);
11
12let driver;
13let caps = _.defaults({
14  appPackage: 'io.appium.android.apis',
15  appActivity: '.view.TextFields'
16}, DEFAULT_CAPS);
17
18describe('performance', () => {
19  before(async () => {
20    driver = new AndroidDriver();
21    await driver.createSession(caps);
22  });
23  after(async () => {
24    await driver.deleteSession();
25  });
26
27  describe('getPerformanceData', () => {
28    it('should get the performancedata', async () => {
29      let capability = await driver.getPerformanceDataTypes();
30      capability.should.eql(_.keys(SUPPORTED_PERFORMANCE_DATA_TYPES));
31    });
32
33    it('should throw an Error for unsupported capability data type ', async  () => {
34      await driver.getPerformanceData(caps.appPackage, 'randominfo', 2).should.be.rejected;
35    });
36
37    it('should get the amount of cpu by user and kernel process', async function () {
38      // TODO: why does this fail?
39      let apiLevel = await driver.adb.getApiLevel();
40      if ([21, 24, 25].indexOf(apiLevel) >= 0) {
41        return this.skip();
42      }
43      let cpu = await driver.getPerformanceData(caps.appPackage, 'cpuinfo', 50);
44
45      Array.isArray(cpu).should.be.true;
46      cpu.length.should.be.above(1);
47      cpu[0].should.eql(CPU_KEYS);
48      if (cpu.length > 1) {
49        for (let i = 1; i < cpu.length; i++) {
50          cpu[0].length.should.equal(cpu[i].length);
51        }
52      }
53    });
54    it('should get the amount of memory used by the process', async () => {
55      let memory = await driver.getPerformanceData(caps.appPackage, 'memoryinfo', 2);
56
57      Array.isArray(memory).should.be.true;
58      memory.length.should.be.above(1);
59      memory[0].should.eql(MEMORY_KEYS);
60      if (memory.length > 1) {
61        for (let i = 1; i < memory.length; i++) {
62          memory[0].length.should.equal(memory[i].length);
63        }
64      }
65    });
66    it('should get the remaining battery power', async () => {
67      let battery = await driver.getPerformanceData(caps.appPackage, 'batteryinfo', 2);
68
69      Array.isArray(battery).should.be.true;
70      battery.length.should.be.above(1);
71      battery[0].should.eql(BATTERY_KEYS);
72      if (battery.length > 1) {
73        for (let i = 1; i < battery.length; i++) {
74          battery[0].length.should.equal(battery[i].length);
75        }
76      }
77    });
78    it('should get the network statistics', async function () {
79      // TODO: why does adb fail with a null pointer exception on 5.1
80      if (await driver.adb.getApiLevel() === 22) {
81        return this.skip();
82      }
83      let network = await driver.getPerformanceData(caps.appPackage, 'networkinfo', 2);
84
85      Array.isArray(network).should.be.true;
86      network.length.should.be.above(1);
87
88      let compare = false;
89      for (let j = 0; j < NETWORK_KEYS.length; ++j) {
90        if (_.isEqual(NETWORK_KEYS[j], network[0])) {
91          compare = true;
92        }
93      }
94
95      compare.should.equal(true);
96
97      if (network.length > 1) {
98        for (let i = 1; i < network.length; ++i) {
99          network[0].length.should.equal(network[i].length);
100        }
101      }
102    });
103  });
104});
105
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Android Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)