swamp 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72f601901bae303907f20a56ceaed96006e6a5ca
4
- data.tar.gz: be3344d7497cfd4ac6fc6581fbe36c3e8de6cfe1
3
+ metadata.gz: 15fa292671e998ec2b364b1893e815773df39785
4
+ data.tar.gz: 85175279ded0c63c318c152877a99e03003b9e4e
5
5
  SHA512:
6
- metadata.gz: 83936ff3cab3c8652958e68e2875edcee976ccba2c9f2cde8f1827dba4a158034e225e6f33ea88629a83867c34036f68ecdebd4775102a3fe10f19516419e9b8
7
- data.tar.gz: 3b60605c340ec0f5f4643b0d49edb2802ab759da30e110048d36bf0c104a2f6746be7f612f22441ae22c8b232a8439a6d0482113f43f6f73f5e7602af410db6e
6
+ metadata.gz: 53afdc9793bbf5148ee8d9da1774e59c202747d1bb8a3dc9079a12d5393d88ebcf3a6af54f1661c2f9275c1f055391ec5058e3180bf263a32c63c9e5d4aed4fa
7
+ data.tar.gz: 7e18435b353cbb5b647ea1f0c19653eca2e432ea94cc3819f7c22010ffb7db0ba7983fa47aa461db4289c42383ba61fafcc08623fec20610ad697b8cca48cda4
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ Gemfile.lock
5
6
  coverage
6
7
  InstalledFiles
7
8
  lib/bundler/man
data/README.md CHANGED
@@ -1,5 +1,110 @@
1
+ # Swamp
2
+
1
3
  [![Build Status](https://travis-ci.org/Juraci/swamp.png?branch=master)](https://travis-ci.org/Juraci/swamp)
4
+
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) and [capybara-page-object](https://github.com/andyw8/capybara-page-object).
7
+
8
+ ## How to install
9
+
10
+ It requires Ruby 1.9.3 or later and Firefox 24.0 or later. To install, type:
11
+
12
+ ```bash
13
+ gem install swamp
14
+ ```
15
+
16
+ ## How to use
17
+
18
+ * In the terminal type:
19
+
20
+ ```shell
2
21
  swamp
3
- =====
22
+ ```
23
+ * It will ask you to provide an URL:
24
+
25
+ ```shell
26
+ Enter the url for the page to be scanned:
27
+ ```
28
+
29
+ * Provide a valid one, beginning with `http://` or `https://` for instance:
30
+
31
+ ```shell
32
+ Enter the url for the page to be scanned:
33
+ https://accounts.google.com
34
+ ```
35
+
36
+ * Hit enter and wait for the code snippets, like this:
37
+
38
+ ```shell
39
+ Enter the url for the page to be scanned:
40
+ https://accounts.google.com
41
+
42
+ Scanning, please wait...
43
+
44
+ def type_email(input)
45
+ source.fill_in("Email", with: input)
46
+ end
47
+ def type_passwd(input)
48
+ source.fill_in("Passwd", with: input)
49
+ end
50
+ def sign_in
51
+ source.find(:css, "#signIn").click
52
+ end
53
+ def select_lang_chooser(option)
54
+ source.select(option, :from => "lang-chooser")
55
+ end
56
+ def link_forgot_passwd
57
+ source.click_link("link-forgot-passwd")
58
+ end
59
+ def link_signup
60
+ source.click_link("link-signup")
61
+ end
62
+ ```
63
+ (notice that the method names are a best guess and you are always free to change them)
64
+
65
+ * Copy the code snippets and paste inside your capybara-page-object classes like this:
66
+
67
+ ```ruby
68
+ module PageObjects
69
+ class SignIn < CapybaraPageObject::Page
70
+
71
+ path ""
72
+
73
+ def type_email(input)
74
+ source.fill_in("Email", with: input)
75
+ end
76
+
77
+ def type_passwd(input)
78
+ source.fill_in("Passwd", with: input)
79
+ end
80
+
81
+ def sign_in
82
+ source.find(:css, "#signIn").click
83
+ end
84
+
85
+ def select_lang_chooser(option)
86
+ source.select(option, :from => "lang-chooser")
87
+ end
88
+
89
+ def link_forgot_passwd
90
+ source.click_link("link-forgot-passwd")
91
+ end
92
+
93
+ def link_signup
94
+ source.click_link("link-signup")
95
+ end
96
+ end
97
+ end
98
+ ```
99
+
100
+ * Then just call the methods passing the expected parameters when necessary. For instance:
101
+
102
+ ```ruby
103
+ When /^I attempt to sign in with valid credentials/ do
104
+ sign_in_page = PageObjects::SignIn.visit
105
+ sign_in_page.type_email "username@email.com"
106
+ sign_in_page.type_passwd "mypassword"
107
+ sign_in_page.sign_in
108
+ end
109
+ ```
4
110
 
5
- automatically generates the interfaces for the most common actions that a page can provide
@@ -1,4 +1,4 @@
1
- Feature: user scans a page interactively
1
+ Feature: user scans a page interactively
2
2
 
3
3
  As a swamp user
4
4
  I want to scan the page interactively
@@ -9,3 +9,10 @@ Feature: user scans a page interactively
9
9
  When I attempt to hit enter at the terminal
10
10
  Then swamp should scan the current page
11
11
  And I should see "Scanning, please wait..."
12
+
13
+ Scenario: User scans the current page but it has no detectable elements
14
+ Given that swamp is already running
15
+ And I enter the url for this page: "no_elements.html"
16
+ When swamp scans that page
17
+ Then swamp should not output any snippet
18
+ And I should see "No elements were detected"
@@ -7,7 +7,7 @@ Feature: user scans fields in a page
7
7
  Background: swamp is running
8
8
  Given that swamp is already running
9
9
 
10
- Scenario: A standard field
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
13
  Then swamp should output the following code snippet
@@ -17,7 +17,17 @@ Feature: user scans fields in a page
17
17
  end
18
18
  """
19
19
 
20
- Scenario: A field without the id attribute
20
+ Scenario: An input that has no name, has id and whose the type is text
21
+ Given I enter the url for this page: "field_without_name.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: An input without the id attribute that has name and the type is text
21
31
  Given I enter the url for this page: "field_without_id.html"
22
32
  When swamp scans that page
23
33
  Then swamp should output the following code snippet
@@ -27,12 +37,12 @@ Feature: user scans fields in a page
27
37
  end
28
38
  """
29
39
 
30
- Scenario: A checkbox
40
+ Scenario: An input whose the type is checkbox
31
41
  Given I enter the url for this page: "checkbox.html"
32
42
  When swamp scans that page
33
43
  Then swamp should not output any snippet
34
44
 
35
- Scenario: A radio
45
+ Scenario: An input whose the type is radio
36
46
  Given I enter the url for this page: "radio.html"
37
47
  When swamp scans that page
38
48
  Then swamp should not output any snippet
@@ -23,9 +23,11 @@ Then /^swamp should output the following code snippets?$/ do |string|
23
23
  end
24
24
 
25
25
  Then /^swamp should not output any snippet$/ do
26
- prompt_message = "Enter the url for the page to be scanned:"
27
- output.should have_at_least(1).messages
28
- output.messages.should include(prompt_message)
26
+ output.should have_at_most(3).messages
27
+ output.messages.each do |m|
28
+ m.should_not include("def")
29
+ m.should_not include("source.")
30
+ end
29
31
  end
30
32
 
31
33
  Given /^that swamp already have scanned a page$/ do
@@ -41,6 +43,7 @@ When /^I attempt to hit enter at the terminal$/ do
41
43
  end
42
44
 
43
45
  Then /^swamp should scan the current page$/ do
44
- output.should have_at_least(3).messages
45
- output.messages.last.should == "def sign_up\n source.click_button(\"Sign Up\")\nend"
46
+ output.should have_at_most(5).messages
47
+ output.messages[3].should == "Scanning, please wait..."
48
+ output.messages[4].should == "def sign_up\n source.click_button(\"Sign Up\")\nend"
46
49
  end
@@ -0,0 +1 @@
1
+ <input id="username" placeholder="Digite" class="texto usuario" type="text" maxlength="30">
File without changes
data/lib/swamp/fields.rb CHANGED
@@ -3,10 +3,12 @@ module Swamp
3
3
  def get
4
4
  elements = []
5
5
  page.all('input').map do |element|
6
- if element.visible? and has_name?(element) and valid_type?(element)
7
- if has_id?(element)
6
+ if element.visible? and valid_type?(element)
7
+ if has_id?(element) and has_name?(element)
8
8
  elements << Swamp::Field.new(element['name'], element['id'])
9
- else
9
+ elsif has_id?(element)
10
+ elements << Swamp::Field.new(element['id'], element['id'])
11
+ elsif has_name?(element)
10
12
  elements << Swamp::Field.new(element['name'], element['name'])
11
13
  end
12
14
  end
@@ -15,7 +17,7 @@ module Swamp
15
17
  end
16
18
 
17
19
  def valid_type?(element)
18
- element['type'] != "radio" and element['type'] != "checkbox" and element['type'] != "submit" ? true : false
20
+ element['type'] != "button" and element['type'] != "radio" and element['type'] != "checkbox" and element['type'] != "submit" ? true : false
19
21
  end
20
22
  end
21
23
  end
@@ -3,6 +3,7 @@ module Swamp
3
3
 
4
4
  WELCOME_MESSAGE = ['Enter the url for the page to be scanned:']
5
5
  INVALID_REQUEST_MESSAGE = ['Please enter a valid url!']
6
+ NO_ELEMENTS_MESSAGE = ['No elements were detected']
6
7
 
7
8
  def initialize(output, wrapper)
8
9
  @output = output
@@ -15,16 +16,10 @@ module Swamp
15
16
 
16
17
  def scan(input)
17
18
  @output.puts "Scanning, please wait..."
18
- evaluator = Swamp::Evaluator.new(input, @wrapper)
19
- messages = (evaluator.valid_url? or evaluator.refresh_command?) ? request(input) : INVALID_REQUEST_MESSAGE
19
+ messages = valid_request?(input) ? request(input) : INVALID_REQUEST_MESSAGE
20
20
  present messages
21
21
  end
22
22
 
23
- def request(input)
24
- @wrapper.explore(input)
25
- @wrapper.scan
26
- end
27
-
28
23
  private
29
24
 
30
25
  def present(messages)
@@ -32,5 +27,18 @@ module Swamp
32
27
  @output.puts(message)
33
28
  end
34
29
  end
30
+
31
+ def valid_request?(input)
32
+ evaluator(input).valid_url? or evaluator(input).refresh_command?
33
+ end
34
+
35
+ def evaluator(input)
36
+ Swamp::Evaluator.new(input, @wrapper)
37
+ end
38
+
39
+ def request(input)
40
+ @wrapper.explore(input)
41
+ @wrapper.scan.empty? ? NO_ELEMENTS_MESSAGE : @wrapper.scan
42
+ end
35
43
  end
36
44
  end
data/lib/swamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swamp
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -11,64 +11,72 @@ module Swamp
11
11
  end
12
12
 
13
13
  context "when the input element is visible" do
14
- context "when the name attribute is present" do
15
- context "when it has the id attribute" do
16
- it "returns the element in the array using the name as the name and the id as the selector" do
17
- element = {'name' => "username", 'type' => "text", 'id' => "u_0_b"}
14
+ context "when it has a valid type" do
15
+ let (:type) { ["text", "email", "password"].sample }
16
+
17
+ context "when it has the id and the name attribute" do
18
+ let (:element) { {'name' => "username", 'type' => type, 'id' => "u_0_b"} }
19
+
20
+ before(:each) do
18
21
  element.stub(:visible?).and_return(true)
19
22
  fields.page.stub(:all).with('input').and_return([element])
23
+ end
24
+
25
+ it "returns the element in the array using the name as the method's name" do
20
26
  fields.get.should have(1).field
21
27
  fields.get.first.name.should == "username"
28
+ end
29
+
30
+ it "returns the element in the array using the id as the selector" do
31
+ fields.get.should have(1).field
22
32
  fields.get.first.selector.should == "u_0_b"
23
33
  end
24
34
  end
25
35
 
26
- context "when its type is text" do
27
- it "returns the element in the array" do
28
- element = {'name' => "username", 'type' => "text"}
36
+ context "when it has only the id attribute" do
37
+ let (:element) { {'type' => type, 'id' => "username"} }
38
+
39
+ before(:each) do
29
40
  element.stub(:visible?).and_return(true)
30
41
  fields.page.stub(:all).with('input').and_return([element])
42
+ end
43
+
44
+ it "returns the element in the array using the id as the method's name" do
31
45
  fields.get.should have(1).field
32
46
  fields.get.first.name.should == "username"
33
- fields.get.first.selector.should == "username"
34
47
  end
35
- end
36
48
 
37
- context "when its type is email" do
38
- it "returns the element in the array" do
39
- element = {'name' => "useremail", 'type' => "email"}
40
- element.stub(:visible?).and_return(true)
41
- fields.page.stub(:all).with('input').and_return([element])
49
+ it "returns the element in the array using the id as the selector" do
42
50
  fields.get.should have(1).field
43
- fields.get.first.name.should == "useremail"
44
- fields.get.first.selector.should == "useremail"
51
+ fields.get.first.selector.should == "username"
45
52
  end
46
53
  end
47
54
 
48
- context "when its type is password" do
49
- it "returns the element in the array" do
50
- element = {'name' => "password", 'type' => "password"}
55
+ context "when it has only the name attribute" do
56
+ let (:element) { {'name' => "username", 'type' => type} }
57
+
58
+ before(:each) do
51
59
  element.stub(:visible?).and_return(true)
52
60
  fields.page.stub(:all).with('input').and_return([element])
61
+ end
62
+
63
+ it "returns the element in the array using the name as the method's name" do
53
64
  fields.get.should have(1).field
54
- fields.get.first.name.should == "password"
55
- fields.get.first.selector.should == "password"
65
+ fields.get.first.name.should == "username"
56
66
  end
57
- end
58
67
 
59
- context "when the input element type is invalid" do
60
- it "returns an empty array" do
61
- element = {'name' => "username", 'type' => "radio"}
62
- element.stub(:visible?).and_return(true)
63
- fields.page.stub(:all).with('input').and_return([element])
64
- fields.get.should == []
68
+ it "returns the element in the array using the name as the selector" do
69
+ fields.get.should have(1).field
70
+ fields.get.first.selector.should == "username"
65
71
  end
66
72
  end
67
73
  end
68
74
 
69
- context "when the input element has no name attribute" do
75
+ context "when the input element type is invalid" do
76
+ let (:type) { ["radio", "checkbox", "submit", "button"].sample }
77
+
70
78
  it "returns an empty array" do
71
- element = {'name' => "", 'type' => "text"}
79
+ element = {'name' => "username", 'type' => type}
72
80
  element.stub(:visible?).and_return(true)
73
81
  fields.page.stub(:all).with('input').and_return([element])
74
82
  fields.get.should == []
@@ -29,10 +29,20 @@ module Swamp
29
29
  end
30
30
 
31
31
  context "when it scans a valid url" do
32
- it "sends the code snippets of the scanned page to the output" do
33
- wrapper.stub(:scan).and_return(["code_snippet"])
34
- output.should_receive(:puts).with("code_snippet")
35
- interface.scan("http://www.fakepage.com")
32
+ context "when elements were found" do
33
+ it "sends the code snippets of the scanned page to the output" do
34
+ wrapper.stub(:scan).and_return(["code_snippet"])
35
+ output.should_receive(:puts).with("code_snippet")
36
+ interface.scan("http://www.fakepage.com")
37
+ end
38
+ end
39
+
40
+ context "when no elements were found" do
41
+ it "sends a warning message to the output telling that no elements were found" do
42
+ wrapper.stub(:scan).and_return([])
43
+ output.should_receive(:puts).with("No elements were detected")
44
+ interface.scan("http://www.fakepage.com")
45
+ end
36
46
  end
37
47
  end
38
48
 
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.0
4
+ version: 1.0.1
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-10-02 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -149,7 +149,6 @@ files:
149
149
  - .rspec
150
150
  - .travis.yml
151
151
  - Gemfile
152
- - Gemfile.lock
153
152
  - README.md
154
153
  - Rakefile
155
154
  - bin/swamp
@@ -170,11 +169,13 @@ files:
170
169
  - features/support/page_examples/checkbox.html
171
170
  - features/support/page_examples/field.html
172
171
  - features/support/page_examples/field_without_id.html
172
+ - features/support/page_examples/field_without_name.html
173
173
  - features/support/page_examples/input_submit.html
174
174
  - features/support/page_examples/input_submit_without_id.html
175
175
  - features/support/page_examples/link.html
176
176
  - features/support/page_examples/link.html~
177
177
  - features/support/page_examples/link_with_id.html
178
+ - features/support/page_examples/no_elements.html
178
179
  - features/support/page_examples/radio.html
179
180
  - features/support/page_examples/select_box_with_id.html
180
181
  - features/support/page_examples/select_box_with_name_only.html
@@ -254,11 +255,13 @@ test_files:
254
255
  - features/support/page_examples/checkbox.html
255
256
  - features/support/page_examples/field.html
256
257
  - features/support/page_examples/field_without_id.html
258
+ - features/support/page_examples/field_without_name.html
257
259
  - features/support/page_examples/input_submit.html
258
260
  - features/support/page_examples/input_submit_without_id.html
259
261
  - features/support/page_examples/link.html
260
262
  - features/support/page_examples/link.html~
261
263
  - features/support/page_examples/link_with_id.html
264
+ - features/support/page_examples/no_elements.html
262
265
  - features/support/page_examples/radio.html
263
266
  - features/support/page_examples/select_box_with_id.html
264
267
  - features/support/page_examples/select_box_with_name_only.html
data/Gemfile.lock DELETED
@@ -1,79 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- swamp (0.0.5)
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.8.0)
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
73
- cucumber
74
- json
75
- pry
76
- pry-nav
77
- rake
78
- rspec
79
- swamp!