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.net.URL;
18  
19  import org.eclipse.jetty.server.Server;
20  import org.htmlunit.WebClient;
21  import org.htmlunit.WebDriverTestCase;
22  import org.htmlunit.WebServerTestCase;
23  import org.htmlunit.junit.annotation.Alerts;
24  import org.htmlunit.junit.annotation.HtmlUnitNYI;
25  import org.junit.jupiter.api.AfterAll;
26  import org.junit.jupiter.api.BeforeAll;
27  import org.junit.jupiter.api.Test;
28  import org.openqa.selenium.By;
29  import org.openqa.selenium.WebDriver;
30  import org.openqa.selenium.htmlunit.HtmlUnitDriver;
31  
32  /**
33   * Tests for https://github.com/slab/quill.
34   *
35   * @author Ronald Brill
36   */
37  public class QuillTest extends WebDriverTestCase {
38  
39      /** The server. */
40      protected static Server SERVER_;
41  
42      /**
43       * @throws Exception if an error occurs
44       */
45      @BeforeAll
46      public static void startSesrver() throws Exception {
47          SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/quill/", null);
48      }
49  
50      /**
51       * @throws Exception if an error occurs
52       */
53      @AfterAll
54      public static void stopServer() throws Exception {
55          if (SERVER_ != null) {
56              SERVER_.stop();
57              SERVER_.destroy();
58              SERVER_ = null;
59          }
60      }
61  
62      /**
63       * @return the resource base URL
64       */
65      protected URL getBaseUrl() {
66          return URL_FIRST;
67      }
68  
69      /**
70       * @throws Exception if the test fails
71       */
72      @Test
73      @Alerts("Bold Italic\\nHello World!\\nSome initial bold text")
74      @HtmlUnitNYI
75      public void basic() throws Exception {
76          // fails because the lib uses classes
77          doTest("QuillTest.html");
78      }
79  
80      private void doTest(final String filename) throws Exception {
81          final WebDriver driver = getWebDriver();
82          if (driver instanceof HtmlUnitDriver) {
83              final WebClient webClient = ((HtmlUnitDriver) driver).getWebClient();
84              webClient.getOptions().setThrowExceptionOnScriptError(false);
85          }
86  
87          driver.get(getBaseUrl() + filename);
88  
89          String content = driver.findElement(By.tagName("body")).getText();
90          content = content.replace("\r", "").replace("\n", "\\n");
91          assertEquals(getExpectedAlerts()[0], content);
92      }
93  }