From c21178ad6b84a7aff27884c2b39d19c76630ad5c Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Thu, 5 Dec 2024 10:16:09 +0100 Subject: [PATCH] cleanup after merge --- config/neodymium.properties | 2 +- .../neodymium/util/LighthouseUtilsTest.java | 179 +++++++++++------- .../SelenideErrorDetailsFormatterTest.java | 3 +- 3 files changed, 115 insertions(+), 69 deletions(-) diff --git a/config/neodymium.properties b/config/neodymium.properties index b295ef3a..ff18b926 100644 --- a/config/neodymium.properties +++ b/config/neodymium.properties @@ -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 diff --git a/src/test/java/com/xceptance/neodymium/util/LighthouseUtilsTest.java b/src/test/java/com/xceptance/neodymium/util/LighthouseUtilsTest.java index 001c0294..3aa1e56c 100644 --- a/src/test/java/com/xceptance/neodymium/util/LighthouseUtilsTest.java +++ b/src/test/java/com/xceptance/neodymium/util/LighthouseUtilsTest.java @@ -20,45 +20,67 @@ 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 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 { @@ -66,32 +88,38 @@ public void testLighthouseUtilsPerformanceException() throws Exception 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 { @@ -99,32 +127,38 @@ public void testLighthouseUtilsAccessibilityException() throws Exception 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 { @@ -132,32 +166,38 @@ public void testLighthouseUtilsBestPracticesException() throws Exception 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 { @@ -165,36 +205,42 @@ public void testLighthouseUtilsSeoException() throws Exception 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"); } @@ -202,20 +248,21 @@ else if (System.getProperty("os.name").toLowerCase().contains("linux") || System { 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")); } } } \ No newline at end of file diff --git a/src/test/java/com/xceptance/neodymium/util/SelenideErrorDetailsFormatterTest.java b/src/test/java/com/xceptance/neodymium/util/SelenideErrorDetailsFormatterTest.java index 1a085aca..2b91d3f2 100644 --- a/src/test/java/com/xceptance/neodymium/util/SelenideErrorDetailsFormatterTest.java +++ b/src/test/java/com/xceptance/neodymium/util/SelenideErrorDetailsFormatterTest.java @@ -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 @@ -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."); }