side_to_capybara 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/side2capybara +24 -0
- data/lib/side_to_capybara/base.rb +76 -0
- data/lib/side_to_capybara/minitest.rb +33 -0
- data/lib/side_to_capybara/version.rb +3 -0
- data/lib/side_to_capybara.rb +19 -0
- data/side_to_capybara.gemspec +24 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4782d6ff7fa955a88f58ed0f998fef8e37564b647a89be7f04383a5d9be10dc5
|
4
|
+
data.tar.gz: 495d92f8a688ebc3b7fd306be24dcc6a413d7c01b59e9d3f13a7e486963a1993
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9744b0e838a57880a1f4b963ffe7cb2627376a00860d4b7f179cdcbe5766b61d33d7c9149a8c3725fa1bd275b4d3306bf6f11ccccd37e0c8cfcda394ef1ee22a
|
7
|
+
data.tar.gz: 1b72b6a7deac061cafe6658af0898c769327126408b204fc3d8cf35b6dd5218a0621c8795a38183f97c403b5829435262343aae8d3edc195c3a0237539978f67
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
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,86 @@
|
|
1
|
+
# SideToCapybara
|
2
|
+
|
3
|
+
side2capybara 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
|
+
`side2capybara 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 `side2capybara` install:
|
40
|
+
|
41
|
+
$ gem install side_to_capybara
|
42
|
+
|
43
|
+
|
44
|
+
### ... as a library
|
45
|
+
|
46
|
+
Add this line to your Gemfile:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem 'side_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 `side2capybara path/to/saved/*.side`
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
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.
|
73
|
+
|
74
|
+
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).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/DarkSwoop/side_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.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
83
|
+
|
84
|
+
## Code of Conduct
|
85
|
+
|
86
|
+
Everyone interacting in the SideToCapybara project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DarkSwoop/side_to_capybara/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "side_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
data/exe/side2capybara
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
require 'side_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 SideToCapybara.to_minitest(test_instance['name'], test_instance['commands'])
|
24
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module SideToCapybara
|
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
|
+
|
48
|
+
# add the alternative selectors as comments
|
49
|
+
translation.unshift(commented_targets.join("\n")) if targets.size > 1
|
50
|
+
translation.join("\n")
|
51
|
+
else
|
52
|
+
"# WARNING: Conversion for '#{command}' not found."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def split_target(target)
|
59
|
+
/^(\w+)=(.*)$/.match(target)[1..2]
|
60
|
+
end
|
61
|
+
|
62
|
+
def _selector(target)
|
63
|
+
split_target(target).last
|
64
|
+
end
|
65
|
+
|
66
|
+
def _selector_type(target)
|
67
|
+
split_target(target).first
|
68
|
+
end
|
69
|
+
|
70
|
+
def commented_targets
|
71
|
+
targets.map { |target| "# #{_selector_type(target.first)}: #{_selector(target.first)}" }.uniq
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SideToCapybara
|
2
|
+
|
3
|
+
class Minitest < Base
|
4
|
+
def open
|
5
|
+
"visit('#{target}')"
|
6
|
+
end
|
7
|
+
|
8
|
+
def double_click
|
9
|
+
case selector_type
|
10
|
+
when 'css'
|
11
|
+
"find('#{selector}').double_click"
|
12
|
+
when 'id'
|
13
|
+
"find('##{selector}').double_click"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def click
|
18
|
+
case selector_type
|
19
|
+
when 'css'
|
20
|
+
"find('#{selector}').click"
|
21
|
+
when 'id'
|
22
|
+
"find('##{selector}').click"
|
23
|
+
when 'linkText'
|
24
|
+
"click_on('#{selector}')"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_text
|
29
|
+
"assert_selector('#{selector}', text: '#{value}')"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "side_to_capybara/version"
|
2
|
+
require 'side_to_capybara/base'
|
3
|
+
require 'side_to_capybara/minitest'
|
4
|
+
|
5
|
+
module SideToCapybara
|
6
|
+
|
7
|
+
def self.to_minitest(name, commands)
|
8
|
+
test_commands = commands.map do |command|
|
9
|
+
Minitest.new(command).translate
|
10
|
+
end
|
11
|
+
|
12
|
+
<<~EOS
|
13
|
+
test '#{name}' do
|
14
|
+
#{test_commands.map {|x| " #{x.gsub(/\n/, "\n ")}"}.join("\n\n")}
|
15
|
+
end
|
16
|
+
EOS
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "side_to_capybara/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "side_to_capybara"
|
7
|
+
spec.version = SideToCapybara::VERSION
|
8
|
+
spec.authors = ["Benjamin Behr"]
|
9
|
+
spec.email = ["benny@digitalbehr.de"]
|
10
|
+
|
11
|
+
spec.summary = %q{Translate .side files to capybara tests}
|
12
|
+
spec.homepage = "https://github.com/DarkSwoop/side_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: side_to_capybara
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Behr
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-14 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
|
+
- side2capybara
|
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/side2capybara
|
58
|
+
- lib/side_to_capybara.rb
|
59
|
+
- lib/side_to_capybara/base.rb
|
60
|
+
- lib/side_to_capybara/minitest.rb
|
61
|
+
- lib/side_to_capybara/version.rb
|
62
|
+
- side_to_capybara.gemspec
|
63
|
+
homepage: https://github.com/DarkSwoop/side_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: Translate .side files to capybara tests
|
87
|
+
test_files: []
|