Skip to content

Commit

Permalink
Update user-flow.md to reflect current release
Browse files Browse the repository at this point in the history
- Change flow import path from `import lighthouse from 'lighthouse/core/api.js';` to `import {startFlow} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';`

- remove `startNavigation`/`endNavigation`

- change interactive navigation with `startNavigation`/`endNavigation` to a callback navigation

- change `beginTimepsan` to `startTimespan`
  • Loading branch information
ChristopherPHolder authored Dec 11, 2022
1 parent 03674e9 commit 35b25e4
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions docs/user-flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ In DevTools, navigation is easy: ensure it's the selected mode and then click _A
```js
import {writeFileSync} from 'fs';
import puppeteer from 'puppeteer';
import lighthouse from 'lighthouse/core/api.js';
import {startFlow} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';

(async function() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const flow = await lighthouse.startFlow(page);
const flow = await startFlow(page);

// Navigate with a URL
await flow.navigate('https://example.com');
Expand All @@ -55,11 +55,6 @@ import lighthouse from 'lighthouse/core/api.js';
await page.click('a.link');
});

// Navigate with startNavigation/endNavigation
await flow.startNavigation();
await page.click('a.link');
await flow.endNavigation();

This comment has been minimized.

Copy link
@ChristopherPHolder

ChristopherPHolder Dec 11, 2022

Author Contributor

Should this also be converted into a callback?

await flow.navigate(async () => await page.click('a.link'));

This comment has been minimized.

Copy link
@adamraine

adamraine Dec 12, 2022

Member

No there is another example using a callback above it

await browser.close();
writeFileSync('report.html', await flow.generateReport());
})();
Expand All @@ -75,8 +70,6 @@ Instead of providing a URL to navigate to, you can provide a callback function o
This callback function _must_ perform an action that will trigger a navigation. Any interactions completed before the callback promise resolves will be captured by the navigation.

The `startNavigation`/`endNavigation` functions _must_ surround an action that triggers a navigation. Any interactions completed after `startNavigation` is invoked and before `endNavigation` is invoked will be captured by the navigation.

### Timespan

<img src="https://user-images.githubusercontent.com/39191/170560055-fb599418-c94d-44bf-9921-be4dce6abccf.png">
Expand All @@ -90,15 +83,15 @@ In DevTools, select "Timespan" as the mode and click _Start timespan_. Record wh
```js
import {writeFileSync} from 'fs';
import puppeteer from 'puppeteer';
import lighthouse from 'lighthouse/core/api.js';
import {startFlow} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';

(async function() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://secret.login');
const flow = await lighthouse.startFlow(page);
const flow = await startFlow(page);

await flow.beginTimespan();
await flow.startTimespan();
await page.type('#password', 'L1ghth0useR0cks!');
await page.click('#login');
await page.waitForSelector('#dashboard');
Expand All @@ -125,13 +118,13 @@ In DevTools, select "Snapshot" as the mode. Set up the page in the state you wan
```js
import {writeFileSync} from 'fs';
import puppeteer from 'puppeteer';
import lighthouse from 'lighthouse/core/api.js';
import {startFlow} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';

(async function() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const flow = await lighthouse.startFlow(page);
const flow = await startFlow(page);

await page.click('#expand-sidebar');
await flow.snapshot();
Expand Down Expand Up @@ -164,7 +157,7 @@ The below example codifies a user flow for an ecommerce site where the user navi
import {writeFileSync} from 'fs';
import puppeteer from 'puppeteer';
import * as pptrTestingLibrary from 'pptr-testing-library';
import lighthouse from 'lighthouse/core/api.js';
import {startFlow} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';

const {getDocument, queries} = pptrTestingLibrary;

Expand All @@ -182,15 +175,13 @@ async function search(page) {
// Setup the browser and Lighthouse.
const browser = await puppeteer.launch();
const page = await browser.newPage();
const flow = await lighthouse.startFlow(page);
const flow = await startFlow(page);

// Phase 1 - Navigate to the landing page.
await flow.navigate('https://www.bestbuy.com');

// Phase 2 - Interact with the page and submit the search form.
await flow.startTimespan();
await search(page);
await flow.endTimespan();
await flow.navigate(async () => await search(page));

// Phase 3 - Analyze the new state.
await flow.snapshot();
Expand Down

0 comments on commit 35b25e4

Please sign in to comment.