swamp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +79 -0
- data/README.md +5 -0
- data/Rakefile +8 -0
- data/bin/swamp +20 -0
- data/features/specifications/user_scans_a_page_interactively.feature +10 -0
- data/features/specifications/user_scans_buttons_in_a_page.feature +43 -0
- data/features/specifications/user_scans_fields_in_a_page.feature +38 -0
- data/features/specifications/user_scans_input_buttons_in_a_page.feature +28 -0
- data/features/specifications/user_scans_links_in_a_page.feature +18 -0
- data/features/specifications/user_scans_select_box_elements_in_a_page.feature +28 -0
- data/features/specifications/user_starts_swamp.feature +10 -0
- data/features/step_definitions/swamp_steps.rb +46 -0
- data/features/support/env.rb +2 -0
- data/features/support/page_examples/button.html +1 -0
- data/features/support/page_examples/button.html~ +0 -0
- data/features/support/page_examples/button_without_text.html +1 -0
- data/features/support/page_examples/button_without_text_id_and_value.html +1 -0
- data/features/support/page_examples/button_without_text_without_id_with_value.html +1 -0
- data/features/support/page_examples/checkbox.html +1 -0
- data/features/support/page_examples/field.html +1 -0
- data/features/support/page_examples/field_without_id.html +1 -0
- data/features/support/page_examples/input_submit.html +1 -0
- data/features/support/page_examples/input_submit_without_id.html +1 -0
- data/features/support/page_examples/link.html +1 -0
- data/features/support/page_examples/link.html~ +0 -0
- data/features/support/page_examples/link_with_id.html +5 -0
- data/features/support/page_examples/radio.html +1 -0
- data/features/support/page_examples/select_box_with_id.html +1 -0
- data/features/support/page_examples/select_box_with_name_only.html +1 -0
- data/features/support/setup.rb +42 -0
- data/lib/swamp/base.rb +29 -0
- data/lib/swamp/builder.rb +35 -0
- data/lib/swamp/button.rb +11 -0
- data/lib/swamp/buttons.rb +19 -0
- data/lib/swamp/element.rb +23 -0
- data/lib/swamp/elements.rb +39 -0
- data/lib/swamp/evaluator.rb +20 -0
- data/lib/swamp/field.rb +11 -0
- data/lib/swamp/fields.rb +21 -0
- data/lib/swamp/formatter.rb +51 -0
- data/lib/swamp/input_button.rb +11 -0
- data/lib/swamp/input_buttons.rb +19 -0
- data/lib/swamp/interface.rb +33 -0
- data/lib/swamp/link.rb +11 -0
- data/lib/swamp/links.rb +15 -0
- data/lib/swamp/select_box.rb +11 -0
- data/lib/swamp/select_boxes.rb +17 -0
- data/lib/swamp/version.rb +3 -0
- data/lib/swamp/wrapper.rb +25 -0
- data/lib/swamp.rb +26 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/swamp/builder_spec.rb +36 -0
- data/spec/swamp/buttons_spec.rb +93 -0
- data/spec/swamp/evaluator_spec.rb +75 -0
- data/spec/swamp/fields_spec.rb +88 -0
- data/spec/swamp/formatter_spec.rb +59 -0
- data/spec/swamp/input_buttons_spec.rb +62 -0
- data/spec/swamp/interface_spec.rb +62 -0
- data/spec/swamp/links_spec.rb +34 -0
- data/spec/swamp/select_boxes_spec.rb +53 -0
- data/spec/swamp/wrapper_spec.rb +104 -0
- data/swamp.gemspec +31 -0
- metadata +274 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 713e7f0bd7a7b052bcd1f90f476fbe4ff2a8a18f
|
4
|
+
data.tar.gz: 7ad124d4b613d636732929afdf56fc83404a9634
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70333aa5bcd6183513b20a6c0a55b87197bce65f0d88224929b0679b43127feb66cac1608fd60e85daee6e9f04b88cef15aceccd53247ea796fc81e9b1af3631
|
7
|
+
data.tar.gz: 2365c3852f58d9b6952fb200e2d0bb85cfdacc2cbc332d555c90b4be0a4edd9080aeaff8de8e4f2377432a5f07fd309fb1bf3c26383a2986370f4446ded306c9
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
swamp (0.0.1)
|
5
|
+
capybara
|
6
|
+
selenium-webdriver
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
builder (3.2.2)
|
12
|
+
capybara (2.1.0)
|
13
|
+
mime-types (>= 1.16)
|
14
|
+
nokogiri (>= 1.3.3)
|
15
|
+
rack (>= 1.0.0)
|
16
|
+
rack-test (>= 0.5.4)
|
17
|
+
xpath (~> 2.0)
|
18
|
+
childprocess (0.3.9)
|
19
|
+
ffi (~> 1.0, >= 1.0.11)
|
20
|
+
coderay (1.0.9)
|
21
|
+
cucumber (1.3.8)
|
22
|
+
builder (>= 2.1.2)
|
23
|
+
diff-lcs (>= 1.1.3)
|
24
|
+
gherkin (~> 2.12.1)
|
25
|
+
multi_json (>= 1.7.5, < 2.0)
|
26
|
+
multi_test (>= 0.0.2)
|
27
|
+
diff-lcs (1.2.4)
|
28
|
+
ffi (1.9.0)
|
29
|
+
gherkin (2.12.1)
|
30
|
+
multi_json (~> 1.3)
|
31
|
+
json (1.7.7)
|
32
|
+
method_source (0.8.2)
|
33
|
+
mime-types (1.25)
|
34
|
+
mini_portile (0.5.1)
|
35
|
+
multi_json (1.8.0)
|
36
|
+
multi_test (0.0.2)
|
37
|
+
nokogiri (1.6.0)
|
38
|
+
mini_portile (~> 0.5.0)
|
39
|
+
pry (0.9.12.2)
|
40
|
+
coderay (~> 1.0.5)
|
41
|
+
method_source (~> 0.8)
|
42
|
+
slop (~> 3.4)
|
43
|
+
pry-nav (0.2.3)
|
44
|
+
pry (~> 0.9.10)
|
45
|
+
rack (1.5.2)
|
46
|
+
rack-test (0.6.2)
|
47
|
+
rack (>= 1.0)
|
48
|
+
rake (10.1.0)
|
49
|
+
rspec (2.14.1)
|
50
|
+
rspec-core (~> 2.14.0)
|
51
|
+
rspec-expectations (~> 2.14.0)
|
52
|
+
rspec-mocks (~> 2.14.0)
|
53
|
+
rspec-core (2.14.5)
|
54
|
+
rspec-expectations (2.14.3)
|
55
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
56
|
+
rspec-mocks (2.14.3)
|
57
|
+
rubyzip (0.9.9)
|
58
|
+
selenium-webdriver (2.35.1)
|
59
|
+
childprocess (>= 0.2.5)
|
60
|
+
multi_json (~> 1.0)
|
61
|
+
rubyzip (< 1.0.0)
|
62
|
+
websocket (~> 1.0.4)
|
63
|
+
slop (3.4.6)
|
64
|
+
websocket (1.0.7)
|
65
|
+
xpath (2.0.0)
|
66
|
+
nokogiri (~> 1.3)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
bundler (~> 1.3)
|
73
|
+
cucumber
|
74
|
+
json
|
75
|
+
pry
|
76
|
+
pry-nav
|
77
|
+
rake
|
78
|
+
rspec
|
79
|
+
swamp!
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/swamp
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'swamp'
|
4
|
+
|
5
|
+
fields = Swamp::Fields.new
|
6
|
+
buttons = Swamp::Buttons.new
|
7
|
+
input_buttons = Swamp::InputButtons.new
|
8
|
+
select_boxes = Swamp::SelectBoxes.new
|
9
|
+
links = Swamp::Links.new
|
10
|
+
meta_collection = [fields, buttons, input_buttons, select_boxes, links]
|
11
|
+
wrapper = Swamp::Wrapper.new(meta_collection)
|
12
|
+
swamp = Swamp::Interface.new(STDOUT, wrapper)
|
13
|
+
swamp.run
|
14
|
+
|
15
|
+
while input = gets
|
16
|
+
if input.chomp == 'exit'
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
swamp.scan(input)
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: user scans a page interactively
|
2
|
+
|
3
|
+
As a swamp user
|
4
|
+
I want to scan the page interactively
|
5
|
+
So I can create the page objects faster
|
6
|
+
|
7
|
+
Scenario: User scans the current page hiting enter
|
8
|
+
Given that swamp already have scanned a page
|
9
|
+
When I attempt to hit enter at the terminal
|
10
|
+
Then swamp should scan the current page
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: user scans buttons in a page
|
2
|
+
|
3
|
+
The user enters an url to a given page, swamp fires up the browser and go to that url
|
4
|
+
once the page is loaded swamp start looking for buttons then swamp generates the code
|
5
|
+
snippets to interact with those elements using capybara.
|
6
|
+
|
7
|
+
Background: swamp is running
|
8
|
+
Given that swamp is already running
|
9
|
+
|
10
|
+
Scenario: A button that has text
|
11
|
+
Given I enter the url for this page: "button.html"
|
12
|
+
When swamp scans that page
|
13
|
+
Then swamp should output the following code snippet
|
14
|
+
"""
|
15
|
+
def sign_up
|
16
|
+
source.click_button("Sign Up")
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario: A button that doesn't has text but has id
|
21
|
+
Given I enter the url for this page: "button_without_text.html"
|
22
|
+
When swamp scans that page
|
23
|
+
Then swamp should output the following code snippet
|
24
|
+
"""
|
25
|
+
def search_button
|
26
|
+
source.click_button("search-button")
|
27
|
+
end
|
28
|
+
"""
|
29
|
+
|
30
|
+
Scenario: A button that doesn't has either text or id but has the value attribute
|
31
|
+
Given I enter the url for this page: "button_without_text_without_id_with_value.html"
|
32
|
+
When swamp scans that page
|
33
|
+
Then swamp should output the following code snippet
|
34
|
+
"""
|
35
|
+
def buy_now
|
36
|
+
source.click_button("buy-now")
|
37
|
+
end
|
38
|
+
"""
|
39
|
+
|
40
|
+
Scenario: A button without text id and value
|
41
|
+
Given I enter the url for this page: "button_without_text_id_and_value.html"
|
42
|
+
When swamp scans that page
|
43
|
+
Then swamp should not output any snippet
|
@@ -0,0 +1,38 @@
|
|
1
|
+
Feature: user scans fields in a page
|
2
|
+
|
3
|
+
The user enters an url to a given page, swamp fires up the browser and go to that url
|
4
|
+
once the page is loaded swamp start looking for fields then swamp generates the code
|
5
|
+
snippets to interact with those elements using capybara.
|
6
|
+
|
7
|
+
Background: swamp is running
|
8
|
+
Given that swamp is already running
|
9
|
+
|
10
|
+
Scenario: A standard field
|
11
|
+
Given I enter the url for this page: "field.html"
|
12
|
+
When swamp scans that page
|
13
|
+
Then swamp should output the following code snippet
|
14
|
+
"""
|
15
|
+
def type_username(input)
|
16
|
+
source.fill_in("id_username", with: input)
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario: A field without the id attribute
|
21
|
+
Given I enter the url for this page: "field_without_id.html"
|
22
|
+
When swamp scans that page
|
23
|
+
Then swamp should output the following code snippet
|
24
|
+
"""
|
25
|
+
def type_username(input)
|
26
|
+
source.fill_in("username", with: input)
|
27
|
+
end
|
28
|
+
"""
|
29
|
+
|
30
|
+
Scenario: A checkbox
|
31
|
+
Given I enter the url for this page: "checkbox.html"
|
32
|
+
When swamp scans that page
|
33
|
+
Then swamp should not output any snippet
|
34
|
+
|
35
|
+
Scenario: A radio
|
36
|
+
Given I enter the url for this page: "radio.html"
|
37
|
+
When swamp scans that page
|
38
|
+
Then swamp should not output any snippet
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Feature: user scans submits in a page
|
2
|
+
|
3
|
+
The user enters an url to a given page, swamp fires up the browser and go to that url
|
4
|
+
once the page is loaded swamp start looking for inputs of type submit then swamp generates the code
|
5
|
+
snippets to interact with those elements using capybara.
|
6
|
+
|
7
|
+
Background: swamp is running
|
8
|
+
Given that swamp is already running
|
9
|
+
|
10
|
+
Scenario: A submit that has value and id
|
11
|
+
Given I enter the url for this page: "input_submit.html"
|
12
|
+
When swamp scans that page
|
13
|
+
Then swamp should output the following code snippet
|
14
|
+
"""
|
15
|
+
def log_in
|
16
|
+
source.find(:css, "#u_0_b").click
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario: A submit that has no id
|
21
|
+
Given I enter the url for this page: "input_submit_without_id.html"
|
22
|
+
When swamp scans that page
|
23
|
+
Then swamp should output the following code snippet
|
24
|
+
"""
|
25
|
+
def continue
|
26
|
+
source.find(:css, "input.button.g-button.g-button-submit[value='Continue']").click
|
27
|
+
end
|
28
|
+
"""
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: user scans links in a page
|
2
|
+
|
3
|
+
The user enters an url to a given page, swamp fires up the browser and go to that url
|
4
|
+
once the page is loaded swamp start looking for links elements in that page then swamp
|
5
|
+
generates the code snippets to interact with those elements using capybara.
|
6
|
+
|
7
|
+
Background: swamp is running
|
8
|
+
Given that swamp is already running
|
9
|
+
|
10
|
+
Scenario: A link that has id
|
11
|
+
Given I enter the url for this page: "link_with_id.html"
|
12
|
+
When swamp scans that page
|
13
|
+
Then swamp should output the following code snippet
|
14
|
+
"""
|
15
|
+
def link_forgot_passwd
|
16
|
+
source.click_link("link-forgot-passwd")
|
17
|
+
end
|
18
|
+
"""
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Feature: user scans select box elements in a page
|
2
|
+
|
3
|
+
The user enters an url to a given page, swamp fires up the browser and go to that url
|
4
|
+
once the page is loaded swamp start looking for select box elements in that page then swamp
|
5
|
+
generates the code snippets to interact with those elements using capybara.
|
6
|
+
|
7
|
+
Background: swamp is running
|
8
|
+
Given that swamp is already running
|
9
|
+
|
10
|
+
Scenario: A select box that has id
|
11
|
+
Given I enter the url for this page: "select_box_with_id.html"
|
12
|
+
When swamp scans that page
|
13
|
+
Then swamp should output the following code snippet
|
14
|
+
"""
|
15
|
+
def select_month(option)
|
16
|
+
source.select(option, :from => "month")
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario: A select box that has name only
|
21
|
+
Given I enter the url for this page: "select_box_with_name_only.html"
|
22
|
+
When swamp scans that page
|
23
|
+
Then swamp should output the following code snippet
|
24
|
+
"""
|
25
|
+
def select_region(option)
|
26
|
+
source.select(option, :from => "Region")
|
27
|
+
end
|
28
|
+
"""
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: user starts swamp
|
2
|
+
|
3
|
+
As a swamp user
|
4
|
+
I want to start the application
|
5
|
+
So that I can magically create my page-objects
|
6
|
+
|
7
|
+
Scenario: Start swamp
|
8
|
+
Given swamp is not yet running
|
9
|
+
When I start it
|
10
|
+
Then I should see "Enter the url for the page to be scanned:"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Given /^swamp is not yet running$/ do
|
2
|
+
end
|
3
|
+
|
4
|
+
When /^(?:I start it|that swamp is already running)$/ do
|
5
|
+
swamp.run
|
6
|
+
end
|
7
|
+
|
8
|
+
Then /^I should see "(.*?)"$/ do |outcome|
|
9
|
+
output.messages.should include(outcome)
|
10
|
+
end
|
11
|
+
|
12
|
+
Given /^I enter the url for this page: "(\w+\.html)"$/ do |page|
|
13
|
+
path = File.join(File.dirname(__FILE__), '../support/page_examples/', page)
|
14
|
+
@url = "file://#{path}"
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^swamp scans that page$/ do
|
18
|
+
swamp.scan(@url)
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^swamp should output the following code snippets?$/ do |string|
|
22
|
+
output.messages.should include(string)
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^swamp should not output any snippet$/ do
|
26
|
+
prompt_message = "Enter the url for the page to be scanned:"
|
27
|
+
output.messages.length.should == 1
|
28
|
+
output.messages.should include(prompt_message)
|
29
|
+
end
|
30
|
+
|
31
|
+
Given /^that swamp already have scanned a page$/ do
|
32
|
+
swamp.run
|
33
|
+
path = File.join(File.dirname(__FILE__), '../support/page_examples/', "button.html")
|
34
|
+
@url = "file://#{path}"
|
35
|
+
swamp.scan(@url)
|
36
|
+
output.messages.should include("def sign_up\n source.click_button(\"Sign Up\")\nend")
|
37
|
+
end
|
38
|
+
|
39
|
+
When /^I attempt to hit enter at the terminal$/ do
|
40
|
+
swamp.scan("\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^swamp should scan the current page$/ do
|
44
|
+
output.messages.length.should == 3
|
45
|
+
output.messages.last.should == "def sign_up\n source.click_button(\"Sign Up\")\nend"
|
46
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<button type="submit" class="_6j mvm _6wk _6wl signup_button _3ma _6o _6v" name="websubmit" id="u_0_2">Sign Up</button>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<button id="search-button" type="submit" class="no-focus search-button" tabindex="-1" value=""><span class="goog-inline-block SPRITE_search_icon_white"></span></button>
|
@@ -0,0 +1 @@
|
|
1
|
+
<button class="search-input-button" data-bind="css: { 'hasContent': searchQuery }, click: clearSearch "></button></div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<button class="btn btn-info" data-ga-action="comprar" data-ga-category="revista-digital-detalhes" data-ga-label="revista-digital:caras:1017-maio-2013" data-track-click="true" name="button" type="submit" value="buy-now"></b></button>
|
@@ -0,0 +1 @@
|
|
1
|
+
<input id="sign-up-terms-and-conditions" name="sign-up-terms-and-conditions" type="checkbox" value="true">
|
@@ -0,0 +1 @@
|
|
1
|
+
<input type="text" name="username" id="id_username" data-bind="username" class="input-large">
|
@@ -0,0 +1 @@
|
|
1
|
+
<input type="text" name="username" data-bind="username" class="input-large">
|
@@ -0,0 +1 @@
|
|
1
|
+
<input value="Log In" tabindex="4" id="u_0_b" type="submit">
|
@@ -0,0 +1 @@
|
|
1
|
+
<input type="submit" class="button g-button g-button-submit" value="Continue">
|
@@ -0,0 +1 @@
|
|
1
|
+
<a href="/help/index" class="bold">help</a>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<input class="radio" type="radio" name="alternativa" id="alternativa1" value="1">
|
@@ -0,0 +1 @@
|
|
1
|
+
<select name="birthday_month" id="month"><option value="0" selected="1">Month</option><option value="1">Jan</option><option value="2">Feb</option><option value="3">Mar</option><option value="4">Apr</option><option value="5">May</option><option value="6">Jun</option><option value="7">Jul</option><option value="8">Aug</option><option value="9">Sep</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dec</option></select>
|
@@ -0,0 +1 @@
|
|
1
|
+
<dl><dt class="create_key"><label for="server_region">Region</label></dt><dd class="create_value regions"><div><select class="provider-select" data-bind="region" name="Region"><optgroup label="Next Generation Cloud Servers"><option value="compute,cloudServersOpenStack,IAD">Northern Virginia (IAD)</option><option value="compute,cloudServersOpenStack,DFW">Dallas (DFW)</option><option value="compute,cloudServersOpenStack,ORD">Chicago (ORD)</option><option value="compute,cloudServersOpenStack,SYD">Sydney (SYD)</option></optgroup><optgroup label="First Generation Cloud Servers"><option value="compute,cloudServers">Dallas (DFW)</option></optgroup></select><span class="tooltip_toggle"></span></div><div class="region-warning" style="display: none;"><strong><i class="icon_region"></i><span class="region-label">All Regions (Global)</span></strong> will now be shown, which may be slower<span class="tooltip_toggle"></span></div></dd></dl>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Output
|
2
|
+
def messages
|
3
|
+
@messages ||= []
|
4
|
+
end
|
5
|
+
|
6
|
+
def puts(message)
|
7
|
+
messages << message
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def output
|
12
|
+
@output ||= Output.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def buttons
|
16
|
+
Swamp::Buttons.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def fields
|
20
|
+
Swamp::Fields.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def input_buttons
|
24
|
+
Swamp::InputButtons.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def select_boxes
|
28
|
+
Swamp::SelectBoxes.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def links
|
32
|
+
Swamp::Links.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def wrapper
|
36
|
+
meta_collection = [fields, buttons, input_buttons, select_boxes, links]
|
37
|
+
Swamp::Wrapper.new(meta_collection)
|
38
|
+
end
|
39
|
+
|
40
|
+
def swamp
|
41
|
+
@swamp ||= Swamp::Interface.new(output, wrapper)
|
42
|
+
end
|
data/lib/swamp/base.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
|
3
|
+
module Swamp
|
4
|
+
class Base
|
5
|
+
include Capybara::DSL
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
setup_capybara
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_capybara
|
12
|
+
Capybara.register_driver :firefox do |app|
|
13
|
+
Capybara::Selenium::Driver.new(app, :browser => :firefox)
|
14
|
+
end
|
15
|
+
|
16
|
+
Capybara.run_server = false
|
17
|
+
Capybara.default_selector = :css
|
18
|
+
Capybara.default_driver = :selenium
|
19
|
+
Capybara.default_wait_time = 60
|
20
|
+
|
21
|
+
Capybara.configure do |config|
|
22
|
+
config.match = :smart
|
23
|
+
config.exact_options = true
|
24
|
+
config.ignore_hidden_elements = true
|
25
|
+
config.visible_text_only = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Swamp
|
2
|
+
class Builder
|
3
|
+
def initialize(element)
|
4
|
+
@element = element
|
5
|
+
end
|
6
|
+
|
7
|
+
def build_snippet
|
8
|
+
if @element.name
|
9
|
+
[method_definition, @element.method_signature, line_break, identation, prefix, @element.accessor, line_break, method_end].join
|
10
|
+
else
|
11
|
+
[prefix, @element.accessor].join
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_definition
|
16
|
+
"def "
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_end
|
20
|
+
"end"
|
21
|
+
end
|
22
|
+
|
23
|
+
def prefix
|
24
|
+
"source."
|
25
|
+
end
|
26
|
+
|
27
|
+
def identation
|
28
|
+
" "
|
29
|
+
end
|
30
|
+
|
31
|
+
def line_break
|
32
|
+
"\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/swamp/button.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Swamp
|
2
|
+
class Buttons < Elements
|
3
|
+
def get
|
4
|
+
elements = []
|
5
|
+
page.all("button").map do |element|
|
6
|
+
if element.visible?
|
7
|
+
if has_valid_text?(element)
|
8
|
+
elements << Swamp::Button.new(element.text, element.text)
|
9
|
+
elsif has_id?(element) and has_valid_id?(element)
|
10
|
+
elements << Swamp::Button.new(element["id"], element["id"])
|
11
|
+
elsif has_value?(element) and has_valid_value?(element)
|
12
|
+
elements << Swamp::Button.new(element["value"], element["value"])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
elements
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Swamp
|
2
|
+
class Element
|
3
|
+
def initialize(name, selector)
|
4
|
+
@name = name
|
5
|
+
@selector = selector
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :name
|
9
|
+
attr_reader :selector
|
10
|
+
|
11
|
+
def method_signature
|
12
|
+
raise NotImplementedError, "Must be implemented by subtypes"
|
13
|
+
end
|
14
|
+
|
15
|
+
def accessor
|
16
|
+
raise NotImplementedError, "Must be implemented by subtypes"
|
17
|
+
end
|
18
|
+
|
19
|
+
def format(text)
|
20
|
+
Swamp::Formatter.new.format(text)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Swamp
|
2
|
+
class Elements < Base
|
3
|
+
def has_id?(element)
|
4
|
+
element['id'] != nil and element['id'] != "" ? true : false
|
5
|
+
end
|
6
|
+
|
7
|
+
def has_name?(element)
|
8
|
+
element['name'] != nil and element['name'] != "" ? true : false
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_value?(element)
|
12
|
+
element['value'] != nil and element['value'] != "" ? true : false
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_class?(element)
|
16
|
+
element['class'] != nil and element['class'] != "" ? true : false
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_valid_text?(element)
|
20
|
+
element.text.length >= 3 and has_no_punctuation?(element.text)
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_valid_value?(element)
|
24
|
+
element["value"].length >= 3 and has_no_punctuation?(element["value"])
|
25
|
+
end
|
26
|
+
|
27
|
+
def has_no_punctuation?(string)
|
28
|
+
string.match(/[.,]/) ? false : true
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_valid_id?(element)
|
32
|
+
element["id"].length <= 1 ? false : true
|
33
|
+
end
|
34
|
+
|
35
|
+
def formatter
|
36
|
+
@formatter ||= Swamp::Formatter.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|