Controlling Cucumber Tests By Driver Script
I will Show you how to filter and run the cucumber tests by using the master driver script.We will use the following components for this as below:
1).YML based Configuration File
**************************************************************
env_1:
Priority : p1
##############
ApplicationData:
ResultsPath : "D:\\TestProject\\Results"
FeaturesFolderPath : "D:\\TestProject"
ResultFormat : "html"
***********************************************************************
This file will help us in providing the following info:
a).Tag Filter "p1" by which we can execute only high priority test scenarios.
b).Results Path Folder
c).Features folder path
d).Desired Result Format
2).Master Driver Script(Driver.rb)
********************************************************************************
#Importing the required libraries
require 'yaml'
require 'FileUtils'
#Reading the YML config file and loading the variables and creating the timestamp to suffix results
time = Time.now.strftime("%Y_%m_%d_%H_%M%S")
configData = YAML.load_file "config.yml"
featureFilePath = configData["ApplicationData"]["FeaturesFolderPath"]
opFileFormat = configData["ApplicationData"]["ResultFormat"]
resBaseFolder = configData["ApplicationData"]["ResultsPath"] + "\\" + "ExecutionStatus_" + time
#Reading the config file and parsing the tags to filter the Features/Scenarios for execution def getTagsFromFilters(configData)
strPriority = configData["env_1"]["Priority"]
if strPriority.to_s.strip.length > 0
if strPriority.include? ","
arrVals = strPriority.split(",")
arrVals.each do |val|
strPriority = strPriority.gsub val,"@" + val
end
strRetVal = " --tags " + strPriority + strRetVal.to_s
else
strRetVal = " --tags " + strPriority.gsub(strPriority,"@" + strPriority) + strRetVal.to_s
end
end
return strRetVal
end
#Creating the cucumber command by concatenating the all config variables
FileUtils.makedirs(resBaseFolder)
strExecutionCmd = "cucumber "
strExecutionCmd = strExecutionCmd + " --out " + resBaseFolder + "\\Test_Results"
strExecutionCmd = strExecutionCmd + " --format " + opFileFormat
strExecutionCmd = strExecutionCmd + " SCREENSHOT_PATH=" + resBaseFolder + "\\"
strTags = getTagsFromFilters(configData)
strExecutionCmd = strExecutionCmd + strTags
print strExecutionCmd + "\n"
system(strExecutionCmd)
********************************************************************************
This driver script can be directly executed from command prompt:
C:\ProjectFolder>ruby Driver.rb
or better can scheduled through a batch file and run automatically as required.
Comments