sunomono 0.2.0.pre

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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +157 -0
  6. data/Rakefile +1 -0
  7. data/bin/suno +3 -0
  8. data/bin/sunomono +3 -0
  9. data/lib/aws/android/app_installation_hooks.rb +30 -0
  10. data/lib/aws/android/app_life_cycle_hooks.rb +13 -0
  11. data/lib/aws/ios/01_launch.rb +43 -0
  12. data/lib/helpers/sunomono_helpers.rb +136 -0
  13. data/lib/helpers/zip_helpers.rb +49 -0
  14. data/lib/skeleton/.gitignore +9 -0
  15. data/lib/skeleton/Gemfile +7 -0
  16. data/lib/skeleton/README.md +165 -0
  17. data/lib/skeleton/config/cucumber.yml +7 -0
  18. data/lib/skeleton/config/email/template.html +14 -0
  19. data/lib/skeleton/config/load_classes.rb +31 -0
  20. data/lib/skeleton/config/scripts/android/run_tests_all_devices.sh +41 -0
  21. data/lib/skeleton/config/scripts/android/start_emulators.sh +52 -0
  22. data/lib/skeleton/config/scripts/android/stop_emulators.sh +13 -0
  23. data/lib/skeleton/config/scripts/break_build_if_failed.sh +6 -0
  24. data/lib/skeleton/config/scripts/check_if_tests_failed.sh +11 -0
  25. data/lib/skeleton/config/scripts/ios/build_app.rb +71 -0
  26. data/lib/skeleton/config/scripts/ios/build_app.yml +13 -0
  27. data/lib/skeleton/config/scripts/ios/devices.txt +4 -0
  28. data/lib/skeleton/config/scripts/ios/run_tests_all_devices.sh +57 -0
  29. data/lib/skeleton/features/android/features/.gitkeep +0 -0
  30. data/lib/skeleton/features/android/screens/.gitkeep +0 -0
  31. data/lib/skeleton/features/android/step_definitions/.gitkeep +0 -0
  32. data/lib/skeleton/features/android/support/app_installation_hooks.rb +36 -0
  33. data/lib/skeleton/features/android/support/app_life_cycle_hooks.rb +11 -0
  34. data/lib/skeleton/features/android/support/hooks.rb +0 -0
  35. data/lib/skeleton/features/ios/features/.gitkeep +0 -0
  36. data/lib/skeleton/features/ios/screens/.gitkeep +0 -0
  37. data/lib/skeleton/features/ios/step_definitions/.gitkeep +0 -0
  38. data/lib/skeleton/features/ios/support/01_launch.rb +94 -0
  39. data/lib/skeleton/features/ios/support/02_pre_stop_hooks.rb +0 -0
  40. data/lib/skeleton/features/support/env.rb +5 -0
  41. data/lib/skeleton/features/support/exceptions.rb +11 -0
  42. data/lib/skeleton/screenshots/android/.gitkeep +0 -0
  43. data/lib/skeleton/screenshots/ios/.gitkeep +0 -0
  44. data/lib/sunomono.rb +238 -0
  45. data/lib/sunomono/locales/en.yml +27 -0
  46. data/lib/sunomono/locales/pt.yml +27 -0
  47. data/lib/sunomono/version.rb +3 -0
  48. data/lib/templates/android_screen_base.tt +186 -0
  49. data/lib/templates/base_steps.tt +48 -0
  50. data/lib/templates/feature.tt +8 -0
  51. data/lib/templates/ios_screen_base.tt +249 -0
  52. data/lib/templates/screen.tt +13 -0
  53. data/lib/templates/steps.tt +5 -0
  54. data/sunomono.gemspec +27 -0
  55. metadata +184 -0
@@ -0,0 +1,13 @@
1
+ dev:
2
+ xcworkspace: "Path_to_the_xcworkspace_folder"
3
+ scheme: TargetName
4
+ configuration: Debug
5
+ destination: "platform=iOS Simulator,name=iPhone 6"
6
+ export_path: "Path_to_export_app_folder"
7
+
8
+ jenkins:
9
+ xcworkspace: <%= ENV['WORKSPACE']%>/Project.xcworkspace
10
+ scheme: TargetName
11
+ configuration: Debug
12
+ destination: "Any_platform_or_device_that_you_want"
13
+ export_path: <%= ENV['WORKSPACE']%>/releases/normal
@@ -0,0 +1,4 @@
1
+ # <DEVICE_TARGET (UUID)> | <DEVICE_ENDPOINT (IP)> | <DEVICE_NAME> | <DEVICE_TYPE> (Simulator or Device)
2
+ 000...000 | http://localhost:37265 | Device0 | Simulator
3
+ 111...111 | http://1.1.1.1:37265 | Device1 | Device
4
+ # EOF - Never erase this comment or the script will have problems to read this file
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+ # ----------------------------------------------------------------------------
3
+ # Uncomment the next line to enable debug
4
+ # set -x
5
+ #
6
+ # $1 -> parameter with the path of the .app bundle for simulators
7
+ # $2 -> parameter with the path of the .app bundle for devices
8
+
9
+ ## CODE BEGIN #############################################################
10
+ export LC_ALL="en_US.UTF-8"
11
+ echo Start: $(date)
12
+
13
+ # Exits if the app path was not informed
14
+ [ $# -lt 2 ] && echo "Wrong number of parameters." && exit 1
15
+
16
+ # Creating the reports path
17
+ reports_path="$WORKSPACE/reports-cal"
18
+ mkdir $reports_path
19
+
20
+ # Changing relative to absolute path if that is the case
21
+ # The simulator path
22
+ original_path="$(pwd)" # Saving the original path where the command was executed
23
+ cd "$1"
24
+ SIMULATOR_APP_PATH="$(pwd)"
25
+ # The device path
26
+ cd "$original_path"
27
+ cd "$2"
28
+ DEVICE_APP_PATH="$(pwd)"
29
+
30
+ cd $WORKSPACE # All tests should run from the root folder of the tests project
31
+
32
+ cat config/scripts/ios/devices.txt | ## Reading the devices.txt file
33
+ grep -v "#" | ## Removing the command lines
34
+ tr -d " " | ## Trimming all the spaces
35
+ while IFS='|' read UUID IP NAME TYPE ## Defining pipe as the separator char and reading the three variable fields
36
+ do
37
+ # Creating the report folder for this device or simulator
38
+ mkdir "$reports_path"/"$NAME"
39
+
40
+ if [ $TYPE == "Simulator" ]
41
+ then
42
+ APP_PATH=$SIMULATOR_APP_PATH
43
+ else
44
+ APP_PATH=$DEVICE_APP_PATH
45
+ fi
46
+
47
+ # Executing calabash for the device or simulator
48
+ APP_BUNDLE_PATH="$APP_PATH" DEVICE_TARGET="$UUID" DEVICE_ENDPOINT="$IP" cucumber -p ios SCREENSHOT_PATH="$reports_path"/"$NAME"/ -f 'Calabash::Formatters::Html' -o "$reports_path"/"$NAME/reports.html" -f junit -o "$reports_path"/"$NAME"
49
+
50
+ # Calabash has a problem with images relative path, the command above will replace all the images path on the
51
+ # html report file to be a relative path
52
+ sed -i.bak 's|'"$reports_path"/"$NAME"/'||g' "$reports_path"/"$NAME"/reports.html
53
+ done
54
+
55
+ echo End: $(date)
56
+ echo 'Bye!'
57
+ ## CODE END #############################################################
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ require 'calabash-android/management/app_installation'
2
+
3
+ AfterConfiguration do
4
+ FeatureMemory.feature = nil
5
+ end
6
+
7
+ Before('@reinstall') do
8
+ uninstall_apps
9
+ install_app(ENV['TEST_APP_PATH'])
10
+ install_app(ENV['APP_PATH'])
11
+ end
12
+
13
+ Before do |scenario|
14
+ scenario = scenario.scenario_outline if
15
+ scenario.respond_to?(:scenario_outline)
16
+
17
+ feature = scenario.feature
18
+ if FeatureMemory.feature != feature || ENV['RESET_BETWEEN_SCENARIOS'] == '1'
19
+ if ENV['RESET_BETWEEN_SCENARIOS'] == '1'
20
+ log 'New scenario - reinstalling apps'
21
+ else
22
+ log 'First scenario in feature - reinstalling apps'
23
+ end
24
+
25
+ uninstall_apps
26
+ install_app(ENV['TEST_APP_PATH'])
27
+ install_app(ENV['APP_PATH'])
28
+
29
+ FeatureMemory.feature = feature
30
+ FeatureMemory.invocation = 1
31
+ else
32
+ FeatureMemory.invocation += 1
33
+ end
34
+ end
35
+
36
+ FeatureMemory = Struct.new(:feature, :invocation).new
@@ -0,0 +1,11 @@
1
+ require 'calabash-android/management/adb'
2
+ require 'calabash-android/operations'
3
+
4
+ Before do
5
+ start_test_server_in_background
6
+ end
7
+
8
+ After do |scenario|
9
+ screenshot_embed if scenario.failed?
10
+ shutdown_test_server
11
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,94 @@
1
+ ########################################
2
+ # #
3
+ # Important Note #
4
+ # #
5
+ # When running calabash-ios tests at #
6
+ # www.xamarin.com/test-cloud #
7
+ # the methods invoked by #
8
+ # CalabashLauncher are overridden. #
9
+ # It will automatically ensure #
10
+ # running on device, installing apps #
11
+ # etc. #
12
+ # #
13
+ ########################################
14
+
15
+ require 'calabash-cucumber/launcher'
16
+
17
+ module Calabash::Launcher
18
+ @@launcher = nil
19
+ def self.launcher
20
+ @@launcher ||= Calabash::Cucumber::Launcher.new
21
+ end
22
+
23
+ def self.launcher=(launcher)
24
+ @@launcher = launcher
25
+ end
26
+ end
27
+
28
+ AfterConfiguration do
29
+ FeatureMemory.feature = nil
30
+ end
31
+
32
+ Before do |scenario|
33
+ launcher = Calabash::Launcher.launcher
34
+ # Relaunch options
35
+ options = { timeout: 3000 }
36
+
37
+ scenario = scenario.scenario_outline if
38
+ scenario.respond_to?(:scenario_outline)
39
+ feature = scenario.feature
40
+
41
+ scenario_tags = scenario.source_tag_names
42
+ if FeatureMemory.feature != feature ||
43
+ ENV['RESET_BETWEEN_SCENARIOS'] == '1' ||
44
+ scenario_tags.include?('@reinstall')
45
+ reinstall_app
46
+ # Reset app if it is a new feature
47
+ options[:reset] = true
48
+
49
+ FeatureMemory.feature = feature
50
+ FeatureMemory.invocation = 1
51
+ else
52
+ FeatureMemory.invocation += 1
53
+ end
54
+
55
+ FeatureMemory.feature = feature
56
+ FeatureMemory.invocation = 1
57
+
58
+ launcher.relaunch(options)
59
+ # Avoid resetting when is not necessary
60
+ options[:reset] = false
61
+ end
62
+
63
+ After do
64
+ calabash_exit if launcher.quit_app_after_scenario?
65
+ end
66
+
67
+ def device?
68
+ # Check if UUID (ENV['DEVICE_TARGET']) is from a device or a simulator
69
+ # Getting all the simulator's UUID
70
+ uuids = `xcrun simctl list`
71
+ return false if uuids.include? ENV['DEVICE_TARGET']
72
+ return true
73
+ end
74
+
75
+ def reinstall_app
76
+ if device?
77
+ system "echo 'Installing the app...'"
78
+ # Trying to reinstall the app
79
+ success = system "ios-deploy -r -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
80
+
81
+ # If the app is not installed the above command will throw an error
82
+ # So we just install the app
83
+ unless success
84
+ success = system "ios-deploy -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
85
+ fail 'Error. Could not install the app.' unless
86
+ success # If there is any error raises an exception
87
+ end
88
+
89
+ system "echo 'Installed.'"
90
+ sleep(3) # Gives a time to finish the installation of the app in the device
91
+ end
92
+ end
93
+
94
+ FeatureMemory = Struct.new(:feature, :invocation).new
@@ -0,0 +1,5 @@
1
+ if ENV['PLATFORM'] == 'ios'
2
+ require 'calabash-cucumber/cucumber'
3
+ elsif ENV['PLATFORM'] == 'android'
4
+ require 'calabash-android/cucumber'
5
+ end
@@ -0,0 +1,11 @@
1
+ class UnexpectedPageError < StandardError
2
+ end
3
+
4
+ class TouchElementError < StandardError
5
+ end
6
+
7
+ class ElementNotFoundError < StandardError
8
+ end
9
+
10
+ class ElementFoundError < StandardError
11
+ end
File without changes
File without changes
data/lib/sunomono.rb ADDED
@@ -0,0 +1,238 @@
1
+ require 'sunomono/version'
2
+
3
+ require 'thor'
4
+ require 'thor/group'
5
+ require 'i18n'
6
+ require 'gherkin' # Used here as a translation source
7
+ require 'json'
8
+ require 'yaml'
9
+
10
+ require_relative File.join('helpers', 'sunomono_helpers')
11
+
12
+ module Sunomono
13
+ # Definition of all gem generators
14
+ class Generate < Thor
15
+ include Thor::Actions
16
+
17
+ desc 'feature [RESOURCE_NAME]', 'Generates an OS independent feature'
18
+ option :lang,
19
+ banner: 'any of the gherkin supported languages',
20
+ default: :en
21
+ def feature(name)
22
+ I18n.config.default_locale = options[:lang]
23
+ in_root_project_folder?
24
+
25
+ create_feature_file(name)
26
+ create_steps_file name
27
+ create_screen_file name, 'Android'
28
+ create_screen_file name, 'IOS'
29
+ end
30
+
31
+ desc 'android-feature [RESOURCE_NAME]',
32
+ 'Generates an Android dependent feature'
33
+ option :lang,
34
+ banner: 'any of the gherkin supported languages',
35
+ default: :en
36
+ def android_feature(name)
37
+ I18n.config.default_locale = options[:lang]
38
+ in_root_project_folder?
39
+
40
+ create_feature_file name, 'Android'
41
+ create_steps_file name, 'Android'
42
+ create_screen_file name, 'Android'
43
+ end
44
+
45
+ desc 'ios-feature [RESOURCE_NAME]', 'Generates an iOS dependent feature'
46
+ option :lang,
47
+ banner: 'any of the gherkin supported languages',
48
+ default: :en
49
+ def ios_feature(name)
50
+ I18n.config.default_locale = options[:lang]
51
+ in_root_project_folder?
52
+
53
+ create_feature_file name, 'IOS'
54
+ create_steps_file name, 'IOS'
55
+ create_screen_file name, 'IOS'
56
+ end
57
+
58
+ desc 'step [RESOURCE_NAME]', 'Generates an OS independent step'
59
+ option :lang,
60
+ banner: 'any of the gherkin supported languages',
61
+ default: :en
62
+ def step(name)
63
+ I18n.config.default_locale = options[:lang]
64
+ in_root_project_folder?
65
+ create_steps_file name
66
+ end
67
+
68
+ desc 'android-step [RESOURCE_NAME]', 'Generates an Android dependent step'
69
+ option :lang,
70
+ banner: 'any of the gherkin supported languages',
71
+ default: :en
72
+ def android_step(name)
73
+ I18n.config.default_locale = options[:lang]
74
+ in_root_project_folder?
75
+ create_steps_file name, 'Android'
76
+ end
77
+
78
+ desc 'ios-step [RESOURCE_NAME]', 'Generates an iOS dependent step'
79
+ option :lang,
80
+ banner: 'any of the gherkin supported languages',
81
+ default: :en
82
+ def ios_step(name)
83
+ I18n.config.default_locale = options[:lang]
84
+ in_root_project_folder?
85
+ create_steps_file name, 'IOS'
86
+ end
87
+
88
+ desc 'screen [RESOURCE_NAME]',
89
+ 'Generates the Android and iOS dependent screens'
90
+ option :lang,
91
+ banner: 'any of the gherkin supported languages',
92
+ default: :en
93
+ def screen(name)
94
+ I18n.config.default_locale = options[:lang]
95
+ in_root_project_folder?
96
+ create_screen_file name, 'Android'
97
+ create_screen_file name, 'IOS'
98
+ end
99
+
100
+ desc 'android-screen [RESOURCE_NAME]',
101
+ 'Generates an Android dependent screen'
102
+ option :lang,
103
+ banner: 'any of the gherkin supported languages',
104
+ default: :en
105
+ def android_screen(name)
106
+ I18n.config.default_locale = options[:lang]
107
+ in_root_project_folder?
108
+ create_screen_file name, 'Android'
109
+ end
110
+
111
+ desc 'ios-screen [RESOURCE_NAME]', 'Generates an iOS dependent screen'
112
+ option :lang,
113
+ banner: 'any of the gherkin supported languages',
114
+ default: :en
115
+ def ios_screen(name)
116
+ I18n.config.default_locale = options[:lang]
117
+ in_root_project_folder?
118
+ create_screen_file name, 'IOS'
119
+ end
120
+
121
+ desc 'aws-zip', 'Prepare a zip file for AWS Device Farm execution'
122
+ option 'skip-char-validation',
123
+ banner: 'skips the special chars validation that can cancel the zip creation',
124
+ type: :boolean,
125
+ lazy_default: true
126
+ def aws_zip
127
+ in_root_project_folder?
128
+
129
+ special_chars_in_exported_path? unless options['skip-char-validation']
130
+
131
+ # Temp folder that will hold the project files to be zipped
132
+ dir = Dir.mktmpdir
133
+ begin
134
+ copy_all_project_files(dir)
135
+ create_screen_shot_dirs(dir)
136
+ # Creating zip file
137
+ create_zip_folder(dir)
138
+ ensure
139
+ # remove the directory.
140
+ FileUtils.remove_entry_secure dir
141
+ end
142
+ end
143
+
144
+ def self.source_root
145
+ File.join(File.dirname(__FILE__), '..', 'lib', 'templates')
146
+ end
147
+ end
148
+ end
149
+
150
+ module Sunomono
151
+ # Definition of the generators groups
152
+ class SunomonoRunner < Thor
153
+ include Thor::Actions
154
+
155
+ map '-v' => :version
156
+ map '--version' => :version
157
+
158
+ default_task :help
159
+
160
+ register Sunomono::Generate, 'generate',
161
+ 'generate [GENERATOR] [RESOURCE_NAME]',
162
+ 'Generates various resources'
163
+ register Sunomono::Generate, 'g',
164
+ 'g [GENERATOR] [RESOURCE_NAME]',
165
+ 'Generates various resources'
166
+
167
+ desc 'new PROJECT_NAME',
168
+ 'Generates the structure of a new project that uses '\
169
+ 'Calabash in both Android and iOS apps'
170
+ option :lang,
171
+ banner: 'any of the gherkin supported languages',
172
+ default: :en
173
+ def new(name)
174
+ I18n.config.default_locale = options[:lang]
175
+ # Thor will be responsible to look for identical
176
+ # files and possibles conflicts
177
+ directory File.join(File.dirname(__FILE__),
178
+ '..', 'lib', 'skeleton'), name
179
+
180
+ # Copying base steps file with localization
181
+ template('base_steps', File.join(name, 'features', 'step_definitions',
182
+ 'base_steps.rb'))
183
+
184
+ # Copying android screen base file with localization
185
+ template('android_screen_base', File.join(name, 'features', 'android',
186
+ 'android_screen_base.rb'))
187
+
188
+ # Copying ios screen base file with localization
189
+ template('ios_screen_base',
190
+ File.join(name, 'features', 'ios', 'ios_screen_base.rb'))
191
+ end
192
+
193
+ desc 'version', 'Shows the gem version'
194
+ def version
195
+ puts "Sunomono Version #{Sunomono::VERSION}"
196
+ end
197
+
198
+ def self.source_root
199
+ File.join(File.dirname(__FILE__), '..', 'lib', 'templates')
200
+ end
201
+
202
+ # Overriding the initialize method to load all the
203
+ # translations supported by the gem gherkin
204
+ def initialize(*args)
205
+ super
206
+ # Loading gherkin accepted translations
207
+ translations_file_path = File.join(
208
+ Gem.loaded_specs['gherkin'].full_gem_path,
209
+ 'lib',
210
+ 'gherkin',
211
+ 'i18n.json'
212
+ )
213
+ # Parsing the JSON file
214
+ # Removing the sequence *| and all the alternative
215
+ # options for the gherkin translations
216
+ translations_json = JSON.parse(
217
+ File.read(translations_file_path)
218
+ .gsub(/\*\|/, '')
219
+ .gsub(/\|.*\"/, '"')
220
+ )
221
+ # Converting the translations to YAML and storing in a temp file
222
+ translations_temp_file = Tempfile.new(['translations', '.yml'])
223
+ File.write(translations_temp_file, translations_json.to_yaml)
224
+ # Loading the translations from gherkin and from the
225
+ # locales folder of this gem
226
+ locales_folder_path = File.join(
227
+ File.dirname(__FILE__),
228
+ '..', 'lib', 'sunomono', 'locales'
229
+ )
230
+ I18n.load_path = Dir[
231
+ translations_temp_file,
232
+ File.join(locales_folder_path, '*.yml')
233
+ ]
234
+ I18n.backend.load_translations
235
+ I18n.config.enforce_available_locales = true
236
+ end
237
+ end
238
+ end