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.ArrayList;
19  import java.util.Arrays;
20  import java.util.List;
21  
22  import org.eclipse.jetty.server.Server;
23  import org.htmlunit.WebDriverTestCase;
24  import org.htmlunit.WebServerTestCase;
25  import org.htmlunit.junit.BrowserRunner;
26  import org.htmlunit.junit.annotation.Alerts;
27  import org.junit.AfterClass;
28  import org.junit.BeforeClass;
29  import org.junit.Test;
30  import org.junit.runner.RunWith;
31  import org.openqa.selenium.By;
32  import org.openqa.selenium.WebDriver;
33  import org.openqa.selenium.WebElement;
34  
35  /**
36   * Tests for compatibility with version 1.2.1 of the <a href="http://mootools.net/">MooTools JavaScript library</a>.
37   *
38   * @author Daniel Gredler
39   * @author Marc Guillemot
40   * @author Frank Danek
41   * @author Ronald Brill
42   */
43  @RunWith(BrowserRunner.class)
44  public class MooTools121Test extends WebDriverTestCase {
45  
46      private static Server SERVER_;
47  
48      /**
49       * @throws Exception if an error occurs
50       */
51      @BeforeClass
52      public static void startSesrver() throws Exception {
53          SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/mootools/1.2.1", null);
54      }
55  
56      /**
57       * @throws Exception if an error occurs
58       */
59      @AfterClass
60      public static void stopServer() throws Exception {
61          if (SERVER_ != null) {
62              SERVER_.stop();
63              SERVER_.destroy();
64              SERVER_ = null;
65          }
66      }
67  
68      /**
69       * @throws Exception if an error occurs
70       */
71      @Alerts({"364", "1", "0",
72               "should return the function bound to an object with multiple arguments"})
73      @Test
74      public void mooTools() throws Exception {
75          final WebDriver driver = getWebDriver();
76          driver.get(URL_FIRST + "Specs/index.html");
77  
78          driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(60));
79          driver.findElement(By.xpath("id('progress')[text() = '100']"));
80          // usually this need 40s but sometimes our build machine is slower
81          // this is not a performance test, we only like to ensure that all
82          // functionality is running
83  
84          final List<WebElement> failed = driver.findElements(By.xpath("//li[@class = 'exception']/h4"));
85          final List<String> failures = new ArrayList<>();
86          for (final WebElement elt : failed) {
87              failures.add(elt.getText());
88          }
89  
90          // final File tmpFile = File.createTempFile("htmlunit", "mootools.html");
91          // System.out.println(tmpFile.getAbsolutePath());
92          // FileUtils.writeStringToFile(tmpFile, driver.getPageSource());
93  
94          assertEquals(Arrays.copyOfRange(getExpectedAlerts(), 3, getExpectedAlerts().length), failures);
95  
96          assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("total_examples")).getText());
97          assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("total_failures")).getText());
98          assertEquals(getExpectedAlerts()[2], driver.findElement(By.id("total_errors")).getText());
99      }
100 }