Skip to content

Commit

Permalink
Merge pull request #310 from Xceptance/support-lighthouse-reports
Browse files Browse the repository at this point in the history
Support lighthouse reports
  • Loading branch information
wurzelkuchen authored Dec 3, 2024
2 parents 45b9820 + 55167d4 commit ff72b1c
Show file tree
Hide file tree
Showing 7 changed files with 645 additions and 8 deletions.
39 changes: 39 additions & 0 deletions config/neodymium.properties
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,45 @@ neodymium.workInProgress = false
# If false: the test data json of the corresponding test does not get attached to the allure report
neodymium.report.enableTestDataInReport = true

#############################
#
# Lighthouse
#
#############################

# Specifies the path to the Lighthouse executable
# If Lighthouse is globally installed and available in PATH, use only the name of the Lighthouse binary
# If Lighthouse is not globally installed and available in PATH, use the absolute/relative path to the Lighthouse binary
neodymium.lighthouse.binaryPath = lighthouse

# Specifies the minimum acceptable score for the performance category in Lighthouse reports
# If the Lighthouse performance score falls below this threshold, the test will fail
# Range: 0.0 - 1.0 (representing 0% to 100%)
# The actual value for the performance score varies alot, so consider using a lower threshold to avoid a lot of false alerts
neodymium.lighthouse.assert.thresholdScore.performance = 0.5

# Specifies the minimum acceptable score for the accessibility category in Lighthouse reports
# If the Lighthouse accessibility score falls below this threshold, the test will fail
# Range: 0.0 - 1.0 (representing 0% to 100%)
# The actual value for the accessibility score varies alot, so consider using a lower threshold to avoid a lot of false alerts
neodymium.lighthouse.assert.thresholdScore.accessibility = 0.5

# Specifies the minimum acceptable score for the best practices category in Lighthouse reports
# If the Lighthouse best practices score falls below this threshold, the test will fail
# Range: 0.0 - 1.0 (representing 0% to 100%)
# The actual value for the best practices score varies alot, so consider using a lower threshold to avoid a lot of false alerts
neodymium.lighthouse.assert.thresholdScore.bestPractices = 0.5

# Specifies the minimum acceptable score for the seo category in Lighthouse reports
# If the Lighthouse seo score falls below this threshold, the test will fail
# Range: 0.0 - 1.0 (representing 0% to 100%)
# 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, we use internal json id's from the report itself
# A full list of all audit id's and their corresponding titles can be found here: https://github.com/Xceptance/neodymium/wiki/Reports#lighthouse-audit-validation
#neodymium.lighthouse.assert.audits =

#############################
#
# Proxy configuration properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openqa.selenium.firefox.GeckoDriverService.Builder;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.os.ExecutableFinder;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.HttpCommandExecutor;
Expand Down Expand Up @@ -235,6 +236,12 @@ else if (Neodymium.configuration().useProxy())
{
options.addArguments("--headless");
}

// find a free port for each chrome session (important for lighthouse)
var remoteDebuggingPort = PortProber.findFreePort();
Neodymium.setRemoteDebuggingPort(remoteDebuggingPort);
options.addArguments("--remote-debugging-port=" + remoteDebuggingPort);

if (config.getArguments() != null && config.getArguments().size() > 0)
{
options.addArguments(config.getArguments());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -84,13 +85,23 @@ public synchronized void run()
{
long start = new Date().getTime();

File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
writer.compressImageIfNeeded(file, recordingConfigurations.imageScaleFactor(), recordingConfigurations.imageQuality());
long delay = recordingConfigurations.oneImagePerMilliseconds() > duration ? recordingConfigurations.oneImagePerMilliseconds()
: duration;
writer.write(file, delay);
file.delete();
duration = new Date().getTime() - start;

try
{
File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
writer.compressImageIfNeeded(file, recordingConfigurations.imageScaleFactor(), recordingConfigurations.imageQuality());
long delay = recordingConfigurations.oneImagePerMilliseconds() > duration ? recordingConfigurations.oneImagePerMilliseconds()
: duration;
writer.write(file, delay);
file.delete();

}
catch (NoSuchWindowException e)
{
// catching the exception prevents the video from failing
}

duration = new Date().getTime() - start;
millis += duration;
turns++;
long sleep = recordingConfigurations.oneImagePerMilliseconds() - duration;
Expand Down
Loading

0 comments on commit ff72b1c

Please sign in to comment.