testimonium 1.2.0 → 1.2.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 +4 -4
- data/lib/testimonium/find_functions.rb +51 -20
- data/lib/testimonium/help_functions.rb +19 -2
- data/lib/testimonium/tap_functions.rb +28 -10
- data/lib/testimonium/validate_functions.rb +26 -16
- data/lib/testimonium/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b21b53f330b2f5650b1955c05221bdb92e6796e8375d8c99f9222954ab3e6598
|
4
|
+
data.tar.gz: 29562b6c0cb967808d7e1c45843527764ce476d968d9269cb37317781e19040c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc0ce457603e0207038623812c406b25abbc1ca5d73b4a82fefc14b2f9f71a4e7bc7f140733cd2710dbc00034a6a22b09cecacd26bfe3d5d9ce6b13748c1330
|
7
|
+
data.tar.gz: a13d134380a80097d4c5aec069f837bfac65c4c81a5b289105d1ef7c88b7c3fa4042ccaef2e95abb6c01abc233db4af05223b743b6236e4b14759172cc913ae7
|
@@ -3,7 +3,12 @@
|
|
3
3
|
module Testimonium
|
4
4
|
# Find functions
|
5
5
|
module Find
|
6
|
-
# Find element by xpath
|
6
|
+
# Find element by xpath.
|
7
|
+
#
|
8
|
+
# @param xpath [String] Element Xpath.
|
9
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
10
|
+
# @param retries [Integer] Amount of retries.
|
11
|
+
# @return [element] if element is found.
|
7
12
|
def find_element_by_xpath(path, timeout = 3, retries = 5)
|
8
13
|
element = nil
|
9
14
|
count = 0
|
@@ -17,54 +22,80 @@ module Testimonium
|
|
17
22
|
rescue Selenium::WebDriver::Error::NoSuchElementError
|
18
23
|
end
|
19
24
|
|
20
|
-
|
25
|
+
logger("Found '#{path}' on attempt #{count}") if element
|
21
26
|
return element if element
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
logger("Failed to find '#{path}'. Number of attempts: #{count}")
|
30
|
+
nil
|
26
31
|
end
|
27
32
|
|
28
|
-
# Find element by element id
|
29
|
-
|
30
|
-
|
33
|
+
# Find element by element id.
|
34
|
+
#
|
35
|
+
# @param id [String] Element ID.
|
36
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
37
|
+
# @param retries [Integer] Amount of retries.
|
38
|
+
# @return [element] if element is found.
|
39
|
+
def find_element_by_id(id, timeout = 2, retries = 5)
|
40
|
+
find_element_id(id, timeout, retries)
|
31
41
|
end
|
32
42
|
|
33
|
-
# Find element by text
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
# Find element by text.
|
44
|
+
#
|
45
|
+
# @param text [String] Element Text.
|
46
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
47
|
+
# @param retries [Integer] Amount of retries.
|
48
|
+
# @return [element] if element is found.
|
49
|
+
def find_element_by_text(text, timeout = 2, retries = 5)
|
50
|
+
return find_element_by_xpath("//*[@text='#{text}']", timeout, retries) if device_android
|
51
|
+
return find_text_ios(text, timeout, retries) if device_ios
|
39
52
|
end
|
40
53
|
|
41
|
-
#
|
54
|
+
# Find element by resourceid.
|
55
|
+
#
|
56
|
+
# Android only - Needs app package name set as constant ANDROID_PACKAGE.
|
57
|
+
#
|
58
|
+
# @param id [String] Element ID.
|
59
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
60
|
+
# @param retries [Integer] Amount of retries.
|
61
|
+
# @return [element] if element is found.
|
42
62
|
def find_element_by_resourceid(id, timeout = 2, retries = 5)
|
43
63
|
if defined?(ANDROID_PACKAGE).nil?
|
44
|
-
|
64
|
+
logger('ANDROID_PACKAGE is missing.', 'fatal')
|
45
65
|
raise Selenium::WebDriver::Error::NoSuchElementError
|
46
66
|
end
|
47
67
|
|
48
68
|
find_element_by_xpath("//*[@resource-id='#{ANDROID_PACKAGE}:id/#{id}']", timeout, retries)
|
49
69
|
end
|
50
70
|
|
51
|
-
#
|
52
|
-
|
71
|
+
# Find all elements with id.
|
72
|
+
#
|
73
|
+
# Android needs app package name set as constant ANDROID_PACKAGE.
|
74
|
+
#
|
75
|
+
# @param id [String] Element ID.
|
76
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
77
|
+
# @param retries [Integer] Amount of retries.
|
78
|
+
# @return [list] if elements are found.
|
79
|
+
def find_all_elements_by_id(id, timeout = 2, retries = 5)
|
53
80
|
list = nil
|
81
|
+
count = 0
|
54
82
|
|
55
83
|
retries.times do
|
56
84
|
sleep timeout
|
85
|
+
count += 1
|
57
86
|
|
58
87
|
begin
|
59
|
-
list = ids(
|
60
|
-
list = find_elements(:id,
|
88
|
+
list = ids(id) if device_android
|
89
|
+
list = find_elements(:id, id) if device_ios
|
61
90
|
rescue Selenium::WebDriver::Error::NoSuchElementError
|
62
91
|
end
|
63
92
|
|
93
|
+
logger("Found all elements with id '#{id}' on attempt #{count}") if list
|
64
94
|
return list if list
|
65
95
|
end
|
66
96
|
|
67
|
-
|
97
|
+
logger("Failed to find elements with id '#{id}'. Number of attempts: #{count}")
|
98
|
+
nil
|
68
99
|
end
|
69
100
|
end
|
70
101
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
3
5
|
def find_function(function_type, parameter, timeout_time = 2, retries = 5)
|
4
6
|
element = nil
|
5
7
|
count = 0
|
@@ -14,11 +16,11 @@ def find_function(function_type, parameter, timeout_time = 2, retries = 5)
|
|
14
16
|
rescue Selenium::WebDriver::Error::NoSuchElementError
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
logger("Found: '#{parameter}' on attempt #{count}") if element
|
18
20
|
return element if element
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
logger("Failed to find: '#{function_type} = #{parameter}'. Number of attempts: #{count}")
|
22
24
|
false
|
23
25
|
end
|
24
26
|
|
@@ -37,3 +39,18 @@ end
|
|
37
39
|
def device_ios
|
38
40
|
ENV['PLATFORM'] == 'ios'
|
39
41
|
end
|
42
|
+
|
43
|
+
# @param msg [String] the log message
|
44
|
+
# @param severity [String] the severity of the message, 'debug' by default
|
45
|
+
def logger(msg, severity = 'debug')
|
46
|
+
logger = Logger.new($stdout)
|
47
|
+
logger.formatter = proc { |severity, datetime, _progname, msg| "#{severity}, #{datetime}, #{msg}\n" }
|
48
|
+
|
49
|
+
if severity.eql?('debug')
|
50
|
+
logger.debug(msg)
|
51
|
+
elsif severity.eql?('fatal')
|
52
|
+
logger.fatal(msg)
|
53
|
+
else
|
54
|
+
logger.info(msg)
|
55
|
+
end
|
56
|
+
end
|
@@ -3,26 +3,44 @@
|
|
3
3
|
module Testimonium
|
4
4
|
# Tap functions
|
5
5
|
module Tap
|
6
|
-
# Tap element by
|
7
|
-
|
8
|
-
|
6
|
+
# Tap element by id.
|
7
|
+
#
|
8
|
+
# @param id [String] Element ID.
|
9
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
10
|
+
# @param retries [Integer] Amount of retries.
|
11
|
+
def tap_element_by_id(id, timeout = 2, retries = 5)
|
12
|
+
find_element_by_id(id, timeout, retries).click
|
9
13
|
end
|
10
14
|
|
11
|
-
# Tap element by text
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
# Tap element by text.
|
16
|
+
#
|
17
|
+
# @param text [String] Element Text.
|
18
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
19
|
+
# @param retries [Integer] Amount of retries.
|
20
|
+
def tap_element_by_text(text, timeout = 2, retries = 5)
|
21
|
+
find_element_by_text(text, timeout, retries).click if device_android
|
22
|
+
find_text_ios(text, timeout, retries).click if device_ios
|
15
23
|
end
|
16
24
|
|
17
|
-
# Tap element by xpath
|
25
|
+
# Tap element by xpath.
|
26
|
+
#
|
27
|
+
# @param xpath [String] Element Xpath.
|
28
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
29
|
+
# @param retries [Integer] Amount of retries.
|
18
30
|
def tap_element_by_xpath(path, timeout = 2, retries = 5)
|
19
31
|
find_element_by_xpath(path, timeout, retries).click
|
20
32
|
end
|
21
33
|
|
22
|
-
#
|
34
|
+
# Tap element by resourceid.
|
35
|
+
#
|
36
|
+
# Android only: Needs app package name set as constant ANDROID_PACKAGE.
|
37
|
+
#
|
38
|
+
# @param id [String] Element ID.
|
39
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
40
|
+
# @param retries [Integer] Amount of retries.
|
23
41
|
def tap_element_by_resourceid(id, timeout = 2, retries = 5)
|
24
42
|
if defined?(ANDROID_PACKAGE).nil?
|
25
|
-
|
43
|
+
logger('ANDROID_PACKAGE is missing.', 'fatal')
|
26
44
|
raise Selenium::WebDriver::Error::NoSuchElementError
|
27
45
|
end
|
28
46
|
|
@@ -3,32 +3,42 @@
|
|
3
3
|
module Testimonium
|
4
4
|
# Validate functions
|
5
5
|
module Validate
|
6
|
-
# Validate element by element id
|
6
|
+
# Validate element by element id.
|
7
|
+
#
|
8
|
+
# @param id [String] Element ID.
|
9
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
10
|
+
# @param retries [Integer] Amount of retries.
|
7
11
|
def validate_element_by_id(id, timeout = 2, retries = 5)
|
8
|
-
unless find_element_by_id(id, timeout, retries)
|
9
|
-
raise Selenium::WebDriver::Error::NoSuchElementError
|
10
|
-
end
|
12
|
+
raise Selenium::WebDriver::Error::NoSuchElementError unless find_element_by_id(id, timeout, retries)
|
11
13
|
end
|
12
14
|
|
13
|
-
# Validate element by text
|
15
|
+
# Validate element by text.
|
16
|
+
#
|
17
|
+
# @param text [String] Element Text.
|
18
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
19
|
+
# @param retries [Integer] Amount of retries.
|
14
20
|
def validate_element_by_text(text, timeout = 5, retries = 5)
|
15
|
-
unless find_element_by_text(text, timeout, retries)
|
16
|
-
raise Selenium::WebDriver::Error::NoSuchElementError
|
17
|
-
end
|
21
|
+
raise Selenium::WebDriver::Error::NoSuchElementError unless find_element_by_text(text, timeout, retries)
|
18
22
|
end
|
19
23
|
|
20
|
-
# Validate element by xpath
|
24
|
+
# Validate element by xpath.
|
25
|
+
#
|
26
|
+
# @param xpath [String] Element Xpath.
|
27
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
28
|
+
# @param retries [Integer] Amount of retries.
|
21
29
|
def validate_element_by_xpath(path, timeout = 2, retries = 5)
|
22
|
-
unless find_element_by_xpath(path, timeout, retries)
|
23
|
-
raise Selenium::WebDriver::Error::NoSuchElementError
|
24
|
-
end
|
30
|
+
raise Selenium::WebDriver::Error::NoSuchElementError unless find_element_by_xpath(path, timeout, retries)
|
25
31
|
end
|
26
32
|
|
27
|
-
#
|
33
|
+
# Validate element by resourceid.
|
34
|
+
#
|
35
|
+
# Android only: Needs app package name set as constant ANDROID_PACKAGE.
|
36
|
+
#
|
37
|
+
# @param id [String] Element ID.
|
38
|
+
# @param timeout [Integer] Timeout seconds between retries.
|
39
|
+
# @param retries [Integer] Amount of retries.
|
28
40
|
def validate_element_by_resourceid(id, timeout = 2, retries = 5)
|
29
|
-
unless find_element_by_resourceid(id, timeout, retries)
|
30
|
-
raise Selenium::WebDriver::Error::NoSuchElementError
|
31
|
-
end
|
41
|
+
raise Selenium::WebDriver::Error::NoSuchElementError unless find_element_by_resourceid(id, timeout, retries)
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
data/lib/testimonium/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testimonium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M2mobi
|
@@ -83,5 +83,5 @@ requirements: []
|
|
83
83
|
rubygems_version: 3.0.3
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
|
-
summary: testimonium-1.2.
|
86
|
+
summary: testimonium-1.2.1
|
87
87
|
test_files: []
|