sunomono 0.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
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,49 @@
1
+ require 'zip'
2
+
3
+ # This is a simple example which uses rubyzip to
4
+ # recursively generate a zip file from the contents of
5
+ # a specified directory. The directory itself is not
6
+ # included in the archive, rather just its contents.
7
+ #
8
+ # Usage:
9
+ # directoryToZip = "/tmp/input"
10
+ # outputFile = "/tmp/out.zip"
11
+ # zf = ZipFileGenerator.new(directoryToZip, outputFile)
12
+ # zf.write()
13
+ class ZipFileGenerator
14
+ # Initialize with the directory to zip and the location of the output archive.
15
+ def initialize(input_dir, output_file)
16
+ @input_dir = input_dir
17
+ @output_file = output_file
18
+ end
19
+
20
+ # Zip the input directory.
21
+ def write
22
+ entries = Dir.entries(@input_dir)
23
+ entries.delete('.')
24
+ entries.delete('..')
25
+ io = Zip::File.open(@output_file, Zip::File::CREATE)
26
+
27
+ write_entries(entries, '', io)
28
+ io.close
29
+ end
30
+
31
+ # A helper method to make the recursion work.
32
+ private
33
+
34
+ def write_entries(entries, path, io)
35
+ entries.each do |e|
36
+ zip_file_path = path == '' ? e : File.join(path, e)
37
+ disk_file_path = File.join(@input_dir, zip_file_path)
38
+ if File.directory?(disk_file_path)
39
+ io.mkdir(zip_file_path)
40
+ subdir = Dir.entries(disk_file_path)
41
+ subdir.delete('.')
42
+ subdir.delete('..')
43
+ write_entries(subdir, zip_file_path, io)
44
+ else
45
+ io.get_output_stream(zip_file_path) { |f| f.puts(File.open(disk_file_path, 'rb').read) }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ .irb-history
2
+ reports/*
3
+ test_servers/*
4
+ .DS_Store
5
+ screenshot*.png
6
+ screenshots/android/*
7
+ !screenshots/android/.*
8
+ screenshots/ios/*
9
+ !screenshots/ios/.*
@@ -0,0 +1,7 @@
1
+ # Gemfile to help setting up the initial development environment
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'calabash-common'
5
+ gem 'calabash-android', '~> 0.7'
6
+ gem 'calabash-cucumber', '~> 0.19'
7
+ gem 'sunomono', '~> 0.2'
@@ -0,0 +1,165 @@
1
+ #Getting Started
2
+
3
+ ## Ruby
4
+
5
+ There is a lot of ways of installing ruby, one is using RVM (http://rvm.io/rvm/install):
6
+
7
+ Install RVM stable with ruby:
8
+
9
+ ```
10
+ $ \curl -sSL https://get.rvm.io | bash -s stable --ruby
11
+ ```
12
+
13
+ After this, include the following lines in you `~/.bashrc` file.
14
+
15
+ ```
16
+ export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
17
+ [[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
18
+ ```
19
+
20
+ # Android
21
+
22
+ ## Installing the Gems
23
+
24
+ Install the following gems
25
+
26
+ ```
27
+ gem install calabash-common calabash-android
28
+ ```
29
+
30
+ **Warning!**
31
+
32
+ The gem **`calabash-android`** can install the beta version of the cucumber gem.
33
+ This gem brokes the execution of the calabash. After the installation of calabash-android, check your installed gems with the command `gem list | grep cucumber` and install the stable version of the cucumber gem (command: `gem install cucumber`) and remove the beta version (command: `gem uninstall cucumber`), if that is the case.
34
+
35
+ ## Running the tests
36
+ To run the android tests, you need to:
37
+
38
+ 1. Open the Android AVD
39
+ 2. Open the terminal on the tests folder
40
+ 3. Execute the command:
41
+
42
+ ```
43
+ calabash-android run features/app-QA.apk -p android
44
+ ```
45
+
46
+
47
+ > To run in a computer with more than one emulator or device, use the command:
48
+ >
49
+ >```
50
+ > ADB_DEVICE_ARG=emulator-5554 calabash-android run features/app-QA.apk -p android
51
+ >```
52
+ >
53
+ >Given that 'emulator-5554' is one of the returns of the command `$ adb devices` on the terminal
54
+
55
+
56
+ > To run on all connected devices, run the script `run_tests_all_devices.sh`, located on the `config/scripts/android` folder of the project
57
+
58
+ > **!! IMPORTANT !!**
59
+
60
+ > Remember to export the WORKSPACE variable with the path of the cloned test repository
61
+
62
+ > Remember to pass the APK path as the parameter of the script
63
+ >
64
+ > ```
65
+ > ./config/scripts/android/run_tests_all_devices.sh PATH_OF_APK_FILE
66
+ >```
67
+
68
+
69
+ ## Calabash Terminal
70
+
71
+ The calabash terminal allows you to run the calabash commands without being on a test context
72
+ To open the calabash terminal, you need to:
73
+
74
+ 1. Open the Android AVD
75
+ 2. Open the terminal on the tests folder
76
+ 3. Execute the command:
77
+
78
+ ```
79
+ calabash-android console features/app-QA.apk -p android
80
+ ```
81
+
82
+ 4. Run the commands
83
+
84
+ ```
85
+ reinstall_apps
86
+ start_test_server_in_background
87
+ ```
88
+
89
+ 5. Run the commands you want to.
90
+
91
+ # iOS
92
+
93
+ ## Installing the Gems
94
+
95
+ Install the following gems
96
+
97
+ ```
98
+ gem install calabash-common calabash-cucumber
99
+ ```
100
+
101
+ ## Configuring the iOS project
102
+
103
+ 1. Run the command `pod install`
104
+ 2. Run the command `calabash-ios setup` and follow the instructions
105
+ 3. Make sure that the signing is a wildcard
106
+
107
+
108
+ ## Running the tests
109
+ To run the iOS tests in a device, you need to:
110
+
111
+ 1. Open the terminal on the tests folder
112
+ 2. Compile the project to create the .app file with the command
113
+
114
+ ```
115
+ ./config/scripts/ios/build_app.sh xcworkspace_path TargetName-cal iphoneos8.1 ConfigurationName
116
+ ```
117
+
118
+ PS.1: TargetName-cal is the name of the target created with the command `calabash-ios setup`
119
+ PS.2: iphoneos8.1 is the sdk for devices, for emulatores use iphonesimulator8.1
120
+ PS.3: Configuration name can be Dev, Debug, Release, Prod or any other configuration build
121
+ PS.4: The path to the .app file is the last output line of the above command
122
+
123
+ 3. To execute one feature, run the command
124
+
125
+ ```
126
+ APP_BUNDLE_PATH=AppFilePath DEVICE_TARGET=DeviceUUID DEVICE_ENDPOINT=CalabashServerEndpointDevice cucumber -p ios
127
+ ```
128
+
129
+ 4. To execute all the features in the configured devices run the script
130
+
131
+ ```
132
+ ./config/scripts/ios/run_tests_all_devices.sh AppFilePath
133
+ ```
134
+
135
+ PS.: Remember to configure all the connected devices on the file `./config/scripts/ios/devices`.
136
+ In this file you need to inform the device UUID, the device IP with the calabash server port and a name to identify this device on the reports. Remember to leave an empty line at the end of the file and to split the informations using pipes.
137
+
138
+ ## Calabash Terminal (Device)
139
+
140
+ The calabash terminal allows you to run the calabash commands without being on a test context
141
+ To open the calabash terminal, you need to:
142
+
143
+ 1. Connect the device
144
+ 2. Open the terminal on the tests folder
145
+ 3. Execute the command:
146
+
147
+ ```
148
+ APP_BUNDLE_PATH=AppFilePath DEVICE_TARGET=DeviceUUID DEVICE_ENDPOINT=CalabashServerEndpointDevice calabash-ios console
149
+ ```
150
+
151
+ 4. Run the command
152
+
153
+ ```
154
+ start_test_server_in_background
155
+ ```
156
+
157
+ 5. Run the commands you want to.
158
+
159
+ ## Pitfalls
160
+
161
+ 1. Always build the project with the device connected
162
+ 2. Ensure that the device is enabled to Development and the UI Automations is enabled on the Developer menu (Settings)
163
+ 3. If the device in pin locked, ensure that it is unlocked. If there is no pin, the calabash will automatically unlock the device
164
+ 4. Ensure that the device WIFI is enabled and it is accessible from the computer that is starting the tests. The calabash server works sending commands to the device by the network.
165
+ 5. Always run the target -cal on the Xcode one first time to see if the target is ok and running. The calabash-ios gem cannot print errors of execution, but Xcode can.
@@ -0,0 +1,7 @@
1
+ # config/cucumber.yml
2
+ ##YAML Template
3
+ ---
4
+ android: PLATFORM=android SCREENSHOT_PATH=screenshots/android/ -r features/support -r features/android -r features/step_definitions --exclude features/ios
5
+
6
+
7
+ ios: PLATFORM=ios SCREENSHOT_PATH=screenshots/ios/ -r features/support -r features/ios -r features/step_definitions --exclude features/android
@@ -0,0 +1,14 @@
1
+ <html>
2
+ <head>
3
+ <meta charset="UTF-8">
4
+ <title>Project Name - Sunomono _OS_ - _STATUS_TITLE_</title>
5
+ </head>
6
+ <body>
7
+ <center>
8
+ <h1>Continuous Integration</h1>
9
+ <h2>Job Status: _JOB_NAME_, build number: #_BUILD_NUMBER_</h2>
10
+ Hello. I'm here to let you know that the tests <strong>_STATUS_</strong>.<br>
11
+ To view the reports, click <a href="http://jenkins_url/reports/_JOB_NAME_/_BUILD_NUMBER_">here.</a><br>
12
+ </center>
13
+ </body>
14
+ </html>
@@ -0,0 +1,31 @@
1
+ # Choosing the platform using two environment vars that are mandatory for
2
+ # calabash-ios console execution.
3
+ # If they are not set, then we are executing a calabash android console
4
+ # otherwise, if they are set, then we are execution calabash ios console
5
+ if ENV['APP_BUNDLE_PATH'].nil? && ENV['DEVICE_TARGET'].nil?
6
+ platform = 'android'
7
+ else
8
+ platform = 'ios'
9
+ end
10
+
11
+ puts "Loading #{platform} classes..."
12
+
13
+ features_path = File.join(File.expand_path('.', Dir.pwd), 'features')
14
+
15
+ # Loading the support ruby files
16
+ Dir[File.join(features_path, 'support', '*.rb')].each do |file|
17
+ # We can't load hook files in calabash console context
18
+ load file unless file.include? 'hooks.rb'
19
+ end
20
+
21
+ platform_path = File.join(features_path, platform)
22
+
23
+ # Loading all ruby files in the base screen path
24
+ Dir[File.join(platform_path, '*.rb')].each do |file|
25
+ load file
26
+ end
27
+
28
+ # Loading all screens files
29
+ Dir[File.join(platform_path, 'screens', '*.rb')].each do |screen|
30
+ load screen
31
+ end
@@ -0,0 +1,41 @@
1
+ #!/bin/bash
2
+ # ----------------------------------------------------------------------------
3
+ # Uncomment the next line to enable debug
4
+ # set -x
5
+ #
6
+ # $1 -> parameter with the name of the apk
7
+ # $2 -> parameter to indicates the tapume to run. Can be null and can have other 2 values: must or should
8
+
9
+ ## CODE BEGIN #############################################################
10
+ [ $# -lt 1 ] && echo "Wrong number of parameters." && exit 1
11
+
12
+ # Counting the number of lines returned from the command adb devices
13
+ # This command will return at least 2 as result, because of one header line and one empty line at end
14
+ # So if the result is less than or equal 2, it means that there are no devices or emulators connected
15
+ number_of_devices=$(adb devices | wc -l)
16
+ [ $number_of_devices -le 2 ] && echo "There are no devices or emulators connected!" && exit 1
17
+
18
+ echo Inicio da execução: $(date)
19
+
20
+ # Creating the reports folder for the html format
21
+ reports_path="$WORKSPACE/reports-cal"
22
+ mkdir $reports_path
23
+
24
+ for device in $(adb devices | grep "device$" | cut -f 1)
25
+ do
26
+ cd $WORKSPACE
27
+ # Creates the reports folder
28
+ mkdir "$reports_path"/"$device"
29
+
30
+ {
31
+ ADB_DEVICE_ARG=$device calabash-android run $1 -p android SCREENSHOT_PATH="$reports_path"/"$device"/ -f 'Calabash::Formatters::Html' -o "$reports_path"/"$device"/reports.html -f junit -o "$reports_path"/"$device"
32
+ # Calabash has a problem with images relative path, the command above will replace all the images path on the
33
+ # html report file to be a relative path
34
+ sed -i.bak 's|'"$reports_path"/"$device"/'||g' "$reports_path"/"$device"/reports.html
35
+ }&
36
+
37
+ done
38
+ wait
39
+
40
+ echo Fim da execução: $(date)
41
+ ## CODE END #############################################################
@@ -0,0 +1,52 @@
1
+ #!/bin/bash
2
+ # Author: Victor Nascimento
3
+
4
+ bash stop_emulators.sh
5
+
6
+ # Suffix name of the AVD
7
+ SUFFIX="CALABASH_AVD_4."
8
+
9
+ # All $SUFFIX emulators are started
10
+ for AVD in ${HOME}/.android/avd/${SUFFIX}*.avd
11
+ do
12
+ # remove any locks that were left
13
+ rm "$AVD/*.lock" 2> /dev/null
14
+ # takes only the name of the AVD
15
+ echo $AVD
16
+ AVD="$(basename ${AVD/.avd/})"
17
+ echo starting "$AVD"...
18
+ emulator -wipe-data -gpu on -noaudio -scale 0.5 -no-boot-anim -accel on -avd "$AVD" -qemu -m 1024 -enable-kvm &
19
+ done
20
+
21
+ sleep 15
22
+ # lists all emulators with adb and check for its online state
23
+
24
+ # finds the port through adb emulator name
25
+ for porta in $(adb devices -l | grep ^emulator | cut -d " " -f 1 | cut -d - -f 2)
26
+ do
27
+ echo Searching for emulator PID for port: ${porta}
28
+ pid=$(netstat -tlnp 2> /dev/null | grep "$porta" | tr -s " " | cut -d " " -f 7 | cut -d "/" -f 1)
29
+ echo gets the AVD name from the exec command
30
+ avd=$(ps -ef | grep -v grep | grep "$pid" | egrep -o '\-avd .*' | cut -d " " -f 2)
31
+ echo AVD: ${avd}
32
+ # if name contains suffix
33
+ if echo "$avd" | grep -q "$SUFFIX"
34
+ then
35
+ echo Waiting for "emulator-${porta}:${avd}" to be ready
36
+
37
+ # Wait for online state with maximum 60 tries
38
+ COUNT=0
39
+
40
+ while adb -s "emulator-${porta}" shell getprop dev.bootcomplete | grep -q error
41
+ do
42
+ if [ "$COUNT" -eq 60 ]
43
+ then
44
+ echo "Emulator took too long to start up"
45
+ exit 1
46
+ fi
47
+
48
+ let COUNT++
49
+ sleep 1
50
+ done
51
+ fi
52
+ done
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+ # Author: Victor Nascimento
3
+
4
+ SUFFIX=CALABASH_AVD_4.
5
+
6
+ for AVD in $HOME/.android/avd/${SUFFIX}*.avd
7
+ do
8
+ AVD="$(basename ${AVD/.avd/})"
9
+ echo chuck killing "$AVD"...
10
+ pkill -9 -f "$AVD"
11
+ done
12
+
13
+
@@ -0,0 +1,6 @@
1
+ # Looking for errors on the report files and returns an error
2
+ if [ $TESTS_RESULT == "Failed" ]
3
+ then
4
+ echo "Setting build as failed"
5
+ exit 1
6
+ fi
@@ -0,0 +1,11 @@
1
+ # Looking for errors on the report files and returns an error
2
+ cd "$WORKSPACE/reports-cal"
3
+
4
+ export TESTS_RESULT="Ok"
5
+ for folder in *
6
+ do
7
+ if egrep '[0-9]+ failed' "$folder/reports.html"
8
+ then
9
+ export TESTS_RESULT="Failed"
10
+ fi
11
+ done
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ # ----------------------------------------------------------------------------
4
+ #
5
+ # $1 -> configuration environment (dev or jenkins)
6
+ #
7
+ #
8
+ # REMEMBER to fill the configuration file build_app.yml
9
+
10
+ require 'fileutils'
11
+ require 'yaml'
12
+ require 'pathname'
13
+
14
+ # When running on CI
15
+ # It is a good pratice to run pod install when executing this script
16
+ # on the CI to avoid building problems
17
+ # %x(pod install)
18
+
19
+ # Parsing the yaml configuration file
20
+ config = YAML.load_file(File.join(File.dirname(__FILE__), 'build_app.yml'))
21
+
22
+ if ARGV.length != 1
23
+ puts 'Error: Wrong number of arguments!'
24
+ puts 'Usage: build_app.rb environment'
25
+ puts "Available Environments: #{config.keys.join(', ')}"
26
+ exit 1
27
+ end
28
+
29
+ if config[ARGV[0]].nil?
30
+ puts 'Error: Wrong configuration environment!'
31
+ puts "Available Environments: #{config.keys.join(', ')}"
32
+ exit 1
33
+ else
34
+ config = config[ARGV[0]]
35
+ end
36
+
37
+ puts "Starting at #{Time.now.strftime('%H:%M:%S')}"
38
+
39
+ # Creating a folder name from the destination configuration parameter
40
+ folder_name = config['destination'].gsub('platform=', '').gsub('name=', '')
41
+ .tr(' ', '_').tr(',', '_')
42
+ export_path = File.join(config['export_path'], folder_name)
43
+
44
+ # Removing the folder where the .app will be stored if it already exists
45
+ FileUtils.rm_r export_path if Dir.exist?(export_path)
46
+
47
+ # Creating the folder where the .app will be stored
48
+ FileUtils.mkdir_p export_path
49
+
50
+ puts 'Building project'
51
+
52
+ system <<eos
53
+ xcodebuild -workspace "#{config['xcworkspace']}" \
54
+ -scheme "#{config['scheme']}" -destination "#{config['destination']}" \
55
+ -configuration "#{config['configuration']}" clean build \
56
+ CONFIGURATION_BUILD_DIR="#{export_path}"
57
+ eos
58
+
59
+ # Getting the app folder that was created
60
+ # Listing all folders on the export path folder
61
+ folders = Pathname.new(export_path).children.select { |c| c.directory? }
62
+ # Getting the folder which ends with .app
63
+ app_pathname = folders.select { |f| f.to_s.match('.app$') }
64
+ # Getting the app folder path
65
+ app_path = app_pathname.first.to_s
66
+
67
+ # Printing the APP_BUNDLE_PATH in the terminal
68
+ puts "APP_BUNDLE_PATH=#{app_path}"
69
+
70
+ puts "End: #{Time.now.strftime('%H:%M:%S')}"
71
+ puts 'Bye!'