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