swamp 1.1.2 → 1.2.0
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 +4 -4
- data/README.md +30 -14
- data/bin/swamp +7 -3
- data/features/specifications/scope_changing.feature +34 -0
- data/features/specifications/user_scans_buttons_in_a_page.feature +3 -3
- data/features/specifications/user_scans_fields_in_a_page.feature +3 -3
- data/features/specifications/user_scans_input_buttons_in_a_page.feature +2 -2
- data/features/specifications/user_scans_links_in_a_page.feature +1 -1
- data/features/specifications/user_scans_select_box_elements_in_a_page.feature +3 -3
- data/features/step_definitions/swamp_steps.rb +19 -8
- data/features/support/setup.rb +9 -4
- data/lib/swamp.rb +2 -0
- data/lib/swamp/assertions.rb +7 -0
- data/lib/swamp/builder.rb +10 -6
- data/lib/swamp/interface.rb +8 -2
- data/lib/swamp/setup.rb +49 -0
- data/lib/swamp/version.rb +1 -1
- data/lib/swamp/wrapper.rb +5 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/swamp/builder_spec.rb +18 -8
- data/spec/swamp/buttons_spec.rb +37 -37
- data/spec/swamp/evaluator_spec.rb +10 -10
- data/spec/swamp/fields_spec.rb +36 -36
- data/spec/swamp/formatter_spec.rb +7 -7
- data/spec/swamp/input_buttons_spec.rb +24 -24
- data/spec/swamp/interface_spec.rb +31 -15
- data/spec/swamp/links_spec.rb +12 -12
- data/spec/swamp/select_boxes_spec.rb +30 -30
- data/spec/swamp/setup_spec.rb +41 -0
- data/spec/swamp/wrapper_spec.rb +28 -26
- metadata +32 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 321488f9c4e58a1213185e05bce1473a6777bf6d
|
4
|
+
data.tar.gz: 929ab8a776d0303b5c211b1cd9e0787435d6ebd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f9c38ba1d09493db01a42820a7befd550ba1d0b8d7fd20dc72d5423e81ea37e0a31e9415075a5a9441439c6bed341b6596ed3c3fe6b945466250c0c74caa317
|
7
|
+
data.tar.gz: 5324834c433679cf9a7409ceac75d3f9f4d886e759d1db0b8ce249e8714e4766aa4f5869b763d9d776272009b7519c560d5db135687e819fb78d7feab97018ec
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/Juraci/swamp)
|
4
4
|
|
5
5
|
Automatically generates the interfaces for the most common actions that a page can provide,
|
6
|
-
so you can use the generated methods to quickly create your page objects using [capybara](https://github.com/jnicklas/capybara)
|
6
|
+
so you can use the generated methods to quickly create your page objects using [capybara](https://github.com/jnicklas/capybara).
|
7
7
|
|
8
8
|
## How to install
|
9
9
|
|
@@ -42,22 +42,22 @@ https://accounts.google.com
|
|
42
42
|
Scanning, please wait...
|
43
43
|
|
44
44
|
def type_email(input)
|
45
|
-
|
45
|
+
page.fill_in("Email", with: input)
|
46
46
|
end
|
47
47
|
def type_passwd(input)
|
48
|
-
|
48
|
+
page.fill_in("Passwd", with: input)
|
49
49
|
end
|
50
50
|
def sign_in
|
51
|
-
|
51
|
+
page.find(:css, "#signIn").click
|
52
52
|
end
|
53
53
|
def select_lang_chooser(option)
|
54
|
-
|
54
|
+
page.select(option, :from => "lang-chooser")
|
55
55
|
end
|
56
56
|
def link_forgot_passwd
|
57
|
-
|
57
|
+
page.click_link("link-forgot-passwd")
|
58
58
|
end
|
59
59
|
def link_signup
|
60
|
-
|
60
|
+
page.click_link("link-signup")
|
61
61
|
end
|
62
62
|
```
|
63
63
|
(notice that the method names are a best guess and you are always free to change them)
|
@@ -66,32 +66,32 @@ end
|
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
module PageObjects
|
69
|
-
class SignIn
|
69
|
+
class SignIn
|
70
70
|
|
71
71
|
path ""
|
72
72
|
|
73
73
|
def type_email(input)
|
74
|
-
|
74
|
+
page.fill_in("Email", with: input)
|
75
75
|
end
|
76
76
|
|
77
77
|
def type_passwd(input)
|
78
|
-
|
78
|
+
page.fill_in("Passwd", with: input)
|
79
79
|
end
|
80
80
|
|
81
81
|
def sign_in
|
82
|
-
|
82
|
+
page.find(:css, "#signIn").click
|
83
83
|
end
|
84
84
|
|
85
85
|
def select_lang_chooser(option)
|
86
|
-
|
86
|
+
page.select(option, :from => "lang-chooser")
|
87
87
|
end
|
88
88
|
|
89
89
|
def link_forgot_passwd
|
90
|
-
|
90
|
+
page.click_link("link-forgot-passwd")
|
91
91
|
end
|
92
92
|
|
93
93
|
def link_signup
|
94
|
-
|
94
|
+
page.click_link("link-signup")
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -118,6 +118,22 @@ end
|
|
118
118
|
* Then just go to the terminal and hit ENTER
|
119
119
|
* Swamp will detect the new elements (if any) and will generate the code snippets the same way as before
|
120
120
|
|
121
|
+
### Generating code snippets to use with [capybara-page-object](https://github.com/andyw8/capybara-page-object)
|
122
|
+
|
123
|
+
You can easily change the scope from "page" to "source" by using the following command:
|
124
|
+
|
125
|
+
```shell
|
126
|
+
:scope = source
|
127
|
+
```
|
128
|
+
|
129
|
+
then the code snippets will be generated with the "source" scope like this:
|
130
|
+
|
131
|
+
```shell
|
132
|
+
def link_signup
|
133
|
+
source.click_link("link-signup")
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
121
137
|
## How it works?
|
122
138
|
|
123
139
|
It uses capybara to fireup the browser and visit the target URL then it looks for patterns like:
|
data/bin/swamp
CHANGED
@@ -2,19 +2,23 @@
|
|
2
2
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
3
|
require 'swamp'
|
4
4
|
|
5
|
+
setup = Swamp::Setup.new
|
5
6
|
fields = Swamp::Fields.new
|
6
7
|
buttons = Swamp::Buttons.new
|
7
8
|
input_buttons = Swamp::InputButtons.new
|
8
9
|
select_boxes = Swamp::SelectBoxes.new
|
9
10
|
links = Swamp::Links.new
|
10
11
|
meta_collection = [fields, buttons, input_buttons, select_boxes, links]
|
11
|
-
wrapper = Swamp::Wrapper.new(meta_collection)
|
12
|
-
swamp = Swamp::Interface.new(STDOUT, wrapper)
|
12
|
+
wrapper = Swamp::Wrapper.new(meta_collection, setup)
|
13
|
+
swamp = Swamp::Interface.new(STDOUT, wrapper, setup)
|
13
14
|
swamp.run
|
14
15
|
|
15
16
|
while input = gets
|
16
17
|
if input.chomp == 'exit'
|
17
18
|
exit
|
19
|
+
elsif input[0] == ':'
|
20
|
+
swamp.setup_command(input)
|
21
|
+
else
|
22
|
+
swamp.scan(input)
|
18
23
|
end
|
19
|
-
swamp.scan(input)
|
20
24
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Feature: user changes the scope in the runtime
|
2
|
+
|
3
|
+
As a swamp user
|
4
|
+
I want to change the scope from "page" to "source"
|
5
|
+
So I can have snippets that are compatible with capybara-page-object gem
|
6
|
+
|
7
|
+
Scenario Outline: User receives feedback from swamp on command execution
|
8
|
+
Given that swamp is already running
|
9
|
+
When I attempt to execute the command <command>
|
10
|
+
Then I should see <expected>
|
11
|
+
|
12
|
+
Examples: Happy paths
|
13
|
+
| command | expected |
|
14
|
+
| ":scope = source" | "Option :scope set to source" |
|
15
|
+
| ":scope = page" | "Option :scope set to page" |
|
16
|
+
|
17
|
+
Examples: Corner cases
|
18
|
+
| command | expected |
|
19
|
+
| ":scope=source" | "Option :scope set to source" |
|
20
|
+
| ":scope = page" | "Option :scope set to page" |
|
21
|
+
| ":scope = " | "Invalid command" |
|
22
|
+
| ":whatever = random" | "Invalid command" |
|
23
|
+
| ": = " | "Invalid command" |
|
24
|
+
|
25
|
+
Scenario: User changes the scope from page to source
|
26
|
+
Given that swamp is already running
|
27
|
+
When I attempt to execute the command ":scope = source"
|
28
|
+
And I attempt to scan this page: "button.html"
|
29
|
+
Then swamp should output the following code snippet
|
30
|
+
"""
|
31
|
+
def sign_up
|
32
|
+
source.click_button("Sign Up")
|
33
|
+
end
|
34
|
+
"""
|
@@ -14,7 +14,7 @@ Feature: user scans buttons in a page
|
|
14
14
|
And it should output the following code snippet
|
15
15
|
"""
|
16
16
|
def sign_up
|
17
|
-
|
17
|
+
page.click_button("Sign Up")
|
18
18
|
end
|
19
19
|
"""
|
20
20
|
|
@@ -25,7 +25,7 @@ Feature: user scans buttons in a page
|
|
25
25
|
And it should output the following code snippet
|
26
26
|
"""
|
27
27
|
def search_button
|
28
|
-
|
28
|
+
page.click_button("search-button")
|
29
29
|
end
|
30
30
|
"""
|
31
31
|
|
@@ -36,7 +36,7 @@ Feature: user scans buttons in a page
|
|
36
36
|
And it should output the following code snippet
|
37
37
|
"""
|
38
38
|
def buy_now
|
39
|
-
|
39
|
+
page.click_button("buy-now")
|
40
40
|
end
|
41
41
|
"""
|
42
42
|
|
@@ -14,7 +14,7 @@ Feature: user scans fields in a page
|
|
14
14
|
And it should output the following code snippet
|
15
15
|
"""
|
16
16
|
def type_username(input)
|
17
|
-
|
17
|
+
page.fill_in("id_username", with: input)
|
18
18
|
end
|
19
19
|
"""
|
20
20
|
|
@@ -25,7 +25,7 @@ Feature: user scans fields in a page
|
|
25
25
|
Then it should output the following code snippet
|
26
26
|
"""
|
27
27
|
def type_username(input)
|
28
|
-
|
28
|
+
page.fill_in("username", with: input)
|
29
29
|
end
|
30
30
|
"""
|
31
31
|
|
@@ -36,7 +36,7 @@ Feature: user scans fields in a page
|
|
36
36
|
Then it should output the following code snippet
|
37
37
|
"""
|
38
38
|
def type_username(input)
|
39
|
-
|
39
|
+
page.fill_in("username", with: input)
|
40
40
|
end
|
41
41
|
"""
|
42
42
|
|
@@ -14,7 +14,7 @@ Feature: user scans submits in a page
|
|
14
14
|
And it should output the following code snippet
|
15
15
|
"""
|
16
16
|
def log_in
|
17
|
-
|
17
|
+
page.find(:css, "#u_0_b").click
|
18
18
|
end
|
19
19
|
"""
|
20
20
|
|
@@ -25,6 +25,6 @@ Feature: user scans submits in a page
|
|
25
25
|
And it should output the following code snippet
|
26
26
|
"""
|
27
27
|
def continue
|
28
|
-
|
28
|
+
page.find(:css, "input.button.g-button.g-button-submit[value='Continue']").click
|
29
29
|
end
|
30
30
|
"""
|
@@ -14,7 +14,7 @@ Feature: user scans select box elements in a page
|
|
14
14
|
And it should output the following code snippet
|
15
15
|
"""
|
16
16
|
def select_month(option)
|
17
|
-
|
17
|
+
page.select(option, :from => "month")
|
18
18
|
end
|
19
19
|
"""
|
20
20
|
|
@@ -25,7 +25,7 @@ Feature: user scans select box elements in a page
|
|
25
25
|
And it should output the following code snippet
|
26
26
|
"""
|
27
27
|
def select_region(option)
|
28
|
-
|
28
|
+
page.select(option, :from => "Region")
|
29
29
|
end
|
30
30
|
"""
|
31
31
|
|
@@ -36,6 +36,6 @@ Feature: user scans select box elements in a page
|
|
36
36
|
And it should output the following code snippet
|
37
37
|
"""
|
38
38
|
def provider_select(option)
|
39
|
-
|
39
|
+
page.find(:css, "select.provider-select option[value='#{option}']").click
|
40
40
|
end
|
41
41
|
"""
|
@@ -6,7 +6,7 @@ When /^(?:I start it|that swamp is already running)$/ do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
Then /^I should see "(.*?)"$/ do |outcome|
|
9
|
-
|
9
|
+
fake_output.messages.should include(outcome)
|
10
10
|
end
|
11
11
|
|
12
12
|
Given /^I enter the url for this page: "(\w+\.html)"$/ do |page|
|
@@ -18,15 +18,22 @@ When /^swamp scans that page$/ do
|
|
18
18
|
swamp.scan(@url)
|
19
19
|
end
|
20
20
|
|
21
|
+
When /^I attempt to scan this page: "(\w+\.html)"$/ do |page|
|
22
|
+
path = File.join(File.dirname(__FILE__), '../support/page_examples/', page)
|
23
|
+
url = "file://#{path}"
|
24
|
+
swamp.scan(url)
|
25
|
+
end
|
26
|
+
|
21
27
|
Then /^(?:swamp|it) should output the following code snippets?$/ do |string|
|
22
|
-
|
28
|
+
fake_output.messages.should include(string)
|
23
29
|
end
|
24
30
|
|
25
31
|
Then /^swamp should not output any snippet$/ do
|
26
|
-
|
27
|
-
|
32
|
+
fake_output.messages.size.should <= 3
|
33
|
+
fake_output.messages.each do |m|
|
28
34
|
m.should_not include("def")
|
29
35
|
m.should_not include("source.")
|
36
|
+
m.should_not include("page.")
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
@@ -35,7 +42,7 @@ Given /^that swamp already have scanned a page$/ do
|
|
35
42
|
path = File.join(File.dirname(__FILE__), '../support/page_examples/', "button.html")
|
36
43
|
@url = "file://#{path}"
|
37
44
|
swamp.scan(@url)
|
38
|
-
|
45
|
+
fake_output.messages.should include("def sign_up\n page.click_button(\"Sign Up\")\nend")
|
39
46
|
end
|
40
47
|
|
41
48
|
When /^I attempt to hit enter at the terminal$/ do
|
@@ -43,9 +50,9 @@ When /^I attempt to hit enter at the terminal$/ do
|
|
43
50
|
end
|
44
51
|
|
45
52
|
Then /^swamp should scan the current page$/ do
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
fake_output.messages.size.should <= 5
|
54
|
+
fake_output.messages[3].should == "Scanning, please wait..."
|
55
|
+
fake_output.messages[4].should == "def sign_up\n page.click_button(\"Sign Up\")\nend"
|
49
56
|
end
|
50
57
|
|
51
58
|
Then /^swamp should highlight this (element|link): "(.+)"$/ do |mode, selector|
|
@@ -58,3 +65,7 @@ Then /^swamp should highlight this (element|link): "(.+)"$/ do |mode, selector|
|
|
58
65
|
page.find(selector)[:style].should include("background-color: rgb(255, 0, 0)")
|
59
66
|
end
|
60
67
|
end
|
68
|
+
|
69
|
+
When /^I attempt to execute the command "(.*?)"$/ do |command|
|
70
|
+
swamp.setup_command(command)
|
71
|
+
end
|
data/features/support/setup.rb
CHANGED
@@ -8,8 +8,12 @@ class Output
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
@
|
11
|
+
def fake_output
|
12
|
+
@fake_output ||= Output.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@setup ||= Swamp::Setup.new
|
13
17
|
end
|
14
18
|
|
15
19
|
def buttons
|
@@ -34,9 +38,10 @@ end
|
|
34
38
|
|
35
39
|
def wrapper
|
36
40
|
meta_collection = [fields, buttons, input_buttons, select_boxes, links]
|
37
|
-
Swamp::Wrapper.new(meta_collection)
|
41
|
+
Swamp::Wrapper.new(meta_collection, setup)
|
38
42
|
end
|
39
43
|
|
44
|
+
|
40
45
|
def swamp
|
41
|
-
@swamp ||= Swamp::Interface.new(
|
46
|
+
@swamp ||= Swamp::Interface.new(fake_output, wrapper, setup)
|
42
47
|
end
|
data/lib/swamp.rb
CHANGED
data/lib/swamp/builder.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module Swamp
|
2
2
|
class Builder
|
3
|
-
|
3
|
+
|
4
|
+
attr_reader :element
|
5
|
+
|
6
|
+
def initialize(element, setup)
|
4
7
|
@element = element
|
8
|
+
@setup = setup
|
5
9
|
end
|
6
10
|
|
7
11
|
def build_snippet
|
8
|
-
if
|
9
|
-
[method_definition,
|
12
|
+
if element.name
|
13
|
+
[method_definition, element.method_signature, line_break, identation, scope, element.accessor, line_break, method_end].join
|
10
14
|
else
|
11
|
-
[
|
15
|
+
[scope, element.accessor].join
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -20,8 +24,8 @@ module Swamp
|
|
20
24
|
"end"
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
"
|
27
|
+
def scope
|
28
|
+
[@setup.scope, "."].join
|
25
29
|
end
|
26
30
|
|
27
31
|
def identation
|
data/lib/swamp/interface.rb
CHANGED
@@ -5,9 +5,10 @@ module Swamp
|
|
5
5
|
INVALID_REQUEST_MESSAGE = ['Please enter a valid url!']
|
6
6
|
NO_ELEMENTS_MESSAGE = ['No elements were detected']
|
7
7
|
|
8
|
-
def initialize(output, wrapper)
|
8
|
+
def initialize(output, wrapper, setup)
|
9
9
|
@output = output
|
10
10
|
@wrapper = wrapper
|
11
|
+
@setup = setup
|
11
12
|
end
|
12
13
|
|
13
14
|
def run
|
@@ -20,7 +21,10 @@ module Swamp
|
|
20
21
|
present messages
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
def setup_command(input)
|
25
|
+
messages = @setup.handle_command(input)
|
26
|
+
present messages
|
27
|
+
end
|
24
28
|
|
25
29
|
def present(messages)
|
26
30
|
messages.each do |message|
|
@@ -28,6 +32,8 @@ module Swamp
|
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
35
|
+
private
|
36
|
+
|
31
37
|
def valid_request?(input)
|
32
38
|
evaluator(input).valid_url? or evaluator(input).refresh_command?
|
33
39
|
end
|