Skip to content

Commit

Permalink
cleanup after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Dec 5, 2024
1 parent d77768f commit c21178a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 69 deletions.
2 changes: 1 addition & 1 deletion config/neodymium.properties
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

# Enables advanced screenshot capabilities with additional features
# When set to true, provides more sophisticated screenshot taking mechanisms
neodymium.screenshots.enableAdvancedScreenshots = true
neodymium.screenshots.enableAdvancedScreenshots = false

# Controls whether screenshots are taken for successful test scenarios
# When set to false, screenshots will not be captured for passing tests
Expand Down
179 changes: 113 additions & 66 deletions src/test/java/com/xceptance/neodymium/util/LighthouseUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,202 +20,249 @@ public void testLighthouseUtilsHappyPath() throws Exception
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.accessiblity", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.bestPractices", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.seo", "0.5");

Class<LighthouseUtils> clazz = LighthouseUtils.class;
Method runProcess = clazz.getDeclaredMethod("runProcess", String[].class);
runProcess.setAccessible(true);
Process p = null;
if (System.getProperty("os.name").toLowerCase().contains("win"))

if (System.getProperty("os.name").toLowerCase().contains("win"))
{
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 | echo makeCommentWork #");
p = (Process) runProcess.invoke(null, new Object[]{new String[]{"cmd.exe", "/c", "echo fabricatedHtml > target/lighthouseUtilsReport.report.html"}});
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 | echo makeCommentWork #");
p = (Process) runProcess.invoke(null, new Object[]
{
new String[]
{
"cmd.exe", "/c", "echo fabricatedHtml > target/lighthouseUtilsReport.report.html"
}
});
}
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac"))
{
try
try
{
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");
p = (Process) runProcess.invoke(null, new Object[]{new String[]{"sh", "-c", "echo fabricatedHtml > target/lighthouseUtilsReport.report.html"}});
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");
p = (Process) runProcess.invoke(null, new Object[]
{
new String[]
{
"sh", "-c", "echo fabricatedHtml > target/lighthouseUtilsReport.report.html"
}
});
}
catch (Exception e)
catch (Exception e)
{
p = (Process) runProcess.invoke(null, new Object[]{new String[]{"echo fabricatedHtml > target/lighthouseUtilsReport.report.html"}});
p = (Process) runProcess.invoke(null, new Object[]
{
new String[]
{
"echo fabricatedHtml > target/lighthouseUtilsReport.report.html"
}
});
}
}
else
else
{
throw new Exception("your current operation system is not supported, please use Windows, Linux or MacOS");
}

BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (r.readLine() != null)
{
continue;
}

Selenide.open("https://blog.xceptance.com/");

LighthouseUtils.createLightHouseReport("lighthouseUtilsReport");
}

@NeodymiumTest
public void testLighthouseUtilsPerformanceException() throws Exception
{
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.performance", "0.51");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.accessibility", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.bestPractices", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.seo", "0.5");
if (System.getProperty("os.name").toLowerCase().contains("win"))

if (System.getProperty("os.name").toLowerCase().contains("win"))
{
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 | echo makeCommentWork #");
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 | echo makeCommentWork #");
}
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");
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");
}
else
else
{
throw new Exception("your current operation system is not supported, please use Windows, Linux or MacOS");
}

Selenide.open("https://blog.xceptance.com/");
try

try
{
LighthouseUtils.createLightHouseReport("lighthouseUtilsReport");
}
catch (AssertionError e)
catch (AssertionError e)
{
Assert.assertTrue("the compared error messages doesn't match", e.getMessage().contains("The Lighthouse performance score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
Assert.assertTrue("the compared error messages doesn't match",
e.getMessage()
.contains("The Lighthouse performance score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
}
}

@NeodymiumTest
public void testLighthouseUtilsAccessibilityException() throws Exception
{
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.performance", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.accessibility", "0.51");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.bestPractices", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.seo", "0.5");
if (System.getProperty("os.name").toLowerCase().contains("win"))

if (System.getProperty("os.name").toLowerCase().contains("win"))
{
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 | echo makeCommentWork #");
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 | echo makeCommentWork #");
}
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");
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");
}
else
else
{
throw new Exception("your current operation system is not supported, please use Windows, Linux or MacOS");
}

Selenide.open("https://blog.xceptance.com/");
try

try
{
LighthouseUtils.createLightHouseReport("lighthouseUtilsReport");
}
catch (AssertionError e)
catch (AssertionError e)
{
Assert.assertTrue("the compared error messages doesn't match", e.getMessage().contains("The Lighthouse accessibility score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
Assert.assertTrue("the compared error messages doesn't match",
e.getMessage()
.contains("The Lighthouse accessibility score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
}
}

@NeodymiumTest
public void testLighthouseUtilsBestPracticesException() throws Exception
{
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.performance", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.accessibility", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.bestPractices", "0.51");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.seo", "0.5");
if (System.getProperty("os.name").toLowerCase().contains("win"))

if (System.getProperty("os.name").toLowerCase().contains("win"))
{
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 | echo makeCommentWork #");
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 | echo makeCommentWork #");
}
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");
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");
}
else
else
{
throw new Exception("your current operation system is not supported, please use Windows, Linux or MacOS");
}

Selenide.open("https://blog.xceptance.com/");
try

try
{
LighthouseUtils.createLightHouseReport("lighthouseUtilsReport");
}
catch (AssertionError e)
catch (AssertionError e)
{
Assert.assertTrue("the compared error messages doesn't match", e.getMessage().contains("The Lighthouse best practices score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
Assert.assertTrue("the compared error messages doesn't match",
e.getMessage()
.contains("The Lighthouse best practices score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
}
}

@NeodymiumTest
public void testLighthouseUtilsSeoException() throws Exception
{
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.performance", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.accessibility", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.bestPractices", "0.5");
Neodymium.configuration().setProperty("neodymium.lighthouse.assert.thresholdScore.seo", "0.51");
if (System.getProperty("os.name").toLowerCase().contains("win"))

if (System.getProperty("os.name").toLowerCase().contains("win"))
{
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 | echo makeCommentWork #");
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 | echo makeCommentWork #");
}
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");
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");
}
else
else
{
throw new Exception("your current operation system is not supported, please use Windows, Linux or MacOS");
}

Selenide.open("https://blog.xceptance.com/");
try

try
{
LighthouseUtils.createLightHouseReport("lighthouseUtilsReport");
}
catch (AssertionError e)
catch (AssertionError e)
{
Assert.assertTrue("the compared error messages doesn't match", e.getMessage().contains("The Lighthouse seo score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
Assert.assertTrue("the compared error messages doesn't match",
e.getMessage()
.contains("The Lighthouse seo score 0.5 doesn't exceed nor match the required threshold of 0.51, please improve the score to match expectations"));
}
}

@NeodymiumTest
public void testLighthouseUtilsBinNotFound() throws Exception
{
if (System.getProperty("os.name").toLowerCase().contains("win"))
if (System.getProperty("os.name").toLowerCase().contains("win"))
{
Neodymium.configuration().setProperty("neodymium.lighthouse.binaryPath", "programmWhichIsDefinitelyNotInstalled");
}
else if (System.getProperty("os.name").toLowerCase().contains("linux") || System.getProperty("os.name").toLowerCase().contains("mac"))
{
Neodymium.configuration().setProperty("neodymium.lighthouse.binaryPath", "programmWhichIsDefinitelyNotInstalled");
}
else
else
{
throw new Exception("your current operation system is not supported, please use Windows, Linux or MacOS");
}

Selenide.open("https://blog.xceptance.com/");
try

try
{
LighthouseUtils.createLightHouseReport("lighthouseUtilsReport");
}
catch (Exception e)
catch (Exception e)
{
Assert.assertTrue("the compared error messages doesn't match", e.getMessage().contains("lighthouse binary not found at"));
Assert.assertTrue("the compared error messages doesn't match",
e.getMessage().contains("please install lighthouse and add it to the PATH or enter the correct lighthouse binary location"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void testCollectionErrorDetailesDeactivated()
public void testCollectionErrorDetailesActivated()
{
Neodymium.configuration().setProperty("neodymium.report.showSelenideErrorDetails", "true");
Neodymium.configuration().setProperty("neodymium.screenshots.enableAdvancedScreenshots", "false");
Assertions.assertTrue(Neodymium.configuration().showSelenideErrorDetails());

try
Expand All @@ -91,9 +92,7 @@ public void testCollectionErrorDetailesActivated()
}
catch (AssertionError e)
{
System.out.println(e.getMessage());
assertExpectedMessageContains(e.getMessage(), "List size mismatch: expected: > 5, actual: 0, collection: #someUnknownIDForThisSepcificTest\n");
assertExpectedMessageContains(e.getMessage(), "Screenshot: ");
assertExpectedMessageContains(e.getMessage(), "Page source: ");
assertExpectedMessageContains(e.getMessage(), "Timeout: 0 ms.");
}
Expand Down

0 comments on commit c21178a

Please sign in to comment.