|
1 | | -import { Builder } from "selenium-webdriver"; |
2 | | -import * as chrome from "selenium-webdriver/chrome"; |
| 1 | +import { Builder } from 'selenium-webdriver'; |
| 2 | +import * as chrome from 'selenium-webdriver/chrome'; |
3 | 3 | import 'chromedriver'; |
4 | 4 | import { GooglePage } from '../pages/googlePage'; |
5 | 5 | import { Lighthouse } from '../lighthouse'; |
6 | 6 | import { getFreePort } from 'endpoint-utils'; |
7 | 7 | import * as DesktopConfig from 'lighthouse/lighthouse-core/config/desktop-config.js'; |
8 | | -import { cdpConfig } from "../config/cdpConfig"; |
| 8 | +import { cdpConfig } from '../config/cdpConfig'; |
9 | 9 |
|
10 | 10 | jest.setTimeout(cdpConfig.maxTimeout); |
11 | 11 |
|
12 | 12 | test('Test Lighthouse', async () => { |
| 13 | + const port = await getFreePort(); |
| 14 | + const options = new chrome.Options(); |
13 | 15 |
|
14 | | - const port = await getFreePort(); |
15 | | - const options = new chrome.Options(); |
| 16 | + options.addArguments(`--remote-debugging-port=${port}`); |
| 17 | + options.excludeSwitches('--enable-logging'); |
16 | 18 |
|
17 | | - options.addArguments(`--remote-debugging-port=${port}`); |
18 | | - options.excludeSwitches('--enable-logging'); |
| 19 | + const driver = await new Builder() |
| 20 | + .forBrowser('chrome') |
| 21 | + .setChromeOptions(options) |
| 22 | + .build(); |
19 | 23 |
|
20 | | - const driver = await new Builder().forBrowser('chrome') |
21 | | - .setChromeOptions(options) |
22 | | - .build(); |
| 24 | + const googlePage = new GooglePage(driver); |
23 | 25 |
|
24 | | - const googlePage = new GooglePage(driver); |
| 26 | + const lighthouse = new Lighthouse(port); |
25 | 27 |
|
26 | | - const lighthouse = new Lighthouse(port); |
| 28 | + await lighthouse.initWorkFlow('Google search', DesktopConfig.settings); |
27 | 29 |
|
28 | | - await lighthouse.initWorkFlow('Google search', DesktopConfig.settings); |
| 30 | + await lighthouse.navigate('https://www.google.com'); |
29 | 31 |
|
30 | | - await lighthouse.navigate("https://www.google.com"); |
| 32 | + await lighthouse.startTrace('search operation'); |
31 | 33 |
|
32 | | - await lighthouse.startTrace('search operation'); |
| 34 | + await googlePage.search('test'); |
33 | 35 |
|
34 | | - await googlePage.search('test'); |
| 36 | + const res = await lighthouse.stopTrace(); |
35 | 37 |
|
36 | | - const res = await lighthouse.stopTrace(); |
| 38 | + await driver.quit(); |
37 | 39 |
|
38 | | - await driver.quit(); |
39 | | - |
40 | | - await lighthouse.generateFlowReport('lighthouse.html'); |
41 | | - |
42 | | - res.forEach((step) => { |
43 | | - expect(step.lhr.categories.performance.score).toBeGreaterThanOrEqual(0.8); |
44 | | - }) |
| 40 | + await lighthouse.generateFlowReport('lighthouse.html'); |
45 | 41 |
|
| 42 | + res.forEach((step) => { |
| 43 | + expect(step.lhr.categories.performance.score).toBeGreaterThanOrEqual(0.8); |
| 44 | + }); |
46 | 45 | }); |
0 commit comments