From 24bad4af166bebf44208b6c61e6f23a1b8534704 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 13 Dec 2024 15:41:13 +0100 Subject: [PATCH 1/3] [#327] Improvement: Support popup selectors with quotes --- .../neodymium/util/JavaScriptUtils.java | 14 +++++++----- .../popupblocker/PopupBlockerTestclass.java | 22 +++++++++++++++---- .../popupblocker/PopupBlockerTestclass.java | 22 +++++++++++++++---- .../junit5/tests/PopupBlockerTest.java | 7 +++--- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/xceptance/neodymium/util/JavaScriptUtils.java b/src/main/java/com/xceptance/neodymium/util/JavaScriptUtils.java index cb04c28a..f9ecd5ac 100644 --- a/src/main/java/com/xceptance/neodymium/util/JavaScriptUtils.java +++ b/src/main/java/com/xceptance/neodymium/util/JavaScriptUtils.java @@ -113,12 +113,14 @@ public static void injectJavascriptPopupBlocker(String popupSelector) { String popupBlocker = "function popupBlocker()" + "{" + - " var popupElement = document.querySelector(\"" + popupSelector + "\");" + - " if(popupElement != null)" + - " {" + - " popupElement.click();" + - " console.log('Popup " + popupSelector + "closed')" + - " }" + + " var popupElement = document.querySelector('" + popupSelector.replaceAll("\"", "\\\\\"").replaceAll("'", + "\\\\\"") + + "');" + + " if(popupElement != null)" + + " {" + + " popupElement.click();" + + " console.log('Popup " + popupSelector.replaceAll("\"", "\\\\\"").replaceAll("'", "\\\\\"") + "closed')" + + " }" + "}" + "" + "setInterval(popupBlocker," + Neodymium.configuration().getPopupBlockerInterval() + ");"; diff --git a/src/test/java/com/xceptance/neodymium/junit4/testclasses/popupblocker/PopupBlockerTestclass.java b/src/test/java/com/xceptance/neodymium/junit4/testclasses/popupblocker/PopupBlockerTestclass.java index 87862e86..92cc88a1 100644 --- a/src/test/java/com/xceptance/neodymium/junit4/testclasses/popupblocker/PopupBlockerTestclass.java +++ b/src/test/java/com/xceptance/neodymium/junit4/testclasses/popupblocker/PopupBlockerTestclass.java @@ -19,16 +19,30 @@ public class PopupBlockerTestclass extends NeodymiumTest public void testPopUpIsBlocked() { Selenide.open("https://www.xceptance.com/"); - String popup = "var e = document.createElement(\"div\");\r\n" - + "e.innerHTML = \"testThing\";\r\n" - + "e.setAttribute('id','myWindow');\r\n" - + "e.setAttribute('onclick','this.remove()');\r\n" + String popup = "var e = document.createElement('div');" + + "e.innerHTML = 'testThing';" + + "e.setAttribute('id','myWindow');" + + "e.setAttribute('onclick','this.remove()');" + "document.body.appendChild(e);"; Selenide.executeJavaScript(popup, ""); Selenide.sleep(1500); $("#myWindow").shouldNotBe(visible); } + @Test + public void testPopUpWithQuotesSelectorIsBlocked() + { + Selenide.open("https://www.xceptance.com/"); + String popup = "var e = document.createElement('div');" + + "e.innerHTML = 'testThing';" + + "e.setAttribute('data-testid','closeIcon');" + + "e.setAttribute('onclick','this.remove()');" + + "document.body.appendChild(e);"; + Selenide.executeJavaScript(popup); + Selenide.sleep(1500); + $("[data-testid='closeIcon']").shouldNotBe(visible); + } + @Test public void testPopUpIsNotBlocked() { diff --git a/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java b/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java index f9e04ab8..d060ac78 100644 --- a/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java +++ b/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java @@ -15,16 +15,30 @@ public class PopupBlockerTestclass extends AbstractNeodymiumTest public void testPopUpIsBlocked() { Selenide.open("https://www.xceptance.com/"); - String popup = "var e = document.createElement(\"div\");\r\n" - + "e.innerHTML = \"testThing\";\r\n" - + "e.setAttribute('id','myWindow');\r\n" - + "e.setAttribute('onclick','this.remove()');\r\n" + String popup = "var e = document.createElement('div');" + + "e.innerHTML = 'testThing';" + + "e.setAttribute('id','myWindow');" + + "e.setAttribute('onclick','this.remove()');" + "document.body.appendChild(e);"; Selenide.executeJavaScript(popup, ""); Selenide.sleep(1500); $("#myWindow").shouldNotBe(visible); } + // @NeodymiumTest + public void testPopUpWithQuotesSelectorIsBlocked() + { + Selenide.open("https://www.xceptance.com/"); + String popup = "var e = document.createElement('div');" + + "e.innerHTML = 'testThing';" + + "e.setAttribute('data-testid','closeIcon');" + + "e.setAttribute('onclick','this.remove()');" + + "document.body.appendChild(e);"; + Selenide.executeJavaScript(popup); + Selenide.sleep(1500); + $("[data-testid='closeIcon']").shouldNotBe(visible); + } + @NeodymiumTest public void testPopUpIsNotBlocked() { diff --git a/src/test/java/com/xceptance/neodymium/junit5/tests/PopupBlockerTest.java b/src/test/java/com/xceptance/neodymium/junit5/tests/PopupBlockerTest.java index 9b4e4082..4ffa603f 100644 --- a/src/test/java/com/xceptance/neodymium/junit5/tests/PopupBlockerTest.java +++ b/src/test/java/com/xceptance/neodymium/junit5/tests/PopupBlockerTest.java @@ -3,9 +3,9 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import com.xceptance.neodymium.junit4.testclasses.popupblocker.PopupBlockerTestclass; +import com.xceptance.neodymium.junit5.testclasses.popupblocker.PopupBlockerTestclass; import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary; public class PopupBlockerTest extends AbstractNeodymiumTest @@ -16,10 +16,11 @@ public void testPopupBlocker() Map properties = new HashMap<>(); properties.put("neodymium.popup.custom", "#myWindow"); + properties.put("neodymium.popup.customWithQuotes", "[data-testid='closeIcon']"); addPropertiesForTest("temp-PopupBlockerTest-neodymium.properties", properties); NeodymiumTestExecutionSummary summary = run(PopupBlockerTestclass.class); - checkPass(summary, 3, 0); + checkPass(summary, 4, 0); } } From e413a78c6cf9185db7d3dc78a245b3fbfecac348 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Mon, 16 Dec 2024 15:11:53 +0100 Subject: [PATCH 2/3] [#327] fix popup blocker unit tests --- .../com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java | 2 +- .../junit5/testclasses/popupblocker/PopupBlockerTestclass.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java b/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java index 3ddb2f07..f8bb4d5d 100644 --- a/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java +++ b/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java @@ -21,6 +21,6 @@ public void testPopupBlocker() addPropertiesForTest("temp-PopupBlockerTest-neodymium.properties", properties); Result result = JUnitCore.runClasses(PopupBlockerTestclass.class); - checkPass(result, 3, 0); + checkPass(result, 4, 0); } } diff --git a/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java b/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java index d060ac78..94138310 100644 --- a/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java +++ b/src/test/java/com/xceptance/neodymium/junit5/testclasses/popupblocker/PopupBlockerTestclass.java @@ -25,7 +25,7 @@ public void testPopUpIsBlocked() $("#myWindow").shouldNotBe(visible); } - // @NeodymiumTest + @NeodymiumTest public void testPopUpWithQuotesSelectorIsBlocked() { Selenide.open("https://www.xceptance.com/"); From 4c33a31c5f06ee1b1882b08de7ae10e4ae9280b6 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Mon, 16 Dec 2024 15:18:10 +0100 Subject: [PATCH 3/3] [#327] add line to block popup with quotes --- .../com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java b/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java index f8bb4d5d..11ba33dc 100644 --- a/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java +++ b/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java @@ -17,6 +17,7 @@ public void testPopupBlocker() Map properties = new HashMap<>(); properties.put("neodymium.popup.custom", "#myWindow"); + properties.put("neodymium.popup.customWithQuotes", "[data-testid='closeIcon']"); addPropertiesForTest("temp-PopupBlockerTest-neodymium.properties", properties);