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/junit4/tests/PopupBlockerTest.java b/src/test/java/com/xceptance/neodymium/junit4/tests/PopupBlockerTest.java index 3ddb2f07..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,10 +17,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); 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 f9e04ab8..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 @@ -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); } }