eyes_selenium 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25174d9df260b6f0bfdfa1f5789a9d2842b42404
4
- data.tar.gz: 0556cc0f386dc6806fe60b7441262953eaff6fe6
3
+ metadata.gz: 895307ec918bff0502fa49b951d2cbee119042fd
4
+ data.tar.gz: 6c7cc9590dd8e500c932666c4503e1b8cc4412d6
5
5
  SHA512:
6
- metadata.gz: 3f36baf91d2e267d7aeb40fa90fab826a49fd751fea219a32f88a2f901a53e7c1f56dc071d1e51aca79ac1df85a06be7a7b46d96dd927cc7db4e1f6a3771f5a6
7
- data.tar.gz: 710c72a2ea4459115a78e24e838fd7279bf4d8fdb53f734f4e24fb1a8dcfd9f90f240a67f9fdd8f905d17bffc121b827d48ff7306b88d7c47dda4ab344192e78
6
+ metadata.gz: 5153a65ae4f19faa5c26489b82aa6e37cde45c3d3015f83951bfaa646dc92e777509a555b090c6d04085dbb16372096dcef980067b5743f0d77027c366395869
7
+ data.tar.gz: 167494187f8870bbc825a20cd1efb386c37fe0392d09941c6be645ead06a677c83d6148ef5469aefb5fe21edd98d9135d927195b107cdd7dc5bc046cf05205d2
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .*.swp
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -13,7 +14,6 @@ pkg
13
14
  rdoc
14
15
  .idea/
15
16
  .idea-*/
16
- spec/
17
17
  spec/reports
18
18
  test/tmp
19
19
  test/version_tmp
@@ -55,12 +55,38 @@ class Applitools::Driver
55
55
  Applitools::EyesKeyboard.new(self, driver.keyboard)
56
56
  end
57
57
 
58
- def find_element(by, selector)
59
- Applitools::Element.new(self, driver.find_element(by, selector))
58
+ FINDERS = {
59
+ :class => 'class name',
60
+ :class_name => 'class name',
61
+ :css => 'css selector',
62
+ :id => 'id',
63
+ :link => 'link text',
64
+ :link_text => 'link text',
65
+ :name => 'name',
66
+ :partial_link_text => 'partial link text',
67
+ :tag_name => 'tag name',
68
+ :xpath => 'xpath',
69
+ }
70
+
71
+ def find_element(*args)
72
+ how, what = extract_args(args)
73
+
74
+ # Make sure that "how" is a valid locator.
75
+ unless FINDERS[how.to_sym]
76
+ raise ArgumentError, "cannot find element by #{how.inspect}"
77
+ end
78
+
79
+ Applitools::Element.new(self, driver.find_element(how, what))
60
80
  end
61
81
 
62
- def find_elements(by, selector)
63
- driver.find_elements(by, selector).map { |el| Applitools::Element.new(self, el) }
82
+ def find_elements(*args)
83
+ how, what = extract_args(args)
84
+
85
+ unless FINDERS[how.to_sym]
86
+ raise ArgumentError, "cannot find element by #{how.inspect}"
87
+ end
88
+
89
+ driver.find_elements(how, what).map { |el| Applitools::Element.new(self, el) }
64
90
  end
65
91
 
66
92
  def ie?
@@ -99,7 +125,7 @@ class Applitools::Driver
99
125
 
100
126
  def get_local_ip
101
127
  begin
102
- Socket.ip_address_list.detect do |intf|
128
+ Socket.ip_address_list.detect do |intf|
103
129
  intf.ipv4? and !intf.ipv4_loopback? and !intf.ipv4_multicast?
104
130
  end.ip_address
105
131
  rescue SocketError => e
@@ -107,6 +133,29 @@ class Applitools::Driver
107
133
  end
108
134
  end
109
135
 
136
+ def extract_args(args)
137
+ case args.size
138
+ when 2
139
+ args
140
+ when 1
141
+ arg = args.first
142
+
143
+ unless arg.respond_to?(:shift)
144
+ raise ArgumentError, "expected #{arg.inspect}:#{arg.class} to respond to #shift"
145
+ end
146
+
147
+ # this will be a single-entry hash, so use #shift over #first or #[]
148
+ arr = arg.dup.shift
149
+ unless arr.size == 2
150
+ raise ArgumentError, "expected #{arr.inspect} to have 2 elements"
151
+ end
152
+
153
+ arr
154
+ else
155
+ raise ArgumentError, "wrong number of arguments (#{args.size} for 2)"
156
+ end
157
+ end
158
+
110
159
  end
111
160
 
112
161
  ## .bridge, .session_id and .server_url are private methods in Selenium::WebDriver gem
@@ -1,3 +1,3 @@
1
1
  module Applitools
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
data/spec/find_spec.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'eyes_selenium'
2
+
3
+ describe 'find_element(s)' do
4
+
5
+ before(:each) do |example|
6
+ @eyes = Applitools::Eyes.new
7
+ @eyes.api_key = ENV['APPLITOOLS_ACCESS_KEY']
8
+ driver = Selenium::WebDriver.for :firefox
9
+ @driver = @eyes.open(app_name: 'the-internet', test_name: example.metadata[:full_description],
10
+ viewport_size: {width: 800, height: 600}, driver: driver)
11
+ @driver.get 'http://the-internet.herokuapp.com'
12
+ end
13
+
14
+ after(:each) do
15
+ @eyes.close
16
+ @driver.quit
17
+ end
18
+
19
+ context 'single element' do
20
+
21
+ it 'explicit' do
22
+ link = @driver.find_element(:css, 'a')
23
+ expect(link).to_not be nil
24
+ expect(link).to be_a Applitools::Element
25
+ end
26
+
27
+ it 'by hash' do
28
+ link = @driver.find_element(css: 'a')
29
+ expect(link).to_not be nil
30
+ expect(link).to be_a Applitools::Element
31
+ end
32
+
33
+ end
34
+
35
+ context 'all elements' do
36
+
37
+ it 'explicit' do
38
+ collection = @driver.find_elements(css: 'a')
39
+ expect(collection).to_not be nil
40
+ expect(collection[0]).to be_a Applitools::Element
41
+ expect(collection[1]).to be_a Applitools::Element
42
+ end
43
+
44
+ it 'by hash' do
45
+ collection = @driver.find_elements(css: 'a')
46
+ expect(collection).to_not be nil
47
+ expect(collection[0]).to be_a Applitools::Element
48
+ expect(collection[1]).to be_a Applitools::Element
49
+ end
50
+
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyes_selenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Applitools team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -165,6 +165,7 @@ files:
165
165
  - lib/eyes_selenium/utils.rb
166
166
  - lib/eyes_selenium/utils/image_delta_compressor.rb
167
167
  - lib/eyes_selenium/version.rb
168
+ - spec/find_spec.rb
168
169
  - test_script.rb
169
170
  homepage: http://www.applitools.com
170
171
  licenses:
@@ -190,4 +191,5 @@ rubygems_version: 2.4.1
190
191
  signing_key:
191
192
  specification_version: 4
192
193
  summary: Applitools Ruby SDK
193
- test_files: []
194
+ test_files:
195
+ - spec/find_spec.rb