generic_test 0.1.8 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +2 -2
- data/ChangeLog +24 -0
- data/Dockerfile +1 -1
- data/README.md +36 -3
- data/Rakefile +5 -2
- data/exe/generic_test +8 -2
- data/generic_test.gemspec +14 -10
- data/lib/generic_test.rb +10 -15
- data/lib/generic_test/checker.rb +9 -5
- data/lib/generic_test/html_reporter.rb +13 -0
- data/lib/generic_test/page.rb +12 -2
- data/lib/generic_test/setup.rb +39 -2
- data/lib/generic_test/version.rb +1 -1
- data/lib/generic_test/xpath.rb +25 -0
- data/spec/generic_test_spec.rb +18 -7
- data/spec/spec_helper.rb +11 -1
- data/spec/test_gem/page_spec.rb +39 -0
- data/spec/test_gem/xpath_spec.rb +11 -0
- data/test_site/about.html +1 -0
- data/test_site/index.html +6 -0
- data/test_site/login_page.html +23 -0
- metadata +68 -8
- data/spec/test_gem_spec.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7fd4592cd7c34e39ae05d9db02ea20dd6ca739f368851db22dac04168504ec1
|
4
|
+
data.tar.gz: fb55093d314dfc89e13d0ec4342317106d6caef89dcd9e7341c42c79a59f464b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ec80dd8977f15b6ffc3a66cec286a2183da371a10eb4d4428ff0f607d849e818bc303ffa96c3295e9ba787f7dcf092e95d64729318dcd357ee390937ec9680
|
7
|
+
data.tar.gz: 92d050bbbd02da8821ba2685cec5bcf86a1187a3f9a3ab82d4cc0ef44b0bc5d47644c520e81b5fd8859293021b840bb16571cf407f7fdc08924beaf67dbef97f
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -8,13 +8,13 @@ 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:19.03.5-dind
|
14
14
|
image: docker:19.03.5
|
15
15
|
script:
|
16
16
|
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
17
|
-
- docker pull $CI_REGISTRY_IMAGE:latest || true
|
17
|
+
- docker pull --quiet $CI_REGISTRY_IMAGE:latest || true
|
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
|
data/ChangeLog
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
Version 0.1.13
|
2
|
+
* Enhancement
|
3
|
+
* Fail if cannot find url of page provided
|
4
|
+
* Ignore checking duplicate links
|
5
|
+
|
6
|
+
Version 0.1.12
|
7
|
+
* Enhancement
|
8
|
+
* More generic matching of username labels allowing any case to be used
|
9
|
+
|
10
|
+
Version 0.1.11
|
11
|
+
* Enhancement
|
12
|
+
* Spell check based on text of page, not HTML.
|
13
|
+
* Reject links that start with 'javascript:'
|
14
|
+
* Initial handling of logging into Login page with generic identifiers
|
15
|
+
|
16
|
+
Version 0.1.10
|
17
|
+
* Bug fix
|
18
|
+
* Add custom file implementing mock of what's needed for RSpecHtmlReporter
|
19
|
+
* Split email addresses into separate list and add validation for them using 'email_address' gem
|
20
|
+
|
21
|
+
Version 0.1.9
|
22
|
+
* Bug fix
|
23
|
+
* rspec-legacy_formatters will be needed for RSpecHtmlFormatter
|
24
|
+
|
1
25
|
Version 0.1.8
|
2
26
|
* Bug fix
|
3
27
|
* Add rspec_html_reporter as required in rspec command
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -4,14 +4,16 @@ This gem provides an easy way to run generic tests for a website/api
|
|
4
4
|
|
5
5
|
Test site is at https://samuel-garratt.gitlab.io/generic_test
|
6
6
|
|
7
|
-
Run test gem through docker against this with
|
7
|
+
Run test gem through docker against this website with (Note it is an example that has some failures)
|
8
8
|
|
9
9
|
`docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test`
|
10
10
|
|
11
|
-
To get a log of your tests share a volume with the container
|
11
|
+
To get a log of your tests share a volume with the container.
|
12
12
|
|
13
13
|
`docker run -v "$PWD":/test -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test`
|
14
14
|
|
15
|
+
> Please share this volume from an empty folder. Running from within another gem might cause an issue
|
16
|
+
|
15
17
|
## Installation
|
16
18
|
|
17
19
|
Add this line to your application's Gemfile:
|
@@ -33,14 +35,45 @@ Or install it yourself as:
|
|
33
35
|
### Running locally.
|
34
36
|
|
35
37
|
Use the executable `generic_test`, add the page command and put a website to check:
|
38
|
+
|
39
|
+
`generic_test page URL_OF_WEBSITE`
|
40
|
+
|
41
|
+
E.g.,
|
42
|
+
|
36
43
|
`generic_test page samuel-garratt.gitlab.io/generic_test`
|
37
44
|
|
38
45
|
### Run with docker
|
39
46
|
|
40
|
-
docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page
|
47
|
+
`docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page URL_OF_WEBSITE`
|
41
48
|
|
42
49
|
`docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test`
|
43
50
|
|
51
|
+
### Through login page
|
52
|
+
|
53
|
+
Environment variables store Login URL, username and password
|
54
|
+
* GT_LOGIN_URL: Url to login at
|
55
|
+
* GT_USERNAME: Username to use
|
56
|
+
* GT_PASSWORD: Password to use
|
57
|
+
|
58
|
+
At the moment Generic test tries to be smart to identify the username, password and submit elements. In
|
59
|
+
the future, option will be given to provide your own identifiers if this does not work.
|
60
|
+
|
61
|
+
These variables can be set in `docker run`
|
62
|
+
|
63
|
+
`docker run -e "GT_LOGIN_URL=samuel-garratt.gitlab.io/generic_test/login_page" -e "GT_USERNAME=Tester" -e "GT_PASSWORD=Pass" -v "$PWD":/test -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test`
|
64
|
+
|
65
|
+
These variables can also be set in a `.generic_test.page.yml` (you will need a volume to have this available to
|
66
|
+
docker container)
|
67
|
+
|
68
|
+
E.g., file to login as above:
|
69
|
+
|
70
|
+
```yaml
|
71
|
+
login:
|
72
|
+
url: 'samuel-garratt.gitlab.io/generic_test/login_page'
|
73
|
+
username: 'Tester'
|
74
|
+
password: 'Pass'
|
75
|
+
```
|
76
|
+
|
44
77
|
## Development
|
45
78
|
|
46
79
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -4,20 +4,23 @@ require 'bundler/gem_tasks'
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(spec: :start_website) do |task|
|
7
|
-
task.pattern = 'spec/
|
7
|
+
task.pattern = 'spec/test_gem/*spec.rb'
|
8
8
|
end
|
9
9
|
|
10
10
|
directory 'logs'
|
11
11
|
|
12
12
|
desc 'Start virtual web service'
|
13
13
|
task start_website: :logs do
|
14
|
+
require 'generic_test'
|
14
15
|
mkdir_p 'logs'
|
15
16
|
ENV['test_site_pid'] = Process.spawn('jekyll', 'serve', '-s', 'test_site',
|
16
17
|
err: %w[logs/test_site.log w]).to_s
|
17
18
|
sleep 2 # Wait a little for virtual server to start up
|
18
19
|
puts 'Running test site on pid ' + ENV['test_site_pid']
|
19
20
|
ENV['PAGE_URL'] = 'http://127.0.0.1:4000'
|
20
|
-
ENV[
|
21
|
+
ENV[GT_USERNAME] = 'Test User'
|
22
|
+
ENV[GT_PASSWORD] = 'Test Password'
|
23
|
+
ENV[GT_LOGIN_URL] = 'http://127.0.0.1:4000/login_page.html'
|
21
24
|
end
|
22
25
|
|
23
26
|
task default: :spec
|
data/exe/generic_test
CHANGED
@@ -16,10 +16,16 @@ class Exe < Thor
|
|
16
16
|
desc = ENV['PAGE_URL'].split('://').last.tr('/', '_')
|
17
17
|
junit_format = "-f RspecJunitFormatter --out logs/page_#{desc}.xml"
|
18
18
|
ENV['REPORT_PATH'] = "reports/#{desc}"
|
19
|
-
html_format = '--require
|
19
|
+
html_format = '--require generic_test/html_reporter -f RspecHtmlReporter'
|
20
20
|
command = "rspec #{test_file_path} --format documentation --color #{junit_format} #{html_format}"
|
21
21
|
raise $CHILD_STATUS.to_s unless system command
|
22
22
|
end
|
23
|
+
|
24
|
+
desc 'version', 'Version of generic_test'
|
25
|
+
def version
|
26
|
+
require 'generic_test'
|
27
|
+
puts "GenericTest version #{GenericTest::VERSION}"
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
|
-
Exe.start(ARGV)
|
31
|
+
Exe.start(ARGV)
|
data/generic_test.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
16
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
17
17
|
spec.metadata['source_code_uri'] = 'https://gitlab.com/samuel-garratt/generic_test'
|
18
|
-
spec.metadata['changelog_uri'] = 'https://gitlab.com/samuel-garratt/
|
18
|
+
spec.metadata['changelog_uri'] = 'https://gitlab.com/samuel-garratt/generic_test/blob/master/ChangeLog'
|
19
19
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -27,14 +27,18 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
# Development dependencies are installed too since running external tests within gem
|
29
29
|
spec.add_development_dependency 'jekyll' # For hosting test website
|
30
|
-
spec.
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_dependency 'rspec-legacy_formatters' # Needed for rspec_html_reporter after RSpec 3
|
32
|
+
spec.add_dependency 'rspec_html_reporter' # Pretty HTML reports
|
33
|
+
spec.add_dependency 'rspec_junit_formatter' # Needed for nicer reporting of rspec for use in CI
|
34
|
+
spec.add_dependency 'simplecov' # Code coverage
|
31
35
|
|
32
|
-
spec.add_dependency '
|
33
|
-
spec.add_dependency '
|
34
|
-
spec.add_dependency '
|
35
|
-
spec.add_dependency '
|
36
|
-
spec.add_dependency '
|
37
|
-
spec.add_dependency '
|
38
|
-
spec.add_dependency '
|
39
|
-
spec.add_dependency '
|
36
|
+
spec.add_dependency 'email_address' # Verify email address
|
37
|
+
spec.add_dependency 'rest-client' # Verify links
|
38
|
+
spec.add_dependency 'rspec' # Test framework
|
39
|
+
spec.add_dependency 'spellcheck' # Check for common spelling errors
|
40
|
+
spec.add_dependency 'thor' # Command line utility
|
41
|
+
spec.add_dependency 'watir' # UI interaction
|
42
|
+
spec.add_dependency 'webdrivers' # Download chromedriver automatically
|
43
|
+
spec.add_dependency 'yamler'
|
40
44
|
end
|
data/lib/generic_test.rb
CHANGED
@@ -7,6 +7,7 @@ require 'spellcheck'
|
|
7
7
|
require 'watir'
|
8
8
|
require 'webdrivers'
|
9
9
|
|
10
|
+
# Handles testing of sites generically for common issues
|
10
11
|
module GenericTest
|
11
12
|
class Error < StandardError; end
|
12
13
|
@pages = []
|
@@ -14,24 +15,18 @@ module GenericTest
|
|
14
15
|
# browser so less likely to be accurate for logged in pages
|
15
16
|
@only_javascript = false
|
16
17
|
|
18
|
+
@tested_links = []
|
17
19
|
class << self
|
18
20
|
attr_accessor :browser
|
19
21
|
attr_accessor :pages
|
22
|
+
attr_accessor :tested_links
|
20
23
|
attr_accessor :only_javascript
|
21
|
-
|
22
|
-
def setup
|
23
|
-
ENV['HEADLESS'] ||= 'true'
|
24
|
-
ENV['PAGE_NUM'] ||= '1'
|
25
|
-
browser_args = %w[--disable-popup-blocking --no-sandbox --disable-dev-shm-usage]
|
26
|
-
browser_args << '--headless' if ENV['HEADLESS'] == 'true'
|
27
|
-
|
28
|
-
GenericTest.browser = Watir::Browser.new :chrome, args: browser_args
|
29
|
-
|
30
|
-
raise 'PAGE_URL environment variable not set' unless ENV['PAGE_URL']
|
31
|
-
|
32
|
-
browser = GenericTest.browser
|
33
|
-
browser.goto ENV['PAGE_URL']
|
34
|
-
GenericTest.pages << GenericTest::Page.new(browser)
|
35
|
-
end
|
36
24
|
end
|
37
25
|
end
|
26
|
+
|
27
|
+
# @return [String] Generic Test URL to login before arriving at PAGE_URL to test.
|
28
|
+
# Needs GT_USERNAME and GT_PASSWORD to be used
|
29
|
+
GT_LOGIN_URL = 'GT_LOGIN_URL'
|
30
|
+
GT_USERNAME = 'GT_USERNAME'
|
31
|
+
GT_PASSWORD = 'GT_PASSWORD'
|
32
|
+
GT_PAGE_SETTING_FILE = 'generic_test.page.yml'
|
data/lib/generic_test/checker.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rest-client'
|
4
|
+
require 'email_address'
|
4
5
|
|
5
6
|
# Module for checking parts on a site
|
6
7
|
module Checker
|
7
8
|
class << self
|
8
|
-
|
9
|
-
!href.start_with?('mailto:')
|
10
|
-
end
|
11
|
-
|
12
|
-
# Usign Javascript fetch to retrieve URL. See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch and
|
9
|
+
# Using Javascript fetch to retrieve URL. See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch and
|
13
10
|
# https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters for details
|
14
11
|
# @return [Integer] Status code
|
15
12
|
def link_status(href)
|
13
|
+
return unless href
|
14
|
+
|
16
15
|
init_options = "const myInit = {
|
17
16
|
method: 'GET',
|
18
17
|
credentials: 'same-origin',
|
@@ -27,6 +26,11 @@ module Checker
|
|
27
26
|
raise GenericTest::Error, "Failed to fetch url '#{href}'"
|
28
27
|
end
|
29
28
|
|
29
|
+
# @return [Nil, String] Nil if valid, string if error
|
30
|
+
def valid_email?(email_address)
|
31
|
+
EmailAddress.error email_address
|
32
|
+
end
|
33
|
+
|
30
34
|
# Use rest-client to try and get status of URL
|
31
35
|
def call_via_rest_client(href)
|
32
36
|
RestClient.get(href).code
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Mock implementation of Bundler for use by generic_test where Bundler.root is needed
|
4
|
+
module Bundler
|
5
|
+
class << self
|
6
|
+
# Used just so that RSpecHtmlReporter does not thrown an error
|
7
|
+
def root
|
8
|
+
''
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rspec_html_reporter'
|
data/lib/generic_test/page.rb
CHANGED
@@ -1,20 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GenericTest
|
2
4
|
# Represents a web page state at a particular point of time
|
3
5
|
class Page
|
4
6
|
# @return [Array] List of links
|
5
7
|
attr_accessor :links
|
8
|
+
# @return [Array] List of emails
|
9
|
+
attr_accessor :emails
|
6
10
|
attr_accessor :url
|
7
11
|
attr_accessor :html
|
12
|
+
attr_accessor :text
|
8
13
|
attr_accessor :title
|
9
14
|
|
10
15
|
# Store state of page when it is loaded
|
11
16
|
# @param [Watir::Browser] browser Watir browser
|
12
17
|
def initialize(browser)
|
13
|
-
self.links = browser.links
|
18
|
+
self.emails, self.links = browser.links.partition do |link|
|
19
|
+
link.href.start_with?('mailto:')
|
20
|
+
end
|
21
|
+
links.reject! { |link| link.href.empty? || link.href.start_with?('javascript:') }
|
22
|
+
emails.collect! { |link| link.href.split(':').last }
|
14
23
|
self.url = browser.url
|
15
24
|
self.html = browser.html
|
25
|
+
self.text = browser.text
|
16
26
|
self.title = browser.title
|
17
|
-
puts "Found #{links.count} links at #{url} (#{title})"
|
27
|
+
puts "Found #{links.count} links, #{emails.count} emails at #{url} (#{title})"
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
data/lib/generic_test/setup.rb
CHANGED
@@ -1,4 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# One file to require gem and set things up, arriving at page to check
|
2
4
|
require 'generic_test'
|
5
|
+
require_relative 'xpath'
|
6
|
+
|
7
|
+
ENV['HEADLESS'] ||= 'true'
|
8
|
+
ENV['PAGE_NUM'] ||= '1'
|
9
|
+
browser_args = %w[--disable-popup-blocking --no-sandbox --disable-dev-shm-usage]
|
10
|
+
browser_args << '--headless' if ENV['HEADLESS'] == 'true'
|
11
|
+
|
12
|
+
GenericTest.browser = Watir::Browser.new :chrome, args: browser_args
|
13
|
+
|
14
|
+
raise 'PAGE_URL environment variable not set' unless ENV['PAGE_URL']
|
15
|
+
|
16
|
+
require 'yamler'
|
17
|
+
if File.exist?(GT_PAGE_SETTING_FILE) && !File.read(GT_PAGE_SETTING_FILE).empty?
|
18
|
+
gt_page_settings = Yamler.load 'generic_test.page.yml'
|
19
|
+
if gt_page_settings['login']
|
20
|
+
ENV[GT_USERNAME] = gt_page_settings['login']['username']
|
21
|
+
ENV[GT_PASSWORD] = gt_page_settings['login']['password']
|
22
|
+
ENV[GT_LOGIN_URL] = gt_page_settings['login']['url']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
browser = GenericTest.browser
|
27
|
+
if ENV[GT_LOGIN_URL] && ENV[GT_USERNAME] && ENV[GT_PASSWORD]
|
28
|
+
browser.goto ENV[GT_LOGIN_URL]
|
29
|
+
browser.text_field(xpath: Xpath.label_or_attribute('username')).set ENV[GT_USERNAME]
|
30
|
+
browser.text_field(xpath: Xpath.label_or_attribute('password')).set ENV[GT_PASSWORD]
|
31
|
+
login_button = browser.button(xpath: "//*[@type='submit']|//*[@*='Login']")
|
32
|
+
login_button.click
|
33
|
+
login_button.wait_while(&:present?)
|
34
|
+
puts "Login through #{ENV[GT_LOGIN_URL]} successful!"
|
35
|
+
end
|
3
36
|
|
4
|
-
|
37
|
+
ENV['PAGE_URL'] = RestClient.get(ENV['PAGE_URL']).request.url # Check page exists
|
38
|
+
puts "Checking #{ENV['PAGE_URL']}"
|
39
|
+
browser.goto ENV['PAGE_URL']
|
40
|
+
sleep 2.5 # Give a bit of time for page to load
|
41
|
+
GenericTest.pages << GenericTest::Page.new(browser)
|
data/lib/generic_test/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Module to help form xpaths for generic identification
|
4
|
+
module Xpath
|
5
|
+
class << self
|
6
|
+
# @return [String] Translate string to uppercase letters
|
7
|
+
def upcase(xpath_method)
|
8
|
+
"translate(#{xpath_method},'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [String] Xpath to retrieve input beside a label
|
12
|
+
def input_by_label(label)
|
13
|
+
upcase_text = upcase('text()')
|
14
|
+
"//input[@id=(//label[contains(#{upcase_text},'#{label.upcase}')]/@for)]"
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String] Xpath to retrieve input either by a label or a attribute matching it
|
18
|
+
def label_or_attribute(field_name)
|
19
|
+
any_input_with_atr = "//input[@*='#{field_name}']"
|
20
|
+
input_with_text = "//input[text()='#{field_name}']"
|
21
|
+
[input_by_label(field_name), any_input_with_atr, input_with_text]
|
22
|
+
.join('|')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/generic_test_spec.rb
CHANGED
@@ -1,25 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Used by executable to verify a particular web page
|
3
4
|
require 'generic_test/setup'
|
4
5
|
page = GenericTest.pages.first
|
5
6
|
links = page.links
|
6
7
|
RSpec.describe "#{page.title} Links respond" do
|
7
8
|
links.each_with_index do |link, index|
|
8
|
-
next unless link.href && !link.href.empty?
|
9
|
-
|
10
9
|
link_text = link.text.to_s.empty? ? '' : " \"#{link.text}\""
|
10
|
+
next if GenericTest.tested_links.include? link.href
|
11
|
+
|
12
|
+
GenericTest.tested_links << link.href
|
11
13
|
it "Link (#{index + 1})#{link_text} to '#{link.href}' succeeds" do
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
expect(Checker.link_status(link.href)).to be_between 200, 399
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts "Checking #{GenericTest.tested_links.count} non duplicate links"
|
18
|
+
end
|
19
|
+
|
20
|
+
emails = page.emails
|
21
|
+
RSpec.describe "#{page.title} Emails are valid" do
|
22
|
+
emails.each do |email|
|
23
|
+
it "Email (#{email}) is valid" do
|
24
|
+
expect(Checker.valid_email?(email)).to be nil
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
28
|
+
|
18
29
|
RSpec.describe "#{page.title} Page content" do
|
19
|
-
spellcheck_report = SpellCheck::ProofReader.check(page.
|
30
|
+
spellcheck_report = SpellCheck::ProofReader.check(page.text)
|
20
31
|
context 'does not have common spelling mistakes' do
|
21
32
|
it 'has no mistakes' do
|
22
|
-
expect(spellcheck_report.
|
33
|
+
expect(spellcheck_report.errata.size).to eq 0
|
23
34
|
end
|
24
35
|
spellcheck_report.errata.group_by(&:line_number).each do |line_number, mistakes|
|
25
36
|
context "Line #{line_number}" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.at_exit do
|
10
|
+
SimpleCov.result.format!
|
11
|
+
SimpleCov.minimum_coverage 85
|
12
|
+
end
|
13
|
+
|
4
14
|
require 'generic_test/setup'
|
5
15
|
|
6
16
|
RSpec.configure do |config|
|
7
17
|
# Close test server after all RSpec tests have run
|
8
18
|
config.after(:suite) do
|
9
|
-
GenericTest.browser&.close
|
10
19
|
if ENV['test_site_pid']
|
11
20
|
puts "Closing test site at #{ENV['test_site_pid']}"
|
12
21
|
Process.kill(:QUIT, ENV['test_site_pid'].to_i)
|
13
22
|
end
|
23
|
+
GenericTest.browser&.close
|
14
24
|
end
|
15
25
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Test gem works
|
4
|
+
|
5
|
+
page = GenericTest.pages.first
|
6
|
+
links = page.links
|
7
|
+
|
8
|
+
RSpec.describe 'Links' do
|
9
|
+
it 'counts correctly (not include invalid)' do
|
10
|
+
expect(links.size).to eq 3
|
11
|
+
end
|
12
|
+
context 'successful' do
|
13
|
+
it 'external page' do
|
14
|
+
expect(Checker.link_status(links[0].href)).to be_between 200, 399
|
15
|
+
end
|
16
|
+
it 'internal link' do
|
17
|
+
expect(Checker.link_status(links[2].href)).to be_between 200, 399
|
18
|
+
end
|
19
|
+
end
|
20
|
+
it 'broken causes failure' do
|
21
|
+
puts page.links[1].text
|
22
|
+
puts page.links[1].href
|
23
|
+
expect(Checker.link_status(links[1].href)).to eq 404
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.describe 'Emails' do
|
28
|
+
it 'counts correctly' do
|
29
|
+
expect(page.emails.size).to eq 2
|
30
|
+
end
|
31
|
+
context 'validate' do
|
32
|
+
it 'accepts valid email' do
|
33
|
+
expect(Checker.valid_email?(page.emails[0])).to be nil
|
34
|
+
end
|
35
|
+
it 'returns invalid email error' do
|
36
|
+
expect(Checker.valid_email?(page.emails[1])).to eq 'Domain name not registered'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/test_site/about.html
CHANGED
data/test_site/index.html
CHANGED
@@ -12,6 +12,12 @@
|
|
12
12
|
<p id="broken_link">
|
13
13
|
<a href="broken_link.html">Broken link</a>
|
14
14
|
</p>
|
15
|
+
<h2><a id="special_links"></a> Special links</h2>
|
16
|
+
<p>
|
17
|
+
<a href="mailto:samuel.garratt@integrationqa.com">Email me</a>
|
18
|
+
<a href="#special_links">Link to heading</a>
|
19
|
+
<a href="mailto:invalid.person@bad-d0main.com">Don't try to email this</a>
|
20
|
+
</p>
|
15
21
|
<p>hello world.
|
16
22
|
|
17
23
|
I create aplication now.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Login Page</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<header>
|
7
|
+
<h1>Mock Login Page for testing login inputs can be entered</h1>
|
8
|
+
</header>
|
9
|
+
<p>
|
10
|
+
A login page like this can be entered before generic test done
|
11
|
+
</p>
|
12
|
+
<p>
|
13
|
+
<form action="about.html">
|
14
|
+
<label for="jdlksjdlsa">User-name</label>
|
15
|
+
<input id="jdlksjdlsa" value="username" />
|
16
|
+
<label for="231321321">Password</label>
|
17
|
+
<input id="231321321" />
|
18
|
+
<button type="submit">Submit</button>
|
19
|
+
</form>
|
20
|
+
</p>
|
21
|
+
<a href="index.html">Index page</a>
|
22
|
+
</body>
|
23
|
+
</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.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-legacy_formatters
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rspec_html_reporter
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rspec_junit_formatter
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: simplecov
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -81,7 +95,35 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: email_address
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rest-client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
86
128
|
requirements:
|
87
129
|
- - ">="
|
@@ -150,6 +192,20 @@ dependencies:
|
|
150
192
|
- - ">="
|
151
193
|
- !ruby/object:Gem::Version
|
152
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: yamler
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
153
209
|
description: Easy way to run generic tests for a website/api.
|
154
210
|
email:
|
155
211
|
- samuel.garratt@integrationqa.com
|
@@ -175,21 +231,25 @@ files:
|
|
175
231
|
- generic_test.gemspec
|
176
232
|
- lib/generic_test.rb
|
177
233
|
- lib/generic_test/checker.rb
|
234
|
+
- lib/generic_test/html_reporter.rb
|
178
235
|
- lib/generic_test/page.rb
|
179
236
|
- lib/generic_test/setup.rb
|
180
237
|
- lib/generic_test/version.rb
|
238
|
+
- lib/generic_test/xpath.rb
|
181
239
|
- spec/generic_test_spec.rb
|
182
240
|
- spec/spec_helper.rb
|
183
|
-
- spec/
|
241
|
+
- spec/test_gem/page_spec.rb
|
242
|
+
- spec/test_gem/xpath_spec.rb
|
184
243
|
- test_site/about.html
|
185
244
|
- test_site/index.html
|
245
|
+
- test_site/login_page.html
|
186
246
|
homepage: https://gitlab.com/samuel-garratt/generic_test
|
187
247
|
licenses:
|
188
248
|
- MIT
|
189
249
|
metadata:
|
190
250
|
homepage_uri: https://gitlab.com/samuel-garratt/generic_test
|
191
251
|
source_code_uri: https://gitlab.com/samuel-garratt/generic_test
|
192
|
-
changelog_uri: https://gitlab.com/samuel-garratt/
|
252
|
+
changelog_uri: https://gitlab.com/samuel-garratt/generic_test/blob/master/ChangeLog
|
193
253
|
post_install_message:
|
194
254
|
rdoc_options: []
|
195
255
|
require_paths:
|
data/spec/test_gem_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Test gem works internally
|
4
|
-
|
5
|
-
page = GenericTest.pages.first
|
6
|
-
links = page.links
|
7
|
-
puts links.collect(&:text)
|
8
|
-
RSpec.describe 'Links respond' do
|
9
|
-
it 'successful link passes' do
|
10
|
-
expect(Checker.link_status(links[0].href)).to be_between 200, 399
|
11
|
-
end
|
12
|
-
it 'broken link causes failure' do
|
13
|
-
expect(Checker.link_status(links[1].href)).to eq 404
|
14
|
-
end
|
15
|
-
end
|