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.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   * <p>Tests for compatibility with <a href="http://tinymce.moxiecode.com/">TinyMCE</a>.</p>
33   *
34   * <p>TODO: more tests to add</p>
35   *
36   * @author Daniel Gredler
37   * @author Marc Guillemot
38   * @author Frank Danek
39   * @author Ronald Brill
40   */
41  @RunWith(BrowserRunner.class)
42  public class TinyMceTest extends WebDriverTestCase {
43  
44      /**
45       * @throws Exception if an error occurs
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       * @throws Exception if an error occurs
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       * Performs pre-test initialization.
97       * @throws Exception if an error occurs
98       */
99      @Before
100     public void setUp() throws Exception {
101         startWebServer("src/test/resources/libraries/tinymce/3.2.7", null, null);
102     }
103 }