|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {HarnessLoader} from '@angular/cdk/testing'; |
| 9 | +import {HarnessLoader, HarnessPredicate} from '@angular/cdk/testing'; |
10 | 10 | import {MatButtonHarness} from '@angular/material/button/testing/button-harness';
|
11 |
| -import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities'; |
12 | 11 | import {ProtractorHarnessEnvironment} from '@angular/cdk/testing/protractor';
|
| 12 | +import {$$, element, by, browser} from 'protractor'; |
| 13 | +import {benchmark} from './protractor-benchmark-utilities'; |
| 14 | +import {NUM_BUTTONS} from './constants'; |
13 | 15 |
|
14 |
| -let loader: HarnessLoader; |
| 16 | +const FIRST_BUTTON = '0'; |
| 17 | +const MIDDLE_BUTTON = `${Math.floor(NUM_BUTTONS / 2)}`; |
| 18 | +const LAST_BUTTON = `${NUM_BUTTONS - 1}`; |
15 | 19 |
|
16 |
| -describe('perf test for basic protractor harness', () => { |
17 |
| - it('should load the protractor harness environment', async () => { |
18 |
| - await runBenchmark({ |
19 |
| - id: 'initial-harness-load', |
20 |
| - url: '', |
21 |
| - ignoreBrowserSynchronization: true, |
22 |
| - params: [], |
23 |
| - work: () => { loader = ProtractorHarnessEnvironment.loader(); }, |
24 |
| - }); |
25 |
| - }); |
| 20 | +describe('performance baseline for the protractor harness', () => { |
| 21 | + beforeEach(async () => { |
| 22 | + await browser.get(''); |
| 23 | + }); |
26 | 24 |
|
27 |
| - it('should retrieve all of the buttons', async () => { |
28 |
| - await runBenchmark({ |
29 |
| - id: 'get-first-button', |
30 |
| - url: '', |
31 |
| - ignoreBrowserSynchronization: true, |
32 |
| - params: [], |
33 |
| - setup: () => { loader = ProtractorHarnessEnvironment.loader(); }, |
34 |
| - work: async () => await loader.getAllHarnesses(MatButtonHarness), |
35 |
| - }); |
36 |
| - }); |
| 25 | + it('(baseline) should retrieve all of the buttons', async () => { |
| 26 | + await benchmark('(baseline) get every button', async () => { |
| 27 | + await $$('.mat-button'); |
| 28 | + }); |
| 29 | + }); |
37 | 30 |
|
38 |
| - it('should retrieve the first button', async () => { |
39 |
| - await runBenchmark({ |
40 |
| - id: 'get-first-button', |
41 |
| - url: '', |
42 |
| - ignoreBrowserSynchronization: true, |
43 |
| - params: [], |
44 |
| - setup: () => { loader = ProtractorHarnessEnvironment.loader(); }, |
45 |
| - work: async () => await (await loader.getHarness(MatButtonHarness.with({text: '0'}))).click(), |
46 |
| - }); |
47 |
| - }); |
| 31 | + it('(baseline) should click the first button', async () => { |
| 32 | + await benchmark('(baseline) click first button', async () => { |
| 33 | + await element(by.buttonText(FIRST_BUTTON)).click(); |
| 34 | + }); |
| 35 | + }); |
48 | 36 |
|
49 |
| - it('should retrieve the middle button', async () => { |
50 |
| - await runBenchmark({ |
51 |
| - id: 'get-middle-button', |
52 |
| - url: '', |
53 |
| - ignoreBrowserSynchronization: true, |
54 |
| - params: [], |
55 |
| - setup: () => { loader = ProtractorHarnessEnvironment.loader(); }, |
56 |
| - work: async () => await (await loader.getHarness(MatButtonHarness.with({text: '49'}))).click(), |
57 |
| - }); |
58 |
| - }); |
| 37 | + it('(baseline) should click the middle button', async () => { |
| 38 | + await benchmark('(baseline) click middle button', async () => { |
| 39 | + await element(by.buttonText(MIDDLE_BUTTON)).click(); |
| 40 | + }); |
| 41 | + }); |
59 | 42 |
|
60 |
| - it('should retrieve the last button', async () => { |
61 |
| - await runBenchmark({ |
62 |
| - id: 'get-last-button', |
63 |
| - url: '', |
64 |
| - ignoreBrowserSynchronization: true, |
65 |
| - params: [], |
66 |
| - setup: () => { loader = ProtractorHarnessEnvironment.loader(); }, |
67 |
| - work: async () => await (await loader.getHarness(MatButtonHarness.with({text: '99'}))).click(), |
68 |
| - }); |
69 |
| - }); |
| 43 | + it('(baseline) should click the last button', async () => { |
| 44 | + await benchmark('(baseline) click last button', async () => { |
| 45 | + await element(by.buttonText(LAST_BUTTON)).click(); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it('(baseline) should click all of the buttons', async () => { |
| 50 | + await benchmark('(baseline) click every button', async () => { |
| 51 | + const buttons = $$('.mat-button'); |
| 52 | + await buttons.each(async (button) => await button!.click()); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +describe('performance tests for the protractor harness', () => { |
| 58 | + let loader: HarnessLoader; |
| 59 | + |
| 60 | + beforeEach(async () => { |
| 61 | + await browser.get(''); |
| 62 | + loader = ProtractorHarnessEnvironment.loader(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should retrieve all of the buttons', async () => { |
| 66 | + await benchmark('get every button', async () => { |
| 67 | + await loader.getAllHarnesses(MatButtonHarness); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should click the first button', async () => { |
| 72 | + await benchmark('click first button', async () => { |
| 73 | + const button = await loader.getHarness(MatButtonHarness.with({text: FIRST_BUTTON})); |
| 74 | + await button.click(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should click the middle button', async () => { |
| 79 | + await benchmark('click middle button', async () => { |
| 80 | + const button = await loader.getHarness(MatButtonHarness.with({text: MIDDLE_BUTTON})); |
| 81 | + await button.click(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should click the last button', async () => { |
| 86 | + await benchmark('click last button', async () => { |
| 87 | + const button = await loader.getHarness(MatButtonHarness.with({text: LAST_BUTTON})); |
| 88 | + await button.click(); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should click all of the buttons', async () => { |
| 93 | + await benchmark('click every button', async () => { |
| 94 | + const buttons = await loader.getAllHarnesses(MatButtonHarness); |
| 95 | + for (let i = 0; i < buttons.length; i++) { |
| 96 | + const button = buttons[i]; |
| 97 | + await button.click(); |
| 98 | + } |
| 99 | + }); |
| 100 | + }); |
70 | 101 | });
|
0 commit comments