page_magic 2.0.6 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/page_magic/session.rb +0 -6
  4. metadata +55 -90
  5. data/.codeclimate.yml +0 -4
  6. data/.pullreview.yml +0 -14
  7. data/.rspec +0 -1
  8. data/.rubocop.yml +0 -39
  9. data/.simplecov +0 -10
  10. data/.zsh_config +0 -6
  11. data/Dockerfile +0 -11
  12. data/Gemfile +0 -24
  13. data/Gemfile.lock +0 -175
  14. data/Makefile +0 -17
  15. data/Rakefile +0 -32
  16. data/circle.yml +0 -8
  17. data/page_magic.gemspec +0 -128
  18. data/spec/lib/active_support/core_ext/object/to_query_test.rb +0 -78
  19. data/spec/page_magic/class_methods_spec.rb +0 -92
  20. data/spec/page_magic/comparator/fuzzy_spec.rb +0 -44
  21. data/spec/page_magic/comparator/literal_spec.rb +0 -41
  22. data/spec/page_magic/comparator/null_spec.rb +0 -35
  23. data/spec/page_magic/comparator/parameter_map_spec.rb +0 -75
  24. data/spec/page_magic/driver_spec.rb +0 -40
  25. data/spec/page_magic/drivers/poltergeist_spec.rb +0 -8
  26. data/spec/page_magic/drivers/rack_test_spec.rb +0 -8
  27. data/spec/page_magic/drivers/selenium_spec.rb +0 -15
  28. data/spec/page_magic/drivers_spec.rb +0 -48
  29. data/spec/page_magic/element/locators_spec.rb +0 -36
  30. data/spec/page_magic/element/not_found_spec.rb +0 -24
  31. data/spec/page_magic/element/query/multiple_results_spec.rb +0 -14
  32. data/spec/page_magic/element/query/single_result_spec.rb +0 -21
  33. data/spec/page_magic/element/query_spec.rb +0 -38
  34. data/spec/page_magic/element/selector_spec.rb +0 -166
  35. data/spec/page_magic/element_context_spec.rb +0 -72
  36. data/spec/page_magic/element_definition_builder_spec.rb +0 -19
  37. data/spec/page_magic/element_spec.rb +0 -256
  38. data/spec/page_magic/elements/config_spec.rb +0 -203
  39. data/spec/page_magic/elements_spec.rb +0 -125
  40. data/spec/page_magic/instance_methods_spec.rb +0 -90
  41. data/spec/page_magic/mapping_spec.rb +0 -181
  42. data/spec/page_magic/session_methods_spec.rb +0 -40
  43. data/spec/page_magic/session_spec.rb +0 -164
  44. data/spec/page_magic/transitions_spec.rb +0 -43
  45. data/spec/page_magic/utils/string_spec.rb +0 -29
  46. data/spec/page_magic/utils/url_spec.rb +0 -9
  47. data/spec/page_magic/wait_methods_spec.rb +0 -35
  48. data/spec/page_magic/watcher_spec.rb +0 -22
  49. data/spec/page_magic/watchers_spec.rb +0 -80
  50. data/spec/page_magic_spec.rb +0 -115
  51. data/spec/spec_helper.rb +0 -15
  52. data/spec/support/shared_contexts.rb +0 -5
  53. data/spec/support/shared_examples.rb +0 -25
@@ -1,35 +0,0 @@
1
- RSpec.describe PageMagic::Comparator::Null do
2
- describe '#fuzzy?' do
3
- context 'when one value is fuzzy' do
4
- it 'returns true' do
5
- expect(described_class.new).not_to be_fuzzy
6
- end
7
- end
8
- end
9
-
10
- describe 'match?' do
11
- it 'returns false' do
12
- expect(described_class.new).to be_match(true)
13
- end
14
- end
15
-
16
- describe '#<=>' do
17
- context 'when other is `Null`' do
18
- it 'is equal' do
19
- expect(described_class.new <=> described_class.new).to be 0
20
- end
21
- end
22
-
23
- context 'when other is `Fuzzy`' do
24
- it 'is greater' do
25
- expect(described_class.new <=> PageMagic::Comparator::Fuzzy.new(//)).to be 1
26
- end
27
- end
28
-
29
- context 'when other is `Literal`' do
30
- it 'is greater' do
31
- expect(described_class.new <=> PageMagic::Comparator::Literal.new('/')).to be 1
32
- end
33
- end
34
- end
35
- end
@@ -1,75 +0,0 @@
1
- RSpec.describe PageMagic::Comparator::ParameterMap do
2
- describe '#fuzzy?' do
3
- context 'when one value is fuzzy' do
4
- it 'returns true' do
5
- map = described_class.new({ param1: //, param2: '' })
6
- expect(map).to be_fuzzy
7
- end
8
- end
9
-
10
- context 'when all values are literal' do
11
- it 'returns true' do
12
- map = described_class.new({ param1: '', param2: '' })
13
- expect(map).not_to be_fuzzy
14
- end
15
- end
16
- end
17
-
18
- describe '#match?' do
19
- context 'when param has compatible params' do
20
- it 'returns true' do
21
- expect(described_class.new({ param: '1' })).to be_match(param: '1')
22
- end
23
- end
24
-
25
- context 'when it does not have compatible params' do
26
- it 'returns false' do
27
- expect(described_class.new({ param: '1' })).not_to be_match(param: '2')
28
- end
29
- end
30
-
31
- context 'when it does not meet all of the requirements' do
32
- it 'returns false' do
33
- expect(described_class.new({ param: '1', another_param: '2' })).not_to be_match(param: '1')
34
- end
35
- end
36
- end
37
-
38
- describe '#<=>' do
39
- context 'when other is empty' do
40
- context 'and self is empty' do
41
- it 'is equal' do
42
- expect(described_class.new({}) <=> described_class.new({})).to be 0
43
- end
44
- end
45
-
46
- context 'self is not empty' do
47
- it 'is greater' do
48
- expect(described_class.new({ param: 1 }) <=> described_class.new({})).to be 1
49
- end
50
- end
51
- end
52
-
53
- context 'when other contains matchers' do
54
- context 'when other has the same number' do
55
- context 'and matchers are of the same type' do
56
- it 'is equal' do
57
- expect(described_class.new({ param: // }) <=> described_class.new({ param: // })).to be 0
58
- end
59
- end
60
-
61
- context 'and has less literal matchers' do
62
- it 'is lesser' do
63
- expect(described_class.new({ param: '' }) <=> described_class.new({ param: // })).to be 1
64
- end
65
- end
66
- end
67
-
68
- context 'when other has the less' do
69
- it 'is lesser' do
70
- expect(described_class.new({ param: // }) <=> described_class.new({})).to be 1
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Driver do
4
- describe '#build' do
5
- it 'returns the result of the block passed to the driver class constructor' do
6
- subject = described_class.new(:custom_browser) do
7
- :driver
8
- end
9
- expect(subject.build(:rack_app, browser: :custom_browser, options: {})).to eq(:driver)
10
- end
11
-
12
- it 'passes rack app to the handler' do
13
- subject = described_class.new(:custom_browser) do |app, options, browser|
14
- expect(app).to eq(:rack_app)
15
- expect(options).to eq(:options)
16
- expect(browser).to eq(:browser)
17
- end
18
-
19
- subject.build(:rack_app, options: :options, browser: :browser)
20
- end
21
- end
22
-
23
- describe '#supports?' do
24
- subject do
25
- described_class.new :custom_browser
26
- end
27
-
28
- context 'browser is in supported browsers' do
29
- it 'returns true' do
30
- expect(subject.support?(:custom_browser)).to eq(true)
31
- end
32
- end
33
-
34
- context 'browser is not in supported browsers' do
35
- it 'returns false' do
36
- expect(subject.support?(:unsupported_browser)).to eq(false)
37
- end
38
- end
39
- end
40
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Drivers::Poltergeist do
4
- it "is capybara's poltergeist driver" do
5
- driver = described_class.build(:app, browser: :poltergeist, options: {})
6
- expect(driver).to be_a(Capybara::Poltergeist::Driver)
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Drivers::RackTest do
4
- it "is capybara's rack test driver" do
5
- driver = described_class.build(:app, browser: :rack_test, options: {})
6
- expect(driver).to be_a(Capybara::RackTest::Driver)
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Drivers::Selenium do
4
- subject do
5
- described_class.build(:app, browser: :selenium, options: {})
6
- end
7
-
8
- it 'is selenium' do
9
- expect(subject).to be_a(Capybara::Selenium::Driver)
10
- end
11
-
12
- it 'sets the browser option' do
13
- expect(subject.options[:browser]).to be(:selenium)
14
- end
15
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Drivers do
4
- describe '#find' do
5
- it 'returns the registered driver' do
6
- drivers = described_class.new
7
- expected_driver = PageMagic::Driver.new(:browser_driver)
8
-
9
- drivers.register expected_driver
10
- expect(drivers.find(:browser_driver)).to eq(expected_driver)
11
- end
12
- end
13
-
14
- describe '#load' do
15
- require 'tmpdir'
16
-
17
- def scratch_dir
18
- @scratch_dir ||= Dir.mktmpdir
19
- end
20
-
21
- let(:class_definition) do
22
- <<-RUBY
23
- class CustomDriver;
24
- def self.support?(_browser)
25
- true
26
- end
27
- end
28
- RUBY
29
- end
30
-
31
- it 'loads the drivers in the specified path' do
32
- File.write("#{scratch_dir}/custom_driver.rb", class_definition)
33
-
34
- drivers = described_class.new
35
- drivers.load(scratch_dir)
36
- expect(drivers.find(:custom_browser)).to be(::CustomDriver)
37
- end
38
- end
39
-
40
- describe '#register' do
41
- it 'stores the driver' do
42
- drivers = described_class.new
43
- expected_driver = PageMagic::Driver.new(:browser_driver)
44
- drivers.register expected_driver
45
- expect(drivers.all).to eq([expected_driver])
46
- end
47
- end
48
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Element::Locators do
4
- subject { element_clazz.new }
5
-
6
- let(:element_clazz) do
7
- Class.new do
8
- extend(PageMagic::Elements)
9
- include(PageMagic::Element::Locators)
10
- end
11
- end
12
-
13
- describe '#element_by_name' do
14
- it 'returns the required element' do
15
- selector = { id: 'child' }
16
- element_clazz.element :child1, selector
17
- element_clazz.element :child2, id: 'child 2'
18
-
19
- child_1_builder = PageMagic::ElementDefinitionBuilder.new(
20
- definition_class: PageMagic::Element,
21
- selector: PageMagic::Element::Selector.find(:id).build(:element, 'child')
22
- )
23
-
24
- expect(subject.element_by_name(:child1)).to eq(child_1_builder)
25
- end
26
-
27
- context 'element not found' do
28
- it 'raises an error' do
29
- expected_message = (described_class::ELEMENT_NOT_DEFINED_MSG % :child)
30
- expect do
31
- subject.element_by_name(:child)
32
- end.to raise_exception PageMagic::ElementMissingException, expected_message
33
- end
34
- end
35
- end
36
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe PageMagic::Element::NotFound do
4
- describe '#method_missing' do
5
- it 'raises an error' do
6
- subject = described_class.new(Exception.new('message'))
7
- expect { subject.any_missing_method }.to raise_exception(PageMagic::ElementMissingException, 'message')
8
- end
9
- end
10
-
11
- describe '#visible?' do
12
- it 'returns false' do
13
- subject = described_class.new(Exception.new('message'))
14
- expect(subject.visible?).to eq(false)
15
- end
16
- end
17
-
18
- describe '#present?' do
19
- it 'returns false' do
20
- subject = described_class.new(Exception.new('message'))
21
- expect(subject.present?).to eq(false)
22
- end
23
- end
24
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Element::Query::MultipleResults do
4
- describe '#find' do
5
- context 'when multiple results found' do
6
- it 'returns an array' do
7
- element = PageMagic::Element.load('<a></a><a></a>')
8
- subject = described_class.new('a')
9
- result = subject.execute(element)
10
- expect(result.size).to eq(2)
11
- end
12
- end
13
- end
14
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Element::Query::SingleResult do
4
- describe '#find' do
5
- context 'when more than one result is returned' do
6
- it 'raises an error' do
7
- element = PageMagic::Element.load('<a></a><a></a>')
8
- query = described_class.new('a')
9
- expected_message = 'Ambiguous match, found 2 elements matching visible css "a"'
10
- expect { query.execute(element) }.to raise_error PageMagic::AmbiguousQueryException, expected_message
11
- end
12
- end
13
-
14
- it 'returns the result of the capybara query' do
15
- element = PageMagic::Element.load('<a>link</a>')
16
- query = described_class.new('a')
17
- result = query.execute(element)
18
- expect(result.text).to eq('link')
19
- end
20
- end
21
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Element::Query do
4
- describe '#execute' do
5
- it 'calls find' do
6
- subject = described_class.new
7
- allow(subject).to receive(:find)
8
-
9
- subject.execute(:capybara_element)
10
- expect(subject).to have_received(:find).with(:capybara_element)
11
- end
12
-
13
- context 'when a formatter supplied' do
14
- it 'uses it' do
15
- subject = described_class.new
16
- allow(subject).to receive(:find) { |_r, &formatter| formatter.call(:result) }
17
-
18
- result = subject.execute(:capybara_element) { |capybara_result| "formatter_called_on_#{capybara_result}" }
19
- expect(result).to eq('formatter_called_on_result')
20
- end
21
- end
22
-
23
- context 'when no results are found' do
24
- subject(:query_class) do
25
- Class.new(described_class) do
26
- def find(element)
27
- element.find('missing')
28
- end
29
- end
30
- end
31
-
32
- it 'Returns `NotFound`' do
33
- element = PageMagic::Element.load('<html></html>')
34
- expect(query_class.new.execute(element)).to be_a(PageMagic::Element::NotFound)
35
- end
36
- end
37
- end
38
- end
@@ -1,166 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Element::Selector do
4
- describe '.find' do
5
- it 'returns the constant with the given name' do
6
- expect(described_class.find(:css)).to be(described_class::CSS)
7
- end
8
-
9
- context 'when selector not found' do
10
- it 'raises an exception' do
11
- expect { described_class.find(:invalid) }.to raise_exception(PageMagic::UnsupportedCriteriaException)
12
- end
13
- end
14
- end
15
-
16
- describe '#build' do
17
- it 'puts the locator and element type in to the result' do
18
- expect(described_class.new.build(:field, :locator)).to have_attributes(
19
- args: [:locator]
20
- )
21
- end
22
-
23
- context 'when exact matching is required' do
24
- it 'is added to options' do
25
- expect(described_class.new(exact: true).build(:field, :locator)).to have_attributes(
26
- options: { exact: true }
27
- )
28
- end
29
- end
30
-
31
- context 'when supports_type true' do
32
- it 'includes the element type' do
33
- expect(described_class.new(supports_type: true).build(:field, :locator)).to have_attributes(
34
- args: %i[field locator]
35
- )
36
- end
37
- end
38
-
39
- # TODO: - new class?
40
- context 'when selector formatter is provided' do
41
- subject(:selector) do
42
- described_class.new do |param|
43
- "formatted_#{param}".to_sym
44
- end
45
- end
46
-
47
- it 'uses the formatter' do
48
- expect(selector.build(:field, :locator)).to have_attributes(
49
- args: [:formatted_locator]
50
- )
51
- end
52
- end
53
-
54
- context 'when type supplied' do
55
- it 'is added to the result' do
56
- expect(described_class.new(:css).build(:field, :locator)).to have_attributes(
57
- args: %i[css locator]
58
- )
59
- end
60
- end
61
- end
62
-
63
- describe '#initialize' do
64
- context 'when exact' do
65
- it 'sets the option' do
66
- subject = described_class.new(exact: true).build(:element_type, {})
67
- expect(subject.options).to eq({ exact: true })
68
- end
69
- end
70
- end
71
-
72
- describe 'predefined selectors' do
73
- shared_examples 'a selector' do |named: false, **options|
74
- def selector_name
75
- self.class.metadata[:parent_example_group][:description].to_sym
76
- end
77
-
78
- subject do
79
- described_class.find(selector_name).build(:element_type, :locator)
80
- end
81
-
82
- it 'contains the selector args' do
83
- name_arg = named && (named == true ? selector_name : named)
84
-
85
- expected_args = [name_arg, :locator].compact
86
- expect(subject.args).to eq(expected_args)
87
- end
88
-
89
- it 'contains the options' do
90
- expect(subject.options).to eq(options)
91
- end
92
- end
93
-
94
- let(:capybara_element) do
95
- html_source = <<~HTML_SOURCE
96
- <a href='#'>a link</a>
97
-
98
-
99
- <div id='form' class="form">
100
- <a id='form_link' href='/page2'>link in a form</a>
101
- <label>enter text
102
- <input id='field_id' name='field_name' class='input_class' type='text' value='filled in'/>
103
- </label>
104
- <button id='form_button' type='submit' value='a button'/>
105
- </form>
106
- HTML_SOURCE
107
- PageMagic::Element.load(html_source)
108
- end
109
-
110
- describe 'label' do
111
- it_behaves_like 'a selector', named: :field, exact: true
112
-
113
- it 'finds elements by label' do
114
- selector = described_class.find(:label).build(:text_field, 'enter text')
115
- query = PageMagic::Element::Query::SingleResult.new(*selector.args)
116
- expect(query.execute(capybara_element)[:name]).to eq('field_name')
117
- end
118
- end
119
-
120
- describe 'name' do
121
- it 'formats locators' do
122
- name = 'my_button'
123
- expect(described_class::NAME.build(:element_type, name)).to have_attributes(
124
- args: ["*[name='#{name}']"],
125
- options: {}
126
- )
127
- end
128
-
129
- it 'finds elements by name' do
130
- selector = described_class.find(:name).build(:text_field, 'field_name')
131
- query = PageMagic::Element::Query::SingleResult.new(*selector.args)
132
- expect(query.execute(capybara_element)[:name]).to eq('field_name')
133
- end
134
- end
135
-
136
- describe 'xpath' do
137
- it_behaves_like 'a selector', named: true
138
-
139
- it 'finds elements by xpath' do
140
- selector = described_class.find(:xpath).build(:element, '//div/label/input')
141
- query = PageMagic::Element::Query::SingleResult.new(*selector.args)
142
- expect(query.execute(capybara_element)[:name]).to eq('field_name')
143
- end
144
- end
145
-
146
- describe 'id' do
147
- it_behaves_like 'a selector', named: true
148
-
149
- it 'finds elements by id' do
150
- selector = described_class.find(:id).build(:text_field, 'field_id')
151
- query = PageMagic::Element::Query::SingleResult.new(*selector.args)
152
- expect(query.execute(capybara_element)[:name]).to eq('field_name')
153
- end
154
- end
155
-
156
- describe 'text' do
157
- it_behaves_like 'a selector', named: :element_type
158
-
159
- it 'finds elements by text' do
160
- selector = described_class.find(:text).build(:link, 'a link')
161
- query = PageMagic::Element::Query::SingleResult.new(*selector.args)
162
- expect(query.execute(capybara_element).text).to eq('a link')
163
- end
164
- end
165
- end
166
- end