rudra 1.1.0 → 1.1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudra.rb +90 -6
  3. metadata +22 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b59cfa6497e4560d80369dc076df45638ec043abe069b5f6665e5749aefdef87
4
- data.tar.gz: 51e97a957330ffce97411d9f3ad40e01a4be439cc677306d5507ae0136577beb
3
+ metadata.gz: ff3f69221a8e01fb0c0bf5a517c11547872f475b4cdc7aa551a26f81929c8373
4
+ data.tar.gz: e039db5f85576af890d9b58f8deed4f7f30cf09ea474d8b2226c6574cad9c115
5
5
  SHA512:
6
- metadata.gz: f7984dccb05ea056c716dd533c5d4662e83ea8711c62a2fc3f02f95d0d7a795914d16c2ceacd2ef2cf1eff26374ae9c8ed795a14797186f696356f3c02c687bf
7
- data.tar.gz: 4bfb07ee8abe3ce212c85ca19ab052fb134b47c42e225e7160ea6463795e425e22a594998d2e89365709a3d2b1495a2c5cbbb0894b64bd1bfc073a190519ef8f
6
+ metadata.gz: a632f5ee68fa9417a78e86642246c47d2b4480292ca4816471b8f948458d7c6444150ccb7eb1a65fe8d7167f25dca32e1271f97cd725dbc86643362d763d4361
7
+ data.tar.gz: 9edc12b61b22302ef0d80698a682d859a124acaa7c3d121d87353f83c84fef948f9fa93971ce85074c4b7faf52b27bf9ebef4bdedcb14429a8ef7222b73854f3
@@ -177,7 +177,7 @@ class Rudra
177
177
 
178
178
  element ||= driver.find_element(how, what)
179
179
 
180
- abort("Failed to find element: #{locator}") unless element
180
+ raise Selenium::WebDriver::Error::NoSuchElementError, "Failed to find element: #{locator}" unless element
181
181
 
182
182
  wait_for { element.displayed? }
183
183
 
@@ -189,8 +189,11 @@ class Rudra
189
189
  # @return [Array<Selenium::WebDriver::Element>] the elements found
190
190
  def find_elements(locator)
191
191
  how, what = parse_locator(locator)
192
- driver.find_elements(how, what) ||
193
- abort("Failed to find elements: #{locator}")
192
+ elements = driver.find_elements(how, what)
193
+
194
+ raise Selenium::WebDriver::Error::NoSuchElementError, "Failed to find elements: #{locator}" if elements.empty?
195
+
196
+ elements
194
197
  end
195
198
 
196
199
  # Move forward a single entry in the browser's history
@@ -310,6 +313,7 @@ class Rudra
310
313
  end
311
314
 
312
315
  # Switch to the frame with the given id
316
+ # @param [String] id the frame id
313
317
  def switch_to_frame(id)
314
318
  driver.switch_to.frame(id)
315
319
  end
@@ -345,6 +349,48 @@ class Rudra
345
349
  wait_for { find_element(locator).enabled? }
346
350
  end
347
351
 
352
+ # Wait until the element, identified by locator, is found in frame
353
+ # @param [String] frame_id the frame id
354
+ # @param [String] locator the locator to identify the element
355
+ def wait_for_element_found_in_frame(frame_id, locator)
356
+ switch_to_frame frame_id
357
+
358
+ how, what = parse_locator(locator)
359
+
360
+ wait_for do
361
+ begin
362
+ driver.find_element(how, what)
363
+ rescue Selenium::WebDriver::Error::NoSuchWindowError
364
+ false
365
+ end
366
+ end
367
+ end
368
+
369
+ # Wait (in seconds) until the element is not displayed
370
+ # @param [String, Selenium::WebDriver::Element] locator the locator to
371
+ # identify the element or Selenium::WebDriver::Element
372
+ # @param [Integer] seconds seconds before timed out
373
+ def wait_for_not_visible(locator, seconds = 2)
374
+ how, what = parse_locator(locator)
375
+
376
+ begin
377
+ wait_for(seconds) do
378
+ begin
379
+ elements = driver.find_elements(how, what)
380
+ elements.empty? || elements.map(&:displayed?).none?
381
+ rescue Selenium::WebDriver::Error::NoSuchElementError
382
+ true
383
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError
384
+ false
385
+ end
386
+ end
387
+ rescue Selenium::WebDriver::Error::TimeoutError
388
+ true
389
+ rescue Net::ReadTimeout
390
+ true
391
+ end
392
+ end
393
+
348
394
  # Wait until the title of the page including the given string
349
395
  # @param [String] string the string to compare
350
396
  def wait_for_title(string)
@@ -393,7 +439,7 @@ class Rudra
393
439
  # @param [String] attribute the name of the attribute
394
440
  # @return [String, nil] attribute value
395
441
  def attribute(locator, attribute)
396
- find_element(locator).property(attribute)
442
+ find_element(locator).attribute(attribute)
397
443
  end
398
444
 
399
445
  # If the element, identified by locator, has the given attribute
@@ -428,7 +474,13 @@ class Rudra
428
474
  # @param [String, Selenium::WebDriver::Element] locator the locator to
429
475
  # identify the element or Selenium::WebDriver::Element
430
476
  def click(locator)
431
- find_element(locator).click
477
+ wait_for do
478
+ begin
479
+ find_element(locator).click.nil?
480
+ rescue Selenium::WebDriver::Error::ElementClickInterceptedError
481
+ false
482
+ end
483
+ end
432
484
  end
433
485
 
434
486
  # Click the given element, identified by locator, with an offset
@@ -741,6 +793,38 @@ class Rudra
741
793
  ), find_element(locator), event)
742
794
  end
743
795
 
796
+ # Wait until the element, identified by locator, attribute has value
797
+ # @param [String, Selenium::WebDriver::Element] locator the locator to identify the element
798
+ # @param [String] attribute the name of the attribute
799
+ # @param [String] value the value of the attribute
800
+ def wait_for_attribute_to_include(locator, attribute, value)
801
+ how, what = parse_locator(locator)
802
+
803
+ wait_for do
804
+ begin
805
+ driver.find_element(how, what)&.attribute(attribute)&.downcase&.include?(value.downcase)
806
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError
807
+ false
808
+ end
809
+ end
810
+ end
811
+
812
+ # Wait until the element, identified by locator, excluding string in text
813
+ # @param [String, Selenium::WebDriver::Element] locator the locator to
814
+ # identify the element or Selenium::WebDriver::Element
815
+ # @param [String] string the string to exclude
816
+ def wait_for_text_to_exclude(locator, string)
817
+ wait_for { text(locator).exclude?(string) }
818
+ end
819
+
820
+ # Wait until the element, identified by locator, including string in text
821
+ # @param [String, Selenium::WebDriver::Element] locator the locator to
822
+ # identify the element or Selenium::WebDriver::Element
823
+ # @param [String] string the string to compare
824
+ def wait_for_text_to_include(locator, string)
825
+ wait_for { text(locator).include?(string) }
826
+ end
827
+
744
828
  #
745
829
  # Tool Functions
746
830
  #
@@ -1206,7 +1290,7 @@ class Rudra
1206
1290
  how.to_sym
1207
1291
  end
1208
1292
 
1209
- abort("Cannot parse locator: #{locator}") unless HOWS.include?(how)
1293
+ raise Selenium::WebDriver::Error::InvalidSelectorError, "Cannot parse locator: #{locator}" unless HOWS.include?(how)
1210
1294
 
1211
1295
  [how, what]
1212
1296
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.25
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.9.0
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '3.9'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.9.0
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.9'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: selenium-webdriver
29
49
  requirement: !ruby/object:Gem::Requirement