SurfCustomCalabash 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +11 -0
- data/README.md +68 -4
- data/SurfCustomCalabash.gemspec +4 -4
- data/bin/SurfCustomCalabash +54 -0
- data/bin/surf-calabash-console.rb +62 -0
- data/bin/surf-calabash-gen.rb +17 -0
- data/bin/surf-calabash-helpers.rb +34 -0
- data/lib/SurfCustomCalabash/CommonMethods.rb +292 -207
- data/lib/SurfCustomCalabash/DroidMethods.rb +103 -73
- data/lib/SurfCustomCalabash/IosMethods.rb +113 -68
- data/lib/SurfCustomCalabash/version.rb +1 -1
- data/sources/Backdoors list b/data/sources/Backdoors → list +0 -0
- data/sources/Gemfile +27 -0
- data/sources/Scripts/and.sh +5 -0
- data/sources/Scripts/ca.sh +5 -0
- data/sources/Scripts/ci.sh +5 -0
- data/sources/Scripts/data +7 -0
- data/sources/Scripts/fa.sh +6 -0
- data/sources/Scripts/fi.sh +5 -0
- data/sources/Scripts/get_apk.rb +68 -0
- data/sources/Scripts/get_scenarios.rb +193 -0
- data/sources/Scripts/import_scenarios.rb +172 -0
- data/sources/Scripts/ios.sh +5 -0
- data/sources/Scripts/parallel_android_smoke.sh +4 -0
- data/sources/Scripts/parallel_android_test.sh +4 -0
- data/sources/Scripts/ra.sh +12 -0
- data/sources/Scripts/ri.sh +9 -0
- data/sources/Scripts/smoke_and.sh +5 -0
- data/sources/Scripts/smoke_ios.sh +5 -0
- data/sources/Scripts/ta.sh +5 -0
- data/sources/Scripts/ti.sh +5 -0
- data/sources/Scripts/to_exec.sh +19 -0
- data/sources/Scripts/update.sh +24 -0
- data/sources/Scripts/update_exec.rb +96 -0
- data/sources/TestFolder/small.gif +0 -0
- data/sources/ci/JenkinsfileUiTestAndroid.groovy +22 -0
- data/sources/ci/JenkinsfileUiTestIos.groovy +23 -0
- data/sources/config/cucumber.yml +24 -0
- data/sources/features/android/pages/standard/DroidCommon.rb +33 -0
- data/sources/features/android/pages/standard/Init_android.rb +8 -0
- data/sources/features/android/pages/test.rb +43 -0
- data/sources/features/android/support/app_life_cycle_hooks.rb +147 -0
- data/sources/features/android/support/log_hooks_and.rb +40 -0
- data/sources/features/android/support/video_hooks_and.rb +110 -0
- data/sources/features/ios/pages/standard/Init_ios.rb +5 -0
- data/sources/features/ios/pages/standard/IosCommon.rb +30 -0
- data/sources/features/ios/pages/test.rb +37 -0
- data/sources/features/ios/support/01_launch.rb +194 -0
- data/sources/features/ios/support/log_hooks_ios.rb +40 -0
- data/sources/features/ios/support/video_hooks_ios.rb +58 -0
- data/sources/features/net/net.rb +28 -0
- data/sources/features/net/screentest_api.rb +186 -0
- data/sources/features/scenarios/eng.feature +8 -0
- data/sources/features/scenarios/rus.feature +8 -0
- data/sources/features/step_definitions/test.rb +43 -0
- data/sources/features/support/credentials.rb +11 -0
- data/sources/features/support/env.rb +8 -0
- data/sources/features/support/hooks.rb +21 -0
- data/sources/features/support/localization.rb +8 -0
- data/sources/find_id.rb +95 -0
- data/sources/group_steps.rb +39 -0
- data/sources/irbrcs/android/irbrc +105 -0
- data/sources/irbrcs/ios/irbrc +132 -0
- data/sources/start.sh +134 -0
- metadata +69 -11
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10324a3851f0d2c8a774575861c3489d6519d9a6fed70ac48244565ed9c03da6
|
4
|
+
data.tar.gz: 70572d7c07b601e2407cc9cf8e0d3317a680b919afb56faca9be2d3cb9f68f04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4092df2ff8c18a451ad3e0132accbb3eae2c66ee24526e43d7c0adfa51f17e47234f8573999d248df0de0eb24a91f264fed8cd1310a8784309e44eb5776bdc57
|
7
|
+
data.tar.gz: 89d7c2269fd6aa04b72eb58ace406dad941a2dcaf2ae84559729802ff1ea65e65e39db5d1902577e70df131b35f5e4e13f8abdebfe3b2054e798caa336eac22d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
|
5
|
+
## v1.0.0 - 28.08.2020
|
6
|
+
### Added
|
7
|
+
- Changelog.md
|
8
|
+
- Added template file for initializing a new autotest project (use **SurfCustomCalabash gen**)
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- method close_keybord can now be called with optional parameters **x_start** and **y_start** (by default **x_start:** 100, **y_start:** 150)
|
data/README.md
CHANGED
@@ -21,11 +21,75 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
This gem provides methods for easier use Calabash.
|
23
23
|
|
24
|
-
Install gem in your project, add
|
24
|
+
Install gem in your exist project, add in your ios or android ruby files.
|
25
25
|
|
26
|
-
IosCommon
|
26
|
+
$require 'SurfCustomCalabash/IosCommon'
|
27
|
+
|
28
|
+
$require 'SurfCustomCalabash/DroidCommon'
|
29
|
+
|
30
|
+
**IosCommon** contains custom swipe methods for ios.
|
31
|
+
|
32
|
+
**DroidCommon** contains custom swipe methods for android.
|
33
|
+
|
34
|
+
**CommonMethods** contains different methods (taps, swipes, waits and other) for both platforms.
|
35
|
+
|
36
|
+
### Create new project
|
37
|
+
You should move to the directory which would contains folder with your tests.
|
38
|
+
surf-calabash will create it by itself with the name **Change_it_to_your_own_project_name**:
|
39
|
+
|
40
|
+
$ SurfCustomCalabash gen
|
41
|
+
|
42
|
+
After that you'll see many folders inside them. Each of them will be describe below.
|
43
|
+
|
44
|
+
#### ci
|
45
|
+
|
46
|
+
It is used for all scripts for continuous integration. In Surfstudio we have .groovy files for them.
|
27
47
|
|
28
|
-
|
48
|
+
|
49
|
+
#### config
|
50
|
+
|
51
|
+
Contains only cucumber.yml file. It named arguments are called profiles - e.g. iOS or Android for run.
|
52
|
+
|
53
|
+
|
54
|
+
#### features
|
55
|
+
|
56
|
+
Main folder of all project. Every feature, step definition, support files and page objects are here. You can read about it more in each file of this folder.
|
57
|
+
|
58
|
+
|
59
|
+
#### irbrcs
|
60
|
+
|
61
|
+
Our own shtick. We change calabash-android console and calabash-ios console a little, so you can write your own complex functions, which you'll implement in the step_definitions or in page objects. So for the correct work we had to change irbrc-files of gems too.
|
62
|
+
|
63
|
+
#### reports
|
64
|
+
|
65
|
+
Folder with screenshots of errors.
|
66
|
+
|
67
|
+
|
68
|
+
#### test_servers
|
69
|
+
|
70
|
+
Standard calabash-android folder with signed apk-files.
|
71
|
+
|
72
|
+
#### TestFolder
|
73
|
+
|
74
|
+
Contains some additional files, e.g. jpg-pictures or other data which can be used in tests.
|
75
|
+
|
76
|
+
#### Backdoors list
|
77
|
+
|
78
|
+
We use backdoors for our applications for get around the limit of nativity of calabash.
|
79
|
+
|
80
|
+
#### Gemfile
|
81
|
+
|
82
|
+
All required gems for surf-calabash. You should run installing all gems by bundle after initializing project when you rename **Change_it_to_your_own_project_name** to your own name.
|
83
|
+
|
84
|
+
$bundle install
|
85
|
+
|
86
|
+
#### Scripts
|
87
|
+
|
88
|
+
Some shell scripts which can help to start tests faster because of typing smaller count of symbols. :)
|
89
|
+
Also it shows some integration with Xray Jira plugin.
|
90
|
+
|
91
|
+
#### start.sh
|
29
92
|
|
30
|
-
|
93
|
+
Shell script for useful launch all helpful scripts of folder above.
|
31
94
|
|
95
|
+
|
data/SurfCustomCalabash.gemspec
CHANGED
@@ -6,7 +6,7 @@ require "SurfCustomCalabash/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "SurfCustomCalabash"
|
8
8
|
spec.version = SurfCustomCalabash::VERSION
|
9
|
-
spec.authors = ["Alexey Hripunov"]
|
9
|
+
spec.authors = ["Alexey Hripunov", "Igor Tolubaev"]
|
10
10
|
spec.email = ["hripunov@surfstudio.ru"]
|
11
11
|
|
12
12
|
spec.summary = "Custom methods for calabash ios and android"
|
@@ -32,9 +32,9 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
33
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
34
|
end
|
35
|
-
spec.bindir = "exe"
|
36
|
-
spec.executables =
|
37
|
-
spec.require_paths = ["lib"]
|
35
|
+
# spec.bindir = "exe"
|
36
|
+
spec.executables = ["SurfCustomCalabash"]
|
37
|
+
# spec.require_paths = ["lib"]
|
38
38
|
|
39
39
|
spec.add_development_dependency "bundler", "~> 1.17"
|
40
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
# for ruby 1.9.1 and earlier
|
7
|
+
unless defined? RbConfig.ruby
|
8
|
+
def RbConfig.ruby
|
9
|
+
File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require File.join(File.dirname(__FILE__), "surf-calabash-helpers")
|
14
|
+
|
15
|
+
@hierarchy = File.join(FileUtils.pwd, "Change_it_to_your_own_project_name")
|
16
|
+
@source_dir = File.join(File.dirname(__FILE__), '..', 'sources')
|
17
|
+
|
18
|
+
if ARGV.length == 0
|
19
|
+
print_usage
|
20
|
+
else
|
21
|
+
cmd = ARGV.shift
|
22
|
+
|
23
|
+
case cmd
|
24
|
+
when 'help'
|
25
|
+
print_help
|
26
|
+
when 'gen'
|
27
|
+
gen = File.join(File.dirname(__FILE__), "surf-calabash-gen")
|
28
|
+
require gen
|
29
|
+
surf_gen
|
30
|
+
when 'android_console'
|
31
|
+
require 'calabash-android/helpers'
|
32
|
+
require 'calabash-android/utils'
|
33
|
+
require 'calabash-android/java_keystore'
|
34
|
+
require 'calabash-android/env'
|
35
|
+
require File.join(File.dirname(__FILE__), "surf-calabash-console")
|
36
|
+
|
37
|
+
if ARGV.empty? or not is_apk_file?(ARGV.first)
|
38
|
+
Kernel.puts "The first parameter must be the path to the apk file."
|
39
|
+
exit 1
|
40
|
+
else
|
41
|
+
android_console(relative_to_full_path(ARGV.shift))
|
42
|
+
end
|
43
|
+
|
44
|
+
when 'ios_console'
|
45
|
+
require File.join(File.dirname(__FILE__), "surf-calabash-console")
|
46
|
+
ios_console
|
47
|
+
when 'version'
|
48
|
+
require_relative '../lib/SurfCustomCalabash/version'
|
49
|
+
Kernel.puts SurfCustomCalabash::VERSION
|
50
|
+
else
|
51
|
+
Kernel.puts "Invalid command '#{cmd}'"
|
52
|
+
print_usage
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
def android_console(app_path = nil)
|
7
|
+
test_server_path = test_server_path(app_path)
|
8
|
+
|
9
|
+
path = ENV['CALABASH_IRBRC']
|
10
|
+
Kernel.puts(path)
|
11
|
+
|
12
|
+
unless path
|
13
|
+
if File.exist?('irbrc')
|
14
|
+
path = File.expand_path('irbrc')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
unless path
|
19
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), '../sources/irbrcs/android', 'irbrc'))
|
20
|
+
end
|
21
|
+
|
22
|
+
ENV['IRBRC'] = path
|
23
|
+
Kernel.puts(path)
|
24
|
+
|
25
|
+
unless ENV['APP_PATH']
|
26
|
+
ENV['APP_PATH'] = app_path
|
27
|
+
end
|
28
|
+
|
29
|
+
unless ENV['TEST_APP_PATH']
|
30
|
+
ENV['TEST_APP_PATH'] = test_server_path
|
31
|
+
end
|
32
|
+
|
33
|
+
build_test_server_if_needed(app_path)
|
34
|
+
|
35
|
+
Kernel.puts 'Starting calabash-android console...'
|
36
|
+
Kernel.puts "Loading #{ENV['IRBRC']}"
|
37
|
+
Kernel.puts 'Running irb...'
|
38
|
+
exec('irb')
|
39
|
+
end
|
40
|
+
|
41
|
+
def is_apk_file?(file_path)
|
42
|
+
file_path.end_with? ".apk" and File.exist? file_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def relative_to_full_path(file_path)
|
46
|
+
File.expand_path(file_path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def ios_console
|
50
|
+
path = ENV['CALABASH_IRBRC']
|
51
|
+
unless path
|
52
|
+
if File.exist?('.irbrc')
|
53
|
+
path = File.expand_path('.irbrc')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
unless path
|
57
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), '../sources/irbrcs/ios', 'irbrc'))
|
58
|
+
end
|
59
|
+
ENV['IRBRC'] = path
|
60
|
+
puts "Running irb..."
|
61
|
+
exec("irb")
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
def surf_gen
|
2
|
+
if File.exists?(@hierarchy)
|
3
|
+
Kernel.puts "hierarchy is already created. Stopping..."
|
4
|
+
exit 1
|
5
|
+
end
|
6
|
+
msg("Question") do
|
7
|
+
Kernel.puts "I'm about to create a subdirectory called sources."
|
8
|
+
Kernel.puts "Please change name of it to name of your own project."
|
9
|
+
Kernel.puts "Please hit return to confirm that's what you want."
|
10
|
+
end
|
11
|
+
exit 2 unless STDIN.gets.chomp == ''
|
12
|
+
|
13
|
+
FileUtils.cp_r(@source_dir, @hierarchy)
|
14
|
+
msg("Info") do
|
15
|
+
Kernel.puts "hierarchy was created. \n"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'json'
|
3
|
+
require "rubygems"
|
4
|
+
|
5
|
+
def msg(title, &block)
|
6
|
+
Kernel.puts "\n" + "-"*10 + title + "-"*10
|
7
|
+
block.call
|
8
|
+
Kernel.puts "-"*10 + "-------" + "-"*10 + "\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
def print_usage
|
12
|
+
Kernel.puts <<EOF
|
13
|
+
Usage: SurfCustomCalabash <command-name> [parameters] [options]
|
14
|
+
<command-name> can be one of
|
15
|
+
help
|
16
|
+
prints more detailed help information.
|
17
|
+
gen
|
18
|
+
generate a features folder structure.
|
19
|
+
version
|
20
|
+
prints the gem version
|
21
|
+
|
22
|
+
<options> can be
|
23
|
+
-v, --verbose
|
24
|
+
Turns on verbose logging
|
25
|
+
EOF
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_help
|
29
|
+
print_usage
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_json?(str)
|
33
|
+
str[0..0] == '{'
|
34
|
+
end
|
@@ -1,280 +1,365 @@
|
|
1
1
|
require 'rspec/expectations'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
def enter_text_from_keyboard(text, timeout_duration: 5)
|
4
|
+
wait_for_keyboard(timeout: timeout_duration)
|
5
|
+
keyboard_enter_text(text)
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
# ----------------------------------------------Custom Taps-----------------------------------------------------------
|
9
|
+
# wait element and tap
|
10
|
+
def tap_on(element, timeout_duration: 15, sleep_duration: 0.5)
|
11
|
+
wait_element(element, timeout_duration: timeout_duration, sleep_duration: sleep_duration)
|
12
|
+
touch(element)
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
wait_for_elements_exist(element, :timeout=>15, :retry_frequency=>5)
|
15
|
-
sleep(0.5)
|
16
|
-
touch(element)
|
17
|
-
end
|
15
|
+
def tap_on_text(text, timeout_duration: 15, sleep_duration: 0.5)
|
16
|
+
tap_on("* {text CONTAINS'#{text}'}", timeout_duration: timeout_duration, sleep_duration: sleep_duration)
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# if element exists - tap, if not - swipe until element exists and tap
|
20
|
+
def tap_or_swipe(element, timeout_duration: 30, sleep_duration: 0.5)
|
21
|
+
if element_does_not_exist(element)
|
22
|
+
light_swipe_until_exists('down', element, timeout_duration: timeout_duration)
|
21
23
|
end
|
24
|
+
tap_on(element, sleep_duration: sleep_duration)
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
until_element_exists(element,:action => lambda{light_swipe('down')}, :timeout => 30)
|
30
|
-
light_swipe('down')
|
31
|
-
sleep(1)
|
32
|
-
touch(element)
|
33
|
-
end
|
34
|
-
end
|
27
|
+
# ----------------------------------------------------Custom Waits----------------------------------------------------
|
28
|
+
def wait_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3)
|
29
|
+
wait_for_element_exists(element, timeout: timeout_duration, retry_frequency: retry_frequency)
|
30
|
+
sleep(sleep_duration)
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def wait_no_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3)
|
34
|
+
wait_for_element_does_not_exist(element, timeout: timeout_duration, retry_frequency: retry_frequency)
|
35
|
+
sleep(sleep_duration)
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
# wait trait-element on screen
|
39
|
+
def wait_for_screen(timeout_duration: 30, sleep_duration: 0, retry_frequency: 0.3)
|
40
|
+
wait_element(trait, sleep_duration: sleep_duration, timeout_duration: timeout_duration, retry_frequency: retry_frequency)
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
# ----------------------------------------------------Custom Swipe----------------------------------------------------
|
44
|
+
def strong_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
45
|
+
Timeout::timeout(timeout_duration) do
|
46
|
+
while element_exists(element_destination) do
|
47
|
+
strong_swipe(dir, sleep_duration: sleep_duration)
|
48
|
+
end
|
48
49
|
end
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def normal_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
53
|
+
Timeout::timeout(timeout_duration) do
|
54
|
+
while element_exists(element_destination) do
|
55
|
+
normal_swipe(dir, sleep_duration: sleep_duration)
|
56
|
+
end
|
54
57
|
end
|
58
|
+
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
def light_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
61
|
+
Timeout::timeout(timeout_duration) do
|
62
|
+
while element_exists(element_destination) do
|
63
|
+
light_swipe(dir, sleep_duration: sleep_duration)
|
64
|
+
end
|
59
65
|
end
|
66
|
+
end
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
|
68
|
+
def strong_swipe_until_exists(dir, element_destination, sleep_duration: 0.5, timeout_duration: 30)
|
69
|
+
Timeout::timeout(timeout_duration) do
|
70
|
+
while element_does_not_exist(element_destination) do
|
71
|
+
strong_swipe(dir, sleep_duration: sleep_duration)
|
72
|
+
end
|
64
73
|
end
|
74
|
+
end
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
|
76
|
+
def normal_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
77
|
+
Timeout::timeout(timeout_duration) do
|
78
|
+
while element_does_not_exist(element_destination) do
|
79
|
+
normal_swipe(dir, sleep_duration: sleep_duration)
|
80
|
+
end
|
69
81
|
end
|
82
|
+
end
|
70
83
|
|
71
|
-
|
72
|
-
|
73
|
-
|
84
|
+
def light_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
85
|
+
Timeout::timeout(timeout_duration) do
|
86
|
+
while element_does_not_exist(element_destination) do
|
87
|
+
light_swipe(dir, sleep_duration: sleep_duration)
|
88
|
+
end
|
74
89
|
end
|
90
|
+
end
|
75
91
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
92
|
+
def strong_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30)
|
93
|
+
Timeout::timeout(timeout_duration) do
|
94
|
+
while element_does_not_exist(element_destination) do
|
95
|
+
strong_swipe_element(element, dir, sleep_duration: sleep_duration)
|
96
|
+
end
|
80
97
|
end
|
98
|
+
end
|
81
99
|
|
82
|
-
|
83
|
-
|
84
|
-
|
100
|
+
def normal_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
101
|
+
Timeout::timeout(timeout_duration) do
|
102
|
+
while element_does_not_exist(element_destination) do
|
103
|
+
normal_swipe_element(element, dir, sleep_duration: sleep_duration)
|
104
|
+
end
|
85
105
|
end
|
106
|
+
end
|
86
107
|
|
87
|
-
|
88
|
-
|
89
|
-
|
108
|
+
def light_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
109
|
+
Timeout::timeout(timeout_duration) do
|
110
|
+
while element_does_not_exist(element_destination) do
|
111
|
+
light_swipe_element(element, dir, sleep_duration: sleep_duration)
|
112
|
+
end
|
90
113
|
end
|
114
|
+
end
|
91
115
|
|
92
|
-
|
93
|
-
|
94
|
-
|
116
|
+
def strong_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30)
|
117
|
+
Timeout::timeout(timeout_duration) do
|
118
|
+
while element_exists(element_destination) do
|
119
|
+
strong_swipe_element(element, dir, sleep_duration: sleep_duration)
|
120
|
+
end
|
95
121
|
end
|
122
|
+
end
|
96
123
|
|
97
|
-
|
98
|
-
|
99
|
-
|
124
|
+
def normal_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
125
|
+
Timeout::timeout(timeout_duration) do
|
126
|
+
while element_exists(element_destination) do
|
127
|
+
normal_swipe_element(element, dir, sleep_duration: sleep_duration)
|
128
|
+
end
|
100
129
|
end
|
130
|
+
end
|
101
131
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
elsif dir == 'вниз'
|
107
|
-
until_element_exists("* {text CONTAINS'#{text}'}", :action => lambda{light_swipe('down'); sleep(1.5)}, :timeout => 60)
|
132
|
+
def light_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
|
133
|
+
Timeout::timeout(timeout_duration) do
|
134
|
+
while element_exists(element_destination) do
|
135
|
+
light_swipe_element(element, dir, sleep_duration: sleep_duration)
|
108
136
|
end
|
109
137
|
end
|
138
|
+
end
|
110
139
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
y_from = get_coordinate_y(element_from)
|
140
|
+
def swipe_to_text(dir, text, sleep_duration:0.2, timeout_duration: 30)
|
141
|
+
light_swipe_until_exists(dir, "* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
|
142
|
+
end
|
115
143
|
|
116
|
-
|
117
|
-
|
118
|
-
|
144
|
+
# -------------------------------------------------Asserts------------------------------------------------------------
|
145
|
+
def assert_eql_with_rescue(element1, element2)
|
146
|
+
begin
|
147
|
+
expect(element1).to eq(element2)
|
148
|
+
true
|
149
|
+
rescue RSpec::Expectations::ExpectationNotMetError
|
150
|
+
false
|
119
151
|
end
|
152
|
+
end
|
120
153
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
expect(element1).to eq(element2)
|
125
|
-
true
|
126
|
-
rescue Exception => e
|
127
|
-
false
|
128
|
-
end
|
129
|
-
end
|
154
|
+
def assert_eql(element1, element2)
|
155
|
+
expect(element1).to eq(element2)
|
156
|
+
end
|
130
157
|
|
131
|
-
|
132
|
-
|
133
|
-
|
158
|
+
def assert_not_eql(element1, element2)
|
159
|
+
expect(element1).not_to eql(element2)
|
160
|
+
end
|
134
161
|
|
135
|
-
|
136
|
-
|
137
|
-
|
162
|
+
def assert_true(element)
|
163
|
+
expect(element).to be true
|
164
|
+
end
|
138
165
|
|
139
|
-
|
140
|
-
|
141
|
-
|
166
|
+
def assert_false(element)
|
167
|
+
expect(element).to be false
|
168
|
+
end
|
142
169
|
|
143
|
-
|
144
|
-
|
145
|
-
|
170
|
+
def assert_nil(element)
|
171
|
+
expect(element).to be_nil
|
172
|
+
end
|
146
173
|
|
147
|
-
|
148
|
-
|
149
|
-
|
174
|
+
# ------------------------------------------Generate String-----------------------------------------------------------
|
175
|
+
def get_random_num_string(length)
|
176
|
+
source = (0..9).to_a
|
177
|
+
key = ""
|
178
|
+
length.times{ key += source[rand(source.size)].to_s }
|
179
|
+
return key
|
180
|
+
end
|
150
181
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
182
|
+
def get_random_text_string(length)
|
183
|
+
source = ("a".."z").to_a
|
184
|
+
key = ""
|
185
|
+
length.times{ key += source[rand(source.size)].to_s }
|
186
|
+
return key
|
187
|
+
end
|
158
188
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
length.times{ key += source[rand(source.size)].to_s }
|
163
|
-
return key
|
164
|
-
end
|
189
|
+
def get_random_email
|
190
|
+
return get_random_text_string(7) + "@" + get_random_text_string(2) + ".test"
|
191
|
+
end
|
165
192
|
|
166
|
-
|
167
|
-
|
168
|
-
|
193
|
+
# get first digital from string
|
194
|
+
def extract_num_from_str(text)
|
195
|
+
text.gsub!(/[[:space:]]/, '')
|
196
|
+
num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).first
|
197
|
+
p num
|
198
|
+
end
|
169
199
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
200
|
+
# get last digital from string
|
201
|
+
def extract_last_num_from_str(text)
|
202
|
+
text.gsub!(/[[:space:]]/, '')
|
203
|
+
num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).last
|
204
|
+
p num
|
205
|
+
end
|
176
206
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
207
|
+
# get text from first element
|
208
|
+
def remember(element, sleep_duration: 1, timeout_duration: 5)
|
209
|
+
wait_element(element, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
|
210
|
+
name = query(element)
|
211
|
+
save_name = name.first['text']
|
212
|
+
Kernel.puts(save_name)
|
213
|
+
return save_name
|
214
|
+
end
|
183
215
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
end
|
216
|
+
# get text from last element
|
217
|
+
def remember_last_text(element, sleep_duration: 1, timeout_duration: 5)
|
218
|
+
wait_element(element, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
|
219
|
+
name = query(element)
|
220
|
+
save_name = name.last['text']
|
221
|
+
Kernel.puts(save_name)
|
222
|
+
return save_name
|
223
|
+
end
|
193
224
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
name = query(element)
|
199
|
-
save_name = name.last['text']
|
200
|
-
puts(save_name)
|
201
|
-
return save_name
|
202
|
-
end
|
225
|
+
# wait text
|
226
|
+
def check_text(text, sleep_duration: 0, timeout_duration: 5)
|
227
|
+
wait_element("* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
|
228
|
+
end
|
203
229
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
230
|
+
def no_check_text(text, timeout_duration: 5)
|
231
|
+
warn "Deprecated with 0.1.9 version SurfCustomCalabash, use check_no_text intead"
|
232
|
+
check_no_text(text, timeout_duration: timeout_duration)
|
233
|
+
end
|
208
234
|
|
209
|
-
|
210
|
-
|
211
|
-
|
235
|
+
def check_no_text(text, sleep_duration: 0, timeout_duration: 5)
|
236
|
+
wait_no_element("* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
|
237
|
+
end
|
212
238
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
end
|
239
|
+
# get element's coordinates
|
240
|
+
def get_coordinate_x(element)
|
241
|
+
el = query(element)
|
242
|
+
coordinate = el[0]['rect']['center_x']
|
243
|
+
return coordinate.to_i
|
244
|
+
end
|
220
245
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
246
|
+
def get_coordinate_y(element)
|
247
|
+
el = query(element)
|
248
|
+
coordinate = el[0]['rect']['center_y']
|
249
|
+
return coordinate.to_i
|
250
|
+
end
|
227
251
|
|
252
|
+
# Drag element from one place to place of other element
|
253
|
+
def drag_element(element_from , element_to)
|
254
|
+
x_from = get_coordinate_x(element_from)
|
255
|
+
y_from = get_coordinate_y(element_from)
|
228
256
|
|
229
|
-
|
230
|
-
|
231
|
-
|
257
|
+
x_to = get_coordinate_x(element_to)
|
258
|
+
y_to = get_coordinate_y(element_to)
|
259
|
+
drag_coordinates(x_from, y_from, x_to, y_to, 10, 0.5, 0.5)
|
260
|
+
end
|
261
|
+
|
262
|
+
# if elements cross - return true, if not - false
|
263
|
+
def cross_coordinate(element_front, element_behind, delta: 100)
|
264
|
+
cross = false
|
232
265
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
delta = 100
|
266
|
+
if element_exists(element_front) && element_exists(element_behind)
|
267
|
+
coordinate_front = get_coordinate_y(element_front)
|
268
|
+
coordinate_behind = get_coordinate_y(element_behind)
|
237
269
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
270
|
+
if coordinate_front < coordinate_behind + delta
|
271
|
+
cross = true
|
272
|
+
else
|
273
|
+
cross = false
|
243
274
|
end
|
244
|
-
# puts(cross)
|
245
|
-
return cross
|
246
275
|
end
|
276
|
+
# Kernel.puts(cross)
|
277
|
+
return cross
|
278
|
+
end
|
247
279
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
280
|
+
# swipe down if two element cross
|
281
|
+
def swipe_if_cross(element_front, element_behind, timeout_duration: 30, sleep_duration: 1)
|
282
|
+
Timeout::timeout(timeout_duration) do
|
283
|
+
while cross_coordinate(element_front, element_behind) do
|
284
|
+
light_swipe("down", sleep_duration: sleep_duration)
|
252
285
|
end
|
253
|
-
sleep(1)
|
254
286
|
end
|
287
|
+
end
|
255
288
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
289
|
+
# --------------------------------------------------Localization------------------------------------------------------
|
290
|
+
# get locale apps - Ru or Eng
|
291
|
+
# parameter - element with text
|
292
|
+
def get_app_location(element, sleep_duration: 1)
|
293
|
+
sleep(sleep_duration)
|
294
|
+
if element_exists(element)
|
295
|
+
text_element = remember(element)
|
296
|
+
if check_cyrillic(text_element)
|
297
|
+
locale = 'RUS'
|
264
298
|
else
|
265
|
-
|
299
|
+
locale = 'ENG'
|
266
300
|
end
|
301
|
+
else
|
302
|
+
p "Fail localization"
|
303
|
+
locale = ''
|
267
304
|
end
|
305
|
+
p locale
|
306
|
+
return locale
|
307
|
+
end
|
308
|
+
|
309
|
+
# check cyrillic symbols in string
|
310
|
+
def check_cyrillic(str)
|
311
|
+
regexp = /\p{Cyrillic}+.*?\.?/
|
312
|
+
if str.match(regexp).nil?
|
313
|
+
return false
|
314
|
+
else
|
315
|
+
return true
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
# if apps support two localization, this method check exists text in different locations
|
320
|
+
def text_with_locale(text_locale1, text_locale2, sleep_duration: 1)
|
321
|
+
sleep(sleep_duration)
|
322
|
+
|
323
|
+
# $locale is global variables
|
324
|
+
# $locale setup in first app launch
|
325
|
+
if !$locale.nil?
|
326
|
+
if check_cyrillic(text_locale1)
|
327
|
+
rus_locale = "* {text CONTAINS '#{text_locale1}'}"
|
328
|
+
eng_locale = "* {text CONTAINS '#{text_locale2}'}"
|
329
|
+
elsif check_cyrillic(text_locale2)
|
330
|
+
rus_locale = "* {text CONTAINS '#{text_locale2}'}"
|
331
|
+
eng_locale = "* {text CONTAINS '#{text_locale1}'}"
|
332
|
+
end
|
268
333
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
return
|
273
|
-
|
274
|
-
|
334
|
+
if $locale == "RUS"
|
335
|
+
return rus_locale
|
336
|
+
elsif $locale == "ENG"
|
337
|
+
return eng_locale
|
338
|
+
end
|
339
|
+
else
|
340
|
+
# if $locale is not Rus or Eng
|
341
|
+
# wait element on screen with text_locale1 or text_locale2
|
342
|
+
locale_el1 = "* {text CONTAINS '#{text_locale1}'}"
|
343
|
+
locale_el2 = "* {text CONTAINS '#{text_locale2}'}"
|
344
|
+
|
345
|
+
if element_exists(locale_el1)
|
346
|
+
return locale_el1
|
347
|
+
elsif element_exists(locale_el2)
|
348
|
+
return locale_el2
|
275
349
|
else
|
276
|
-
return
|
350
|
+
return ("No such query!")
|
277
351
|
end
|
278
352
|
end
|
353
|
+
end
|
279
354
|
|
355
|
+
# if apps support two localization, this method check exists label in different locations
|
356
|
+
def label_with_locale(mark1, mark2)
|
357
|
+
if element_exists("* marked:'#{mark1}'")
|
358
|
+
return "* marked:'#{mark1}'"
|
359
|
+
elsif element_exists("* marked:'#{mark2}'")
|
360
|
+
return "* marked:'#{mark2}'"
|
361
|
+
else
|
362
|
+
return false
|
363
|
+
end
|
280
364
|
end
|
365
|
+
|