-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support lighthouse reports #310
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work, now for the polishing ;)
src/main/java/com/xceptance/neodymium/util/LighthouseUtils.java
Outdated
Show resolved
Hide resolved
validateAudits(jsonFile); | ||
|
||
// add report html to allure | ||
Allure.addAttachment(reportName, "text/html", FileUtils.openInputStream(new File("target/" + reportName + ".report.html")), "html"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if any assertion is thrown, we won't add the report as an attachment. we need to first add it as an attachment, and afterwards, validate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
String assertAuditsString = Neodymium.configuration().lighthouseAssertAudits(); | ||
List<String> errorAudits = new ArrayList<>(); | ||
|
||
if (!assertAuditsString.isEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is null if not set, so calling isEmpty() on a null object will crash. Use StringUtils.isNotBlank(assertAuditString)
for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* The name of the Lighthouse report attachment in the Allure report | ||
* @throws Exception | ||
*/ | ||
public static void createLightHouseReport(WebDriver driver, String reportName) throws Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make the interface as simple as possible. There is no need to have the webdriver given as a parameter. Just use Neodymium.getWebdriver()
inside this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac")) | ||
{ | ||
Neodymium.configuration().setProperty("neodymium.lighthouse.binaryPath", "echo {\"categories\": {\"performance\": {\"score\": 0.5}, \"accessibility\": {\"score\": 0.5}, \"best-practices\": {\"score\": 0.5}, \"seo\": {\"score\": 0.5}}} > target/lighthouseUtilsReport.report.json"); | ||
builder = new ProcessBuilder("fabricatedHtml > target/lighthouseUtilsReport.report.html"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be changed to new ProcessBuilder("sh", "-c", "echo fabricatedHtml > target/lighthouseUtilsReport.report.html");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac")) | ||
{ | ||
builder = new ProcessBuilder(Neodymium.configuration().lighthouseBinaryPath(), "--chrome-flags=\"--ignore-certificate-errors\"", URL, "--port=" + Neodymium.getRemoteDebuggingPort(), "--preset=desktop", "--output=json", "--output=html", "--output-path=target/" + reportName + ".json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for linux please change this to call the shell by using new ProcessBuilder("sh", "-c", Neodymium.config....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac")) | ||
{ | ||
new ProcessBuilder(Neodymium.configuration().lighthouseBinaryPath(), "--version").start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for linux please change this to call the shell by using new ProcessBuilder("sh", "-c", Neodymium.config....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only the documentation of the audits property and the link to the documentation in the neo config (when finished)
* The name of the Lighthouse report attachment in the Allure report | ||
* @throws Exception | ||
*/ | ||
public static void createLightHouseReport(WebDriver driver, String reportName) throws Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac")) | ||
{ | ||
builder = new ProcessBuilder(Neodymium.configuration().lighthouseBinaryPath(), "--chrome-flags=\"--ignore-certificate-errors\"", URL, "--port=" + Neodymium.getRemoteDebuggingPort(), "--preset=desktop", "--output=json", "--output=html", "--output-path=target/" + reportName + ".json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
String assertAuditsString = Neodymium.configuration().lighthouseAssertAudits(); | ||
List<String> errorAudits = new ArrayList<>(); | ||
|
||
if (!assertAuditsString.isEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/main/java/com/xceptance/neodymium/util/LighthouseUtils.java
Outdated
Show resolved
Hide resolved
} | ||
if (errorAudits.size() > 0) | ||
{ | ||
throw new Exception("the following audits " + errorAudits + " contain errors that need to be fixed, please look into the corresponding html for further information"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac")) | ||
{ | ||
Neodymium.configuration().setProperty("neodymium.lighthouse.binaryPath", "echo {\"categories\": {\"performance\": {\"score\": 0.5}, \"accessibility\": {\"score\": 0.5}, \"best-practices\": {\"score\": 0.5}, \"seo\": {\"score\": 0.5}}} > target/lighthouseUtilsReport.report.json"); | ||
builder = new ProcessBuilder("fabricatedHtml > target/lighthouseUtilsReport.report.html"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
config/neodymium.properties
Outdated
# The actual value for the seo score varies alot, so consider using a lower threshold to avoid a lot of false alerts | ||
neodymium.lighthouse.assert.thresholdScore.seo = 0.5 | ||
|
||
# To be able to validate Lighthouse report audits, wo use internal json id's from the report itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
} | ||
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac")) | ||
{ | ||
new ProcessBuilder("sh", "-c", Neodymium.configuration().lighthouseBinaryPath(), "--version").start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several things here:
- We need to check for the error code as we did for windows
- the "sh" "c" parameter need to be removed to make it work (on my system) and the mac I tested on, recheck on another linux mashine is WIP.
- since this seems to be the main cause of pain and other users will have other setups, we should improve our error handling here. We should add the proccess output to the error message in cases something goes wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we have for cases (these two and the two where we actually create the report) where we need to start a process with a given set of parameters, check for the error code and collect the logs, we should create a seperate method for this, and just pass all the parameters we would give to the ProcessBuilder
Inside this method we could also add the PATH variable of the process to the error message in a failure case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we have a seperate method We can do some double safety and try each process with "sh" "-c" and if it fails we can do it without. that way we have an additional safety net for strange setups and will make sure our unit test mokup works as intendet ;)
added the possibility to create lighthouse reports