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
    
        data/lib/swamp/setup.rb
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            module Swamp
         | 
| 2 | 
            +
              class Setup
         | 
| 3 | 
            +
                attr_reader :scope
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                COMMAND_LIST = {
         | 
| 6 | 
            +
                  ":scope" => ["source", "page"]
         | 
| 7 | 
            +
                }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                include Swamp::Assertions
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def initialize
         | 
| 12 | 
            +
                  @scope = "page"
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def handle_command(input)
         | 
| 16 | 
            +
                  @input = input
         | 
| 17 | 
            +
                  remove_white_spaces
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  begin
         | 
| 20 | 
            +
                    assert { COMMAND_LIST[command] && COMMAND_LIST[command].include?(value) }
         | 
| 21 | 
            +
                  rescue ArgumentError
         | 
| 22 | 
            +
                    return ["Invalid command"]
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  @scope = value
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  [success_message]
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                private
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def success_message
         | 
| 33 | 
            +
                  ["Option", " ",  command, " ", "set", " ", "to", " ", value].join
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def command
         | 
| 37 | 
            +
                  @input.split("=")[0]
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def value
         | 
| 41 | 
            +
                  @input.split("=")[1]
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def remove_white_spaces
         | 
| 45 | 
            +
                  @input = @input.gsub(/\s+/, "")
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
            end
         | 
    
        data/lib/swamp/version.rb
    CHANGED
    
    
    
        data/lib/swamp/wrapper.rb
    CHANGED
    
    | @@ -1,12 +1,13 @@ | |
| 1 1 | 
             
            module Swamp
         | 
| 2 2 | 
             
              class Wrapper < Base
         | 
| 3 | 
            -
                 | 
| 3 | 
            +
                attr_reader :page_visited
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(meta_collection, setup)
         | 
| 4 6 | 
             
                  @meta_collection = meta_collection
         | 
| 5 7 | 
             
                  @page_visited = false
         | 
| 8 | 
            +
                  @setup = setup
         | 
| 6 9 | 
             
                end
         | 
| 7 10 |  | 
| 8 | 
            -
                attr_reader :page_visited
         | 
| 9 | 
            -
             | 
| 10 11 | 
             
                def explore(url)
         | 
| 11 12 | 
             
                  if !page_visited
         | 
| 12 13 | 
             
                    visit url
         | 
| @@ -17,7 +18,7 @@ module Swamp | |
| 17 18 | 
             
                def scan
         | 
| 18 19 | 
             
                  found_snippets = []
         | 
| 19 20 | 
             
                  @meta_collection.each do | element_collection |
         | 
| 20 | 
            -
                    found_snippets += element_collection.get.map { | element | Swamp::Builder.new(element).build_snippet }
         | 
| 21 | 
            +
                    found_snippets += element_collection.get.map { | element | Swamp::Builder.new(element, @setup).build_snippet }
         | 
| 21 22 | 
             
                  end
         | 
| 22 23 | 
             
                  found_snippets
         | 
| 23 24 | 
             
                end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        data/spec/swamp/builder_spec.rb
    CHANGED
    
    | @@ -1,35 +1,45 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 | 
             
            module Swamp
         | 
| 3 3 | 
             
              describe Builder do
         | 
| 4 | 
            +
                let(:setup) { setup = Swamp::Setup.new }
         | 
| 5 | 
            +
             | 
| 4 6 | 
             
                describe "#build_method" do
         | 
| 5 7 | 
             
                  context "when the type is field" do
         | 
| 6 | 
            -
                    let(:type) { :field }
         | 
| 7 8 | 
             
                    context "when the name and the selector are present" do
         | 
| 8 9 | 
             
                      it "returns the method's snippet" do
         | 
| 9 10 | 
             
                        element = Swamp::Field.new("User-Name", "User-Name")
         | 
| 10 | 
            -
                        builder = Swamp::Builder.new(element)
         | 
| 11 | 
            -
                        builder.build_snippet. | 
| 11 | 
            +
                        builder = Swamp::Builder.new(element, setup)
         | 
| 12 | 
            +
                        expect(builder.build_snippet).to eq("def type_user_name(input)\n  page.fill_in(\"User-Name\", with: input)\nend")
         | 
| 12 13 | 
             
                      end
         | 
| 13 14 | 
             
                    end
         | 
| 14 15 | 
             
                  end
         | 
| 15 16 |  | 
| 16 17 | 
             
                  context "when the type is button" do
         | 
| 17 | 
            -
                    let(:type) { :button }
         | 
| 18 18 | 
             
                    context "when the name and the selector are present" do
         | 
| 19 19 | 
             
                      it "returns the method's snippet" do
         | 
| 20 20 | 
             
                        element = Swamp::Button.new("Log_in", "Log_in")
         | 
| 21 | 
            -
                        builder = Swamp::Builder.new(element)
         | 
| 22 | 
            -
                        builder.build_snippet. | 
| 21 | 
            +
                        builder = Swamp::Builder.new(element, setup)
         | 
| 22 | 
            +
                        expect(builder.build_snippet).to eq("def log_in\n  page.click_button(\"Log_in\")\nend")
         | 
| 23 23 | 
             
                      end
         | 
| 24 24 | 
             
                    end
         | 
| 25 25 |  | 
| 26 26 | 
             
                    context "when just the selector is present" do
         | 
| 27 27 | 
             
                      it "returns just the selector snippet" do
         | 
| 28 28 | 
             
                        element = Swamp::Button.new(nil, "$ 9.90 Buy")
         | 
| 29 | 
            -
                        builder = Swamp::Builder.new(element)
         | 
| 30 | 
            -
                        builder.build_snippet. | 
| 29 | 
            +
                        builder = Swamp::Builder.new(element, setup)
         | 
| 30 | 
            +
                        expect(builder.build_snippet).to eq("page.click_button(\"$ 9.90 Buy\")")
         | 
| 31 | 
            +
                      end
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    context "when the scope has changed" do
         | 
| 35 | 
            +
                      it "returns the method's snippet with the changed scope" do
         | 
| 36 | 
            +
                        element = Swamp::Button.new("Log_in", "Log_in")
         | 
| 37 | 
            +
                        allow(setup).to receive(:scope).and_return("source")
         | 
| 38 | 
            +
                        builder = Swamp::Builder.new(element, setup)
         | 
| 39 | 
            +
                        expect(builder.build_snippet).to eq("def log_in\n  source.click_button(\"Log_in\")\nend")
         | 
| 31 40 | 
             
                      end
         | 
| 32 41 | 
             
                    end
         | 
| 42 | 
            +
             | 
| 33 43 | 
             
                  end
         | 
| 34 44 | 
             
                end
         | 
| 35 45 | 
             
              end
         | 
    
        data/spec/swamp/buttons_spec.rb
    CHANGED
    
    | @@ -5,10 +5,10 @@ module Swamp | |
| 5 5 |  | 
| 6 6 | 
             
                it "delegates to capybara the responsibility to get the buttons" do
         | 
| 7 7 | 
             
                  element = {'id' => "u_0_2"}
         | 
| 8 | 
            -
                  element. | 
| 9 | 
            -
                  element. | 
| 10 | 
            -
                  buttons.page. | 
| 11 | 
            -
                  buttons.page. | 
| 8 | 
            +
                  allow(element).to receive(:text).and_return("Sign Up")
         | 
| 9 | 
            +
                  allow(element).to receive(:visible?).and_return(true)
         | 
| 10 | 
            +
                  allow(buttons.page).to receive(:execute_script).and_return(nil)
         | 
| 11 | 
            +
                  expect(buttons.page).to receive(:all).with('button').and_return([element])
         | 
| 12 12 | 
             
                  buttons.get
         | 
| 13 13 | 
             
                end
         | 
| 14 14 |  | 
| @@ -17,21 +17,21 @@ module Swamp | |
| 17 17 | 
             
                    let(:element) { {'id' => "u_0_2"} }
         | 
| 18 18 |  | 
| 19 19 | 
             
                    before(:each) do
         | 
| 20 | 
            -
                      element. | 
| 21 | 
            -
                      element. | 
| 22 | 
            -
                      buttons.page. | 
| 20 | 
            +
                      allow(element).to receive(:visible?).and_return(true)
         | 
| 21 | 
            +
                      allow(element).to receive(:text).and_return("Sign Up")
         | 
| 22 | 
            +
                      allow(buttons.page).to receive(:all).with('button').and_return([element])
         | 
| 23 23 | 
             
                    end
         | 
| 24 24 |  | 
| 25 25 | 
             
                    it "highlights the element" do
         | 
| 26 | 
            -
                      buttons.page. | 
| 26 | 
            +
                      expect(buttons.page).to receive(:execute_script).twice
         | 
| 27 27 | 
             
                      buttons.get
         | 
| 28 28 | 
             
                    end
         | 
| 29 29 |  | 
| 30 30 | 
             
                    it "returns the element in the array using the text as both the name and the selector" do
         | 
| 31 | 
            -
                      buttons.page. | 
| 32 | 
            -
                      buttons.get. | 
| 33 | 
            -
                      buttons.get.each.first.name. | 
| 34 | 
            -
                      buttons.get.each.first.selector. | 
| 31 | 
            +
                      allow(buttons.page).to receive(:execute_script).and_return(nil)
         | 
| 32 | 
            +
                      expect(buttons.get.size).to eq(1)
         | 
| 33 | 
            +
                      expect(buttons.get.each.first.name).to eq("Sign Up")
         | 
| 34 | 
            +
                      expect(buttons.get.each.first.selector).to eq("Sign Up")
         | 
| 35 35 | 
             
                    end
         | 
| 36 36 | 
             
                  end
         | 
| 37 37 |  | 
| @@ -40,21 +40,21 @@ module Swamp | |
| 40 40 | 
             
                      let(:element) { {'id' => "search-button"} }
         | 
| 41 41 |  | 
| 42 42 | 
             
                      before(:each) do
         | 
| 43 | 
            -
                        element. | 
| 44 | 
            -
                        element. | 
| 45 | 
            -
                        buttons.page. | 
| 43 | 
            +
                        allow(element).to receive(:visible?).and_return(true)
         | 
| 44 | 
            +
                        allow(element).to receive(:text).and_return("")
         | 
| 45 | 
            +
                        allow(buttons.page).to receive(:all).with('button').and_return([element])
         | 
| 46 46 | 
             
                      end
         | 
| 47 47 |  | 
| 48 48 | 
             
                      it "highlights the element" do
         | 
| 49 | 
            -
                        buttons.page. | 
| 49 | 
            +
                        expect(buttons.page).to receive(:execute_script).twice
         | 
| 50 50 | 
             
                        buttons.get
         | 
| 51 51 | 
             
                      end
         | 
| 52 52 |  | 
| 53 53 | 
             
                      it "returns the element in the array using the id as both the name and the selector" do
         | 
| 54 | 
            -
                        buttons.page. | 
| 55 | 
            -
                        buttons.get. | 
| 56 | 
            -
                        buttons.get.each.first.name. | 
| 57 | 
            -
                        buttons.get.each.first.selector. | 
| 54 | 
            +
                        allow(buttons.page).to receive(:execute_script).and_return(nil)
         | 
| 55 | 
            +
                        expect(buttons.get.size).to eq(1)
         | 
| 56 | 
            +
                        expect(buttons.get.each.first.name).to eq("search-button")
         | 
| 57 | 
            +
                        expect(buttons.get.each.first.selector).to eq("search-button")
         | 
| 58 58 | 
             
                      end
         | 
| 59 59 | 
             
                    end
         | 
| 60 60 |  | 
| @@ -63,21 +63,21 @@ module Swamp | |
| 63 63 | 
             
                        let(:element) { {'value' => "search-button", 'id' => ""} }
         | 
| 64 64 |  | 
| 65 65 | 
             
                        before(:each) do
         | 
| 66 | 
            -
                          element. | 
| 67 | 
            -
                          element. | 
| 68 | 
            -
                          buttons.page. | 
| 66 | 
            +
                          allow(element).to receive(:visible?).and_return(true)
         | 
| 67 | 
            +
                          allow(element).to receive(:text).and_return("")
         | 
| 68 | 
            +
                          allow(buttons.page).to receive(:all).with('button').and_return([element])
         | 
| 69 69 | 
             
                        end
         | 
| 70 70 |  | 
| 71 71 | 
             
                        it "highlights the element" do
         | 
| 72 | 
            -
                          buttons.page. | 
| 72 | 
            +
                          expect(buttons.page).to receive(:execute_script).twice
         | 
| 73 73 | 
             
                          buttons.get
         | 
| 74 74 | 
             
                        end
         | 
| 75 75 |  | 
| 76 76 | 
             
                        it "returns the element in the array using the value as both the name and the selector" do
         | 
| 77 | 
            -
                          buttons.page. | 
| 78 | 
            -
                          buttons.get. | 
| 79 | 
            -
                          buttons.get.each.first.name. | 
| 80 | 
            -
                          buttons.get.each.first.selector. | 
| 77 | 
            +
                          allow(buttons.page).to receive(:execute_script).and_return(nil)
         | 
| 78 | 
            +
                          expect(buttons.get.size).to eq(1)
         | 
| 79 | 
            +
                          expect(buttons.get.each.first.name).to eq("search-button")
         | 
| 80 | 
            +
                          expect(buttons.get.each.first.selector).to eq("search-button")
         | 
| 81 81 | 
             
                        end
         | 
| 82 82 | 
             
                      end
         | 
| 83 83 |  | 
| @@ -85,14 +85,14 @@ module Swamp | |
| 85 85 | 
             
                        let(:element) { {'value' => "", 'id' => ""} }
         | 
| 86 86 |  | 
| 87 87 | 
             
                        before(:each) do
         | 
| 88 | 
            -
                          element. | 
| 89 | 
            -
                          element. | 
| 90 | 
            -
                          buttons.page. | 
| 88 | 
            +
                          allow(element).to receive(:visible?).and_return(true)
         | 
| 89 | 
            +
                          allow(element).to receive(:text).and_return("")
         | 
| 90 | 
            +
                          allow(buttons.page).to receive(:all).with('button').and_return([element])
         | 
| 91 91 | 
             
                        end
         | 
| 92 92 |  | 
| 93 93 | 
             
                        it "returns an empty array" do
         | 
| 94 | 
            -
                          buttons. | 
| 95 | 
            -
                          buttons.get. | 
| 94 | 
            +
                          allow(buttons).to receive(:all).with('button').and_return([element])
         | 
| 95 | 
            +
                          expect(buttons.get).to eq([])
         | 
| 96 96 | 
             
                        end
         | 
| 97 97 | 
             
                      end
         | 
| 98 98 | 
             
                    end
         | 
| @@ -102,10 +102,10 @@ module Swamp | |
| 102 102 | 
             
                context "when the button element is not visible" do
         | 
| 103 103 | 
             
                  it "returns an empty array" do
         | 
| 104 104 | 
             
                    element = {'id' => "u_0_2"}
         | 
| 105 | 
            -
                    element. | 
| 106 | 
            -
                    element. | 
| 107 | 
            -
                    buttons.page. | 
| 108 | 
            -
                    buttons.get. | 
| 105 | 
            +
                    allow(element).to receive(:text).and_return("Sign Up")
         | 
| 106 | 
            +
                    allow(element).to receive(:visible?).and_return(false)
         | 
| 107 | 
            +
                    allow(buttons.page).to receive(:all).with('button').and_return([element])
         | 
| 108 | 
            +
                    expect(buttons.get).to eq([])
         | 
| 109 109 | 
             
                  end
         | 
| 110 110 | 
             
                end
         | 
| 111 111 | 
             
              end
         | 
| @@ -9,7 +9,7 @@ module Swamp | |
| 9 9 | 
             
                      it "returns true" do
         | 
| 10 10 | 
             
                        input = "http://fakepage.com"
         | 
| 11 11 | 
             
                        evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 12 | 
            -
                        evaluator. | 
| 12 | 
            +
                        expect(evaluator).to be_valid_url
         | 
| 13 13 | 
             
                      end
         | 
| 14 14 | 
             
                    end
         | 
| 15 15 |  | 
| @@ -17,7 +17,7 @@ module Swamp | |
| 17 17 | 
             
                      it "returns true" do
         | 
| 18 18 | 
             
                        input = "https://fakepage.com"
         | 
| 19 19 | 
             
                        evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 20 | 
            -
                        evaluator. | 
| 20 | 
            +
                        expect(evaluator).to be_valid_url
         | 
| 21 21 | 
             
                      end
         | 
| 22 22 | 
             
                    end
         | 
| 23 23 |  | 
| @@ -25,7 +25,7 @@ module Swamp | |
| 25 25 | 
             
                      it "returns true" do
         | 
| 26 26 | 
             
                        input = "file://fakepage.html"
         | 
| 27 27 | 
             
                        evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 28 | 
            -
                        evaluator. | 
| 28 | 
            +
                        expect(evaluator).to be_valid_url
         | 
| 29 29 | 
             
                      end
         | 
| 30 30 | 
             
                    end
         | 
| 31 31 | 
             
                  end
         | 
| @@ -35,7 +35,7 @@ module Swamp | |
| 35 35 | 
             
                      it "returns false" do
         | 
| 36 36 | 
             
                        input = "www.fakepage.com"
         | 
| 37 37 | 
             
                        evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 38 | 
            -
                        evaluator. | 
| 38 | 
            +
                        expect(evaluator).not_to be_valid_url
         | 
| 39 39 | 
             
                      end
         | 
| 40 40 | 
             
                    end
         | 
| 41 41 | 
             
                  end
         | 
| @@ -45,29 +45,29 @@ module Swamp | |
| 45 45 | 
             
                  context "when the input is an enter keystroke" do
         | 
| 46 46 | 
             
                    context "when a page was already visited" do
         | 
| 47 47 | 
             
                      it "returns true" do
         | 
| 48 | 
            -
                        wrapper. | 
| 48 | 
            +
                        allow(wrapper).to receive(:page_visited).and_return(true)
         | 
| 49 49 | 
             
                        input = "\n"
         | 
| 50 50 | 
             
                        evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 51 | 
            -
                        evaluator. | 
| 51 | 
            +
                        expect(evaluator).to be_refresh_command
         | 
| 52 52 | 
             
                      end
         | 
| 53 53 | 
             
                    end
         | 
| 54 54 |  | 
| 55 55 | 
             
                    context "when no page was yet visited" do
         | 
| 56 56 | 
             
                      it "returns false" do
         | 
| 57 | 
            -
                        wrapper. | 
| 57 | 
            +
                        allow(wrapper).to receive(:page_visited).and_return(false)
         | 
| 58 58 | 
             
                        input = "\n"
         | 
| 59 59 | 
             
                        evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 60 | 
            -
                        evaluator. | 
| 60 | 
            +
                        expect(evaluator).not_to be_refresh_command
         | 
| 61 61 | 
             
                      end
         | 
| 62 62 | 
             
                    end
         | 
| 63 63 | 
             
                  end
         | 
| 64 64 |  | 
| 65 65 | 
             
                  context "when the input is not an enter keystroke" do
         | 
| 66 66 | 
             
                    it "returns false" do
         | 
| 67 | 
            -
                      wrapper. | 
| 67 | 
            +
                      allow(wrapper).to receive(:page_visited).and_return(true)
         | 
| 68 68 | 
             
                      input = " "
         | 
| 69 69 | 
             
                      evaluator = Swamp::Evaluator.new(input, wrapper)
         | 
| 70 | 
            -
                      evaluator. | 
| 70 | 
            +
                      expect(evaluator).not_to be_refresh_command
         | 
| 71 71 | 
             
                    end
         | 
| 72 72 | 
             
                  end
         | 
| 73 73 | 
             
                end
         | 
    
        data/spec/swamp/fields_spec.rb
    CHANGED
    
    | @@ -5,9 +5,9 @@ module Swamp | |
| 5 5 |  | 
| 6 6 | 
             
                it "delegates to capybara the responsibility to get the fields" do
         | 
| 7 7 | 
             
                  element = {'name' => "username", 'type' => "text"}
         | 
| 8 | 
            -
                  element. | 
| 9 | 
            -
                  fields.page. | 
| 10 | 
            -
                  fields.page. | 
| 8 | 
            +
                  allow(element).to receive(:visible?).and_return(true)
         | 
| 9 | 
            +
                  allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 10 | 
            +
                  expect(fields.page).to receive(:all).with('input').and_return([element])
         | 
| 11 11 | 
             
                  fields.get
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| @@ -19,25 +19,25 @@ module Swamp | |
| 19 19 | 
             
                      let (:element) { {'name' => "username", 'type' => type, 'id' => "u_0_b"} }
         | 
| 20 20 |  | 
| 21 21 | 
             
                      before(:each) do
         | 
| 22 | 
            -
                        element. | 
| 23 | 
            -
                        fields.page. | 
| 22 | 
            +
                        allow(element).to receive(:visible?).and_return(true)
         | 
| 23 | 
            +
                        allow(fields.page).to receive(:all).with('input').and_return([element])
         | 
| 24 24 | 
             
                      end
         | 
| 25 25 |  | 
| 26 26 | 
             
                      it "highlights the element" do
         | 
| 27 | 
            -
                        fields.page. | 
| 27 | 
            +
                        expect(fields.page).to receive(:execute_script).twice
         | 
| 28 28 | 
             
                        fields.get
         | 
| 29 29 | 
             
                      end
         | 
| 30 30 |  | 
| 31 31 | 
             
                      it "returns the element in the array using the name as the method's name" do
         | 
| 32 | 
            -
                        fields.page. | 
| 33 | 
            -
                        fields.get. | 
| 34 | 
            -
                        fields.get.first.name. | 
| 32 | 
            +
                        allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 33 | 
            +
                        expect(fields.get.size).to eq(1)
         | 
| 34 | 
            +
                        expect(fields.get.first.name).to eq("username")
         | 
| 35 35 | 
             
                      end
         | 
| 36 36 |  | 
| 37 37 | 
             
                      it "returns the element in the array using the id as the selector" do
         | 
| 38 | 
            -
                        fields.page. | 
| 39 | 
            -
                        fields.get. | 
| 40 | 
            -
                        fields.get.first.selector. | 
| 38 | 
            +
                        allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 39 | 
            +
                        expect(fields.get.size).to eq(1)
         | 
| 40 | 
            +
                        expect(fields.get.first.selector).to eq("u_0_b")
         | 
| 41 41 | 
             
                      end
         | 
| 42 42 | 
             
                    end
         | 
| 43 43 |  | 
| @@ -45,25 +45,25 @@ module Swamp | |
| 45 45 | 
             
                      let (:element) { {'type' => type, 'id' => "username"} }
         | 
| 46 46 |  | 
| 47 47 | 
             
                      before(:each) do
         | 
| 48 | 
            -
                        element. | 
| 49 | 
            -
                        fields.page. | 
| 48 | 
            +
                        allow(element).to receive(:visible?).and_return(true)
         | 
| 49 | 
            +
                        allow(fields.page).to receive(:all).with('input').and_return([element])
         | 
| 50 50 | 
             
                      end
         | 
| 51 51 |  | 
| 52 52 | 
             
                      it "highlights the element" do
         | 
| 53 | 
            -
                        fields.page. | 
| 53 | 
            +
                        expect(fields.page).to receive(:execute_script).twice
         | 
| 54 54 | 
             
                        fields.get
         | 
| 55 55 | 
             
                      end
         | 
| 56 56 |  | 
| 57 57 | 
             
                      it "returns the element in the array using the id as the method's name" do
         | 
| 58 | 
            -
                        fields.page. | 
| 59 | 
            -
                        fields.get. | 
| 60 | 
            -
                        fields.get.first.name. | 
| 58 | 
            +
                        allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 59 | 
            +
                        expect(fields.get.size).to eq(1)
         | 
| 60 | 
            +
                        expect(fields.get.first.name).to eq("username")
         | 
| 61 61 | 
             
                      end
         | 
| 62 62 |  | 
| 63 63 | 
             
                      it "returns the element in the array using the id as the selector" do
         | 
| 64 | 
            -
                        fields.page. | 
| 65 | 
            -
                        fields.get. | 
| 66 | 
            -
                        fields.get.first.selector. | 
| 64 | 
            +
                        allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 65 | 
            +
                        expect(fields.get.size).to eq(1)
         | 
| 66 | 
            +
                        expect(fields.get.first.selector).to eq("username")
         | 
| 67 67 | 
             
                      end
         | 
| 68 68 | 
             
                    end
         | 
| 69 69 |  | 
| @@ -71,25 +71,25 @@ module Swamp | |
| 71 71 | 
             
                      let (:element) { {'name' => "username", 'type' => type} }
         | 
| 72 72 |  | 
| 73 73 | 
             
                      before(:each) do
         | 
| 74 | 
            -
                        element. | 
| 75 | 
            -
                        fields.page. | 
| 74 | 
            +
                        allow(element).to receive(:visible?).and_return(true)
         | 
| 75 | 
            +
                        allow(fields.page).to receive(:all).with('input').and_return([element])
         | 
| 76 76 | 
             
                      end
         | 
| 77 77 |  | 
| 78 78 | 
             
                      it "highlights the element" do
         | 
| 79 | 
            -
                        fields.page. | 
| 79 | 
            +
                        expect(fields.page).to receive(:execute_script).twice
         | 
| 80 80 | 
             
                        fields.get
         | 
| 81 81 | 
             
                      end
         | 
| 82 82 |  | 
| 83 83 | 
             
                      it "returns the element in the array using the name as the method's name" do
         | 
| 84 | 
            -
                        fields.page. | 
| 85 | 
            -
                        fields.get. | 
| 86 | 
            -
                        fields.get.first.name. | 
| 84 | 
            +
                        allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 85 | 
            +
                        expect(fields.get.size).to eq(1)
         | 
| 86 | 
            +
                        expect(fields.get.first.name).to eq("username")
         | 
| 87 87 | 
             
                      end
         | 
| 88 88 |  | 
| 89 89 | 
             
                      it "returns the element in the array using the name as the selector" do
         | 
| 90 | 
            -
                        fields.page. | 
| 91 | 
            -
                        fields.get. | 
| 92 | 
            -
                        fields.get.first.selector. | 
| 90 | 
            +
                        allow(fields.page).to receive(:execute_script).and_return(nil)
         | 
| 91 | 
            +
                        expect(fields.get.size).to eq(1)
         | 
| 92 | 
            +
                        expect(fields.get.first.selector).to eq("username")
         | 
| 93 93 | 
             
                      end
         | 
| 94 94 | 
             
                    end
         | 
| 95 95 | 
             
                  end
         | 
| @@ -99,9 +99,9 @@ module Swamp | |
| 99 99 |  | 
| 100 100 | 
             
                    it "returns an empty array" do
         | 
| 101 101 | 
             
                      element = {'name' => "username", 'type' => type}
         | 
| 102 | 
            -
                      element. | 
| 103 | 
            -
                      fields.page. | 
| 104 | 
            -
                      fields.get. | 
| 102 | 
            +
                      allow(element).to receive(:visible?).and_return(true)
         | 
| 103 | 
            +
                      allow(fields.page).to receive(:all).with('input').and_return([element])
         | 
| 104 | 
            +
                      expect(fields.get).to eq([])
         | 
| 105 105 | 
             
                    end
         | 
| 106 106 | 
             
                  end
         | 
| 107 107 | 
             
                end
         | 
| @@ -109,9 +109,9 @@ module Swamp | |
| 109 109 | 
             
                context "when the input element is not visible" do
         | 
| 110 110 | 
             
                  it "returns an empty array" do
         | 
| 111 111 | 
             
                    element = {'name' => "username", 'type' => "text"}
         | 
| 112 | 
            -
                    element. | 
| 113 | 
            -
                    fields.page. | 
| 114 | 
            -
                    fields.get. | 
| 112 | 
            +
                    allow(element).to receive(:visible?).and_return(false)
         | 
| 113 | 
            +
                    allow(fields.page).to receive(:all).with('input').and_return([element])
         | 
| 114 | 
            +
                    expect(fields.get).to eq([])
         | 
| 115 115 | 
             
                  end
         | 
| 116 116 | 
             
                end
         | 
| 117 117 | 
             
              end
         |