def execute_behave(statechart, features, coverage, parameters): # Create temporary directory with tempfile.TemporaryDirectory() as tempdir: # Move statechart inside _, statechart_filename = os.path.split(statechart) shutil.copy(statechart, os.path.join(tempdir, statechart_filename)) # Move features inside for feature in features: _, feature_filename = os.path.split(feature) shutil.copy(feature, os.path.join(tempdir, feature_filename)) # Create an environment file with open(os.path.join(tempdir, 'environment.py'), 'w') as environment: content = DEFAULT_ENVIRONMENT_CONTENT if coverage: content += COVERAGE_ENVIRONMENT_CONTENT environment.write(content.replace('{{path}}', os.path.join(tempdir, statechart_filename))) # Create a steps subdirectory os.mkdir(os.path.join(tempdir, 'steps')) # Create steps file with open(os.path.join(tempdir, 'steps', 'steps.py'), 'w') as step: step.write(DEFAULT_STEPS_CONTENT) # Execute behave # subprocess.call(['behave'] + parameters, cwd=tempdir) cwd = os.getcwd() os.chdir(tempdir) behave_main.main(parameters) os.chdir(cwd)
def __run_test_cases(): """ para correr los escenarios con behave, llamamos al main cuando se genera un error lo tomamos y mostramos.""" try: behave_script.main() except Exception as e: logging.error("Error al ejecutar los steps: " + str(e)) traceback.print_exc()
# feature file path featureFilePath = ' feature_files_folder/Octopus_People.feature ' # tag option tagOptions = '' tagOptions = ' --tags=tag_me ' # command line argument to capture console output commonRunOptions = ' --no-capture --no-capture-stderr -f plain ' # full list of command line options Run_Options = tagOptions + featureFilePath + reporting_allure + commonRunOptions # run Behave with Python code runner_with_options.main(Run_Options) # read result json file listOfJsonFiles = glob.glob(reporting_folder_name + "/*.json") finalJson = '' for cnt in range(0, len(listOfJsonFiles)): listOfJsonFiles[cnt] = ' {"' + "Scenario_" + str( cnt) + '"' + ' : ' + open(listOfJsonFiles[cnt], 'r').read() + '}' if cnt < (-1 + len(listOfJsonFiles)): listOfJsonFiles[cnt] = listOfJsonFiles[cnt] + ',' finalJson = finalJson + listOfJsonFiles[cnt] finalJson = '[ ' + finalJson + ' ]' # convert json to html html_content = json2html.convert(json=finalJson) html_report_file = open(reporting_folder_name + '/' + 'index.html', 'w')
'/data', '{}/../reports/blackbox-tests/metrics'.format(cwd), '{}/../reports/blackbox-tests/logs'.format(cwd), '{}/../reports/blackbox-tests/meta'.format(cwd), '{}/../reports/blackbox-tests/behave'.format(cwd), '{}/../reports/blackbox-tests/cucumber'.format(cwd), '{}/../reports/blackbox-tests/junit'.format(cwd) ]: os.system('mkdir -p {}'.format(path)) os.system('rm -rf {}/*'.format(path)) from behave import __main__ as behave_executable print('\nStarting tests') exit_code = behave_executable.main(args=' '.join(args)) with open('{}/../reports/blackbox-tests/behave/results.json'.format(cwd), 'r') as fd_behave: cucumber_data = None with open('{}/../reports/blackbox-tests/cucumber/results.json'.format(cwd), 'w') as fd_cucumber: behave_data = json.loads(fd_behave.read()) cucumber_data = json.dumps(behave2cucumber.convert(behave_data)) fd_cucumber.write(cucumber_data) Shell.run([ 'json_to_junit', '{}/../reports/blackbox-tests/cucumber/results.json'.format(cwd), '{}/../reports/blackbox-tests/junit/results.xml'.format(cwd) ]) sys.exit(exit_code)
from sys import argv @fixture def fake_data_provider(context: dict, *args, **kwargs) -> None: """Create a new fake data provider. This fixture will create a new fake data provider to be used during the test steps and attach it on the context. """ fake = Faker() fake.add_provider("python") fake.add_provider("address") context.fake = fake def before_all(context: dict) -> None: """Execute actions before all features. This lifecycle method will execute a series of actions and functions before any feature runs. """ use_fixture(fake_data_provider, context) if __name__ == "__main__": main([arg for arg in argv[1:]])
def start_run_behave(tags: str = "~_Execute_All_"): if len(sys.argv) > 1: _run_bash_() else: behave_executable.main('--tags=' + tags + ' --no-skipped --no-snippets')
from behave import __main__ if __name__ == '__main__': __main__.main()
# -*- coding: utf-8 -*- import re import sys from behave.__main__ import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(main())
import sys from logging import getLogger from behave import __main__ as behave_executable from structlog import wrap_logger logger = wrap_logger(getLogger(__name__)) if __name__ == '__main__': if len(sys.argv) < 2: print('You must supply at least one tag e.g acceptance_tests/features --tags=standalone') exit(1) behave_format = os.getenv('BEHAVE_FORMAT', 'progress2') tags = sys.argv.copy() # Strip off program name del tags[0] all_tags = '' for t in tags: all_tags += f' --tags={t}' logger.warn('Running Acceptance Tests with ' + all_tags) behave_executable.main(args=f'--format {behave_format} acceptance_tests/features ' + all_tags)
import sys from behave import __main__ as runner if __name__ == '__main__': sys.stdout.flush() runner.main() # runner with options: commonOptions = "--no-capture --no-capture-stderr -f plain " #behave.ini can also be used for common command line options file1 = "basics.feature" file2 = "basics2.feature" folder = "subfeature1/folder1" tagList1 = "--tags=smoke" #run all scenarios having this tag tagList2 = "--tags=-smoke" #Run all scenarios except not having this tag tagList3 = "--tags=smoke --tags=automated" #AND: scenarios having both tags tagList4 = "--tags=smoke,automated" #OR: scenarios having any one of both tags forJsonReport = ' -f allure_behave.formatter:AllureFormatter -o reports/json ' #runner.main() # by default runs all the feature files(including in subfolders) under "features" folder #runner.main(commonOptions) #CL arguments to print all the print statements in step def files #runner.main(file1+' '+file2) #multifiles run #runner.main(folder) # folder run #runner.main(tagList4) # tag run #runner.main(commonOptions+folder+tagList1) # multiple command line arguments #runner.main(forJsonReport) # for json report
#!/usr/bin/python # -*- coding: utf-8 -*- import sys from behave import __main__ as pythonic_runner_example if __name__ == '__main__': sys.stdout.flush() pythonic_runner_example.main()
def main(): return __main__.main()
# Copyright (c) 2017-2018 {Flair Inc.} WESLEY PENG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys from behave.__main__ import main if __name__ == '__main__': args = [ os.path.join( os.path.dirname(__file__), 'features' ) ] args += sys.argv[1:] sys.exit(main(args))
import sys from behave import __main__ if __name__ == "__main__": sys.stdout.flush() __main__.main()
def _invoke_behave(self, arguments): return behave_main.main(arguments)
#!/usr/bin/python # -*- coding: utf-8 -*- import sys from behave import __main__ as runner_with_options if __name__ == '__main__': sys.stdout.flush() featureFilePath = ' feature_file_folder/Scenarios_tagged.feature ' reportingRelated = ' -f allure_behave.formatter:AllureFormatter -o reporting_folder_json ' commonRunnerOptions = ' --no-capture --no-capture-stderr -f plain ' fullRunnerOptions = featureFilePath + reportingRelated + commonRunnerOptions runner_with_options.main(fullRunnerOptions)
from behave import __main__ as behave behave.main()
def run_behave(): from behave.__main__ import main sys.argv[0] = '' sys.exit(main())
# Copyright (c) 2017-2018 {Flair Inc.} WESLEY PENG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys from behave.__main__ import main if __name__ == '__main__': args = [os.path.join(os.path.dirname(__file__), 'features')] args += sys.argv[1:] sys.exit(main(args))
#!/home/ioan/sd/env/bin/python3.4 # -*- coding: utf-8 -*- import re import sys from behave.__main__ import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(main())
def execute_scenario(self): args = self.feature_list if hasattr(self, 'report_folder'): args = args + ' -f allure_behave.formatter:AllureFormatter -o ' + self.report_folder runner_with_options.main(args)