|
| 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.chartjs; |
| 16 | + |
| 17 | +import java.net.URL; |
| 18 | + |
| 19 | +import org.eclipse.jetty.server.Server; |
| 20 | +import org.htmlunit.WebDriverTestCase; |
| 21 | +import org.htmlunit.WebServerTestCase; |
| 22 | +import org.junit.jupiter.api.AfterAll; |
| 23 | +import org.junit.jupiter.api.BeforeAll; |
| 24 | +import org.junit.jupiter.api.Disabled; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | +import org.openqa.selenium.JavascriptExecutor; |
| 27 | +import org.openqa.selenium.WebDriver; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for compatibility with <a href="https://www.chartjs.org/">Chart.js</a>. |
| 31 | + * |
| 32 | + * @author Ronald Brill |
| 33 | + */ |
| 34 | +public class ChartJs4x5x0Test extends WebDriverTestCase { |
| 35 | + |
| 36 | + /** The server. */ |
| 37 | + protected static Server SERVER_; |
| 38 | + |
| 39 | + /** |
| 40 | + * @throws Exception if an error occurs |
| 41 | + */ |
| 42 | + @BeforeAll |
| 43 | + public static void startSesrver() throws Exception { |
| 44 | + SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/chartjs/4.5.0/", null); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @throws Exception if an error occurs |
| 49 | + */ |
| 50 | + @AfterAll |
| 51 | + public static void stopServer() throws Exception { |
| 52 | + if (SERVER_ != null) { |
| 53 | + SERVER_.stop(); |
| 54 | + SERVER_.destroy(); |
| 55 | + SERVER_ = null; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return the resource base URL |
| 61 | + */ |
| 62 | + protected URL getBaseUrl() { |
| 63 | + return URL_FIRST; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @throws Exception if the test fails |
| 68 | + */ |
| 69 | + @Test |
| 70 | + @Disabled("Fails because of the missing spread support") |
| 71 | + public void simpleBarChart() throws Exception { |
| 72 | + doTest("simple_bar_chart"); |
| 73 | + } |
| 74 | + |
| 75 | + private void doTest(final String filename) throws Exception { |
| 76 | + final WebDriver driver = getWebDriver(); |
| 77 | + driver.get(getBaseUrl() + filename + ".html"); |
| 78 | + |
| 79 | + // final WebElement chart = driver.findElement(By.id("myChart")); |
| 80 | + ((JavascriptExecutor) driver).executeScript("return document.getElementById('myLog').value = " |
| 81 | + + "document.getElementById('myChart').toDataURL('image/png') + '§'"); |
| 82 | + final String expected = loadExpectation("/libraries/chartjs/4.5.0/expectations/" + filename, ".expected"); |
| 83 | + verifyTextArea2(driver, expected); |
| 84 | + } |
| 85 | +} |
0 commit comments