Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit - integrate lighthouse #1350

Closed
wants to merge 2 commits into from
Closed

initial commit - integrate lighthouse #1350

wants to merge 2 commits into from

Conversation

chaudharydeepak
Copy link
Contributor

Draft PR for lighthouse integration

  • Relevant Issues : (compulsory)
  • Relevant PRs : (optional)
  • Type of change :
    • New feature

@chaudharydeepak
Copy link
Contributor Author

chaudharydeepak commented Oct 27, 2020

@ptrthomas - this is draft work - something on the lines of progress so far -

Summary -

  1. This solution relies on lighthouse module installed on the local machine - which possibly could be dockerized for docker based images.

  2. axe-core has a selenium driver integration library. From my understanding, Karate implements its own drivers - hence some work will be required to implement axe-core integration libraries. Otherwise axe provide node based api's - required to be installed locally - more here -> https://www.deque.com/axe/core-documentation/integrations/

  3. Lighthouse exposes cli or node module based api's for programmatic integration - nothing possibly in devtools protocol that we can use out-of-the-box. I believe, lighthouse starts its own devtools protocol sessions and has rules builtin to create reports / numbers out of the raw data fetched from devtools session.

  4. Google also provides lighthouse API - via PageSpeed Insights API: https://developers.google.com/speed/docs/insights/v5/about - which requires google credentials and is bit less responsive.

This is just a sample - wanted to pick your brain before going too further with this. Please let me know, Thank you for the opportunity.

@@ -138,4 +139,6 @@

void robot(String expression);

void lightHouseWrapper(String URL, List<String> options) throws IOException, InterruptedException;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapper around node installed lighthouse module. This takes the URL to analyze and is configurable [ options ].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all driver stuff I prefer this as a driver.lighthouse() API

I know, it is a shift from how karate started, but something I think about. some thoughts here: #398

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptrthomas - actually, this capability isn't linked to driver, hence I didn't placed it there. Lighthouse is cli based, and creates its own cdp session.

@@ -222,4 +226,24 @@ public static String fixJavaScriptFunction(String text) {
}
}

public static class KStreamGobbler implements Runnable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utility method to invoke lighthouse on underlying OS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand. is this a CLI ? do be aware of the utilities that already exist: https://stackoverflow.com/a/62911366/143475

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - its pretty much same thing as Karate CLI support -

@@ -1149,4 +1151,28 @@ public void stop(StepResult lastStepResult) {
}
}

public void lightHouseWrapperAction(String URL, List<String> options) throws IOException, InterruptedException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual lighthouse wrapper implementation - this can be configured further for many different options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it IS a CLI - ! see my comment above. I think you should first get that working as a custom feature and experiment - that may be a good enough first version / experiment

Copy link
Contributor Author

@chaudharydeepak chaudharydeepak Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah! actually, in that case we might not need any of this at all - since Karate CLI support is good enough to run this all -

* def proc = karate.fork('lighthouse https://github.com/login --only-categories=accessibility,performance -- output=json --emulated-form-factor=none --throttling-method=provided')
* proc.waitSync()
* match proc.exitCode == 0

and I hope there is support to parse the response from command to fetch scores / details for categories like accessibility / performance etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so let us start with this simple approach then. this is a good starting point to invite more contributions - at least it helps others including me to get up and running with axe / lighthouse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so anything further needed for this work? since its all pre-existing with CLI support...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think for now this PR can be parked. instead I think if you create a Git example project maybe with a Docker script included that shows how you can call axe / lighthouse and integrate into a karate test via CLI - that would be a great reference that we can build on. does that make sense ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure, will do. Thank you.

* print LHR.categories.accessibility.score
* print LHR.categories.performance.score
#* match LHR.categories.accessibility.score == 0.96
#* match LHR.categories.performance.score == 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible further work to check for > , < threshold values on accessibility / performance etc scores. Additionally, we can generate complete report.

@@ -968,4 +969,29 @@ public void inputFile(String locator, String... relativePaths) {
method("DOM.setFileInputFiles").param("files", files).param("nodeId", nodeId).send();
}

public void enableAccessibility()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attempted devtools protocols around -

  1. enable accessibility -> getFullAXTree ( this tree by itself isnt useful). Need some standard implementations to parse it.

  2. enable audits -> this generates events around issues primarily CORS / mixed content type issues.

  3. enable performance -> getMetrics gives current page load metrics.

All above not much useful ( except performance, which is already provided by lighthouse ).

Just wanted to demonstrate the attempt :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm can you point to a sample of getFullAXTree result if really needed, we can write a custom parser. I'm confident of doing these things if it is JSON. the new rewrite code can even handle scraping HTML BTW

@@ -138,4 +139,6 @@

void robot(String expression);

void lightHouseWrapper(String URL, List<String> options) throws IOException, InterruptedException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all driver stuff I prefer this as a driver.lighthouse() API

I know, it is a shift from how karate started, but something I think about. some thoughts here: #398

@@ -222,4 +226,24 @@ public static String fixJavaScriptFunction(String text) {
}
}

public static class KStreamGobbler implements Runnable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand. is this a CLI ? do be aware of the utilities that already exist: https://stackoverflow.com/a/62911366/143475

@@ -1149,4 +1151,28 @@ public void stop(StepResult lastStepResult) {
}
}

public void lightHouseWrapperAction(String URL, List<String> options) throws IOException, InterruptedException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it IS a CLI - ! see my comment above. I think you should first get that working as a custom feature and experiment - that may be a good enough first version / experiment

@@ -968,4 +969,29 @@ public void inputFile(String locator, String... relativePaths) {
method("DOM.setFileInputFiles").param("files", files).param("nodeId", nodeId).send();
}

public void enableAccessibility()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm can you point to a sample of getFullAXTree result if really needed, we can write a custom parser. I'm confident of doing these things if it is JSON. the new rewrite code can even handle scraping HTML BTW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants