Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#327] Improvement: Support popup selectors with quotes #328

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/main/java/com/xceptance/neodymium/util/JavaScriptUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() + ");";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ public void testPopupBlocker()
Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,10 +16,11 @@ public void testPopupBlocker()
Map<String, String> 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);
}
}