MarketSquare / MarketSquare/robotframework-browser-extensions

Support Lighthouse (Browser #1832)

Open
#15 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
23
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Originally posten in https://github.com/MarketSquare/robotframework-browser/issues/1832
by [eldaduzman](https://github.com/eldaduzman) opened [on Mar 5, 2022](https://github.com/MarketSquare/robotframework-browser/issues/1832#issue-1160299836)

Moved...

> **Is your feature request related to a problem? Please describe.**
>
> [Google lighthouse](https://developers.google.com/web/tools/lighthouse) is an awesome client side performance and accessibility testing tool.
>
> It has a good integration with playwright using an [nmp package](https://www.npmjs.com/package/playwright-lighthouse).
>
> It can be very easily used by rf-browser with JS extension, For example:
>
> js-extensions/rfbrowser-lighthouse.js:
>
> ```
> const { playAudit } = require('playwright-lighthouse');
> var path = require('path');
> async function runGoogleLighthouse(page, args) {
> await playAudit({
> page: page,
> port: args[0],
> thresholds: {
> performance: 20,
> accessibility: 80,
> 'best-practices': 20,
> seo: 80,
> pwa: 20,
> },
> reports: {
> formats: {
> html: true,
> csv: true,
> },
> directory: path.join(args[1], `lighthouse`)
> }
> });
> }
> runGoogleLighthouse.rfdoc = "Executes googles lighthouse on current page context";
> exports.__esModule = true;
> exports.runGoogleLighthouse = runGoogleLighthouse;
> ```
>
> test.robot:
>
> ```
> *** Settings ***
> Library Browser jsextension=${CURDIR}/js-extensions/rfbrowser-lighthouse.js
> Library Collections
>
> *** Variables ***
> ${PORT} 9222
>
> *** Test Cases ***
> Example Test
> ${args} Create List --remote-debugging-port=${PORT}
> New Context args=${args}
> New Browser headless=false
> New Page https://playwright.dev
>
> Run Google Lighthouse ${PORT} ${CURDIR}
> ```
>
> The problem is when you need to authenticate. Lighthouse opens a new browser context and this means that all authentication fields are gone.
>
> **Describe the solution you'd like** One option is to use **Persistent Context** with playwrights [launchPersistentContext](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context) function. This can take a directory for storage and other properties and then when lighthouse is activated it keeps the context.
>
> So I guess adding a `new persistent context` keyword which takes a path as first input and all the other context arguments next would solve this problem.
>
> **Describe alternatives you've considered** Maybe it is possible to explicitly support executing lighthouse from rf-browser using a designated keyword, however this might not be flexible enough, + it could require too much maintenance efforts.
>
> **Additional context** I've tried to create a persistent context with a js extention:
>
> ```
> async function getPersistentContextPage(page, args, logger, playwright) {
> tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix));
> logger(tmpDir);
> context= await playwright['chromium'].launchPersistentContext(tmpDir, {
> args: ['--remote-debugging-port=9222'],
> headless: false
> });
> logger('done creating');
>
> return context
> }
> ```
>
> But it's not being stored on rf-browsers cache so it doesn't solve the problem.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with js-extensions/rfbrowser-lighthouse.js and test.robot, then trace the Browser keywords used by New Context and New Browser. The change is complete when a persistent context can be created with the requested path and context arguments, remains available to Lighthouse, and preserves authentication for the example flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, playwright
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.