diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a7a13cd..51a58cd30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.21.6 + +* Removed Frank related code and tests #1378 +* Updated project for blue ocean CI #1379 + ### 0.21.5 This release requires a Calabash iOS Server update. diff --git a/Calabash.podspec b/Calabash.podspec index 1ae276fb9..e3973f565 100644 --- a/Calabash.podspec +++ b/Calabash.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'Calabash' - s.version = '0.21.5' + s.version = '0.21.6' s.license = { :type => 'Eclipse Public License 1.0', :text => <<-LICENSE Calabash-ios Copyright (2016) Xamarin. All rights reserved. The use and distribution terms for this software are covered by the diff --git a/calabash-cucumber/.irbrc b/calabash-cucumber/.irbrc index 81ec28894..5a8dfd79a 100644 --- a/calabash-cucumber/.irbrc +++ b/calabash-cucumber/.irbrc @@ -2,7 +2,7 @@ require 'irb/completion' require 'irb/ext/save-history' require 'benchmark' require 'calabash-cucumber' -require "run_loop" +require 'run_loop' require 'command_runner' AwesomePrint.irb! @@ -45,7 +45,7 @@ puts '' puts '# => Useful Methods <= #' puts '> xcode => Xcode instance' puts '> instruments => Instruments instance' -puts '> simcontrol => SimControl instance' +puts '> simctl => Simctl instance' puts '> default_sim => Default simulator' puts '> verbose => turn on DEBUG logging' puts '> quiet => turn off DEBUG logging' @@ -59,14 +59,14 @@ def instruments @instruments ||= RunLoop::Instruments.new end -def simcontrol - @simcontrol ||= RunLoop::SimControl.new +def simctl + @simctl ||= RunLoop::Simctl.new end def default_sim @default_sim ||= lambda do name = RunLoop::Core.default_simulator(xcode) - simcontrol.simulators.find do |sim| + simctl.simulators.find do |sim| sim.instruments_identifier(xcode) == name end end.call diff --git a/calabash-cucumber/bin/calabash-ios b/calabash-cucumber/bin/calabash-ios index 2f9a1e1e9..63bf712b3 100755 --- a/calabash-cucumber/bin/calabash-ios +++ b/calabash-cucumber/bin/calabash-ios @@ -52,8 +52,6 @@ elsif cmd == 'sim' if subcmd == 'reset' calabash_sim_reset - elsif subcmd == 'acc' - calabash_sim_accessibility elsif subcmd == 'locale' calabash_sim_locale(ARGV) else diff --git a/calabash-cucumber/bin/calabash-ios-helpers.rb b/calabash-cucumber/bin/calabash-ios-helpers.rb index d912f4eaa..6224d00dc 100644 --- a/calabash-cucumber/bin/calabash-ios-helpers.rb +++ b/calabash-cucumber/bin/calabash-ios-helpers.rb @@ -23,8 +23,6 @@ def print_usage change locale and regional settings for an iOS Simulator sim reset reset content and settings in all iOS Simulators - sim acc - enable accessibility in all iOS Simulators check [{|}] check whether an app or ipa is linked with calabash.framework (EXPERIMENTAL) setup [] diff --git a/calabash-cucumber/bin/calabash-ios-setup.rb b/calabash-cucumber/bin/calabash-ios-setup.rb index 8e53d87af..ac09afe13 100644 --- a/calabash-cucumber/bin/calabash-ios-setup.rb +++ b/calabash-cucumber/bin/calabash-ios-setup.rb @@ -2,28 +2,6 @@ require 'rexml/rexml' require "rexml/document" - -def detect_accessibility_support - dirs = Dir.glob(File.join(File.expand_path("~/Library"),"Application Support","iPhone Simulator","*.*","Library","Preferences")) - dirs.each do |sim_pref_dir| - fp = File.expand_path("#{sim_pref_dir}/com.apple.Accessibility.plist") - out = `defaults read "#{fp}" AXInspectorEnabled` - ax_inspector = out.split("\n")[0]=="0" - out = `defaults read "#{fp}" ApplicationAccessibilityEnabled` - app_acc = out.split("\n")[0]=="0" - if not(File.exists?(fp)) || ax_inspector == "0" || app_acc == "0" - msg("Warn") do - puts "Accessibility is not enabled for simulator: #{sim_pref_dir}" - puts "Enabled accessibility as described here:" - puts "https://github.com/calabash/calabash-ios/wiki/01-Getting-started-guide" - puts "Alternatively run command:" - puts "calabash-ios sim acc" - end - end - - end -end - def calabash_setup(args) puts "Checking if Xcode is running..." res = `ps x -o pid,command | grep -v grep | grep Contents/MacOS/Xcode` @@ -34,9 +12,6 @@ def calabash_setup(args) project_name, project_path, xpath = find_project_files(args) setup_project(project_name, project_path, xpath) - calabash_sim_accessibility - detect_accessibility_support - msg("Setup done") do puts "Please validate by running the -cal target" diff --git a/calabash-cucumber/bin/calabash-ios-sim.rb b/calabash-cucumber/bin/calabash-ios-sim.rb index 2f4a95db0..3e4145df4 100644 --- a/calabash-cucumber/bin/calabash-ios-sim.rb +++ b/calabash-cucumber/bin/calabash-ios-sim.rb @@ -1,15 +1,17 @@ require "run_loop" def quit_sim - RunLoop::SimControl.new.quit_sim + RunLoop::CoreSimulator.quit_simulator end def calabash_sim_reset - RunLoop::SimControl.new.reset_sim_content_and_settings -end + xcode = RunLoop::Xcode.new + instruments = RunLoop::Instruments.new + simctl = RunLoop::Simctl.new + + device = RunLoop::Device.detect_device({}, xcode, simctl, instruments) -def calabash_sim_accessibility - RunLoop::SimControl.new.enable_accessibility_on_sims + RunLoop::CoreSimulator.erase(device) end def calabash_sim_locale(args) diff --git a/calabash-cucumber/calabash-cucumber.gemspec b/calabash-cucumber/calabash-cucumber.gemspec index 386347d0a..85530b965 100644 --- a/calabash-cucumber/calabash-cucumber.gemspec +++ b/calabash-cucumber/calabash-cucumber.gemspec @@ -59,7 +59,7 @@ Gem::Specification.new do |s| # Match the xamarin-test-cloud dependency. s.add_dependency('bundler', '~> 1.3') s.add_dependency("clipboard", "~> 1.0") - s.add_dependency("run_loop", ">= 2.6.6", "< 3.0") + s.add_dependency("run_loop", ">= 3.0", "< 4.0") # Shared with run-loop. s.add_dependency('json') diff --git a/calabash-cucumber/lib/calabash-cucumber/map.rb b/calabash-cucumber/lib/calabash-cucumber/map.rb index f897cb821..28a7d27e5 100644 --- a/calabash-cucumber/lib/calabash-cucumber/map.rb +++ b/calabash-cucumber/lib/calabash-cucumber/map.rb @@ -3,6 +3,7 @@ module Cucumber # @!visibility private class Map + VALID_PREDICATES = ['BEGINSWITH', 'CONTAINS', 'ENDSWITH', 'LIKE', 'MATCHES', '<', '>'] require "json" require "calabash-cucumber/http_helpers" @@ -77,28 +78,29 @@ def self.map(query, method_name, *method_args) # # @see map for examples. def self.raw_map(query, method_name, *method_args) - operation_map = { - :method_name => method_name, - :arguments => method_args - } + if correct_predicate?(query) || correct_format?(query) + operation_map = { + :method_name => method_name, + :arguments => method_args + } - route = {:method => :post, :path => "map"} - parameters = {:query => query, - :operation => operation_map} - body = self.map_factory.http(route, parameters) + route = {:method => :post, :path => "map"} + parameters = {:query => query, + :operation => operation_map} + body = self.map_factory.http(route, parameters) - hash = JSON.parse(body) - if hash["outcome"] != "SUCCESS" - message = %Q[ -map #{query}, #{method_name} failed for: + hash = JSON.parse(body) + if hash["outcome"] != "SUCCESS" + message = %Q[ + map #{query}, #{method_name} failed for: + reason: #{hash["reason"]} + details: #{hash["details"]} + ] + self.map_factory.screenshot_and_raise(message) + end - reason: #{hash["reason"]} -details: #{hash["details"]} -] - self.map_factory.screenshot_and_raise(message) + hash end - - hash end # Asserts the result of a calabash `map` call and raises an error with @@ -143,6 +145,49 @@ def self.assert_map_results(map_results, msg) end end + # Return predicate section of query + def self.query_predicate(query) + query.match(/{.*}/) + end + + # Evaluating whether a query contain correct predicate selector + # and if predicate string contain two ' char + # returns true or raise an exceptions + def self.correct_predicate?(query) + match = query_predicate(query) + if !match.nil? + correct = false + predicates = VALID_PREDICATES + predicates.each do |value| + if match.to_s.include?(value) + correct = true + end + end + if !match.to_s.match(/{.*'.*'.*}/).nil? && correct + true + else + raise("Incorrect predicate used, valid operation are: #{predicates}") + end + end + end + + # Evaluating whether a query contain two ' characters + # returns true if query include : character and two ' characters + # like query("label marked:'label'") + # returns true or raise an exceptions + # TODO: We can add additional verification in future + def self.correct_format?(query) + if !query.match(/:'/).nil? && query_predicate(query).nil? + if !query.match(/:'.*'/).nil? + true + else + raise('Incorrect query format please check query string') + end + elsif !query_predicate(query).nil? + else + true + end + end private def self.map_factory diff --git a/calabash-cucumber/lib/calabash-cucumber/version.rb b/calabash-cucumber/lib/calabash-cucumber/version.rb index 9b15affce..c8adfdfad 100644 --- a/calabash-cucumber/lib/calabash-cucumber/version.rb +++ b/calabash-cucumber/lib/calabash-cucumber/version.rb @@ -3,7 +3,7 @@ module Cucumber # @!visibility public # The Calabash iOS gem version. - VERSION = "0.21.5" + VERSION = "0.21.6" # @!visibility public # The minimum required version of the Calabash embedded server. diff --git a/calabash-cucumber/spec/bin/calabash_ios_sim_spec.rb b/calabash-cucumber/spec/bin/calabash_ios_sim_spec.rb index 5d3fe3737..e43ddf39d 100644 --- a/calabash-cucumber/spec/bin/calabash_ios_sim_spec.rb +++ b/calabash-cucumber/spec/bin/calabash_ios_sim_spec.rb @@ -3,20 +3,24 @@ require File.expand_path(File.join(__FILE__, '..', '..', '..', 'bin', 'calabash-ios-sim')) it '#quit_sim' do - sim_control = RunLoop::SimControl.new - sim_control.launch_sim + xcode = RunLoop::Xcode.new + instruments = RunLoop::Instruments.new + simctl = RunLoop::Simctl.new + + device = RunLoop::Device.detect_device({}, xcode, simctl, instruments) + app = RunLoop::App.new(Resources.shared.app_bundle_path(:cal_smoke_app)) + + core_sim = RunLoop::CoreSimulator.new(device, app) + core_sim.launch_simulator quit_sim - expect(sim_control.sim_is_running?).to be == false + + expect(core_sim.simulator_requires_relaunch?).to be_truthy end it '#calabash_sim_reset' do calabash_sim_reset end - it '#calabash_sim_accessibility' do - calabash_sim_accessibility - end - describe "#calabash_sim_locale" do it "prints a helpful message with no args" do actual = true diff --git a/calabash-cucumber/spec/lib/launcher_spec.rb b/calabash-cucumber/spec/lib/launcher_spec.rb index dbecbe883..af3caad4f 100644 --- a/calabash-cucumber/spec/lib/launcher_spec.rb +++ b/calabash-cucumber/spec/lib/launcher_spec.rb @@ -17,7 +17,7 @@ end before(:example) { - RunLoop::SimControl.terminate_all_sims + RunLoop::CoreSimulator.quit_simulator } let(:instruments_automator) do diff --git a/calabash-cucumber/spec/lib/map_spec.rb b/calabash-cucumber/spec/lib/map_spec.rb index 53b59d273..ed596583a 100644 --- a/calabash-cucumber/spec/lib/map_spec.rb +++ b/calabash-cucumber/spec/lib/map_spec.rb @@ -1,10 +1,11 @@ describe Calabash::Cucumber::Map do - + RSpec::Expectations.configuration.warn_about_potential_false_positives = false let(:query) { "view marked:'my mark'" } let(:method_name) { :scrollToViewWithMark } let(:args) { ["arg0", "arg1", "arg2"] } let(:map) { Calabash::Cucumber::Map.new } + let(:correct_predicate) {Calabash::Cucumber::Map::VALID_PREDICATES} it ".map_factory" do actual = Calabash::Cucumber::Map.send(:map_factory) @@ -40,5 +41,153 @@ /map view marked:'my mark', scrollToViewWithMark failed for:/) end end + + describe ".raw_map" do + let(:query) { "view marked:'my mark'" } + let(:incorrect_predicate) {['BEGINSWTH', 'CONTAIN', 'ENDWITH', 'LKE' 'MTCHES']} + + it "receive incorrect predicate operation and raise error" do + + incorrect_predicate.each do |predicate| + merged_query = query + "{text #{predicate} 'sometext'}" + expect do + Calabash::Cucumber::Map.raw_map(merged_query, method_name, args) + end.to raise_error(RuntimeError, + /Incorrect predicate used, valid operation are:/) + end + + end + + it "receive correct predicate operation but incomplete string and raise error" do + + correct_predicate.each do |predicate| + merged_query = query + "{text #{predicate} 'sometext}" + expect do + Calabash::Cucumber::Map.raw_map(merged_query, method_name, args) + end.to raise_error(RuntimeError, + /Incorrect predicate used, valid operation are:/) + end + + end + + it "raw_map receive correct predicate and not raise error" do + + correct_predicate.each do |predicate| + merged_query = query + "{text #{predicate} 'sometext'}" + expect do + Calabash::Cucumber::Map.raw_map(merged_query, method_name, args) + end.not_to raise_error(RuntimeError) + end + + end + end + + describe ".correct_predicate?" do + let(:query) { "view" } + + it "receive query without predicate and return nil" do + expect(Calabash::Cucumber::Map.correct_predicate?(query)).to be nil + end + + it "receive query with correct predicate and return true" do + correct_predicate_operation = ["{text BEGINSWITH 'Cell 1'}", + "{text ENDSWITH '10'}", + "{text LIKE 'C*ll'}", + "{text CONTAINS 'ell'}", + "{text > 'ell'}", + "{text < 'ell'}"] + correct_predicate_operation.each do |predicate| + merged_query = query + predicate + expect(Calabash::Cucumber::Map.correct_predicate?(merged_query)).to be true + end + end + + it "receive query with incorrect predicate operation and raise error" do + test_data = ["{text BEGINWITH 'Cell 1'}", + "{text ENDSITH '10'}", + "{text LIK 'C*ll'}", + "{text CONTAIN 'ell'}", + "{text = 'ell'}", + "{text - 'ell'}"] + test_data.each do |predicate| + merged_query = query + predicate + expect do + Calabash::Cucumber::Map.correct_predicate?(merged_query) + end.to raise_error(RuntimeError) + end + end + + it "receive query with correct predicate operation \ + but incomplete string and raise error" do + test_data = ["{text BEGINSWITH Cell 1'}", + "{text BEGINSWITH 'Cell 1}", + "{text ENDSWITH 10'}", + "{text ENDSWITH '10}", + "{text LIKE C*ll'}", + "{text LIKE 'C*ll}", + "{text CONTAINS ell'}", + "{text CONTAINS 'ell}", + "{text > ell'}", + "{text > 'ell}", + "{text < ell'}", + "{text < 'ell}"] + test_data.each do |predicate| + merged_query = query + predicate + expect do + Calabash::Cucumber::Map.correct_predicate?(merged_query) + end.to raise_error(RuntimeError) + end + end + + it "receive query with correct predicate operation \ + and diacritic lookups and return true" do + lookup = ['c', 'd', 'cd'] + correct_predicate.each do |predicate| + lookup.each do |item| + merged_query = query + "{text #{predicate}[#{item}] 'sometext'}" + expect(Calabash::Cucumber::Map.correct_predicate?(merged_query)).to be true + end + end + end + + it "receive query with correct predicate operation \ + and diacritic lookup but incomplete string and raise error" do + lookup = ['c', 'd', 'cd'] + correct_predicate.each do |predicate| + lookup.each do |item| + merged_query = query + "{text #{predicate}[#{item}] 'sometext}" + expect do + Calabash::Cucumber::Map.correct_predicate?(merged_query) + end.to raise_error(RuntimeError) + end + end + end + end + + describe ".correct_format?" do + let(:query) { "view" } + + it "receive query with predicate and return nil" do + merged_query = query + "{text BEGINSWITH 'Cell 1'}" + expect(Calabash::Cucumber::Map.correct_format?(merged_query)).to be nil + end + + it "receive query without predicate and return true" do + expect(Calabash::Cucumber::Map.correct_format?(query)).to be true + end + + it "receive query with id and return true" do + merged_query = query + "id:'some_id'" + expect(Calabash::Cucumber::Map.correct_format?(merged_query)).to be true + end + + it "receive query with id and incomplete sting and raise error" do + merged_query = query + "id:'some_id" + expect do + Calabash::Cucumber::Map.correct_format?(merged_query) + end.to raise_error(RuntimeError) + end + end + end diff --git a/calabash-cucumber/spec/resources.rb b/calabash-cucumber/spec/resources.rb index 22236aee9..e8fae7ab2 100644 --- a/calabash-cucumber/spec/resources.rb +++ b/calabash-cucumber/spec/resources.rb @@ -20,10 +20,6 @@ def simctl @simctl ||= RunLoop::Simctl.new end - def sim_control - @sim_control ||= RunLoop::SimControl.new - end - def instruments @instruments ||= RunLoop::Instruments.new end