Skip to content

Commit 82ebd82

Browse files
committed
chore: fix test
1 parent 1f2bb26 commit 82ebd82

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

jakarta-test/src/test/java/org/owasp/encoder/testing/jakarta_test/ItemControllerTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
package org.owasp.encoder.testing.jakarta_test;
66

77
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertNull;
89
import org.junit.jupiter.api.BeforeAll;
910
import org.junit.jupiter.api.Test;
1011
import org.openqa.selenium.By;
12+
import org.openqa.selenium.NoSuchElementException;
1113
import org.openqa.selenium.WebElement;
1214
import org.openqa.selenium.chrome.ChromeOptions;
1315
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -29,7 +31,6 @@ public class ItemControllerTest {
2931
@Container
3032
static BrowserWebDriverContainer<?> container = new BrowserWebDriverContainer<>().
3133
withCapabilities(new ChromeOptions());
32-
3334

3435
@LocalServerPort
3536
private int port;
@@ -42,10 +43,20 @@ static void beforeAll(@Autowired Environment environment) {
4243

4344
@Test
4445
void shouldDisplayMessage() {
45-
RemoteWebDriver browser = new RemoteWebDriver(container.getSeleniumAddress(), new ChromeOptions());
46+
RemoteWebDriver browser = new RemoteWebDriver(container.getSeleniumAddress(), new ChromeOptions());
4647
browser.get("http://host.testcontainers.internal:" + port + "/jakarta-test/item/viewItems");
47-
assertEquals("top&lt;script&gt;alert(1)&lt;/script&gt;", browser.findElement(By.id("b2")).getText());
48-
assertEquals("fancy &lt;script&gt;alert(1)&lt;/script&gt;", browser.findElement(By.id("c2")).getText());
48+
WebElement first = browser.findElement(By.id("b2"));
49+
WebElement second = browser.findElement(By.id("c2"));
50+
assertEquals("top<script>alert(1)</script>", first.getText());
51+
assertEquals("fancy <script>alert(1)</script>", second.getText());
52+
//todo yes - there are much better ways to check for an exception in junit
53+
NoSuchElementException exception = null;
54+
try {
55+
first.findElement(By.tagName("script"));
56+
} catch (NoSuchElementException ex) {
57+
exception = ex;
58+
}
59+
assertNull(exception);
4960

5061
}
5162
}

0 commit comments

Comments
 (0)