Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predicate filter proposal #1075

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8576e7e
Merge branch 'release/0.16.2'
jmoody Sep 17, 2015
0b9eab1
Merge pull request #856 from calabash/release/0.16.3
jmoody Sep 17, 2015
78d16b2
Merge pull request #865 from calabash/release/0.16.4
jmoody Oct 1, 2015
efb3f13
Merge pull request #946 from calabash/release/0.17.0
jmoody Dec 9, 2015
43de674
Merge pull request #981 from calabash/release/0.17.1
jmoody Jan 14, 2016
dbbe1d7
Merge pull request #988 from calabash/release/0.18.0
jmoody Feb 2, 2016
bcbc1be
Merge pull request #999 from calabash/release/0.18.1
jmoody Feb 19, 2016
ce91975
Merge pull request #1012 from calabash/release/0.18.2
jmoody Mar 11, 2016
fd8f144
Predicate filter proposal
ark-konopacki Apr 19, 2016
9fe8f33
Merge pull request #1079 from calabash/release/0.19.0
jmoody Apr 21, 2016
6c920fe
Merge branch 'develop' of https://github.com/calabash/calabash-ios in…
ark-konopacki Apr 27, 2016
33b2dd8
Added correct_predicate method
ark-konopacki Apr 27, 2016
1650d00
Added rspec tests for correct_predicate
ark-konopacki Apr 27, 2016
03ee1fb
Remove not needed part in test
ark-konopacki Apr 27, 2016
0f0cacc
added correct_format method
ark-konopacki May 10, 2016
282b64d
Review fixes, improvement in correct_predicate? method
ark-konopacki May 11, 2016
4d24fc6
Minor fixes and adding tests
ark-konopacki May 12, 2016
e226c3f
Merge pull request #1104 from calabash/release/0.19.1
jmoody May 20, 2016
7ec6933
Merge pull request #1110 from calabash/release/0.19.2
jmoody Jun 30, 2016
6af4214
Merge pull request #1153 from calabash/release/0.20.0
jmoody Sep 13, 2016
3732a0b
Merge pull request #1206 from calabash/release/0.20.3
jmoody Oct 14, 2016
4753008
Merge pull request #1250 from calabash/release/0.20.4
jmoody Jan 2, 2017
348a902
Merge pull request #1295 from calabash/release/0.20.5
jmoody Apr 19, 2017
90b064f
Merge pull request #1331 from calabash/release/0.21.1
jmoody Sep 22, 2017
a267dda
Merge pull request #4 from calabash/develop
ark-konopacki Oct 20, 2017
6b44569
Merge pull request #1342 from calabash/release/0.21.2
jmoody Nov 1, 2017
ecb035f
Merge pull request #1360 from calabash/release/0.21.4
jmoody Dec 6, 2017
ee7d0cc
Merge pull request #1373 from calabash/release/0.21.5
jmoody Apr 3, 2018
8a69cf1
Gem: bump version to 0.21.6
AlexWellsHS Aug 15, 2018
280f23c
update run_loop dependency version
AlexWellsHS Aug 30, 2018
deb6224
update cocoapod version
AlexWellsHS Aug 30, 2018
f72a770
remove RunLoop::SimControl methods from quit_sim, calabash_sim_reset
AlexWellsHS Aug 30, 2018
4dff0a2
remove SimControl reference from spec resources
AlexWellsHS Aug 30, 2018
e2d974d
remove accessibility methods and callers
AlexWellsHS Aug 31, 2018
2995a64
update .irbrc SimControl references to Simctl
AlexWellsHS Aug 31, 2018
603acef
Merge pull request #1389 from AlexWellsHS/release/0.21.6
jmoody Sep 5, 2018
503e831
Merge remote-tracking branch 'upstream/master' into feature/predicate…
ark-konopacki Sep 5, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Calabash.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions calabash-cucumber/.irbrc
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions calabash-cucumber/bin/calabash-ios
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions calabash-cucumber/bin/calabash-ios-helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 [{<path to .ipa>|<path to .app>}]
check whether an app or ipa is linked with calabash.framework (EXPERIMENTAL)
setup [<path>]
Expand Down
25 changes: 0 additions & 25 deletions calabash-cucumber/bin/calabash-ios-setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions calabash-cucumber/bin/calabash-ios-sim.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion calabash-cucumber/calabash-cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
81 changes: 63 additions & 18 deletions calabash-cucumber/lib/calabash-cucumber/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Cucumber

# @!visibility private
class Map
VALID_PREDICATES = ['BEGINSWITH', 'CONTAINS', 'ENDSWITH', 'LIKE', 'MATCHES', '<', '>']

require "json"
require "calabash-cucumber/http_helpers"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion calabash-cucumber/lib/calabash-cucumber/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions calabash-cucumber/spec/bin/calabash_ios_sim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion calabash-cucumber/spec/lib/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

before(:example) {
RunLoop::SimControl.terminate_all_sims
RunLoop::CoreSimulator.quit_simulator
}

let(:instruments_automator) do
Expand Down
Loading