generic_test 0.1.11 → 0.1.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e9dabdf7bdc04b3967c77b109f7ce9ee0893896c31d98c05f54a732e9d7f513
4
- data.tar.gz: 715dc1bb7195c5dfb5eab9d5da467fdbbd5d54c431151876397141ed4bed9cbb
3
+ metadata.gz: 5511c72398002fc4468de6f4e1e6a3f8c27783fd2cbeef28decae9a833698f57
4
+ data.tar.gz: 4aaad3513df4be30725c97ac25fd07bc052bc90dac9b7270d286c1f5ce017090
5
5
  SHA512:
6
- metadata.gz: ce37d41116ea08457eeb93d247b517f834d7cc790c1bd43b21457f16cc221af8f82d3cc3d8093aff30682237d0d120e36ab407ef56e0fcbbbcb9a166f6777b4c
7
- data.tar.gz: 4769b1befffe34c5798bf485bc1ff717b86b50f8cb5d26e145d43251ed1f84c737d50dba925df7d76953e7f11e2115588fbebb962097b5c74cd6536253af590c
6
+ metadata.gz: 4848379d61b1064629f36ca3861759a564ee2fe4d156afb235c6a1eddce86dfd14b05980b6d45dec81b46404d5ce27b81a78fe2f25372ac2040bc5ac480283fe
7
+ data.tar.gz: 5c92f007d44d6bcfc74113c091c2fab49a1266c1eef09b093220660eeb2d3db34424f3663f0b752e3c01660df1b8699459954aac88e21e013cf84916f8717370
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.1.12
2
+ * Enhancement
3
+ * More generic matching of username labels allowing any case to be used
4
+
1
5
  Version 0.1.11
2
6
  * Enhancement
3
7
  * Spell check based on text of page, not HTML.
data/README.md CHANGED
@@ -8,10 +8,12 @@ Run test gem through docker against this website with (Note it is an example tha
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 URL
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/test_gem_spec.rb'
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['PAGE_NUM'] = '1'
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
@@ -28,4 +28,4 @@ class Exe < Thor
28
28
  end
29
29
  end
30
30
 
31
- Exe.start(ARGV)
31
+ Exe.start(ARGV)
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 = []
@@ -20,3 +21,10 @@ module GenericTest
20
21
  attr_accessor :only_javascript
21
22
  end
22
23
  end
24
+
25
+ # @return [String] Generic Test URL to login before arriving at PAGE_URL to test.
26
+ # Needs GT_USERNAME and GT_PASSWORD to be used
27
+ GT_LOGIN_URL = 'GT_LOGIN_URL'
28
+ GT_USERNAME = 'GT_USERNAME'
29
+ GT_PASSWORD = 'GT_PASSWORD'
30
+ GT_PAGE_SETTING_FILE = 'generic_test.page.yml'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Mock implementation of Bundler for use by generic_test where Bundler.root is needed
2
4
  module Bundler
3
5
  class << self
@@ -8,4 +10,4 @@ module Bundler
8
10
  end
9
11
  end
10
12
 
11
- require 'rspec_html_reporter'
13
+ require 'rspec_html_reporter'
@@ -1,3 +1,5 @@
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
@@ -2,13 +2,7 @@
2
2
 
3
3
  # One file to require gem and set things up, arriving at page to check
4
4
  require 'generic_test'
5
-
6
- # @return [String] Generic Test URL to login before arriving at PAGE_URL to test.
7
- # Needs GT_USERNAME and GT_PASSWORD to be used
8
- GT_LOGIN_URL = 'GT_LOGIN_URL'
9
- GT_USERNAME = 'GT_USERNAME'
10
- GT_PASSWORD = 'GT_PASSWORD'
11
- GT_PAGE_SETTING_FILE = 'generic_test.page.yml'
5
+ require_relative 'xpath'
12
6
 
13
7
  ENV['HEADLESS'] ||= 'true'
14
8
  ENV['PAGE_NUM'] ||= '1'
@@ -32,8 +26,8 @@ end
32
26
  browser = GenericTest.browser
33
27
  if ENV[GT_LOGIN_URL] && ENV[GT_USERNAME] && ENV[GT_PASSWORD]
34
28
  browser.goto ENV[GT_LOGIN_URL]
35
- browser.text_field(xpath: "//input[@id=(//label[text()='Username']/@for)]|//input[@*='username']").set ENV[GT_USERNAME]
36
- browser.text_field(xpath: "//input[@id=(//label[text()='Password']/@for)]|//input[@*='password']").set ENV[GT_PASSWORD]
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]
37
31
  login_button = browser.button(xpath: "//*[@type='submit']|//*[@*='Login']")
38
32
  login_button.click
39
33
  login_button.wait_while(&:present?)
@@ -42,4 +36,4 @@ end
42
36
 
43
37
  browser.goto ENV['PAGE_URL']
44
38
  sleep 2.5 # Give a bit of time for page to load
45
- GenericTest.pages << GenericTest::Page.new(browser)
39
+ GenericTest.pages << GenericTest::Page.new(browser)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenericTest
4
- VERSION = '0.1.11'
4
+ VERSION = '0.1.12'
5
5
  end
@@ -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/spec_helper.rb CHANGED
@@ -16,10 +16,10 @@ require 'generic_test/setup'
16
16
  RSpec.configure do |config|
17
17
  # Close test server after all RSpec tests have run
18
18
  config.after(:suite) do
19
- GenericTest.browser&.close
20
19
  if ENV['test_site_pid']
21
20
  puts "Closing test site at #{ENV['test_site_pid']}"
22
21
  Process.kill(:QUIT, ENV['test_site_pid'].to_i)
23
22
  end
23
+ GenericTest.browser&.close
24
24
  end
25
25
  end
@@ -6,7 +6,7 @@ page = GenericTest.pages.first
6
6
  links = page.links
7
7
 
8
8
  RSpec.describe 'Links' do
9
- it 'counts correctly (not include )' do
9
+ it 'counts correctly (not include invalid)' do
10
10
  expect(links.size).to eq 3
11
11
  end
12
12
  context 'successful' do
@@ -18,10 +18,12 @@ RSpec.describe 'Links' do
18
18
  end
19
19
  end
20
20
  it 'broken causes failure' do
21
+ puts page.links[1].text
22
+ puts page.links[1].href
21
23
  expect(Checker.link_status(links[1].href)).to eq 404
22
24
  end
23
25
  end
24
- puts page.emails
26
+
25
27
  RSpec.describe 'Emails' do
26
28
  it 'counts correctly' do
27
29
  expect(page.emails.size).to eq 2
@@ -34,4 +36,4 @@ RSpec.describe 'Emails' do
34
36
  expect(Checker.valid_email?(page.emails[1])).to eq 'Domain name not registered'
35
37
  end
36
38
  end
37
- end
39
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generic_test/xpath'
4
+
5
+ describe Xpath do
6
+ context '.upcase' do
7
+ it 'return xpath upcase function' do
8
+ expect(Xpath.upcase('text()')).to include 'translate(text()'
9
+ end
10
+ end
11
+ end
data/test_site/about.html CHANGED
@@ -11,5 +11,6 @@
11
11
  All tests in this page work
12
12
  </p>
13
13
  <a href="index.html">Index page</a>
14
+ <a href="mailto:samuel.garratt@integrationqa.com">Email me</a>
14
15
  </body>
15
16
  </html>
@@ -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.11
4
+ version: 0.1.12
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-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -235,11 +235,14 @@ files:
235
235
  - lib/generic_test/page.rb
236
236
  - lib/generic_test/setup.rb
237
237
  - lib/generic_test/version.rb
238
+ - lib/generic_test/xpath.rb
238
239
  - spec/generic_test_spec.rb
239
240
  - spec/spec_helper.rb
240
- - spec/test_gem_spec.rb
241
+ - spec/test_gem/page_spec.rb
242
+ - spec/test_gem/xpath_spec.rb
241
243
  - test_site/about.html
242
244
  - test_site/index.html
245
+ - test_site/login_page.html
243
246
  homepage: https://gitlab.com/samuel-garratt/generic_test
244
247
  licenses:
245
248
  - MIT