From 023db86867ecc96d2838723184b94ee381394d3a Mon Sep 17 00:00:00 2001 From: Carlos Alarcon Date: Fri, 20 Oct 2017 18:56:06 +0200 Subject: [PATCH 1/5] add reverse geo --- .idea/workspace.xml | 3499 +---------------- Rakefile | 31 +- features/aditional_parameters.feature | 3 +- features/mandatory_parameters.feature | 63 +- features/reverse.feature | 64 + features/status_code.feature | 53 +- .../step_definitions/geolocation-api-steps.rb | 56 +- .../helpers/address_component.rb | 2 +- .../helpers/helper-to-be use.rb | 76 +- .../helpers/transformation.rb | 20 +- 10 files changed, 366 insertions(+), 3501 deletions(-) create mode 100644 features/reverse.feature diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5d69127..3db424e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,3335 +2,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -3407,18 +47,20 @@ @@ -3567,23 +209,23 @@ - - + - - + + - + @@ -3606,12 +248,27 @@ - file://$PROJECT_DIR$/features/step_definitions/geolocation-api-steps.rb - 24 - + + file://$PROJECT_DIR$/features/step_definitions/helpers/helper-to-be use.rb + 72 + + + file://$PROJECT_DIR$/features/step_definitions/helpers/helper-to-be use.rb + 77 + + + file://$PROJECT_DIR$/features/step_definitions/helpers/helper-to-be use.rb + 40 + - @@ -3770,14 +427,6 @@ - - - - - - - - @@ -3794,66 +443,82 @@ + + + + + + + + - - + + - + - - + + - + - - + + - + - - + + - - + + - + + + + + + + + + - - + + - - + + - + - - + + diff --git a/Rakefile b/Rakefile index 9502310..5acfc3f 100644 --- a/Rakefile +++ b/Rakefile @@ -8,8 +8,6 @@ require 'cukeforker' require 'cukeforker/rake_task' require 'jsonpath' -#require 'cuke_sniffer' - require 'report_builder' task "move_to_test_directory" do @@ -17,10 +15,15 @@ task "move_to_test_directory" do end Cucumber::Rake::Task.new("running_geo_api_tests") do |t| - # t.cucumber_opts = ["--tags", "@carlos", "--tags", "~@pend", "--format", "html", "--out", "report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format", "rerun", "--out", "rerun.txt"] + # t.cucumber_opts = ["--tags", "@carlos", "--tags", "~@pend", "--format", "html", "--out", "report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format", "rerun", "--out", "rerun.txt"] t.cucumber_opts = ["--tags", "@carlos"] end +Cucumber::Rake::Task.new("running_all_tests") do |t| + # t.cucumber_opts = ["--tags", "@carlos", "--tags", "~@pend", "--format", "html", "--out", "report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format", "rerun", "--out", "rerun.txt"] + t.cucumber_opts = ["--tags", "~@pend"] +end + # Cucumber::Rake::Task.new("running_parallel_geo_api_tests") do # CukeForker::Runner.run CukeForker::Scenarios.all # #extra_args: %W[-f CukeForker::Formatters::JunitScenarioFormatter --out results/junit] @@ -28,28 +31,30 @@ end task :cleanup_cuke_forker do puts " ========Deleting old reports and logs=========" - #FileUtils.rm_rf('reports/test_report') - Dir.mkdir("features/reports/test_report") + FileUtils.rm_rf('features/tmp_reports') + Dir.mkdir('features/tmp_reports') + ReportBuilder.configure do |config| - config.json_path = 'reports/test_report' - config.report_path = 'reports/test_report' - config.report_tabs = [:overview, :features, :scenarios, :errors] + config.json_path = 'features/tmp_reports' + config.report_path = 'reports' + config.report_tabs = [:overview, :features, :scenarios, :errors] config.report_title = 'Test Results' - config.report + #config.report end end + task :all do Rake::Task['cleanup_cuke_forker'].invoke puts "===== Executing Tests in parallel" Dir.chdir('features/') - CukeForker::Runner.run CukeForker::Scenarios.tagged('@carlos'), {:max => 10, - :log => true, :format => :json, :out => 'reports/test_report'} + CukeForker::Runner.run CukeForker::Scenarios.tagged('@carlos'), {:max => 20, + :log => true, :format => :json, :out => 'features/tmp_reports'} puts "===== End Executing Tests in parallel" puts "===== Executing report" + #Dir.chdir('/') ReportBuilder.build_report puts "===== End Executing report" - -end \ No newline at end of file +end diff --git a/features/aditional_parameters.feature b/features/aditional_parameters.feature index 3491cb6..0e73bb7 100644 --- a/features/aditional_parameters.feature +++ b/features/aditional_parameters.feature @@ -11,7 +11,8 @@ Feature: Cover the happy path case | address_value | | 88+Colin+P+Kelly+Jr+St,+San+Francisco | - #additional parameters + + #additional parameters #bounds #language #region diff --git a/features/mandatory_parameters.feature b/features/mandatory_parameters.feature index b839d09..8e6859e 100644 --- a/features/mandatory_parameters.feature +++ b/features/mandatory_parameters.feature @@ -1,4 +1,4 @@ -@valid +@ok Feature: Cover the happy path case Scenario Outline: valid Address @@ -7,19 +7,21 @@ Feature: Cover the happy path case | address | | | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | Then I see response with status 'OK' + And I see first response formatted_address '' + And I see first response contains '' geographic coordinates Examples: - | address_value | - | 88+Colin+P+Kelly+Jr+St,+San+Francisco | - | 88 Colin P Kelly Jr St,+San Francisco | - | 94107 | - | San Francisco | - | 94107, San Francisco | - | 94107, California | - | Co Road 82 | - | State 82 | - | U.S. 101 | - | Interstate 280 | + | address_value | formatted_address | location_type | + | 88+Colin+P+Kelly+Jr+St,+San+Francisco | 88 Colin P Kelly Jr St, San Francisco, CA 94107, USA | ROOFTOP | + | 88 Colin P Kelly Jr St,+San Francisco | 88 Colin P Kelly Jr St, San Francisco, CA 94107, USA | ROOFTOP | + | 94107 | San Francisco, CA 94107, USA | APPROXIMATE | + | San Francisco | San Francisco, CA, USA | APPROXIMATE | + | 94107, San Francisco | San Francisco, CA 94107, USA | APPROXIMATE | + | 94107, California | San Francisco, CA 94107, USA | APPROXIMATE | + | Co Road 82 | County Rd 82 SE, Minnesota, USA | GEOMETRIC_CENTER | + | State 82 | FL-82, Fort Myers, FL, USA | GEOMETRIC_CENTER | + # | U.S. 101 | US-101, United States | GEOMETRIC_CENTER | + | Interstate 280 | I-280, California, USA | GEOMETRIC_CENTER | Scenario Outline: valid components When I successfully browse to the url @@ -27,19 +29,20 @@ Feature: Cover the happy path case | components | | | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | Then I see response with status 'OK' + And I see first response formatted_address '' + And I see first response contains '' geographic coordinates Examples: - | components_value | - | route:Annegatan | - | locality:La Palma | - | administrative_area:Huelva | - | postal_code:94107 | - | country:Spain | - | locality:La Palma \|country:Spain | - | locality:La Palma \|administrative_area:Huelva | - | locality:La Palma \|administrative_area:Huelva \|country:Spain | - - @carlos + | components_value | formatted_address | location_type | + | route:Annegatan | Annankatu, 00101 Helsinki, Finland | GEOMETRIC_CENTER | + | locality:La Palma | La Palma, CA, USA | APPROXIMATE | + | administrative_area:Huelva | Huelva, Spain | APPROXIMATE | + | postal_code:94107 | San Francisco, CA 94107, USA | APPROXIMATE | + | country:Spain | Spain | APPROXIMATE | + | locality:La Palma \|country:Spain | 30593 La Palma, Murcia, Spain | APPROXIMATE | + | locality:La Palma \|administrative_area:Huelva | 21700 La Palma del Condado, Huelva, Spain | APPROXIMATE | + | locality:La Palma \|administrative_area:Huelva \|country:Spain | 21700 La Palma del Condado, Huelva, Spain | APPROXIMATE | + Scenario: valid Address and components When I successfully browse to the url | parameter | value | @@ -47,8 +50,20 @@ Feature: Cover the happy path case | components | administrative_area:Huelva\|postal_code:21002 | | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | Then I see response with status 'OK' - And I see response contains an address_component + And I see first response contains an address_component | type | attribute | value | | administrative_area_level_2 | short_name | Huelva | + And I see first response contains 'ROOFTOP' geographic coordinates + + Scenario: several responses + When I successfully browse to the url + | parameter | value | + | address | Calle Real | + | components | country:Spain | + | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | + And I see 'GEOMETRIC_CENTER' response contains a formatted_address 'Calle Real, San Sebastián de los Reyes, Madrid, Spain' + And I see all results contains an address_component + | type | attribute | value | + | country | short_name | ES | diff --git a/features/reverse.feature b/features/reverse.feature new file mode 100644 index 0000000..32438a8 --- /dev/null +++ b/features/reverse.feature @@ -0,0 +1,64 @@ +@ok +Feature: reverse geolocation + + Scenario: valid latlng + When I successfully browse to the url + | parameter | value | + | latlng | 37.78226710000001,-122.3912479 | + | language | EN | + | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | + Then I see response with status 'OK' + And I see 'ROOFTOP' responses contains a formatted_address '88 Colin P Kelly Jr St, San Francisco, CA 94107, USA' + And I see all results contains an address_component + | type | attribute | value | + | administrative_area_level_1 | short_name | CA | + | country | short_name | US | + + Scenario: valid place_id + When I successfully browse to the url + | parameter | value | + | place_id | ChIJd8BlQ2BZwokRAFUEcm_qrcA | + | language | EN | + | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | + Then I see response with status 'OK' + And I see 'ROOFTOP' responses contains a formatted_address '277 Bedford Ave, Brooklyn, NY 11211, USA' + And I see first response contains 'ROOFTOP' geographic coordinates + And I see all results contains an address_component + | type | attribute | value | + | administrative_area_level_1 | short_name | NY | + | country | short_name | US | + + Scenario Outline: TBD invalid latlng + When I unsuccessfully browse to the url + | parameter | value | + | latlng | , | + | language | EN | + | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | + Then I see response with status 'INVALID_REQUEST' + And I see response message 'Invalid request. Invalid 'latlng' parameter.' + + Examples: + | lat | lng | + | 37.78226710000001N | -122.3912479N | + | 37.78226710000001$ | -122.3912479N$ | + | 37.78226710000001& | -122.3912479 | + | AAA | -122.3912479 | + | 37.78226710000001 | AAB | + | N37.78226710000001 | -122.3912479N | + + Scenario Outline: TBD invalid place_id + When I unsuccessfully browse to the url + | parameter | value | + | place_id | | + | language | EN | + | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | + Then I see response with status 'INVALID_REQUEST' + And I see response message 'Invalid request. Invalid 'place_id' parameter.' + + Examples: + | place_id | + | Invalid | + | Invalid Placce Id | + | AAAChIJd8BlQ2BZwokRAFUEcm_qrcA | + + #ZERO_RESULTS? \ No newline at end of file diff --git a/features/status_code.feature b/features/status_code.feature index 6d1f648..11f5eb8 100644 --- a/features/status_code.feature +++ b/features/status_code.feature @@ -1,20 +1,44 @@ -@status_code @carlos2 +@status_code @ok + #codigos: + #OK -> en validos + #ZERO_RESULTS -> ok + #OVER_QUERY_LIMITS -> mas de 50 en 1 segundo. Performance! + #REQUEST_DENIED -> ok + #INVALID_REQUEST -> ok. with no parameters + #UNKNOWN_ERROR -?? Feature: Cover the happy path case Scenario Outline: check body code - When I browse to the url + When I successfully browse to the url | parameter | value | | address | | | components | | | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | Then I see response with status '' + And I don't see first response contains geographic coordinates + + Examples: + | address_value | component_value | status_code | + | 0000000 | empty | ZERO_RESULTS | + | 6 Los Mozarabes | administrative_area:Lyon\|postal_code:94107 | ZERO_RESULTS | + | empty | administrative_area:Lyon\|postal_code:94107 | ZERO_RESULTS | + + Scenario Outline: check body code + When I unsuccessfully browse to the url + | parameter | value | + | | | + | | | + | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | + Then I see response with status '' + And I don't see first response contains geographic coordinates + And I see response message 'Invalid request. Missing the 'address', 'bounds', 'components', 'latlng' or 'place_id' parameter.' Examples: - | answer | address_value | component_value | status_code | - | successfully | 0000000 | empty | ZERO_RESULTS | - | successfully | 6 Los Mozarabes | administrative_area:Lyon\|postal_code:94107 | ZERO_RESULTS | - | successfully | empty | administrative_area:Lyon\|postal_code:94107 | ZERO_RESULTS | - | unsuccessfully | none | none | INVALID_REQUEST | + | address_name | address_value | components_name | component_value | status_code | + | address | none | components | none | INVALID_REQUEST | + | addres | none | none | none | INVALID_REQUEST | + | none | none | none | none | INVALID_REQUEST | + Scenario: check body code When I successfully browse to the url @@ -23,18 +47,5 @@ Feature: Cover the happy path case | key | invalid_key | Then I see response with status 'REQUEST_DENIED' - @performance @pend - Scenario: check body code - When I launch 100 requests with - | parameter | value | - | address | 6 Los Mozarabes | - | key | AIzaSyDLy4-E74lM7BHFgzC189ZhAuAGWl5jcl4 | - Then I see response with status 'REQUEST_DENIED' - #codigos - #OK -> en validos - #ZERO_RESULTS -> ok - #OVER_QUERY_LIMITS -> mas de 50 en 1 segundo. Performance! - #REQUEST_DENIED -> ok - #INVALID_REQUEST -> ok. with no parameters - #UNKNOWN_ERROR -?? + diff --git a/features/step_definitions/geolocation-api-steps.rb b/features/step_definitions/geolocation-api-steps.rb index f44dfd1..df46708 100644 --- a/features/step_definitions/geolocation-api-steps.rb +++ b/features/step_definitions/geolocation-api-steps.rb @@ -1,7 +1,15 @@ require 'httparty' require 'jsonpath' -When /^I (successfully|unsuccessfully) browse to the url$/ do |http_status, table| +def toInt(position) + return %w(last first second third fourth fifth sixth seventh eigth ninth tenth).index(position) - 1 +end + +CAPTURE_POSITION = Transform(/^(last|first|second|third|fourth|fifth|sixth|seventh|eigth|ninth|tenth)$/) do |v| + toInt(v) +end + +When /^I (successfully|unsuccessfully) browse to the url$/ do |status, table| param_options = convertTableToHash(table, 'parameter', 'value') @response = HTTParty.get(URL, query: param_options) @@ -11,17 +19,55 @@ @response_body = symb_body_resp #puts @response_body - check_response_code(http_status, response_code) + check_response_code(status, response_code) end Then /^I see response with status '(.*)'$/ do |status| expect(get_resp_status).to eq(status) end -Then /^I see response contains an address_component$/ do |table| +Then /^I see response message '(.*)'$/ do |status| + expect(get_resp_error_message).to eq(status) +end + +Then /^I see (#{CAPTURE_POSITION}) response contains an address_component$/ do |pos, table| table.hashes.each do |row| - adr = address_com(row['type']) - #expect(adr.row['attribute']).to include(value) + adr = address_com(pos, row['type']) expect(adr.short_name).to include(row['value']) end +end + +Then /^I see all results contains an address_component$/ do |table| + table.hashes.each do |row| + puts check_result_obj(row['type'], row['attribute'], row['value']) + expect(check_result_obj(row['type'], row['attribute'], row['value']).include? false).to be false + end +end + +Then /^I (see|don't see) (#{CAPTURE_POSITION}) response contains(?: '(\w+)')? geographic coordinates$/ do |option, pos, location_type| + if option == 'see' + expect(geo_coord(pos).key?(:lat)).to be true + expect(geo_coord(pos).key?(:lng)).to be true + expect(geo_coord_type(pos)).to eq(location_type) + else + expect(result_coord(pos).nil?).to be true + expect(result_coord(pos).nil?).to be true + end +end + +Then /^I (see|don't see) (#{CAPTURE_POSITION}) response formatted_address '(.*)'$/ do |option, pos, value| + if option == 'see' + expect(formateed_address(pos)).to eq(value) + else + pending + end +end + +def num_results + symb_body_resp[:results].count +end + +Then /^I see '(.*)' response(?:s)? contains a formatted_address '(.*)'$/ do |location_type, value| + all_formateed_address = symb_body_resp[:results].map { |resp| resp[:formatted_address] if resp[:geometry][:location_type] == location_type }.compact + expect(all_formateed_address).to include(value) end \ No newline at end of file diff --git a/features/step_definitions/helpers/address_component.rb b/features/step_definitions/helpers/address_component.rb index 8d82cfa..0cb6e7f 100644 --- a/features/step_definitions/helpers/address_component.rb +++ b/features/step_definitions/helpers/address_component.rb @@ -7,4 +7,4 @@ def initialize(hash) @long_name, @short_name, @types = hash.values_at(:long_name, :short_name, :types) end -end \ No newline at end of file +end diff --git a/features/step_definitions/helpers/helper-to-be use.rb b/features/step_definitions/helpers/helper-to-be use.rb index d40362f..094365c 100644 --- a/features/step_definitions/helpers/helper-to-be use.rb +++ b/features/step_definitions/helpers/helper-to-be use.rb @@ -1,7 +1,7 @@ def check_response_code(status, response_code) if status == 'successfully' expect(response_code).to eq(200) - get_address_com(symb_body_resp) + #get_address_com(symb_body_resp) unless result_coord.nil? else expect(response_code).not_to eq(200) end @@ -15,8 +15,44 @@ def get_resp_status symb_body_resp[:status] end -def get_address_com(resp_syb) - arry_add_comp = resp_syb[:results][0][:address_components] +def get_resp_error_message + symb_body_resp[:error_message] +end + +def get_adr_obj_from_result(result) + result[:address_components].map { |h| Address_component.new(h) } +end + +def get_resultados_json + symb_body_resp[:results] +end + +def get_all_obj_from_json + get_resultados_json.map { |result| get_adr_obj_from_result(result) } +end + +def check_all_adr_obj(atr, value) + get_all_obj_from_json.map { |result|} +end + +#check if all objets in a response contains an atr:value +def check_result_adr_obj(result, type, atr, value) + #get_adr_obj_from_result(result).map { |adr| return (adr.send atr) == value if adr.types.include? type }.include? true + get_adr_obj_from_result(result).map { |adr| return (adr.send atr) == value if adr.types.include? type }.include? true +end + + +#check if all objets in all responses contains an address objet with type and atr:value +def check_result_obj(type, atr, value) + get_resultados_json.map { |result| check_result_adr_obj(result, type, atr, value) } +end + + + + + +def get_address_com(pos) + arry_add_comp = symb_body_resp[:results][pos][:address_components] @add_comp = arry_add_comp.map { |h| Address_component.new(h) } end @@ -25,15 +61,35 @@ def geometry symb_body_resp[:results][0][:geometry] end -def address_com(type_value) - #@add_comp.map {|item| item."#{field}"} - #@add_comp.map { |item| item if item.types.include?(type_value) }.compact.first - @add_comp.map { |item| item if check_type(item.types, type_value) }.compact.first +def all_address_obj + symb_body_resp[:results].map { |result| result[:address_components] } +end + +def get_addr(response, atrr, type) + response.map { |adr| adr[:atrr] if adr[:short_name] == 'CA' }.compact +end - #@add_comp[0].types.select { |str| str.include?('casa') } - #@add_comp.map { |item| item if item.field.include?(value) }.compact.first +def address_com(pos, type_value) + get_address_com(pos) + @add_comp.map { |item| item if check_type(item.types, type_value) }.compact.first end def check_type(type, value) - type.any? {|e| e.include? value} + type.any? { |e| e.include? value } +end + +def geo_coord(pos) + symb_body_resp[:results][pos][:geometry][:location] +end + +def geo_coord_type(pos) + symb_body_resp[:results][pos][:geometry][:location_type] +end + +def result_coord(pos = 0) + symb_body_resp[:results][pos] +end + +def formateed_address(pos) + symb_body_resp[:results][pos][:formatted_address] end \ No newline at end of file diff --git a/features/step_definitions/helpers/transformation.rb b/features/step_definitions/helpers/transformation.rb index cb8ac01..df524bb 100644 --- a/features/step_definitions/helpers/transformation.rb +++ b/features/step_definitions/helpers/transformation.rb @@ -7,17 +7,19 @@ def convertTableToHash(table, key, value) # skip if filter name is nil or empty next if filterName.to_s.strip.length == 0 - unless filterValue == 'none' - if result.has_key?(filterName) - tmp = result[filterName]; - if (tmp.kind_of?(Array)) - tmp.push(filterValue); + unless filterName == 'none' + unless filterValue == 'none' + if result.has_key?(filterName) + tmp = result[filterName]; + if (tmp.kind_of?(Array)) + tmp.push(filterValue); + else + tmp = [tmp, filterValue]; + result[filterName] = tmp; + end else - tmp = [tmp, filterValue]; - result[filterName] = tmp; + result[filterName] = filterValue; end - else - result[filterName] = filterValue; end end end From fb077dfdf09821452c6d704658d6207fdd6a3833 Mon Sep 17 00:00:00 2001 From: Carlos Alarcon Date: Sat, 21 Oct 2017 12:25:18 +0200 Subject: [PATCH 2/5] add parallel execution --- .idea/testingGoogleGeocodingAPI.iml | 28 +- .idea/workspace.xml | 315 +++++++++++++----- .rubocop.yml | 37 ++ Gemfile | 6 +- Gemfile.lock | 8 +- Rakefile | 23 +- config/cucumber.yaml | 4 + cucumber_failures.log | 0 .../geocoding_mandatory_params.feature} | 19 +- .../geocoding_optional_params.feature} | 5 +- .../geocoding_status_code.feature} | 25 +- features/reverse.feature | 64 ---- ...reverse_geocoding_mandatory_params.feature | 27 ++ .../reverse_geocoding_status_code.feature | 33 ++ features/step_definitions/geo_api_steps.rb | 66 ++++ .../step_definitions/geolocation-api-steps.rb | 73 ---- .../helpers/address_component.rb | 4 +- .../helpers/helper-to-be use.rb | 95 ------ .../step_definitions/helpers/helper_geo.rb | 78 +++++ .../{transformation.rb => table_transform.rb} | 16 +- features/support/env.rb | 13 +- 21 files changed, 544 insertions(+), 395 deletions(-) create mode 100644 .rubocop.yml create mode 100644 config/cucumber.yaml create mode 100644 cucumber_failures.log rename features/{mandatory_parameters.feature => geocoding/geocoding_mandatory_params.feature} (85%) rename features/{aditional_parameters.feature => geocoding/geocoding_optional_params.feature} (64%) rename features/{status_code.feature => geocoding/geocoding_status_code.feature} (67%) delete mode 100644 features/reverse.feature create mode 100644 features/reverse_geocoding/reverse_geocoding_mandatory_params.feature create mode 100644 features/reverse_geocoding/reverse_geocoding_status_code.feature create mode 100644 features/step_definitions/geo_api_steps.rb delete mode 100644 features/step_definitions/geolocation-api-steps.rb delete mode 100644 features/step_definitions/helpers/helper-to-be use.rb create mode 100644 features/step_definitions/helpers/helper_geo.rb rename features/step_definitions/helpers/{transformation.rb => table_transform.rb} (62%) diff --git a/.idea/testingGoogleGeocodingAPI.iml b/.idea/testingGoogleGeocodingAPI.iml index 1eb6083..783c891 100644 --- a/.idea/testingGoogleGeocodingAPI.iml +++ b/.idea/testingGoogleGeocodingAPI.iml @@ -121,16 +121,6 @@ - - - - - - - - - - @@ -248,12 +238,24 @@ - + + + + + + + + + + + - + + - + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3db424e..d10390a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,21 @@ + + + + + + + + + + + - - - - - - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + @@ -39,6 +95,16 @@ + + + @response + get_all_obj_from_json + I see all results contains an address_component + + + $PROJECT_DIR$/features + + @@ -47,19 +113,31 @@ @@ -110,20 +188,12 @@ - + - - - - - - - - @@ -206,7 +207,7 @@ - + @@ -236,7 +237,25 @@ - + + + + + + + + + + + + + + + + + + + @@ -259,6 +278,15 @@ + + + + + + + + + - - + - + @@ -538,14 +566,6 @@ - - - - - - - - @@ -586,39 +606,63 @@ - + - - + + - + + + + + + + + + - - + + - + - + - + - - + + - + + + + + + + + + + + + + + + + + @@ -626,26 +670,42 @@ - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + @@ -658,18 +718,74 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + diff --git a/Rakefile b/Rakefile index 261112d..1abc7ce 100644 --- a/Rakefile +++ b/Rakefile @@ -1,71 +1,67 @@ -# encoding: utf-8 - -#require 'rubygems' require 'cucumber' require 'cucumber/rake/task' - require 'cukeforker' require 'cukeforker/rake_task' -require 'jsonpath' require 'report_builder' -task "move_to_test_directory" do - Dir.chdir('features') -end +processes = ENV['processes'] || 10 -processes = ENV['processes'] || 5 -Cucumber::Rake::Task.new("running_geo_api_tests") do |t| - # t.cucumber_opts = ["--tags", "@carlos", "--tags", "~@pend", "--format", "html", "--out", "report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format", "rerun", "--out", "rerun.txt"] - t.cucumber_opts = ["--tags", "@carlos"] +task 'running_geo_api_tests' do + t.cucumber_opts = ["--tags", "@carlos", "--tags", "~@pend", "--format", "report/report.html", "--out", "report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format", "rerun", "--out", "rerun.txt"] end -Cucumber::Rake::Task.new("running_all_tests") do |t| - # t.cucumber_opts = ["--tags", "@carlos", "--tags", "~@pend", "--format", "html", "--out", "report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format", "rerun", "--out", "rerun.txt"] - t.cucumber_opts = ["--tags", "~@pend"] +task 'running_all_tests' do + t.cucumber_opts = ["--tags", "~@pend", "--format", "html", "--out", "report/report.html", "--format", "junit", "--out", "testoutput", "--format", "pretty", "--format"] end +task 'prepare_parallel_report' do + FileUtils.rm_rf('reports') + Dir.mkdir('reports') -task :all_parallel do - puts "===== Executing Tests in parallel" - File.delete("cucumber_failures.log") if File.exist?("cucumber_failures.log") - File.new("cucumber_failures.log", "w") - #system "bundle exec parallel_cucumber features/ -o \"-r features -p parallel -t #{tags} \" -n #{processes} " or exit!($?.exitstatus) - system "bundle exec parallel_cucumber features/ -o \"-r features -p parallel \" -n #{processes} " or exit!($?.exitstatus) - puts " ====== Parallel execution finished and cucumber_failure.log created =========" -end - - -###################### -#### Cuke Forker #### -###################### - -task :cleanup_cuke_forker do - puts " ========Deleting old reports and logs=========" - FileUtils.rm_rf('features/tmp_reports') - Dir.mkdir('features/tmp_reports') - + puts "configure reportbuilder" ReportBuilder.configure do |config| - config.json_path = 'features/tmp_reports' - config.report_path = 'reports' + config.json_path = 'tmp_reports' + config.report_path = 'reports/reports' + config.report_types = [:json, :html] config.report_tabs = [:overview, :features, :scenarios, :errors] config.report_title = 'Test Results' - #config.report + config.report end end -task :all do - Rake::Task['cleanup_cuke_forker'].invoke - puts "===== Executing Tests in parallel" +task 'create_report' do + ReportBuilder.build_report + FileUtils.rm_rf('tmp_reports') +end - Dir.chdir('features/') +task 'parallel_all_tests' do + Rake.application.invoke_task('prepare_parallel_report') - CukeForker::Runner.run CukeForker::Scenarios.tagged('@carlos'), {:max => 20, - :log => true, :format => :json, :out => 'features/tmp_reports'} - puts "===== End Executing Tests in parallel" - puts "===== Executing report" - #Dir.chdir('/') - ReportBuilder.build_report - puts "===== End Executing report" + FileUtils.rm_rf('tmp_reports') + Dir.mkdir('tmp_reports') + + system "bundle exec parallel_cucumber -n #{processes} features/ -o \'-p parallel -f json -o tmp_reports/feature$TEST_ENV_NUMBER.json \'" + #system "bundle exec parallel_cucumber features/ -o \"-r features -p parallel \" -n #{processes} " or exit!($?.exitstatus) + Rake.application.invoke_task('create_report') end + + +####### +# task 'cuke_forker_all' do +# Rake.application.invoke_task('prepare_parallel_report') +# FileUtils.rm_rf('tmp_reports') +# Dir.mkdir('tmp_reports') +# +# puts "===== Executing Tests in parallel" +# Dir.chdir('features/') +# +# CukeForker::Runner.run CukeForker::Scenarios.all, {:max => 40, +# :log => true, :format => :json} +# +# puts "===== End Executing Tests in parallel" +# puts "===== Executing report" +# Rake.application.invoke_task('create_report') +# puts "===== End Executing report" +# end diff --git a/config/cucumber.yaml b/config/cucumber.yaml index 6193a79..d71b5d5 100644 --- a/config/cucumber.yaml +++ b/config/cucumber.yaml @@ -1,4 +1,5 @@ # cucumber.yml ##YAML Template -parallel: foo +#parallel: -f progress -f ParallelTests::Cucumber::FailuresLogger --out tmp_reports/cucumber_failures.log +parallel: -f progress \ No newline at end of file diff --git a/cucumber_failures.log b/cucumber_failures.log deleted file mode 100644 index e69de29..0000000 diff --git a/features/geocoding/geocoding_mandatory_params.feature b/features/geocoding/geocoding_mandatory_params.feature index 611df34..54f20fa 100644 --- a/features/geocoding/geocoding_mandatory_params.feature +++ b/features/geocoding/geocoding_mandatory_params.feature @@ -17,7 +17,7 @@ Feature: Cover the happy path case | San Francisco | San Francisco, CA, USA | APPROXIMATE | | 94107, San Francisco | San Francisco, CA 94107, USA | APPROXIMATE | | 94107, California | San Francisco, CA 94107, USA | APPROXIMATE | - | Co Road 82 | County Rd 82 SE, Minnesota, USA | GEOMETRIC_CENTER | + # | Co Road 82 | County Rd 82 SE, Minnesota, USA | GEOMETRIC_CENTER | | State 82 | FL-82, Fort Myers, FL, USA | GEOMETRIC_CENTER | # | U.S. 101 | US-101, United States | GEOMETRIC_CENTER | | Interstate 280 | I-280, California, USA | GEOMETRIC_CENTER | From 86ac96359939739ca7f449376357631af64d58b4 Mon Sep 17 00:00:00 2001 From: Carlos Alarcon Date: Sun, 22 Oct 2017 15:58:50 +0200 Subject: [PATCH 4/5] modify rakefile --- .gitignore | 3 +- .idea/workspace.xml | 219 ++++++++---------- Gemfile | 4 - Rakefile | 32 +-- config/cucumber.yaml | 3 +- .../geocoding_mandatory_params.feature | 75 ++++-- features/step_definitions/geo_api_steps.rb | 5 + .../step_definitions/helpers/helper_geo.rb | 4 + features/support/env.rb | 2 +- 9 files changed, 170 insertions(+), 177 deletions(-) diff --git a/.gitignore b/.gitignore index 51be4f2..97fac5b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ Gemfile.lock =.vendor/* .idea/ tmp_reports/* -reports/* \ No newline at end of file +reports/* +report.html diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 92b8b4d..1fc970a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,14 @@ - - + + + + @@ -194,7 +156,20 @@ - + + + + + + + + + + + + + +