|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require "webdrivers"
|
4 |
| - |
5 |
| -# This class based on https://github.com/smontanari/qunit-selenium, with a few tweaks to make it easier to read output. |
6 |
| -# The license from https://github.com/smontanari/qunit-selenium is enclosed: |
7 |
| -# |
8 |
| -# The MIT License (MIT) |
9 |
| -# |
10 |
| -# Copyright (c) 2014 Silvio Montanari |
11 |
| -# |
12 |
| -# Permission is hereby granted, free of charge, to any person obtaining a copy |
13 |
| -# of this software and associated documentation files (the "Software"), to deal |
14 |
| -# in the Software without restriction, including without limitation the rights |
15 |
| -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
16 |
| -# copies of the Software, and to permit persons to whom the Software is |
17 |
| -# furnished to do so, subject to the following conditions: |
18 |
| -# |
19 |
| -# The above copyright notice and this permission notice shall be included in all |
20 |
| -# copies or substantial portions of the Software. |
21 |
| -# |
22 |
| -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
23 |
| -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
24 |
| -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
25 |
| -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
26 |
| -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
27 |
| -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
28 |
| -# SOFTWARE. |
29 |
| - |
30 |
| -class TestRun |
31 |
| - TestResult = Struct.new(:tests, :assertions, :duration, :raw_output) |
32 |
| - |
33 |
| - ID_TESTRESULT = "qunit-testresult" |
34 |
| - ID_TESTS = "qunit-tests" |
35 |
| - |
36 |
| - def initialize(driver) |
37 |
| - @qunit_testresult = driver[ID_TESTRESULT] |
38 |
| - @qunit_tests = driver[ID_TESTS] |
39 |
| - end |
40 |
| - |
41 |
| - def completed? |
42 |
| - @qunit_testresult.text =~ /Tests completed/ |
43 |
| - end |
44 |
| - |
45 |
| - def result |
46 |
| - assertions = { total: total_assertions, passed: passed_assertions, failed: failed_assertions } |
47 |
| - tests = { total: total_tests, passed: pass_tests, failed: fail_tests } |
48 |
| - TestResult.new(tests, assertions, duration, raw_output) |
49 |
| - end |
50 |
| - |
51 |
| - private |
52 |
| - def raw_output |
53 |
| - @qunit_tests.text |
54 |
| - end |
55 |
| - |
56 |
| - def duration |
57 |
| - match = /Tests completed in (?<milliseconds>\d+) milliseconds/.match @qunit_testresult.text |
58 |
| - match[:milliseconds].to_i / 1000 |
59 |
| - end |
60 |
| - |
61 |
| - %w(total passed failed).each do |result| |
62 |
| - define_method("#{result}_assertions".to_sym) do |
63 |
| - @qunit_testresult.find_elements(:class, result).first.text.to_i |
64 |
| - end |
65 |
| - end |
66 |
| - |
67 |
| - def total_tests |
68 |
| - @qunit_tests.find_elements(:css, "##{ID_TESTS} > *").count |
69 |
| - end |
70 |
| - |
71 |
| - %w(pass fail).each do |result| |
72 |
| - define_method("#{result}_tests".to_sym) do |
73 |
| - @qunit_tests.find_elements(:css, "##{ID_TESTS} > .#{result}").count |
74 |
| - end |
75 |
| - end |
76 |
| -end |
| 4 | +require_relative "test_run" |
77 | 5 |
|
78 | 6 | driver = if ARGV[1]
|
79 | 7 | ::Selenium::WebDriver.for(:remote, url: ARGV[1], desired_capabilities: :chrome)
|
|
0 commit comments