1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.libraries;
16
17 import java.time.Duration;
18 import java.util.List;
19
20 import org.htmlunit.WebDriverTestCase;
21 import org.htmlunit.junit.BrowserRunner;
22 import org.htmlunit.junit.annotation.Alerts;
23 import org.htmlunit.junit.annotation.HtmlUnitNYI;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.WebDriver;
29 import org.openqa.selenium.WebElement;
30
31
32
33
34
35
36
37
38
39
40
41 @RunWith(BrowserRunner.class)
42 public class TinyMceTest extends WebDriverTestCase {
43
44
45
46
47 @Test
48 @Alerts({"348", "0"})
49 public void api() throws Exception {
50 test("api", Integer.parseInt(getExpectedAlerts()[0]), Integer.parseInt(getExpectedAlerts()[1]));
51 }
52
53
54
55
56 @Test
57 @Alerts(DEFAULT = {"89", "0"},
58 CHROME = {"89", "1"},
59 EDGE = {"89", "1"})
60 @HtmlUnitNYI(CHROME = {"70", "50"},
61 EDGE = {"70", "50"},
62 FF = {"70", "50"},
63 FF_ESR = {"70", "50"})
64 public void basic() throws Exception {
65 test("basic", Integer.parseInt(getExpectedAlerts()[0]), Integer.parseInt(getExpectedAlerts()[1]));
66 }
67
68 private void test(final String fileName, final int expectedTotal, final int expectedFailed) throws Exception {
69 final String url = URL_FIRST + "tests/" + fileName + ".html";
70 assertNotNull(url);
71
72 final WebDriver driver = getWebDriver();
73 driver.get(url);
74
75 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
76 final WebElement result = driver.findElement(By.id("testresult"));
77 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
78
79 final WebElement totalSpan = result.findElement(By.xpath("./span[@class='all']"));
80 final int total = Integer.parseInt(totalSpan.getText());
81 assertEquals(expectedTotal, total);
82
83 final List<WebElement> failures = driver.findElements(By.xpath("//li[@class='fail']"));
84 final StringBuilder msg = new StringBuilder();
85 for (final WebElement failure : failures) {
86 msg.append(failure.getText());
87 msg.append("\n\n");
88 }
89
90 final WebElement failedSpan = result.findElement(By.xpath("./span[@class='bad']"));
91 final int failed = Integer.parseInt(failedSpan.getText());
92 assertEquals(expectedFailed, failed);
93 }
94
95
96
97
98
99 @Before
100 public void setUp() throws Exception {
101 startWebServer("src/test/resources/libraries/tinymce/3.2.7", null, null);
102 }
103 }