selenium_to_capybara 0.1.4

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
+ SHA256:
3
+ metadata.gz: ce0be055d93c2e620d876d89dfabc5cccdbcf688bc5ac95e3b98f98d8b907f1c
4
+ data.tar.gz: '0836aa609f702a67c5d96fdcd7555decab993e1398e1edfd57d88ba7796bf58b'
5
+ SHA512:
6
+ metadata.gz: 51c0bb577207d6e1f352e178594d28eb0baf972dfd909d5842f96d6b4cc0efbe5890e83c9f3d924c8c5ea600192536508e65d3510240e8039aa8afebf0f48ea3
7
+ data.tar.gz: 55ea073c84ec06e178c420c30d52f2676e316a9d8b05d76b56bc9b95de49a1059aa4c8a7413f328668bd06815c3453c887b3d2512bb929b4d42af3cebd3bc8dc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at benny@digitalbehr.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in selenium_to_capybara.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Benjamin Behr
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,90 @@
1
+ # SeleniumToCapybara
2
+
3
+ selenium2capybara translates a Selenium `.side` file into executable capybara tests. It is by no way meant to write the final system tests for you but take it as a good starting point.
4
+
5
+ If you do this:
6
+
7
+ `selenium2capybara path/to/saved/*.side`
8
+
9
+ you may get that:
10
+
11
+ ```ruby
12
+ test 'checkout' do
13
+ visit('/')
14
+
15
+ # css: .tile:nth-child(4)
16
+ # xpath: //a[contains(@href, '/products/P23A-S_FW1819')]
17
+ # xpath: //a[4]
18
+ find('.tile:nth-child(4)').click
19
+
20
+ # linkText: Buy now
21
+ # css: .buy
22
+ # xpath: //a[contains(text(),'Buy now')]
23
+ # xpath: //form[@id='new_product_item']/div/a
24
+ # xpath: //a[contains(@href, '#')]
25
+ # xpath: //form/div/a
26
+ click_on('Buy now')
27
+
28
+ # css: tr:nth-child(11) > td:nth-child(3)
29
+ # xpath: //form[@id='new_order']/div/div[3]/div/table/tbody/tr[11]/td[3]
30
+ # xpath: //tr[11]/td[3]
31
+ assert_selector('tr:nth-child(11) > td:nth-child(3)', text: '123.45 €')
32
+ end
33
+ ```
34
+
35
+ ## Installation
36
+
37
+ ### ... as executable
38
+
39
+ To run `selenium2capybara` install:
40
+
41
+ $ gem install selenium_to_capybara
42
+
43
+
44
+ ### ... as a library
45
+
46
+ Add this line to your Gemfile:
47
+
48
+ ```ruby
49
+ gem 'selenium_to_capybara'
50
+ ```
51
+
52
+ And then execute:
53
+
54
+ $ bundle
55
+
56
+
57
+ ### Required Additional Installation
58
+
59
+ In order to create the needed .side files the Selenium IDE plugin must be installed in your webbrowser.
60
+
61
+ - [Chrome](https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd)
62
+ - [Firefox](https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/)
63
+
64
+ ## Usage
65
+
66
+ 1. Create a test with the Selenium IDE plugin
67
+ 2. Save the test to the disk
68
+ 3. run `selenium2capybara path/to/saved/*.side`
69
+
70
+ ## Translation contribution
71
+
72
+ The translations for minitest are currently placed in `lib/selenium_to_capybara/minitest.rb`. Feel free to add more or update the existing translations. To add a new translation open the `.side` file in your favourite text editor. It's a JSON file. Search for the command you want to add and define a new method with the name of the command in `minitest.rb`. For a more detailed description of how to add a new command translation please look at the `minitest.rb` file.
73
+
74
+ ## Development
75
+
76
+ 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.
77
+
78
+ 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).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DarkSwoop/selenium_to_capybara. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the SeleniumToCapybara project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DarkSwoop/selenium_to_capybara/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "selenium_to_capybara"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'pathname'
5
+
6
+ require 'selenium_to_capybara'
7
+
8
+ file_path = ARGV[0]
9
+
10
+ raise "must be a .side file" unless file_path.end_with?('.side')
11
+
12
+ side_file = if file_path.start_with?('~')
13
+ Pathname.new(Dir.home).join(file_path.sub('^~/', ''))
14
+ elsif file_path.start_with?('/')
15
+ Pathname.new(file_path)
16
+ else
17
+ Pathname.getwd.join(file_path)
18
+ end
19
+
20
+ json = JSON.parse(side_file.read)
21
+
22
+ json['tests'].each do |test_instance|
23
+ puts SeleniumToCapybara.to_minitest(test_instance['name'], test_instance['commands'])
24
+ end
@@ -0,0 +1,24 @@
1
+ require "selenium_to_capybara/version"
2
+ require 'selenium_to_capybara/base'
3
+ require 'selenium_to_capybara/minitest'
4
+
5
+ module SeleniumToCapybara
6
+
7
+ def self.to_minitest(name, commands)
8
+ test_commands = commands.map do |command|
9
+ Minitest.new(command).translate
10
+ end
11
+
12
+ warning_present = test_commands.any? {|translation| translation.start_with?('# WARNING:')}
13
+
14
+ output = []
15
+ output << <<~EOS
16
+ test '#{name}' do
17
+ #{test_commands.map {|x| " #{x.gsub(/\n/, "\n ")}"}.join("\n\n")}
18
+ end
19
+ EOS
20
+ output << "\n# WARNING: Some commands are unhandled. Please contribute here: https://github.com/DarkSwoop/selenium_to_capybara" if warning_present
21
+ output.join("\n")
22
+ end
23
+
24
+ end
@@ -0,0 +1,80 @@
1
+ module SeleniumToCapybara
2
+
3
+ class Base
4
+ attr_reader :side_command
5
+ def initialize(side_command)
6
+ @side_command = side_command
7
+ end
8
+
9
+ def target
10
+ @side_command['target']
11
+ end
12
+
13
+ def targets
14
+ @side_command['targets']
15
+ end
16
+
17
+ def value
18
+ @side_command['value']
19
+ end
20
+
21
+ def command
22
+ @side_command['command']
23
+ end
24
+
25
+ def comment
26
+ @side_command['comment']
27
+ end
28
+
29
+ def id
30
+ @side_command['id']
31
+ end
32
+
33
+ def selector_type
34
+ _selector_type(target)
35
+ end
36
+
37
+ def selector
38
+ _selector(target)
39
+ end
40
+
41
+ # returns the translation of the command or a warning if the command can't be translated
42
+ def translate
43
+ method_id = command.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
44
+ if self.class.public_method_defined?(method_id)
45
+ # the translation itself
46
+ translation = public_send(method_id)
47
+ return "# WARNING: '#{command}' found but the selector_type '#{selector_type}' is unhandled." if translation.nil?
48
+
49
+ # add the alternative selectors as comments if present
50
+ if targets.size > 1
51
+ "#{commented_targets.join("\n")}\n#{translation}"
52
+ else
53
+ translation
54
+ end
55
+ else
56
+ "# WARNING: Conversion for '#{command}' not found."
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def split_target(target)
63
+ /^(\w+)=(.*)$/.match(target)[1..2]
64
+ end
65
+
66
+ def _selector(target)
67
+ split_target(target).last
68
+ end
69
+
70
+ def _selector_type(target)
71
+ split_target(target).first
72
+ end
73
+
74
+ def commented_targets
75
+ targets.map { |target| "# #{_selector_type(target.first)}: #{_selector(target.first)}" }.uniq
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,58 @@
1
+ module SeleniumToCapybara
2
+
3
+ # This class holds the translations for minitest.
4
+ #
5
+ # To add a translation you need to do the following steps:
6
+ # 1. Open the .side file and find the command you want to add
7
+ # 2. Define a method in the Minitest class with the command as name.
8
+ # The command name must be translated to the ruby version of the name. `assertText` => `assert_text`
9
+ # 3. Define the translation
10
+ #
11
+ # The properties of the whole .side command object are accessible through ruby methods.
12
+ # - `target` is the preferred target selector of Selenium IDE
13
+ # - `targets` holds all possible target selectors identified by Selenium IDE
14
+ # - `selector_type` identifies the type of the preferred target selector (e.g css, xpath)
15
+ # - `selector` is the selector of the preferred target selector itself. (e.g 'body .header .title')
16
+ # - `value` e.g. the value that a text field should get
17
+ # - `command` the command name itself like `assertText` or `click`
18
+ # - `comment` a optional comment for that command
19
+ # - `id` the internal id generated by Selenium IDE
20
+ class Minitest < Base
21
+ def open
22
+ "visit('#{target}')"
23
+ end
24
+
25
+ def double_click
26
+ case selector_type
27
+ when 'css'
28
+ "find('#{selector}').double_click"
29
+ when 'id'
30
+ "find('##{selector}').double_click"
31
+ when 'xpath'
32
+ "find('#{selector}').double_click"
33
+ when 'name'
34
+ "find('[name=\"#{selector}\"]').double_click"
35
+ end
36
+ end
37
+
38
+ def click
39
+ case selector_type
40
+ when 'css'
41
+ "find('#{selector}').click"
42
+ when 'id'
43
+ "find('##{selector}').click"
44
+ when 'xpath'
45
+ "find('#{selector}').click"
46
+ when 'name'
47
+ "find('[name=\"#{selector}\"]').click"
48
+ when 'linkText'
49
+ "click_link_or_button('#{selector}')"
50
+ end
51
+ end
52
+
53
+ def assert_text
54
+ "assert_selector('#{selector}', text: '#{value}')"
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,3 @@
1
+ module SeleniumToCapybara
2
+ VERSION = "0.1.4"
3
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "selenium_to_capybara/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "selenium_to_capybara"
7
+ spec.version = SeleniumToCapybara::VERSION
8
+ spec.authors = ["Benjamin Behr"]
9
+ spec.email = ["benny@digitalbehr.de"]
10
+
11
+ spec.summary = %q{Translates selenium tests to capybara.}
12
+ spec.homepage = "https://github.com/DarkSwoop/selenium_to_capybara"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium_to_capybara
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Behr
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-15 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ description:
42
+ email:
43
+ - benny@digitalbehr.de
44
+ executables:
45
+ - selenium2capybara
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - exe/selenium2capybara
58
+ - lib/selenium_to_capybara.rb
59
+ - lib/selenium_to_capybara/base.rb
60
+ - lib/selenium_to_capybara/minitest.rb
61
+ - lib/selenium_to_capybara/version.rb
62
+ - selenium_to_capybara.gemspec
63
+ homepage: https://github.com/DarkSwoop/selenium_to_capybara
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.7.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Translates selenium tests to capybara.
87
+ test_files: []