0

I want to capture output which I'm running from the cucumber feature file.

I created one shell script program and placed it in /usr/local/bin/ so it can be accessible from anywhere in system.

abc_qa.sh -

arg=$1
if [[ $arg = 1 ]]
then
    echo $(date)
fi

project structure of cucumber -

aruba -

.

├── features

│ ├── support

│ │ └── env.rb

│ └── use_aruba_cucumber.feature

├── Gemfile

Gemfile -

source 'https://rubygems.org'
gem 'aruba', '~> 0.14.2'

env.rb -

require 'aruba/cucumber'

use_aruba_cucumber.feature -

Feature: Cucumber
 Scenario: First Run
    When I run `bash abc_qa.sh 1`

I want to capture this abc_qa.sh program output in the cucumber itself and compare this date is right or wrong by using any kind of simple test and make this test as a pass.

Eric Duminil
  • 52,989
  • 9
  • 71
  • 124
ketan
  • 2,732
  • 11
  • 34
  • 80

1 Answers1

1

You can use %x(command) to get the stdout of your command.

You can then use Time.parse to convert "Sat Nov 5 12:04:18 CET 2016" to 2016-11-05 12:04:18 +0100 as Time object, and compare it to Time.now :

require 'time'
time_from_abc_script = Time.parse(%x(bash abc_qa.sh 1))
puts (Time.now-time_from_abc_script).abs < 5 # No more than 5s difference between 2 times

You could use this boolean in any test file you want.

For example :

In features/use_aruba_with_cucumber.feature :

Feature: Cucumber
 Scenario: First Run
  When I run `bash abc_qa.sh 1`
  Then the output should be the current time

and features/step_definitions/time_steps.rb :

require 'time'

Then(/^the output should be the current time$/) do
  time_from_script = Time.parse(last_command_started.output)
  expect(time_from_script).to be_within(5).of(Time.now)
end
Eric Duminil
  • 52,989
  • 9
  • 71
  • 124
  • I'm new to cucumber. can you please tell me In which what I need to write and in what manner? – ketan Nov 05 '16 at 11:21
  • I'll install aruba/cucumber on my machine and write a feature and step definition. – Eric Duminil Nov 05 '16 at 12:45
  • @EricDuminil- Fantastic. one more thing, output of shell script contains : Sat Nov 5 19:30:03 IST 2016. I want to check its day is in seven days of week then pass this test. How I can do that? – ketan Nov 05 '16 at 14:00
  • It could probably be another question. If this one is answered, please consider upvoting and accepting my answer. I'm not sure I understand what you want. Do you want to check that "Sat" is the abbreviation of a day of the week? – Eric Duminil Nov 05 '16 at 14:33
  • 1
    see [http://stackoverflow.com/questions/40436724/how-to-compare-date-in-cucumber-aruba] question for better understanding and answer if you got it. – ketan Nov 05 '16 at 15:12