robotframework-browser icon indicating copy to clipboard operation
robotframework-browser copied to clipboard

Support Lighthouse

Open eldaduzman opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Google lighthouse is an awesome client side performance and accessibility testing tool.

It has a good integration with playwright using an nmp package.

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 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.

eldaduzman avatar Mar 05 '22 09:03 eldaduzman

@allcontributors please add @eldaduzman for ideas

aaltat avatar Mar 09 '22 20:03 aaltat

@aaltat

I've put up a pull request to add @eldaduzman! :tada:

allcontributors[bot] avatar Mar 09 '22 20:03 allcontributors[bot]

Can we close this one because persistent context keyword exists?

aaltat avatar Nov 12 '23 20:11 aaltat

@leeuwe Do you think we could move that issue as feature request to browser extensions repository?

Snooz82 avatar Nov 15 '23 14:11 Snooz82

Sure!

leeuwe avatar Nov 15 '23 14:11 leeuwe

closed in favour of https://github.com/MarketSquare/robotframework-browser-extensions/issues/15

Snooz82 avatar Nov 15 '23 15:11 Snooz82