swamp 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/features/specifications/user_scans_buttons_in_a_page.feature +6 -3
- data/features/specifications/user_scans_fields_in_a_page.feature +6 -3
- data/features/specifications/user_scans_input_buttons_in_a_page.feature +4 -2
- data/features/specifications/user_scans_links_in_a_page.feature +2 -1
- data/features/specifications/user_scans_select_box_elements_in_a_page.feature +4 -2
- data/features/step_definitions/swamp_steps.rb +12 -1
- data/lib/swamp/buttons.rb +3 -0
- data/lib/swamp/elements.rb +40 -0
- data/lib/swamp/fields.rb +3 -0
- data/lib/swamp/input_buttons.rb +2 -0
- data/lib/swamp/links.rb +3 -4
- data/lib/swamp/select_boxes.rb +2 -0
- data/lib/swamp/version.rb +1 -1
- data/spec/swamp/buttons_spec.rb +19 -0
- data/spec/swamp/fields_spec.rb +22 -0
- data/spec/swamp/input_buttons_spec.rb +15 -0
- data/spec/swamp/links_spec.rb +10 -2
- data/spec/swamp/select_boxes_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96cb6453a9c92ac8aa2bf96f8f76acd975d49c20
|
4
|
+
data.tar.gz: fb312b21770bfe568ed1d856295bd0510a9a301f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 124b7ddfc62b2b40d89b3f32084a4ea8bf74c8847cd6d553eaad4436218ca7c5c98baab4087fe0b51856ac3d1b7a08de2af73728d993c091e7301f86758188ff
|
7
|
+
data.tar.gz: b23f650148dc0ea3778641aeb9393a221670979995675af3f854212b5e95e6336069b5d9cdf4fc166eb3f09b74ae3bcbfd03b9ba2e3fd4e16e9d75234214b6ac
|
data/README.md
CHANGED
@@ -108,3 +108,29 @@ When /^I attempt to sign in with valid credentials/ do
|
|
108
108
|
end
|
109
109
|
```
|
110
110
|
|
111
|
+
### Dynamically detecting elements
|
112
|
+
|
113
|
+
* You can navigate in the browser that swamp opens
|
114
|
+
* Lets say you need to log in to have access to some page
|
115
|
+
* Just enter the url for this page
|
116
|
+
* Do the login procedure in the oppened browser manually
|
117
|
+
* Wait for the new page to load
|
118
|
+
* Then just go to the terminal and hit ENTER
|
119
|
+
* Swamp will detect the new elements (if any) and will generate the code snippets the same way as before
|
120
|
+
|
121
|
+
## How it works?
|
122
|
+
|
123
|
+
It uses capybara to fireup the browser and visit the target URL then it looks for patterns like:
|
124
|
+
|
125
|
+
* Buttons
|
126
|
+
* Fields
|
127
|
+
* Select boxes
|
128
|
+
* Input buttons
|
129
|
+
* Links
|
130
|
+
|
131
|
+
For each pattern found it verifies if the element is visible, has some key attributes like `id`, `name`, `text` and etc.
|
132
|
+
There is some logic to decide on how to best create the method's name and the capybara's selector.
|
133
|
+
Finally the code snippets are formatted and printed in the output.
|
134
|
+
|
135
|
+
Check the `.feature` files to learn about the overall behavior.
|
136
|
+
Check the `_spec.rb` files to learn about the internal behavior. Feel free to contribute.
|
@@ -10,7 +10,8 @@ Feature: user scans buttons in a page
|
|
10
10
|
Scenario: A button that has text
|
11
11
|
Given I enter the url for this page: "button.html"
|
12
12
|
When swamp scans that page
|
13
|
-
Then swamp should
|
13
|
+
Then swamp should highlight this element: "button"
|
14
|
+
And it should output the following code snippet
|
14
15
|
"""
|
15
16
|
def sign_up
|
16
17
|
source.click_button("Sign Up")
|
@@ -20,7 +21,8 @@ Feature: user scans buttons in a page
|
|
20
21
|
Scenario: A button that doesn't has text but has id
|
21
22
|
Given I enter the url for this page: "button_without_text.html"
|
22
23
|
When swamp scans that page
|
23
|
-
Then swamp should
|
24
|
+
Then swamp should highlight this element: "#search-button"
|
25
|
+
And it should output the following code snippet
|
24
26
|
"""
|
25
27
|
def search_button
|
26
28
|
source.click_button("search-button")
|
@@ -30,7 +32,8 @@ Feature: user scans buttons in a page
|
|
30
32
|
Scenario: A button that doesn't has either text or id but has the value attribute
|
31
33
|
Given I enter the url for this page: "button_without_text_without_id_with_value.html"
|
32
34
|
When swamp scans that page
|
33
|
-
Then swamp should
|
35
|
+
Then swamp should highlight this element: "button[value='buy-now']"
|
36
|
+
And it should output the following code snippet
|
34
37
|
"""
|
35
38
|
def buy_now
|
36
39
|
source.click_button("buy-now")
|
@@ -10,7 +10,8 @@ Feature: user scans fields in a page
|
|
10
10
|
Scenario: An input that has id, name and whose the type is text
|
11
11
|
Given I enter the url for this page: "field.html"
|
12
12
|
When swamp scans that page
|
13
|
-
Then swamp should
|
13
|
+
Then swamp should highlight this element: "#id_username"
|
14
|
+
And it should output the following code snippet
|
14
15
|
"""
|
15
16
|
def type_username(input)
|
16
17
|
source.fill_in("id_username", with: input)
|
@@ -20,7 +21,8 @@ Feature: user scans fields in a page
|
|
20
21
|
Scenario: An input that has no name, has id and whose the type is text
|
21
22
|
Given I enter the url for this page: "field_without_name.html"
|
22
23
|
When swamp scans that page
|
23
|
-
Then swamp should
|
24
|
+
Then swamp should highlight this element: "#username"
|
25
|
+
Then it should output the following code snippet
|
24
26
|
"""
|
25
27
|
def type_username(input)
|
26
28
|
source.fill_in("username", with: input)
|
@@ -30,7 +32,8 @@ Feature: user scans fields in a page
|
|
30
32
|
Scenario: An input without the id attribute that has name and the type is text
|
31
33
|
Given I enter the url for this page: "field_without_id.html"
|
32
34
|
When swamp scans that page
|
33
|
-
Then swamp should
|
35
|
+
Then swamp should highlight this element: "input[name='username']"
|
36
|
+
Then it should output the following code snippet
|
34
37
|
"""
|
35
38
|
def type_username(input)
|
36
39
|
source.fill_in("username", with: input)
|
@@ -10,7 +10,8 @@ Feature: user scans submits in a page
|
|
10
10
|
Scenario: A submit that has value and id
|
11
11
|
Given I enter the url for this page: "input_submit.html"
|
12
12
|
When swamp scans that page
|
13
|
-
Then swamp should
|
13
|
+
Then swamp should highlight this element: "#u_0_b"
|
14
|
+
And it should output the following code snippet
|
14
15
|
"""
|
15
16
|
def log_in
|
16
17
|
source.find(:css, "#u_0_b").click
|
@@ -20,7 +21,8 @@ Feature: user scans submits in a page
|
|
20
21
|
Scenario: A submit that has no id
|
21
22
|
Given I enter the url for this page: "input_submit_without_id.html"
|
22
23
|
When swamp scans that page
|
23
|
-
Then swamp should
|
24
|
+
Then swamp should highlight this element: "input.button.g-button.g-button-submit[value='Continue']"
|
25
|
+
And it should output the following code snippet
|
24
26
|
"""
|
25
27
|
def continue
|
26
28
|
source.find(:css, "input.button.g-button.g-button-submit[value='Continue']").click
|
@@ -10,7 +10,8 @@ Feature: user scans links in a page
|
|
10
10
|
Scenario: A link that has id
|
11
11
|
Given I enter the url for this page: "link_with_id.html"
|
12
12
|
When swamp scans that page
|
13
|
-
Then swamp should
|
13
|
+
Then swamp should highlight this link: "#link-forgot-passwd"
|
14
|
+
And it should output the following code snippet
|
14
15
|
"""
|
15
16
|
def link_forgot_passwd
|
16
17
|
source.click_link("link-forgot-passwd")
|
@@ -10,7 +10,8 @@ Feature: user scans select box elements in a page
|
|
10
10
|
Scenario: A select box that has id
|
11
11
|
Given I enter the url for this page: "select_box_with_id.html"
|
12
12
|
When swamp scans that page
|
13
|
-
Then swamp should
|
13
|
+
Then swamp should highlight this element: "#month"
|
14
|
+
And it should output the following code snippet
|
14
15
|
"""
|
15
16
|
def select_month(option)
|
16
17
|
source.select(option, :from => "month")
|
@@ -20,7 +21,8 @@ Feature: user scans select box elements in a page
|
|
20
21
|
Scenario: A select box that has name only
|
21
22
|
Given I enter the url for this page: "select_box_with_name_only.html"
|
22
23
|
When swamp scans that page
|
23
|
-
Then swamp should
|
24
|
+
Then swamp should highlight this element: "select[name='Region']"
|
25
|
+
And it should output the following code snippet
|
24
26
|
"""
|
25
27
|
def select_region(option)
|
26
28
|
source.select(option, :from => "Region")
|
@@ -18,7 +18,7 @@ When /^swamp scans that page$/ do
|
|
18
18
|
swamp.scan(@url)
|
19
19
|
end
|
20
20
|
|
21
|
-
Then /^swamp should output the following code snippets?$/ do |string|
|
21
|
+
Then /^(?:swamp|it) should output the following code snippets?$/ do |string|
|
22
22
|
output.messages.should include(string)
|
23
23
|
end
|
24
24
|
|
@@ -47,3 +47,14 @@ Then /^swamp should scan the current page$/ do
|
|
47
47
|
output.messages[3].should == "Scanning, please wait..."
|
48
48
|
output.messages[4].should == "def sign_up\n source.click_button(\"Sign Up\")\nend"
|
49
49
|
end
|
50
|
+
|
51
|
+
Then /^swamp should highlight this (element|link): "(.+)"$/ do |mode, selector|
|
52
|
+
page = Capybara.current_session
|
53
|
+
page.should have_css "#{selector}[style]"
|
54
|
+
if mode == "element"
|
55
|
+
page.find(selector)[:style].should include("border-width: 3px")
|
56
|
+
page.find(selector)[:style].should include("border-color: rgb(255, 0, 0)")
|
57
|
+
else
|
58
|
+
page.find(selector)[:style].should include("background-color: rgb(255, 0, 0)")
|
59
|
+
end
|
60
|
+
end
|
data/lib/swamp/buttons.rb
CHANGED
@@ -5,10 +5,13 @@ module Swamp
|
|
5
5
|
page.all("button").map do |element|
|
6
6
|
if element.visible?
|
7
7
|
if has_valid_text?(element)
|
8
|
+
shine %-//button[text()='#{element.text}']-, :xpath
|
8
9
|
elements << Swamp::Button.new(element.text, element.text)
|
9
10
|
elsif has_id?(element) and has_valid_id?(element)
|
11
|
+
shine %-##{element["id"]}-
|
10
12
|
elements << Swamp::Button.new(element["id"], element["id"])
|
11
13
|
elsif has_value?(element) and has_valid_value?(element)
|
14
|
+
shine %-button[value='#{element["value"]}']-
|
12
15
|
elements << Swamp::Button.new(element["value"], element["value"])
|
13
16
|
end
|
14
17
|
end
|
data/lib/swamp/elements.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module Swamp
|
2
2
|
class Elements < Base
|
3
|
+
|
4
|
+
BORDER_SIZE = "3px"
|
5
|
+
BORDER_COLOR = "#ff0000"
|
6
|
+
BACKGROUND_COLOR = "#ff0000"
|
7
|
+
|
3
8
|
def has_id?(element)
|
4
9
|
element['id'] != nil and element['id'] != "" ? true : false
|
5
10
|
end
|
@@ -35,5 +40,40 @@ module Swamp
|
|
35
40
|
def formatter
|
36
41
|
@formatter ||= Swamp::Formatter.new
|
37
42
|
end
|
43
|
+
|
44
|
+
def shine(selector, mode = :css)
|
45
|
+
set_border_size(selector, BORDER_SIZE, mode)
|
46
|
+
set_border_color(selector, BORDER_COLOR, mode)
|
47
|
+
end
|
48
|
+
|
49
|
+
def shine_link(selector)
|
50
|
+
set_background_color selector, BACKGROUND_COLOR
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def set_border_size(selector, size, mode)
|
56
|
+
if mode == :css
|
57
|
+
page.execute_script %-document.querySelector("#{selector}").style.borderWidth='#{size}'-
|
58
|
+
elsif mode == :xpath
|
59
|
+
page.execute_script %-document.evaluate("#{selector}", document, null, 9, null).singleNodeValue.style.borderWidth='#{size}';- rescue false
|
60
|
+
else
|
61
|
+
raise "Mode #{mode} not found"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_border_color(selector, color, mode = :css)
|
66
|
+
if mode == :css
|
67
|
+
page.execute_script %-document.querySelector("#{selector}").style.borderColor='#{color}'-
|
68
|
+
elsif mode == :xpath
|
69
|
+
page.execute_script %-document.evaluate("#{selector}", document, null, 9, null).singleNodeValue.style.borderColor='#{color}';- rescue false
|
70
|
+
else
|
71
|
+
raise "Mode #{mode} not found"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_background_color(selector, color)
|
76
|
+
page.execute_script %-document.querySelector("#{selector}").style.backgroundColor='#{color}'-
|
77
|
+
end
|
38
78
|
end
|
39
79
|
end
|
data/lib/swamp/fields.rb
CHANGED
@@ -5,10 +5,13 @@ module Swamp
|
|
5
5
|
page.all('input').map do |element|
|
6
6
|
if element.visible? and valid_type?(element)
|
7
7
|
if has_id?(element) and has_name?(element)
|
8
|
+
shine %-##{element['id']}-
|
8
9
|
elements << Swamp::Field.new(element['name'], element['id'])
|
9
10
|
elsif has_id?(element)
|
11
|
+
shine %-##{element['id']}-
|
10
12
|
elements << Swamp::Field.new(element['id'], element['id'])
|
11
13
|
elsif has_name?(element)
|
14
|
+
shine %-input[name=#{element['name']}]-
|
12
15
|
elements << Swamp::Field.new(element['name'], element['name'])
|
13
16
|
end
|
14
17
|
end
|
data/lib/swamp/input_buttons.rb
CHANGED
@@ -6,8 +6,10 @@ module Swamp
|
|
6
6
|
if element.visible?
|
7
7
|
if has_value?(element)
|
8
8
|
if has_id?(element)
|
9
|
+
shine %-##{element["id"]}-
|
9
10
|
elements << Swamp::InputButton.new(element["value"], "##{element["id"]}")
|
10
11
|
elsif has_class?(element)
|
12
|
+
shine %-input.#{formatter.format_class(element["class"])}[value='#{element["value"]}']-
|
11
13
|
elements << Swamp::InputButton.new(element["value"], "input.#{formatter.format_class(element["class"])}[value='#{element["value"]}']")
|
12
14
|
end
|
13
15
|
end
|
data/lib/swamp/links.rb
CHANGED
@@ -2,11 +2,10 @@ module Swamp
|
|
2
2
|
class Links < Elements
|
3
3
|
def get
|
4
4
|
elements = []
|
5
|
-
page.all('a[href]').map do | element |
|
5
|
+
page.all('a[href][id]').map do | element |
|
6
6
|
if element.visible?
|
7
|
-
|
8
|
-
|
9
|
-
end
|
7
|
+
shine_link %-##{element["id"]}-
|
8
|
+
elements << Swamp::Link.new(element["id"], element["id"])
|
10
9
|
end
|
11
10
|
end
|
12
11
|
elements
|
data/lib/swamp/select_boxes.rb
CHANGED
@@ -5,8 +5,10 @@ module Swamp
|
|
5
5
|
page.all('select').map do | element |
|
6
6
|
if element.visible?
|
7
7
|
if has_id?(element)
|
8
|
+
shine %-##{element["id"]}-
|
8
9
|
elements << Swamp::SelectBox.new(element["id"], element["id"])
|
9
10
|
elsif has_name?(element)
|
11
|
+
shine %-select[name='#{element["name"]}']-
|
10
12
|
elements << Swamp::SelectBox.new(element["name"], element["name"])
|
11
13
|
end
|
12
14
|
end
|
data/lib/swamp/version.rb
CHANGED
data/spec/swamp/buttons_spec.rb
CHANGED
@@ -7,6 +7,7 @@ module Swamp
|
|
7
7
|
element = {'id' => "u_0_2"}
|
8
8
|
element.stub(:text).and_return("Sign Up")
|
9
9
|
element.stub(:visible?).and_return(true)
|
10
|
+
buttons.page.stub(:execute_script).and_return(nil)
|
10
11
|
buttons.page.should_receive(:all).with('button').and_return([element])
|
11
12
|
buttons.get
|
12
13
|
end
|
@@ -21,7 +22,13 @@ module Swamp
|
|
21
22
|
buttons.page.stub(:all).with('button').and_return([element])
|
22
23
|
end
|
23
24
|
|
25
|
+
it "highlights the element" do
|
26
|
+
buttons.page.should_receive(:execute_script).twice
|
27
|
+
buttons.get
|
28
|
+
end
|
29
|
+
|
24
30
|
it "returns the element in the array using the text as both the name and the selector" do
|
31
|
+
buttons.page.stub(:execute_script).and_return(nil)
|
25
32
|
buttons.get.should have(1).button
|
26
33
|
buttons.get.each.first.name.should == "Sign Up"
|
27
34
|
buttons.get.each.first.selector.should == "Sign Up"
|
@@ -38,7 +45,13 @@ module Swamp
|
|
38
45
|
buttons.page.stub(:all).with('button').and_return([element])
|
39
46
|
end
|
40
47
|
|
48
|
+
it "highlights the element" do
|
49
|
+
buttons.page.should_receive(:execute_script).twice
|
50
|
+
buttons.get
|
51
|
+
end
|
52
|
+
|
41
53
|
it "returns the element in the array using the id as both the name and the selector" do
|
54
|
+
buttons.page.stub(:execute_script).and_return(nil)
|
42
55
|
buttons.get.should have(1).button
|
43
56
|
buttons.get.each.first.name.should == "search-button"
|
44
57
|
buttons.get.each.first.selector.should == "search-button"
|
@@ -55,7 +68,13 @@ module Swamp
|
|
55
68
|
buttons.page.stub(:all).with('button').and_return([element])
|
56
69
|
end
|
57
70
|
|
71
|
+
it "highlights the element" do
|
72
|
+
buttons.page.should_receive(:execute_script).twice
|
73
|
+
buttons.get
|
74
|
+
end
|
75
|
+
|
58
76
|
it "returns the element in the array using the value as both the name and the selector" do
|
77
|
+
buttons.page.stub(:execute_script).and_return(nil)
|
59
78
|
buttons.get.should have(1).button
|
60
79
|
buttons.get.each.first.name.should == "search-button"
|
61
80
|
buttons.get.each.first.selector.should == "search-button"
|
data/spec/swamp/fields_spec.rb
CHANGED
@@ -6,6 +6,7 @@ module Swamp
|
|
6
6
|
it "delegates to capybara the responsibility to get the fields" do
|
7
7
|
element = {'name' => "username", 'type' => "text"}
|
8
8
|
element.stub(:visible?).and_return(true)
|
9
|
+
fields.page.stub(:execute_script).and_return(nil)
|
9
10
|
fields.page.should_receive(:all).with('input').and_return([element])
|
10
11
|
fields.get
|
11
12
|
end
|
@@ -22,12 +23,19 @@ module Swamp
|
|
22
23
|
fields.page.stub(:all).with('input').and_return([element])
|
23
24
|
end
|
24
25
|
|
26
|
+
it "highlights the element" do
|
27
|
+
fields.page.should_receive(:execute_script).twice
|
28
|
+
fields.get
|
29
|
+
end
|
30
|
+
|
25
31
|
it "returns the element in the array using the name as the method's name" do
|
32
|
+
fields.page.stub(:execute_script).and_return(nil)
|
26
33
|
fields.get.should have(1).field
|
27
34
|
fields.get.first.name.should == "username"
|
28
35
|
end
|
29
36
|
|
30
37
|
it "returns the element in the array using the id as the selector" do
|
38
|
+
fields.page.stub(:execute_script).and_return(nil)
|
31
39
|
fields.get.should have(1).field
|
32
40
|
fields.get.first.selector.should == "u_0_b"
|
33
41
|
end
|
@@ -41,12 +49,19 @@ module Swamp
|
|
41
49
|
fields.page.stub(:all).with('input').and_return([element])
|
42
50
|
end
|
43
51
|
|
52
|
+
it "highlights the element" do
|
53
|
+
fields.page.should_receive(:execute_script).twice
|
54
|
+
fields.get
|
55
|
+
end
|
56
|
+
|
44
57
|
it "returns the element in the array using the id as the method's name" do
|
58
|
+
fields.page.stub(:execute_script).and_return(nil)
|
45
59
|
fields.get.should have(1).field
|
46
60
|
fields.get.first.name.should == "username"
|
47
61
|
end
|
48
62
|
|
49
63
|
it "returns the element in the array using the id as the selector" do
|
64
|
+
fields.page.stub(:execute_script).and_return(nil)
|
50
65
|
fields.get.should have(1).field
|
51
66
|
fields.get.first.selector.should == "username"
|
52
67
|
end
|
@@ -60,12 +75,19 @@ module Swamp
|
|
60
75
|
fields.page.stub(:all).with('input').and_return([element])
|
61
76
|
end
|
62
77
|
|
78
|
+
it "highlights the element" do
|
79
|
+
fields.page.should_receive(:execute_script).twice
|
80
|
+
fields.get
|
81
|
+
end
|
82
|
+
|
63
83
|
it "returns the element in the array using the name as the method's name" do
|
84
|
+
fields.page.stub(:execute_script).and_return(nil)
|
64
85
|
fields.get.should have(1).field
|
65
86
|
fields.get.first.name.should == "username"
|
66
87
|
end
|
67
88
|
|
68
89
|
it "returns the element in the array using the name as the selector" do
|
90
|
+
fields.page.stub(:execute_script).and_return(nil)
|
69
91
|
fields.get.should have(1).field
|
70
92
|
fields.get.first.selector.should == "username"
|
71
93
|
end
|
@@ -6,6 +6,7 @@ module Swamp
|
|
6
6
|
it "delegates to capybara the responsibility to get the submit elements" do
|
7
7
|
element = {'value' => "Log In", 'id' => "u_0_b"}
|
8
8
|
element.stub(:visible?).and_return(true)
|
9
|
+
input_buttons.page.stub(:execute_script).and_return(nil)
|
9
10
|
input_buttons.page.should_receive(:all).with('input[type="submit"]').and_return([element])
|
10
11
|
input_buttons.get
|
11
12
|
end
|
@@ -19,12 +20,19 @@ module Swamp
|
|
19
20
|
input_buttons.page.stub(:all).with('input[type="submit"]').and_return([element])
|
20
21
|
end
|
21
22
|
|
23
|
+
it "highlights the element" do
|
24
|
+
input_buttons.page.should_receive(:execute_script).twice
|
25
|
+
input_buttons.get
|
26
|
+
end
|
27
|
+
|
22
28
|
it "returns the element in the array using the value as the name" do
|
29
|
+
input_buttons.page.stub(:execute_script).and_return(nil)
|
23
30
|
input_buttons.get.should have(1).input_submit
|
24
31
|
input_buttons.get.first.name.should == "Log In"
|
25
32
|
end
|
26
33
|
|
27
34
|
it "returns the element in the array using the id as the selector" do
|
35
|
+
input_buttons.page.stub(:execute_script).and_return(nil)
|
28
36
|
input_buttons.get.should have(1).input_submit
|
29
37
|
input_buttons.get.first.selector.should == "#u_0_b"
|
30
38
|
end
|
@@ -38,12 +46,19 @@ module Swamp
|
|
38
46
|
input_buttons.page.stub(:all).with('input[type="submit"]').and_return([element])
|
39
47
|
end
|
40
48
|
|
49
|
+
it "highlights the element" do
|
50
|
+
input_buttons.page.should_receive(:execute_script).twice
|
51
|
+
input_buttons.get
|
52
|
+
end
|
53
|
+
|
41
54
|
it "returns the element in the array using the value as the name" do
|
55
|
+
input_buttons.page.stub(:execute_script).and_return(nil)
|
42
56
|
input_buttons.get.should have(1).input_submit
|
43
57
|
input_buttons.get.first.name.should == "Log In"
|
44
58
|
end
|
45
59
|
|
46
60
|
it "returns the element in the array using the class concatenated with the value as the selector" do
|
61
|
+
input_buttons.page.stub(:execute_script).and_return(nil)
|
47
62
|
input_buttons.get.should have(1).input_submit
|
48
63
|
input_buttons.get.first.selector.should == "input.btn.without.id[value='Log In']"
|
49
64
|
end
|
data/spec/swamp/links_spec.rb
CHANGED
@@ -6,7 +6,8 @@ module Swamp
|
|
6
6
|
it "delegates to capybara the responsibility to get the links" do
|
7
7
|
element = {'id' => "forgot-password", 'href' => "https://somewhere.com"}
|
8
8
|
element.stub(:visible?).and_return(true)
|
9
|
-
links.page.
|
9
|
+
links.page.stub(:execute_script).and_return(nil)
|
10
|
+
links.page.should_receive(:all).with('a[href][id]').and_return([element])
|
10
11
|
links.get
|
11
12
|
end
|
12
13
|
|
@@ -16,15 +17,22 @@ module Swamp
|
|
16
17
|
|
17
18
|
before(:each) do
|
18
19
|
element.stub(:visible?).and_return(true)
|
19
|
-
links.page.stub(:all).with('a[href]').and_return([element])
|
20
|
+
links.page.stub(:all).with('a[href][id]').and_return([element])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "highlights the element" do
|
24
|
+
links.page.should_receive(:execute_script).and_return(nil)
|
25
|
+
links.get
|
20
26
|
end
|
21
27
|
|
22
28
|
it "returns the element in the array using the id as the name" do
|
29
|
+
links.page.stub(:execute_script).and_return(nil)
|
23
30
|
links.get.should have(1).link
|
24
31
|
links.get.first.name.should == "forgot-password"
|
25
32
|
end
|
26
33
|
|
27
34
|
it "returns the element in the array using the id as the selector" do
|
35
|
+
links.page.stub(:execute_script).and_return(nil)
|
28
36
|
links.get.should have(1).select_box
|
29
37
|
links.get.first.selector.should == "forgot-password"
|
30
38
|
end
|
@@ -6,6 +6,7 @@ module Swamp
|
|
6
6
|
it "delegates to capybara the responsibility to get the select box elements" do
|
7
7
|
element = {'id' => "month", 'name' => "birthday_month"}
|
8
8
|
element.stub(:visible?).and_return(true)
|
9
|
+
select_boxes.page.stub(:execute_script).and_return(nil)
|
9
10
|
select_boxes.page.should_receive(:all).with('select').and_return([element])
|
10
11
|
select_boxes.get
|
11
12
|
end
|
@@ -19,12 +20,19 @@ module Swamp
|
|
19
20
|
select_boxes.page.stub(:all).with('select').and_return([element])
|
20
21
|
end
|
21
22
|
|
23
|
+
it "highlights the element" do
|
24
|
+
select_boxes.page.should_receive(:execute_script).twice
|
25
|
+
select_boxes.get
|
26
|
+
end
|
27
|
+
|
22
28
|
it "returns the element in the array using the id as the name" do
|
29
|
+
select_boxes.page.stub(:execute_script).and_return(nil)
|
23
30
|
select_boxes.get.should have(1).select_box
|
24
31
|
select_boxes.get.first.name.should == "month"
|
25
32
|
end
|
26
33
|
|
27
34
|
it "returns the element in the array using the id as the selector" do
|
35
|
+
select_boxes.page.stub(:execute_script).and_return(nil)
|
28
36
|
select_boxes.get.should have(1).select_box
|
29
37
|
select_boxes.get.first.selector.should == "month"
|
30
38
|
end
|
@@ -38,12 +46,19 @@ module Swamp
|
|
38
46
|
select_boxes.page.stub(:all).with('select').and_return([element])
|
39
47
|
end
|
40
48
|
|
49
|
+
it "highlights the element" do
|
50
|
+
select_boxes.page.should_receive(:execute_script).twice
|
51
|
+
select_boxes.get
|
52
|
+
end
|
53
|
+
|
41
54
|
it "returns the element in the array using the name as the name" do
|
55
|
+
select_boxes.page.stub(:execute_script).and_return(nil)
|
42
56
|
select_boxes.get.should have(1).select_box
|
43
57
|
select_boxes.get.first.name.should == "birthday_month"
|
44
58
|
end
|
45
59
|
|
46
60
|
it "returns the element in the array using the name as the selector" do
|
61
|
+
select_boxes.page.stub(:execute_script).and_return(nil)
|
47
62
|
select_boxes.get.should have(1).select_box
|
48
63
|
select_boxes.get.first.selector.should == "birthday_month"
|
49
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juraci de Lima Vieira Neto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|