View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
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.annotation.Alerts;
22  import org.htmlunit.junit.annotation.HtmlUnitNYI;
23  import org.junit.jupiter.api.BeforeEach;
24  import org.junit.jupiter.api.Test;
25  import org.openqa.selenium.By;
26  import org.openqa.selenium.WebDriver;
27  import org.openqa.selenium.WebElement;
28  
29  /**
30   * <p>Tests for compatibility with <a href="http://tinymce.moxiecode.com/">TinyMCE</a>.</p>
31   *
32   * <p>TODO: more tests to add</p>
33   *
34   * @author Daniel Gredler
35   * @author Marc Guillemot
36   * @author Frank Danek
37   * @author Ronald Brill
38   */
39  public class TinyMceTest extends WebDriverTestCase {
40  
41      /**
42       * @throws Exception if an error occurs
43       */
44      @Test
45      @Alerts({"348", "0"})
46      public void api() throws Exception {
47          test("api", Integer.parseInt(getExpectedAlerts()[0]), Integer.parseInt(getExpectedAlerts()[1]));
48      }
49  
50      /**
51       * @throws Exception if an error occurs
52       */
53      @Test
54      @Alerts(DEFAULT = {"89", "0"},
55              CHROME = {"89", "1"},
56              EDGE = {"89", "1"})
57      @HtmlUnitNYI(CHROME = {"70", "50"},
58              EDGE = {"70", "50"},
59              FF = {"70", "50"},
60              FF_ESR = {"70", "50"})
61      public void basic() throws Exception {
62          test("basic", Integer.parseInt(getExpectedAlerts()[0]), Integer.parseInt(getExpectedAlerts()[1]));
63      }
64  
65      private void test(final String fileName, final int expectedTotal, final int expectedFailed) throws Exception {
66          final String url = URL_FIRST + "tests/" + fileName + ".html";
67          assertNotNull(url);
68  
69          final WebDriver driver = getWebDriver();
70          driver.get(url);
71  
72          driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
73          final WebElement result = driver.findElement(By.id("testresult"));
74          driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
75  
76          final WebElement totalSpan = result.findElement(By.xpath("./span[@class='all']"));
77          final int total = Integer.parseInt(totalSpan.getText());
78          assertEquals(expectedTotal, total);
79  
80          final List<WebElement> failures = driver.findElements(By.xpath("//li[@class='fail']"));
81          final StringBuilder msg = new StringBuilder();
82          for (final WebElement failure : failures) {
83              msg.append(failure.getText());
84              msg.append("\n\n");
85          }
86  
87          final WebElement failedSpan = result.findElement(By.xpath("./span[@class='bad']"));
88          final int failed = Integer.parseInt(failedSpan.getText());
89          assertEquals(expectedFailed, failed);
90      }
91  
92      /**
93       * Performs pre-test initialization.
94       * @throws Exception if an error occurs
95       */
96      @BeforeEach
97      public void setUp() throws Exception {
98          startWebServer("src/test/resources/libraries/tinymce/3.2.7", null, null);
99      }
100 }