cs-bdd 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fea4af1f1c087b62438cbecf42def2f539e2fe1
4
- data.tar.gz: affd1d59330b9ed5811fd65a099ec723de85ad24
3
+ metadata.gz: e38a42a921fdc0a1307703e4189a74192a35c6ae
4
+ data.tar.gz: 15b44bd418b4855ab0159ed539d336f077d62579
5
5
  SHA512:
6
- metadata.gz: bef6f96f0d15ce28ccf31738bf1641f1da1d7449f7e317c5b700f473d3bf42ec7beff9872360eb879a33cc2dc357b34348fe8867e315325a0bbdeb0f101a39ae
7
- data.tar.gz: 90370746239e9a6f3f0e3f5b9c5565aec684e0fffdcc9936c45d2e8d0fbff009c1b5f78c54db06b1b348e3ff923e73246a613472e198e85964aba57e46b57bc9
6
+ metadata.gz: 5b97da3a3559e75cf7f2b269177055067c6a27c5a73b1a9f7f608046350ba5397c500922b5349ee5fa19444accf65127ab39501759c8b0aaf34dffa4d5fa64fd
7
+ data.tar.gz: a40f6ca84b956b0fc230680ab0a2351f0ce6efb586d60d3cfc55e2b4b2a88bb4219af27146c28f4da18b31ccf3828ab03186fa1da116695d740891614d1d7783
data/Gemfile CHANGED
@@ -3,6 +3,11 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in cs-bdd.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'thor'
7
+ gem 'i18n'
8
+ gem 'json'
9
+ gem 'gherkin'
10
+
6
11
  # calabash gems
7
12
  gem 'calabash-common'
8
13
  # Only for Linux
data/bin/cs-bdd CHANGED
@@ -1,93 +1,150 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # File based on https://github.com/calabash/calabash-android/blob/e2da2817809edf38256a55093dc1d3835c9c6410/ruby-gem/bin/calabash-android
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'
4
9
 
5
- require 'fileutils'
6
- require 'rbconfig'
7
- require_relative '../lib/cs/bdd/version'
8
-
9
- # for ruby 1.9.1 and earlier
10
- unless defined? RbConfig.ruby
11
- def RbConfig.ruby
12
- File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"])
13
- end
14
- end
15
-
16
- require File.join(File.dirname(__FILE__), "cs-bdd-generate")
17
10
  require File.join(File.dirname(__FILE__), "cs-bdd-helpers")
11
+ require_relative '../lib/cs/bdd/version'
18
12
 
19
- @skeleton_dir = File.join( File.dirname(__FILE__), '..', 'lib', 'skeleton' )
20
- @examples_dir = File.join( File.dirname(__FILE__), "..", "lib", "examples" )
21
- @features_dir = File.join( FileUtils.pwd, "features" )
22
- @steps_dir = File.join(@features_dir, "step_definitions" )
23
- @android_dir = File.join(@features_dir, "android" )
24
- @ios_dir = File.join(@features_dir, "ios" )
25
-
26
- if ARGV.length == 0
27
- print_usage
28
- else
29
- cmd = ARGV.shift
30
-
31
- case cmd
32
- when 'new', 'n'
33
- if ARGV.empty?
34
- puts "Please specify the project name"
35
- exit 1
36
- else
37
- @project_dir = File.join(FileUtils.pwd, ARGV.first)
38
- generate_skeleton
39
- end
40
- when 'generate', 'g'
41
-
42
- # Looks if the user is in the root folder of the project
43
- unless Dir.exists? File.join(FileUtils.pwd, "features", "android", "features")
44
- puts "Please run this command on the root folder of the project"
45
- exit 1
46
- end
47
-
48
- if ARGV.empty?
49
- puts "Please inform the generator that will be used. Type cs-bdd to see the usage info."
50
- exit 1
51
- else
52
- generator = ARGV.shift
53
-
54
- if ARGV.empty?
55
- puts "Please specify the name of the resource to be generated."
56
- exit 1
57
- end
13
+ module CS
14
+ module BDD
15
+ class Generate < Thor
16
+ include Thor::Actions
58
17
 
59
- name = ARGV.first
18
+ desc "feature [RESOURCE_NAME]", "Generates an OS independent feature"
19
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
20
+ def feature name
21
+ I18n.config.default_locale = options[:lang]
22
+ in_root_project_folder?
60
23
 
61
- case generator
62
- when 'feature'
63
24
  create_feature_file name
64
25
  create_steps_file name
65
- create_screen_file name, 'IOS'
66
26
  create_screen_file name, 'Android'
67
- when 'aFeature'
27
+ create_screen_file name, 'IOS'
28
+ end
29
+
30
+ desc "aFeature [RESOURCE_NAME]", "Generates an Android dependent feature"
31
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
32
+ def aFeature name
33
+ I18n.config.default_locale = options[:lang]
34
+ in_root_project_folder?
35
+
68
36
  create_feature_file name, 'Android'
69
37
  create_steps_file name, 'Android'
70
38
  create_screen_file name, 'Android'
71
- when 'iFeature'
39
+ end
40
+
41
+ desc "iFeature [RESOURCE_NAME]", "Generates an iOS dependent feature"
42
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
43
+ def iFeature name
44
+ I18n.config.default_locale = options[:lang]
45
+ in_root_project_folder?
46
+
72
47
  create_feature_file name, 'IOS'
73
48
  create_steps_file name, 'IOS'
74
49
  create_screen_file name, 'IOS'
75
- when 'step'
50
+ end
51
+
52
+ desc "step [RESOURCE_NAME]", "Generates an OS independent step"
53
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
54
+ def step name
55
+ I18n.config.default_locale = options[:lang]
56
+ in_root_project_folder?
76
57
  create_steps_file name
77
- when 'aStep'
58
+ end
59
+
60
+ desc "aStep [RESOURCE_NAME]", "Generates an Android dependent step"
61
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
62
+ def aStep name
63
+ I18n.config.default_locale = options[:lang]
64
+ in_root_project_folder?
78
65
  create_steps_file name, 'Android'
79
- when 'iStep'
66
+ end
67
+
68
+ desc "iStep [RESOURCE_NAME]", "Generates an iOS dependent step"
69
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
70
+ def iStep name
71
+ I18n.config.default_locale = options[:lang]
72
+ in_root_project_folder?
80
73
  create_steps_file name, 'IOS'
81
- when 'aScreen'
74
+ end
75
+
76
+ desc "aScreen [RESOURCE_NAME]", "Generates an Android dependent screen"
77
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
78
+ def aScreen name
79
+ I18n.config.default_locale = options[:lang]
80
+ in_root_project_folder?
82
81
  create_screen_file name, 'Android'
83
- when 'iScreen'
82
+ end
83
+
84
+ desc "iScreen [RESOURCE_NAME]", "Generates an iOS dependent screen"
85
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
86
+ def iScreen name
87
+ I18n.config.default_locale = options[:lang]
88
+ in_root_project_folder?
84
89
  create_screen_file name, 'IOS'
85
90
  end
91
+
92
+ def self.source_root
93
+ File.join( File.dirname(__FILE__), '..', 'lib', 'templates' )
94
+ end
86
95
  end
87
- when 'version', 'v'
88
- puts CS::BDD::VERSION
89
- else
90
- puts "Invalid command '#{cmd}'"
91
- print_usage
92
96
  end
93
- end
97
+ end
98
+
99
+ module CS
100
+ module BDD
101
+ class CsBddRunner < Thor
102
+ include Thor::Actions
103
+
104
+ default_task :help
105
+
106
+ register CS::BDD::Generate, 'generate', 'generate [GENERATOR] [RESOURCE_NAME]', 'Generates various resources'
107
+
108
+ desc "new PROJECT_NAME", "Generates the structure of a new project that uses Calabash in both Android and iOS apps"
109
+ option :lang, :banner => "any of the gherkin supported languages", :default => :en
110
+ def new name
111
+ I18n.config.default_locale = options[:lang]
112
+ # Thor will be responsible to look for identical files and possibles conflicts
113
+ directory File.join( File.dirname(__FILE__), '..', 'lib', 'skeleton' ), name
114
+
115
+ # Copying base steps file with localization
116
+ template( "base_steps", File.join(name, 'features', 'step_definitions', 'base_steps.rb') )
117
+ end
118
+
119
+ desc "version", "Shows the gem version"
120
+ def version
121
+ puts "cs-bdd Version #{CS::BDD::VERSION}"
122
+ end
123
+
124
+ def self.source_root
125
+ File.join( File.dirname(__FILE__), '..', 'lib', 'templates' )
126
+ end
127
+
128
+ # Overriding the initialize method to load all the translations supported by the gem gherkin
129
+ def initialize(*args)
130
+ super
131
+ # Loading gherkin accepted translations
132
+ translations_file_path = File.join(Gem.loaded_specs['gherkin'].full_gem_path, 'lib', 'gherkin', 'i18n.json')
133
+ # Parsing the JSON file
134
+ # Removing the sequence *| and all the alternative options for the gherkin translations
135
+ translations_json = JSON.parse( File.read( translations_file_path ).gsub(/\*\|/, "").gsub( /\|.*\"/, '"') )
136
+ # Converting the translations to YAML and storing in a temp file
137
+ translations_temp_file = Tempfile.new( ["translations", ".yml"] )
138
+ File.write( translations_temp_file, translations_json.to_yaml )
139
+ # Loading the translations from gherkin and from the locales folder of this gem
140
+ locales_folder_path = File.join( File.dirname(__FILE__), '..', 'lib', 'cs', 'bdd', 'locales' )
141
+ I18n.load_path = Dir[translations_temp_file, File.join(locales_folder_path, "*.yml")]
142
+ I18n.backend.load_translations
143
+ I18n.config.enforce_available_locales = true
144
+ end
145
+
146
+ end
147
+ end
148
+ end
149
+
150
+ CS::BDD::CsBddRunner.start
@@ -1,73 +1,68 @@
1
- def print_usage
2
- puts <<EOF
3
- Usage: cs-bdd <command-name> [parameters]
4
- <command-name> can be one of
5
- new or n <project_name>
6
- generate a project folder structure
7
- \033[0;32mEx.: cs-bdd n project_name\033[0m
8
- generate or g <type> <name>
9
- generate a Feature or Step Definition or Screen file
10
- <type> can be one of
11
- feature -> Generate all files that composes an OS independenty feature
12
- aFeature -> Generate all files that composes an Android feature
13
- iFeature -> Generate all files that composes an iOS feature
14
- step -> Generate an OS independenty step
15
- aStep -> Generate a step that will be loaded only in Android
16
- iStep -> Generate a step that will be loaded only in iOS
17
- aScreen -> Generate an Android screen
18
- iScreen -> Generate an iOS screen
19
- \033[0;32mEx.: cs-bdd g aFeature Feature_name\033[0m
20
- version or v
21
- prints the gem version
22
- \033[0;32mEx.: cs-bdd v\033[0m
23
- EOF
24
- end
25
-
26
1
  def create_feature_file name, platform = nil
27
- # Getting the contents of the example.feature file
28
- content = File.read( File.join( @examples_dir, "example.feature" ) )
29
-
30
- # Updating the contents with the name passed as an option
31
- content = content.gsub( "|Name|", name.capitalize )
2
+
3
+ # options used to generate the file in the template function
4
+ opts = {:name => camelize(name)}
32
5
 
33
6
  # If platform is not nil than the feature is OS dependent
34
- file = nil
7
+ file_path = ""
35
8
  if platform.nil?
36
- content = content.gsub( "|Platform|", "") # Don't show any indication of platform inside the feature file
37
- file = File.join( @features_dir, "#{name.downcase}.feature" )
9
+ file_path = File.join( FileUtils.pwd, "features", "#{name.downcase}.feature" )
10
+ opts[:platform] = ""
38
11
  else
39
- content = content.gsub( "|Platform|", "(#{platform} Only)") # Indicates the platform in the title of the feature
40
- file = File.join( @features_dir, platform.downcase, "features", "#{name.downcase}.feature" )
12
+ file_path = File.join( FileUtils.pwd, "features", platform.downcase, "features", "#{name.downcase}.feature" )
13
+ opts[:platform] = platform
41
14
  end
42
15
 
43
- # Creating the feature file with the updated content
44
- File.open( file, 'w' ) { |file| file.puts content }
16
+ # Thor creates a file based on the templates/feature.tt template
17
+ template( "feature", file_path, opts )
45
18
  end
46
19
 
47
20
  def create_steps_file name, platform = nil
48
- # Getting the contents of the example_steps.rb file
49
- content = File.read( File.join( @examples_dir, "example_steps.rb" ) )
50
-
51
- # If platform is not nil than the feature is OS dependent
52
- file = nil
21
+
22
+ # options used to generate the file in the template function
23
+ opts = {:name => camelize(name)}
24
+
25
+ # If platform is not nil than the step is OS dependent
26
+ file_path = nil
53
27
  if platform.nil?
54
- file = File.join( @steps_dir, "#{name.downcase}_steps.rb" )
28
+ file_path = File.join( FileUtils.pwd, "features", "step_definitions", "#{name.downcase}_steps.rb" )
29
+ opts[:platform] = ""
55
30
  else
56
- file = File.join( @features_dir, platform.downcase, "steps_definition", "#{name.downcase}.feature" )
31
+ file_path = File.join( FileUtils.pwd, "features", platform.downcase, "step_definitions", "#{name.downcase}_steps.rb" )
32
+ opts[:platform] = platform
57
33
  end
58
34
 
59
- # Creating the steps file with the default content
60
- File.open( file, 'w' ) { |file| file.puts content }
35
+ # Thor creates a file based on the templates/steps.tt template
36
+ template( "steps", file_path, opts )
61
37
  end
62
38
 
63
39
  def create_screen_file name, platform
64
- # Getting the contents of the example_screen.rb file
65
- content = File.read( File.join( @examples_dir, "example_screen.rb" ) )
66
-
67
- # Updating the contents with the name passed as an option
68
- content = content.gsub( "|Name|", name.capitalize )
69
- content = content.gsub( "|Platform|", platform )
70
-
71
- # Creating the feature file with the updated content
72
- File.open( File.join( @features_dir, platform.downcase, "screens", "#{name.downcase}_screen.rb" ), 'w' ) { |file| file.puts content }
40
+
41
+ # options used to generate the file in the template function
42
+ opts = {:name => camelize(name), :platform => platform}
43
+
44
+ # Thor creates a file based on the templates/screen.tt template
45
+ template( "screen", File.join( FileUtils.pwd, "features", platform.downcase, "screens", "#{name.downcase}_screen.rb"), opts )
46
+ end
47
+
48
+ def camelize string
49
+
50
+ camelized = ""
51
+
52
+ string.split("_").each do |s|
53
+ camelized = camelized + s.capitalize
54
+ end
55
+
56
+ return camelized
57
+ end
58
+
59
+ def in_root_project_folder?
60
+ # Looks if the user is in the root folder of the project
61
+ if !Dir.exists? File.join(FileUtils.pwd, "features", "android", "features") or
62
+ !Dir.exists? File.join(FileUtils.pwd, "features", "ios", "features")
63
+ puts "Please run this command on the root folder of the project"
64
+ exit 1
65
+ end
66
+
67
+ return true
73
68
  end
data/cs-bdd.gemspec CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "thor", "~> 0.19.1"
24
+ spec.add_development_dependency "i18n", "~> 0.6.11"
25
+ spec.add_development_dependency "gherkin", "~> 2.12.2"
23
26
  end
@@ -0,0 +1,18 @@
1
+ en:
2
+ android_only: "(Android Only)"
3
+ ios_only: "(iOS Only)"
4
+ first_scenario: "First Scenario"
5
+ comments:
6
+ trait: "The screen identificator"
7
+ insert_steps: "Insert steps"
8
+ elements: "Declare all the elements of this screen"
9
+ actions: "Declare all actions of this screen"
10
+ steps:
11
+ drag_until: "I (?:drag|dragged) the screen (down|up|left|right) until I see the element"
12
+ page_contains: "I am on a page that contains"
13
+ drag_number_of_times: 'I drag the screen (left|right|down|up) (\d+) times'
14
+ touch_element: 'I (?:touch|touched) the "(.*?)" element'
15
+ drag_screen: "I drag the screen (down|up|left|right)"
16
+ wait_progress_bar: "I (?:wait|waited) for the progress bar to vanish"
17
+ should_see_page: "I should see the page"
18
+ should_see_page_that_contains: "I should see a page that contains"
@@ -0,0 +1,18 @@
1
+ pt:
2
+ android_only: "(Somente Android)"
3
+ ios_only: "(Somente iOS)"
4
+ first_scenario: "Primeiro Cenário"
5
+ comments:
6
+ trait: "Identificador da tela"
7
+ insert_steps: "Insira os passos"
8
+ elements: "Declare todos os elementos da tela"
9
+ actions: "Declare todas as ações da tela"
10
+ steps:
11
+ drag_until: "que Eu (?:arrastei|arrasto) a tela para (baixo|cima|esquerda|direita) até ver o elemento"
12
+ page_contains: "que Eu estou em uma página que contem"
13
+ drag_number_of_times: 'Eu arrasto a tela para (esquerda|direita|baixo|cima) (\d+) vezes'
14
+ touch_element: 'Eu (?:clico|cliquei) no elemento "(.*?)"'
15
+ drag_screen: "Eu arrasto a tela para (baixo|cima|esquerda|direita)"
16
+ wait_progress_bar: "Eu (?:espero|esperei) até a barar de progresso sumir"
17
+ should_see_page: "Eu deveria ver a página"
18
+ should_see_page_that_contains: "Eu deveria ver uma página que contem"
@@ -1,5 +1,5 @@
1
1
  module CS
2
2
  module BDD
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -7,18 +7,29 @@
7
7
 
8
8
 
9
9
  ## CODE BEGIN #############################################################
10
- echo Start: $(date)
10
+ [ $# -ne 1 ] && echo "Wrong number of parameters." && exit 1
11
+
12
+ echo Inicio da execução: $(date)
13
+
14
+ reports_path="/var/www/html/reports/$(date +"%Y%d%m")"
15
+
11
16
  for device in $(adb devices | grep "device$" | cut -f 1)
12
17
  do
13
- rm -r $WORKSPACE/reports/$device &> /dev/null
14
- mkdir -p $WORKSPACE/reports/$device &> /dev/null
18
+ rm -r "$reports_path"/"$device" &> /dev/null
19
+ mkdir -p "$reports_path"/"$device" &> /dev/null
15
20
  echo $device | grep -q emulator
16
21
  # SET THE IGNORE TAGS TRUE IF THE TEST ARE RUNNING IN A DEVICE
17
22
  [ $? -ne 0 ] && ignore='--tags ~@ignore_if_test_in_device'
18
23
  cd $WORKSPACE
19
- ADB_DEVICE_ARG=$device SCREENSHOT_PATH=$WORKSPACE/reports/$device/ calabash-android run $1 -p android --format 'Calabash::Formatters::Html' --out $WORKSPACE/reports/$device/reports.html $ignore &
24
+ ADB_DEVICE_ARG=$device SCREENSHOT_PATH="$reports_path"/"$device"/ calabash-android run $1 -p android --format 'Calabash::Formatters::Html' --out "$reports_path"/"$device"/reports.html $ignore &
20
25
  done
21
26
  wait
22
- echo End: $(date)
23
- echo 'Bye!'
27
+
28
+ # Calabash has a problem with images relative path, the command above will replace all the images path on the
29
+ # html report file to be a relative path
30
+ for device in $(adb devices | grep "device$" | cut -f 1)
31
+ do
32
+ sed -i 's|'"$reports_path"/"$device"/'||g' "$reports_path"/"$device"/reports.html
33
+ done
34
+ echo Fim da execução: $(date)
24
35
  ## CODE END #############################################################
@@ -15,6 +15,10 @@ if [ -z $1 ]; then
15
15
  exit 1
16
16
  fi
17
17
 
18
+ # Remember to install an application server to enable remote access to the reports
19
+ # Remember to previous create the reports folder and give the appropriate permissions
20
+ reports_path="/var/www/reports/$(date +"%Y%d%m")"
21
+
18
22
  # Reads the devices file line by line
19
23
  while read line
20
24
  do
@@ -28,14 +32,14 @@ do
28
32
  name="$(echo $line | cut -d'|' -f3 | tr -d ' ')"
29
33
 
30
34
  # Cleaning the previous reports folder and ensuring its existence
31
- rm -rf "$WORKSPACE/reports/$name" &> /dev/null
32
- mkdir -p "$WORKSPACE/reports/$name" &> /dev/null
35
+ rm -r "$reports_path"/"$name" &> /dev/null
36
+ mkdir -p "$reports_path"/"$name" &> /dev/null
33
37
 
34
38
  # Navigating to the tests root folder
35
39
  cd "$WORKSPACE"
36
40
 
37
41
  # Executing calabash for the device
38
- APP_BUNDLE_PATH="$1" DEVICE_TARGET="$target" DEVICE_ENDPOINT="$endpoint" SCREENSHOT_PATH="$WORKSPACE/reports/$name/" cucumber -p ios --format 'Calabash::Formatters::Html' --out "$WORKSPACE/reports/$name/reports.html"
42
+ APP_BUNDLE_PATH="$1" DEVICE_TARGET="$target" DEVICE_ENDPOINT="$endpoint" SCREENSHOT_PATH="$reports_path"/"$name"/ cucumber -p ios --format 'Calabash::Formatters::Html' --out "$reports_path"/"$name/reports.html"
39
43
 
40
44
  done < config/scripts/ios/devices
41
45
 
@@ -41,17 +41,15 @@ class AndroidScreenBase < Calabash::ABase
41
41
  end
42
42
 
43
43
  def drag_until_element_is_visible_with_special_query direction, element
44
- drag_until_element_is_visible direction, element, "* {text CONTAINS[c] '#{self.get_translation(element)}'}"
44
+ drag_until_element_is_visible direction, element, "* {text CONTAINS[c] '#{element}'}"
45
45
  end
46
46
 
47
47
  def drag_until_element_is_visible direction, element, query = nil, limit = 15
48
48
  i = 0
49
49
 
50
- element_text = get_translation(element)
51
-
52
50
  element_query = ""
53
51
  if query.nil?
54
- element_query = "* marked:'#{element_text}'"
52
+ element_query = "* marked:'#{element}'"
55
53
  else
56
54
  element_query = query
57
55
  end
@@ -62,7 +60,7 @@ class AndroidScreenBase < Calabash::ABase
62
60
  i = i + 1
63
61
  end
64
62
 
65
- raise ("Executed #{limit} moviments #{direction.to_s} and the element '#{element_text}' was not found on this view!") unless i < limit
63
+ raise ("Executed #{limit} moviments #{direction.to_s} and the element '#{element}' was not found on this view!") unless i < limit
66
64
  end
67
65
 
68
66
  def drag_for_specified_number_of_times direction, times
@@ -73,12 +71,10 @@ class AndroidScreenBase < Calabash::ABase
73
71
 
74
72
  def is_on_page? page_text
75
73
 
76
- translated_page_text = get_translation(page_text)[0,50] # Using only the first 50 chars in the comparation
77
-
78
74
  begin
79
- wait_for(:timeout => 5) { has_text? translated_page_text }
75
+ wait_for(:timeout => 5) { has_text? page_text }
80
76
  rescue
81
- raise "Unexpected Page. Expected was: '#{translated_page_text}'"
77
+ raise "Unexpected Page. Expected was: '#{page_text}'"
82
78
  end
83
79
  end
84
80
 
@@ -56,12 +56,13 @@ class IOSScreenBase < Calabash::IBase
56
56
  def ios_element_exists? query
57
57
  second_query = nil
58
58
 
59
- if query.include? "marked"
60
- second_query = query.gsub( 'marked', 'accessibilityLabel' )
61
- end
62
-
63
- if query.include? "accessibilityLabel"
64
- second_query = query.gsub( 'accessibilityLabel', 'marked' )
59
+ if query.include? "CONTAINS[c]"
60
+ if query.include? "marked"
61
+ second_query = query.gsub( 'marked', 'accessibilityLabel' )
62
+ end
63
+ if query.include? "accessibilityLabel"
64
+ second_query = query.gsub( 'accessibilityLabel', 'marked' )
65
+ end
65
66
  end
66
67
 
67
68
  if second_query.nil?
@@ -69,7 +70,6 @@ class IOSScreenBase < Calabash::IBase
69
70
  else
70
71
  element_exists(query) or element_exists(second_query)
71
72
  end
72
-
73
73
  end
74
74
 
75
75
  def drag_until_element_is_visible_with_special_query direction, element
@@ -111,10 +111,13 @@ class IOSScreenBase < Calabash::IBase
111
111
 
112
112
  def enter text, element, query = nil
113
113
  if query.nil?
114
- query( "* marked:'#{element}'", {:setText => text} )
115
- else
116
- query( query, {:setText => text} )
114
+ query = "* marked:'#{element}'"
117
115
  end
116
+
117
+ touch query
118
+ sleep(1)
119
+ keyboard_enter_text text
120
+ done
118
121
  end
119
122
 
120
123
  def touch_screen_element element
@@ -64,21 +64,42 @@ end
64
64
  # Install or reinstall the app on the device
65
65
  def reinstall_app
66
66
 
67
- system( "echo 'Installing the app...'" )
67
+ # If test is in a device
68
+ if( !ENV['APP_BUNDLE_PATH'].include?( "iphonesimulator" ) )
68
69
 
69
- # Trying to reinstall the app
70
- success = system "ios-deploy -r -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
70
+ system( "echo 'Installing the app...'" )
71
71
 
72
- # If the app is not installed the above command will throw an error
73
- # So we just install the app
74
- if !success
75
- success = system "ios-deploy -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
76
- if !success # If there is any error raises an exception
77
- raise 'Error. Could not install the app.'
72
+ # Trying to reinstall the app
73
+ success = system "ios-deploy -r -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
74
+
75
+ # If the app is not installed the above command will throw an error
76
+ # So we just install the app
77
+ if !success
78
+ success = system "ios-deploy -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
79
+ if !success # If there is any error raises an exception
80
+ raise 'Error. Could not install the app.'
81
+ end
78
82
  end
79
- end
80
83
 
81
- system( "echo 'Installed.'" )
84
+ system( "echo 'Installed.'" )
85
+
86
+ sleep(3) # Gives to the iphone a time to finish the installation of the app
87
+ else # If test is in a simulator
88
+
89
+ # APP_BUNDLE_ID must be set in order to uninstall the app from the simulator
90
+ # You can either pass it as a parameter in the cucumber command or set it here
91
+ #ENV["APP_BUNDLE_ID"] = "bundle_id"
82
92
 
83
- sleep(3) # Gives to the iphone a time to finish the installation of the app
93
+ # Reinstalling the app using terminal commands
94
+ system( "echo 'Installing the app...'" )
95
+
96
+ # Removing the app
97
+ %x(xcrun simctl uninstall #{ENV['DEVICE_TARGET']} #{ENV["APP_BUNDLE_ID"]} > /dev/null)
98
+
99
+ # Installing the app
100
+ %x(xcrun simctl install #{ENV['DEVICE_TARGET']} #{ENV['APP_BUNDLE_PATH']} > /dev/null)
101
+
102
+ system( "echo 'Installed.'" )
103
+
104
+ end
84
105
  end
@@ -0,0 +1,38 @@
1
+ ######### <%= I18n.translate( :given ).upcase %> #########
2
+ <%= I18n.translate( :given ).capitalize %>(/^<%= I18n.translate( "steps.drag_until" ) %> "(.*?)"$/) do |direction, element|
3
+ @page.drag_until_element_is_visible_with_special_query direction.to_sym, element
4
+ end
5
+
6
+ <%= I18n.translate( :given ).capitalize %>(/^<%= I18n.translate( "steps.page_contais" ) %> '(.*?)'$/) do |page_text|
7
+ @page.is_on_page? page_text
8
+ end
9
+
10
+ ######### <%= I18n.translate( :when ).upcase %> #########
11
+
12
+ <%= I18n.translate( :when ).capitalize %>(/^<%= I18n.translate( "steps.drag_number_of_times" ) %>$/) do |direction, times|
13
+ @page.drag_for_specified_number_of_times(direction.to_sym, times.to_i)
14
+ end
15
+
16
+ <%= I18n.translate( :when ).capitalize %>(/^<%= I18n.translate( "steps.touch_element" ) %>$/) do |element|
17
+ @page.touch_screen_element element
18
+ end
19
+
20
+ <%= I18n.translate( :when ).capitalize %>(/^<%= I18n.translate( "steps.drag_screen" ) %>$/) do |direction|
21
+ @page.drag_to direction.to_sym
22
+ end
23
+
24
+ ######### <%= I18n.translate( :then ).upcase %> #########
25
+
26
+ <%= I18n.translate( :then ).capitalize %>(/^<%= I18n.translate "steps.wait_progress_bar" %>$/) do
27
+ # wait_for_progress is a method of the base class, so doesn't matter what is the value
28
+ # of the @page variable, because all screens will have this method
29
+ @page.wait_for_progress
30
+ end
31
+
32
+ <%= I18n.translate( :then ).capitalize %>(/^<%= I18n.translate "steps.should_see_page" %> '(.*?)'$/) do |page_text|
33
+ @page.is_on_page? page_text
34
+ end
35
+
36
+ <%= I18n.translate( :then ).capitalize %>(/^<%= I18n.translate "steps.should_see_page_that_contains" %> '(.*?)'$/) do |page_text|
37
+ @page.is_on_page? page_text
38
+ end
@@ -0,0 +1,8 @@
1
+ <%= "# language: #{options[:lang]}" %>
2
+ <%= I18n.translate( :feature ) %>: <%= config[:name] %> <%= !config[:platform].empty? ? I18n.translate( "#{config[:platform].downcase}_only") : "" %>
3
+
4
+ <%= I18n.translate( :background ) %>:
5
+ # <%= I18n.translate( "comments.insert_steps" ) %>
6
+
7
+ <%= I18n.translate( :scenario ) %>: <%= I18n.translate( :first_scenario ) %>
8
+ # <%= I18n.translate( "comments.insert_steps" ) %>
@@ -1,13 +1,13 @@
1
- class ExampleScreen < AndroidScreenBase
1
+ class <%= config[:name] %>Screen < <%= config[:platform] %>ScreenBase
2
2
 
3
- # The screen identificator
3
+ # <%= I18n.translate 'comments.trait' %>
4
4
  #trait(:trait) { "* marked:'#{layout_name}'" }
5
5
 
6
- # Declare all the elements of this screen
6
+ # <%= I18n.translate 'comments.elements' %>
7
7
  #element(:layout_name) {'insert_layout_identificator'}
8
8
  #element(:button) {'insert_button_identificator'}
9
9
 
10
- # Declare all actions of this screen
10
+ # <%= I18n.translate 'comments.actions' %>
11
11
  # action(:touch_button) {
12
12
  # touch("* marked:'#{button}'")
13
13
  # }
@@ -0,0 +1,5 @@
1
+ ######### <%= I18n.translate( :given ).upcase %> #########
2
+
3
+ ######### <%= I18n.translate( :when ).upcase %> #########
4
+
5
+ ######### <%= I18n.translate( :then ).upcase %> #########
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cs-bdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Tanner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: i18n
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.11
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.11
69
+ - !ruby/object:Gem::Dependency
70
+ name: gherkin
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.12.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.12.2
41
83
  description: A simple gem to generate all the folder and files needed to create an
42
84
  android and iOS calabash project.
43
85
  email:
@@ -53,14 +95,12 @@ files:
53
95
  - README.md
54
96
  - Rakefile
55
97
  - bin/cs-bdd
56
- - bin/cs-bdd-generate.rb
57
98
  - bin/cs-bdd-helpers.rb
58
99
  - cs-bdd.gemspec
59
100
  - lib/cs/bdd.rb
101
+ - lib/cs/bdd/locales/en.yml
102
+ - lib/cs/bdd/locales/pt.yml
60
103
  - lib/cs/bdd/version.rb
61
- - lib/examples/example.feature
62
- - lib/examples/example_screen.rb
63
- - lib/examples/example_steps.rb
64
104
  - lib/skeleton/.gitignore
65
105
  - lib/skeleton/README.md
66
106
  - lib/skeleton/config/cucumber.yml
@@ -70,22 +110,20 @@ files:
70
110
  - lib/skeleton/config/scripts/ios/run_tests_all_devices.sh
71
111
  - lib/skeleton/features/android/android_screen_base.rb
72
112
  - lib/skeleton/features/android/features/.gitkeep
73
- - lib/skeleton/features/android/features/android.feature
74
- - lib/skeleton/features/android/screens/example_screen.rb
75
113
  - lib/skeleton/features/android/steps_definition/.gitkeep
76
114
  - lib/skeleton/features/android/support/app_installation_hooks.rb
77
115
  - lib/skeleton/features/android/support/app_life_cycle_hooks.rb
78
116
  - lib/skeleton/features/android/support/hooks.rb
79
- - lib/skeleton/features/example.feature
80
117
  - lib/skeleton/features/ios/features/.gitkeep
81
- - lib/skeleton/features/ios/features/ios.feature
82
118
  - lib/skeleton/features/ios/ios_screen_base.rb
83
- - lib/skeleton/features/ios/screens/example_screen.rb
84
119
  - lib/skeleton/features/ios/steps_definition/.gitkeep
85
120
  - lib/skeleton/features/ios/support/01_launch.rb
86
121
  - lib/skeleton/features/ios/support/02_pre_stop_hooks.rb
87
- - lib/skeleton/features/step_definitions/base_steps.rb
88
122
  - lib/skeleton/features/support/env.rb
123
+ - lib/templates/base_steps.tt
124
+ - lib/templates/feature.tt
125
+ - lib/templates/screen.tt
126
+ - lib/templates/steps.tt
89
127
  homepage: https://github.com/CSOscarTanner/cs-bdd
90
128
  licenses:
91
129
  - MIT
@@ -1,11 +0,0 @@
1
- def generate_skeleton
2
- if File.exists?(@project_dir)
3
- puts "A project directory already exists. Nothing will be done."
4
- exit 1
5
- end
6
-
7
- FileUtils.cp_r(@skeleton_dir, @project_dir)
8
-
9
- puts "Project folder created. \n"
10
-
11
- end
@@ -1,7 +0,0 @@
1
- Feature: |Name| |Platform|
2
-
3
- Background:
4
- # Insert the steps
5
-
6
- Scenario: First Scenario
7
- # Insert the steps
@@ -1,15 +0,0 @@
1
- class |Name|Screen < |Platform|ScreenBase
2
-
3
- # The screen identificator
4
- #trait(:trait) { "* marked:'#{layout_name}'" }
5
-
6
- # Declare all the elements of this screen
7
- #element(:layout_name) {'insert_layout_identificator'}
8
- #element(:button) {'insert_button_identificator'}
9
-
10
- # Declare all actions of this screen
11
- # action(:touch_button) {
12
- # touch("* marked:'#{button}'")
13
- # }
14
-
15
- end
@@ -1,5 +0,0 @@
1
- ######### GIVEN #########
2
-
3
- ######### WHEN #########
4
-
5
- ######### THEN #########
@@ -1,9 +0,0 @@
1
- Feature: Example Android
2
- # This feature will only be executed when the android profile is loaded
3
- # You can rename this file and update its contents or delete it and create new features
4
-
5
- Background:
6
- # Insert the steps
7
-
8
- Scenario: First Scenario
9
- # Insert the steps
@@ -1,9 +0,0 @@
1
- Feature: Example
2
- # This feature will be executed for both SOs
3
- # You can rename this file and update its contents or delete it and create new features
4
-
5
- Background:
6
- # Insert the steps
7
-
8
- Scenario: First Scenario
9
- # Insert the steps
@@ -1,9 +0,0 @@
1
- Feature: Example iOS
2
- # This feature will only be executed when the ios profile is loaded
3
- # You can rename this file and update its contents or delete it and create new features
4
-
5
- Background:
6
- # Insert the steps
7
-
8
- Scenario: First Scenario
9
- # Insert the steps
File without changes
@@ -1,39 +0,0 @@
1
- ######### GIVEN #########
2
-
3
- Given(/^I (?:drag|dragged) the screen (down|up|left|right) until I see the element "(.*?)"$/) do |direction, element|
4
- @page.drag_until_element_is_visible_with_special_query direction.to_sym, element
5
- end
6
-
7
- Given(/^I am on a page that contains '(.*?)'$/) do |page_text|
8
- @page.is_on_page? page_text
9
- end
10
-
11
- ######### WHEN #########
12
-
13
- When(/^I drag the screen (left|right|down|up) (\d+) times$/) do |direction, times|
14
- @page.drag_for_specified_number_of_times(direction.to_sym, times.to_i)
15
- end
16
-
17
- When(/^I (?:touch|touched) the "(.*?)" element$/) do |element|
18
- @page.touch_screen_element element
19
- end
20
-
21
- When(/^I drag the screen (down|up|left|right)$/) do |direction|
22
- @page.drag_to direction.to_sym
23
- end
24
-
25
- ######### THEN #########
26
-
27
- Then(/^I (?:wait|waited) for the progress bar to vanish$/) do
28
- # wait_for_progress is a method of the base class, so doesn't matter what is the value
29
- # of the @page variable, because all screens will have this method
30
- @page.wait_for_progress
31
- end
32
-
33
- Then(/^I should see the page '(.*?)'$/) do |page_text|
34
- @page.is_on_page? page_text
35
- end
36
-
37
- Then(/^I should see a page that contains '(.*?)'$/) do |page_text|
38
- @page.is_on_page? page_text
39
- end