View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo.qunit;
21  
22  import org.junit.jupiter.api.Test;
23  import org.junit.jupiter.params.ParameterizedTest;
24  import org.junit.jupiter.params.provider.Arguments;
25  import org.junit.jupiter.params.provider.MethodSource;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.io.IOException;
30  import java.io.UnsupportedEncodingException;
31  import java.lang.invoke.MethodHandles;
32  import java.net.MalformedURLException;
33  import java.net.UnknownHostException;
34  import java.time.LocalTime;
35  import java.util.List;
36  import java.util.stream.Stream;
37  
38  class StandardTest extends SeleniumBase {
39  
40    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
41  
42    /**
43     * To test only a singe page, just change browser setup, 'portContextPath' and/or 'path'.
44     * Start the docker container with mvn -Pdocker-qunit-tests docker:start
45     */
46    @Test
47    void testSinglePage() throws MalformedURLException, UnknownHostException, UnsupportedEncodingException {
48      final Browser browser = Browser.chrome;
49      final String serverUrl = getServerUrls().get(0);
50      final String path = "content/10-intro/intro.xhtml";
51  
52      LOG.info("browser: " + browser + " - url: " + serverUrl + "/" + path);
53  
54      setupWebDriver(browser, serverUrl, path, false);
55      parseQUnitResults(browser, serverUrl, path);
56    }
57  
58    @ParameterizedTest
59    @MethodSource("standardTestProvider")
60    void testStandard(Browser browser, String serverUrl, String path, LocalTime startTime, int testSize, int testNo)
61        throws MalformedURLException, UnsupportedEncodingException {
62  
63      double percent = 100 * (double) testNo / testSize;
64      final String timeLeft = getTimeLeft(startTime, testSize, testNo);
65  
66      LOG.info("(" + String.format("%.2f", percent) + " % complete" + " | time left: " + timeLeft + ")"
67          + " browser: " + browser + " - url: " + serverUrl + "/" + path);
68  
69      if (isIgnored(serverUrl, path)) {
70        logIgnoreMessage(serverUrl, path);
71      } else {
72        setupWebDriver(browser, serverUrl, path, false);
73        parseQUnitResults(browser, serverUrl, path);
74      }
75    }
76  
77    private static Stream<Arguments> standardTestProvider() throws IOException {
78      final List<String> paths = getStandardTestPaths();
79      return getArguments(paths);
80    }
81  }