locution-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: daf978e5d08a0e9b16b6ad8ceacceaa59b04cc33
4
+ data.tar.gz: d96796664091584803b099e31194575256f1a96f
5
+ SHA512:
6
+ metadata.gz: ede25c8ae83372bd1ef4b04863672daec7a57eb0755a84db2178f3a8bedc1ebc0c181aa80f25d2f7e84420e71769c6f9bfce036de6f24295a8703d2db04d3b51
7
+ data.tar.gz: d2ac9f2e845da997e9ef7efb3fb8394173d6e3f86be5b1b3123c041ffed86b5c5260e4ba174063654d9da8548aba53cac18da001f79a221cde1df04a4e22d4c3
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in locution-sdk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dave Haeffner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Locution::Sdk
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/locution/sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'locution-sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install locution-sdk
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/locution-sdk.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require 'locution/sdk/version'
2
+ require 'locution/sdk/listener'
@@ -0,0 +1,64 @@
1
+ require 'selenium-webdriver'
2
+ require 'rest-client'
3
+
4
+ module Locution
5
+ module Sdk
6
+ class Listener < ::Selenium::WebDriver::Support::AbstractEventListener
7
+
8
+ def initialize(access_token, test_name = "not provided", base_url = 'http://locution.herokuapp.com')
9
+ @base_url = base_url
10
+ @access_token = access_token
11
+ response = ::RestClient.post "#{@base_url}/tests", {
12
+ access_token: access_token,
13
+ test_name: test_name,
14
+ start_time: Time.now
15
+ }
16
+ @test_id = response.body
17
+ end
18
+
19
+ def before_find(by, what, driver)
20
+ @number_of_elements_found = driver.execute_script("return #{get_javascript(by, what)}")
21
+ @locator_start_time = Time.now
22
+ end
23
+
24
+ def after_find(by, what, driver)
25
+ ::RestClient.post "#{@base_url}/tests/#{@test_id}/locators", {
26
+ access_token: @access_token,
27
+ locator_value: "#{by}, #{what}",
28
+ locator_count: @number_of_elements_found,
29
+ start_time: @locator_start_time,
30
+ end_time: Time.now
31
+ }
32
+ end
33
+
34
+ def after_quit(driver)
35
+ ::RestClient.put "#{@base_url}/tests/#{@test_id}", {
36
+ access_token: @access_token,
37
+ end_time: Time.now
38
+ }
39
+ end
40
+
41
+ private
42
+
43
+ def get_javascript(by, what)
44
+ if by.include? 'id'
45
+ "document.querySelectorAll('##{what}').length"
46
+ elsif by.include? 'class'
47
+ "document.getElementsByClassName('#{what}').length"
48
+ elsif by.include? 'tag'
49
+ "document.getElementsByTagName('#{what}').length"
50
+ elsif by.include? 'name'
51
+ "document.getElementsByName('#{what}').length"
52
+ elsif by.include? 'css'
53
+ "document.querySelectorAll('#{what}').length"
54
+ elsif by.include? 'xpath'
55
+ "document.evaluate(\"#{what}\", document.documentElement, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength"
56
+ elsif by.include? 'text'
57
+ what = "//a[contains(text(),'#{what}')]"
58
+ "document.evaluate(\"#{what}\", document.documentElement, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength"
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module Locution
2
+ module Sdk
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'locution/sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "locution-sdk"
8
+ spec.version = Locution::Sdk::VERSION
9
+ spec.authors = ["Dave Haeffner"]
10
+ spec.email = ["dhaeffner@gmail.com"]
11
+
12
+ spec.summary = %q{An SDK to connect your Selenium tests to Locution to get your tests graded}
13
+ spec.description = %q{Find out how reliable your existing Selenium tests are by automatically grading your locators against a battle-tested and curated set of best-practices}
14
+ spec.homepage = "https://rubygems.org/gems/locution-sdk"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.12"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_dependency "selenium-webdriver", "~> 2.53.4"
31
+ spec.add_dependency "rest-client", "~> 2.0.0"
32
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locution-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Haeffner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: selenium-webdriver
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.53.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.53.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
69
+ description: Find out how reliable your existing Selenium tests are by automatically
70
+ grading your locators against a battle-tested and curated set of best-practices
71
+ email:
72
+ - dhaeffner@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/locution-sdk.rb
83
+ - lib/locution/sdk/listener.rb
84
+ - lib/locution/sdk/version.rb
85
+ - locution-sdk.gemspec
86
+ homepage: https://rubygems.org/gems/locution-sdk
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: An SDK to connect your Selenium tests to Locution to get your tests graded
110
+ test_files: []