generic_test 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +6 -8
- data/.rspec +1 -1
- data/ChangeLog +9 -0
- data/README.md +13 -1
- data/exe/generic_test +7 -2
- data/lib/generic_test/page.rb +7 -2
- data/lib/generic_test/setup.rb +6 -1
- data/lib/generic_test/version.rb +1 -1
- data/lib/generic_test.rb +3 -0
- data/spec/generic_test_spec.rb +63 -13
- data/test_site/about.html +2 -1
- data/test_site/sub_page.html +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa5ac1b64df0509fe04187e155f7a5ea61d91abe6e69118f907128dd5debd536
|
4
|
+
data.tar.gz: 0d969885b9c68bc367ef7a0e2f3e57e273106fb23850247c42ca9df58af69d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bafdce738fd92376ee241cf140413ff55e82def63a08a26ff7288714daa424f588dce326f66729d5b7aa3647593c4c6351bc89956e7af02161553d664fa3220c
|
7
|
+
data.tar.gz: b0c8409d760eed8c9df56837c8b98652e7166f801faf7cb4d66abd3d520c109804e6222ec1c6b9f9ed42ff55f344937c97c36ce016e21a8af50c383126ed0be9
|
data/.gitlab-ci.yml
CHANGED
@@ -8,7 +8,7 @@ docker_build:
|
|
8
8
|
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
|
9
9
|
DOCKER_HOST: tcp://docker:2376
|
10
10
|
DOCKER_TLS_CERTDIR: "/certs"
|
11
|
-
stage:
|
11
|
+
stage: deploy # Part of a later stage
|
12
12
|
services:
|
13
13
|
- docker:20.10.11-dind
|
14
14
|
image: docker:20.10.11
|
@@ -18,12 +18,10 @@ docker_build:
|
|
18
18
|
- docker build -t $CI_REGISTRY_IMAGE:latest .
|
19
19
|
- docker run -t $CI_REGISTRY_IMAGE:latest generic_test page samuel-garratt.gitlab.io/generic_test/about.html
|
20
20
|
- docker push $CI_REGISTRY_IMAGE:latest
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
changes:
|
26
|
-
- "*.md"
|
21
|
+
only:
|
22
|
+
- master
|
23
|
+
needs: ["test"]
|
24
|
+
when: manual
|
27
25
|
|
28
26
|
test:
|
29
27
|
image: registry.gitlab.com/samuel-garratt/generic_test
|
@@ -51,7 +49,7 @@ example_test:
|
|
51
49
|
artifacts:
|
52
50
|
paths:
|
53
51
|
- logs/*.xml
|
54
|
-
-
|
52
|
+
- logs/*.html
|
55
53
|
reports:
|
56
54
|
junit: logs/*.xml
|
57
55
|
expire_in: 1 week
|
data/.rspec
CHANGED
data/ChangeLog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
Version 0.3.1
|
2
|
+
* Going through subpages goes 1 level deeper to subpages of subpages
|
3
|
+
|
4
|
+
Version 0.3.0
|
5
|
+
* Added option to test all subpages and skip spellcheck
|
6
|
+
|
7
|
+
Version 0.2.3
|
8
|
+
* Put HTML report into logs folder and mention sourcing it
|
9
|
+
|
1
10
|
Version 0.2.2
|
2
11
|
* Ignore telephone numbers in links
|
3
12
|
|
data/README.md
CHANGED
@@ -16,6 +16,18 @@ To get a log of your tests share a volume with the container.
|
|
16
16
|
|
17
17
|
> Please share this volume from an empty folder. Running from within another gem might cause an issue
|
18
18
|
|
19
|
+
To test test links on all subpages of a site add `--all-subpages` to the command.
|
20
|
+
|
21
|
+
To test without performing spellchecking of common spelling add `--no-spellcheck`
|
22
|
+
|
23
|
+
E.g
|
24
|
+
|
25
|
+
`docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test --all-subpages --no-spellcheck`
|
26
|
+
|
27
|
+
You can see all options by running
|
28
|
+
|
29
|
+
`docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test help page`
|
30
|
+
|
19
31
|
## Add to gitlab CI for your website
|
20
32
|
|
21
33
|
Add the following `YAML` to test against a website
|
@@ -30,7 +42,7 @@ example_test:
|
|
30
42
|
artifacts:
|
31
43
|
paths:
|
32
44
|
- logs/*.xml
|
33
|
-
-
|
45
|
+
- logs/*.html # HTML reports
|
34
46
|
reports:
|
35
47
|
junit: logs/*.xml
|
36
48
|
expire_in: 1 week
|
data/exe/generic_test
CHANGED
@@ -12,17 +12,22 @@ class Exe < Thor
|
|
12
12
|
end
|
13
13
|
|
14
14
|
desc 'page page_url', 'Test web page'
|
15
|
+
method_options all_subpages: false
|
16
|
+
method_options spellcheck: true
|
15
17
|
def page(page_url)
|
16
18
|
ENV['PAGE_URL'] = page_url
|
19
|
+
ENV['ALL_SUBPAGES'] ||= options.all_subpages?.to_s
|
20
|
+
ENV['SPELLCHECK_ON'] = options.spellcheck?.to_s
|
17
21
|
test_file_path = File.join(File.dirname(__FILE__), '..', 'spec', 'generic_test_spec.rb')
|
18
22
|
raise "no file at #{test_file_path}" unless File.exist? test_file_path
|
19
23
|
|
20
24
|
desc = ENV['PAGE_URL'].split('://').last.tr('/', '_')
|
21
25
|
junit_format = "-f RspecJunitFormatter --out logs/page_#{desc}.xml"
|
22
26
|
ENV['REPORT_PATH'] = "reports/#{desc}"
|
23
|
-
html_format = '--format html --out report.html'
|
27
|
+
html_format = '--format html --out logs/report.html'
|
24
28
|
command = "rspec #{test_file_path} --format documentation --color #{junit_format} #{html_format}"
|
25
|
-
|
29
|
+
exit(1) unless system command
|
30
|
+
#raise $CHILD_STATUS.to_s unless system command
|
26
31
|
end
|
27
32
|
|
28
33
|
desc 'version', 'Version of generic_test'
|
data/lib/generic_test/page.rb
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
module GenericTest
|
4
4
|
# Represents a web page state at a particular point of time
|
5
5
|
class Page
|
6
|
-
# @return [Array] List of links
|
6
|
+
# @return [Array] List of links elements on the page
|
7
7
|
attr_accessor :links
|
8
|
+
# @return [Array] List of urls that include domain being tested
|
9
|
+
attr_accessor :internal_links
|
8
10
|
# @return [Array] List of emails
|
9
11
|
attr_accessor :emails
|
10
12
|
attr_accessor :url
|
@@ -18,8 +20,11 @@ module GenericTest
|
|
18
20
|
self.emails, self.links = browser.links.partition do |link|
|
19
21
|
link.href.start_with?('mailto:')
|
20
22
|
end
|
21
|
-
links.reject! { |link| link.href.empty? || link.href.start_with?('javascript:') || link.href.
|
23
|
+
links.reject! { |link| link.href.empty? || link.href.start_with?('javascript:') || link.href.include?('tel:') }
|
22
24
|
emails.collect! { |link| link.href.split(':').last }
|
25
|
+
self.internal_links = links.filter do |link|
|
26
|
+
link.href.include? ENV["PAGE_URL"]
|
27
|
+
end.collect { |link| link.href }.uniq
|
23
28
|
self.url = browser.url
|
24
29
|
self.html = browser.html
|
25
30
|
self.text = browser.text
|
data/lib/generic_test/setup.rb
CHANGED
@@ -34,8 +34,13 @@ if ENV[GT_LOGIN_URL] && ENV[GT_USERNAME] && ENV[GT_PASSWORD]
|
|
34
34
|
puts "Login through #{ENV[GT_LOGIN_URL]} successful!"
|
35
35
|
end
|
36
36
|
|
37
|
+
GenericTest.all_subpages = true if ENV['ALL_SUBPAGES'] == 'true'
|
37
38
|
ENV['PAGE_URL'] = RestClient.get(ENV['PAGE_URL']).request.url # Check page exists
|
38
|
-
puts "
|
39
|
+
puts "Loading..."
|
39
40
|
browser.goto ENV['PAGE_URL']
|
40
41
|
sleep 2.5 # Give a bit of time for page to load
|
42
|
+
puts "Checking #{ENV['PAGE_URL']} (#{browser.title})"
|
41
43
|
GenericTest.pages << GenericTest::Page.new(browser)
|
44
|
+
if GenericTest.all_subpages
|
45
|
+
puts "Subpages include #{GenericTest.pages.first.internal_links.count } links"
|
46
|
+
end
|
data/lib/generic_test/version.rb
CHANGED
data/lib/generic_test.rb
CHANGED
@@ -19,7 +19,10 @@ module GenericTest
|
|
19
19
|
attr_accessor :browser
|
20
20
|
attr_accessor :pages
|
21
21
|
attr_accessor :tested_links
|
22
|
+
# @return [Boolean]
|
22
23
|
attr_accessor :only_javascript
|
24
|
+
# @return [Boolean] Whether to check all subpages of initial page
|
25
|
+
attr_accessor :all_subpages
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
data/spec/generic_test_spec.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# Used by executable to verify a particular web page
|
4
4
|
require 'generic_test/setup'
|
5
5
|
page = GenericTest.pages.first
|
6
|
+
checkmark = "\u2713"
|
6
7
|
links = page.links
|
7
8
|
RSpec.describe "#{page.title} Links respond" do
|
8
9
|
links.each_with_index do |link, index|
|
@@ -10,13 +11,60 @@ RSpec.describe "#{page.title} Links respond" do
|
|
10
11
|
next if GenericTest.tested_links.include? link.href
|
11
12
|
|
12
13
|
GenericTest.tested_links << link.href
|
13
|
-
|
14
|
-
|
14
|
+
link_href = link.href
|
15
|
+
it "Link (#{GenericTest.tested_links.count})#{link_text} to '#{link.href}' succeeds" do
|
16
|
+
expect(Checker.link_status(link_href)).to be_between 200, 399
|
15
17
|
end
|
16
18
|
end
|
17
19
|
puts "Checking #{GenericTest.tested_links.count} non duplicate links"
|
18
20
|
end
|
19
21
|
|
22
|
+
if GenericTest.all_subpages
|
23
|
+
extra_subpage_links = []
|
24
|
+
browser = GenericTest.browser
|
25
|
+
page.internal_links.each do |href|
|
26
|
+
browser.goto href
|
27
|
+
sub_page = GenericTest::Page.new(browser)
|
28
|
+
sub_page.internal_links.each do |internal_link|
|
29
|
+
extra_subpage_links << internal_link unless page.internal_links.include? internal_link
|
30
|
+
end
|
31
|
+
extra_subpage_links.uniq!
|
32
|
+
puts "Extra subpage links #{extra_subpage_links.count}"
|
33
|
+
RSpec.describe "Subpage #{browser.title} #{href}" do
|
34
|
+
sub_page.links.each_with_index do |link, index|
|
35
|
+
link_text = link.text.to_s.empty? ? '' : " \"#{link.text}\""
|
36
|
+
next if GenericTest.tested_links.include? link.href
|
37
|
+
|
38
|
+
GenericTest.tested_links << link.href
|
39
|
+
link_href = link.href
|
40
|
+
it "Link (#{GenericTest.tested_links.count})#{link_text} to '#{link.href}' succeeds" do
|
41
|
+
expect(Checker.link_status(link_href)).to be_between 200, 399
|
42
|
+
end
|
43
|
+
end
|
44
|
+
puts "#{checkmark} Checking #{GenericTest.tested_links.count} non duplicate links"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
extra_subpage_links.each do |href|
|
49
|
+
browser.goto href
|
50
|
+
sub_page = GenericTest::Page.new(browser)
|
51
|
+
|
52
|
+
RSpec.describe "Subpage lv 2 #{browser.title} #{href}" do
|
53
|
+
sub_page.links.each_with_index do |link, index|
|
54
|
+
link_text = link.text.to_s.empty? ? '' : " \"#{link.text}\""
|
55
|
+
next if GenericTest.tested_links.include? link.href
|
56
|
+
|
57
|
+
GenericTest.tested_links << link.href
|
58
|
+
link_href = link.href
|
59
|
+
it "Link (#{GenericTest.tested_links.count})#{link_text} to '#{link.href}' succeeds" do
|
60
|
+
expect(Checker.link_status(link_href)).to be_between 200, 399
|
61
|
+
end
|
62
|
+
end
|
63
|
+
puts "#{checkmark} Checking #{GenericTest.tested_links.count} non duplicate links (lv2)"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
20
68
|
emails = page.emails
|
21
69
|
RSpec.describe "#{page.title} Emails are valid" do
|
22
70
|
emails.each do |email|
|
@@ -26,17 +74,19 @@ RSpec.describe "#{page.title} Emails are valid" do
|
|
26
74
|
end
|
27
75
|
end
|
28
76
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
77
|
+
if ENV['SPELLCHECK_ON'] == 'true'
|
78
|
+
RSpec.describe "#{page.title} Page content spelling" do
|
79
|
+
spellcheck_report = SpellCheck::ProofReader.check(page.text)
|
80
|
+
context 'does not have common spelling mistakes' do
|
81
|
+
it 'has no mistakes' do
|
82
|
+
expect(spellcheck_report.errata.size).to eq 0
|
83
|
+
end
|
84
|
+
spellcheck_report.errata.group_by(&:line_number).each do |line_number, mistakes|
|
85
|
+
context "Line #{line_number}" do
|
86
|
+
mistakes.each_with_index do |mistake, index|
|
87
|
+
it "(#{index + 1}) #{mistake.pattern}" do
|
88
|
+
expect(mistake.pattern).to eq mistake.expected
|
89
|
+
end
|
40
90
|
end
|
41
91
|
end
|
42
92
|
end
|
data/test_site/about.html
CHANGED
@@ -10,7 +10,8 @@
|
|
10
10
|
Generic test page makes things easy
|
11
11
|
All tests in this page work
|
12
12
|
</p>
|
13
|
-
<a href="
|
13
|
+
<a href="sub_page.html">Sub page</a>
|
14
14
|
<a href="mailto:samuel.garratt@integrationqa.com">Email me</a>
|
15
|
+
<a href="tel:021234567">Ignore telephone</a>
|
15
16
|
</body>
|
16
17
|
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: generic_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- test_site/about.html
|
202
202
|
- test_site/index.html
|
203
203
|
- test_site/login_page.html
|
204
|
+
- test_site/sub_page.html
|
204
205
|
homepage: https://gitlab.com/samuel-garratt/generic_test
|
205
206
|
licenses:
|
206
207
|
- MIT
|