Exemplo n.º 1
0
    def test_convert(self):
        with open(BEHAVE_JSON) as f:
            converted = behave2cucumber.convert(json.load(f))

        with open(EXPECTED_JSON) as f:
            expected_result = json.load(f)

        assert (sorted(converted) == sorted(expected_result))
Exemplo n.º 2
0
    def test_dedupe_convert(self):
        with open(AUTORETRY_BEHAVE_JSON) as f:
            converted = behave2cucumber.convert(json.load(f), deduplicate=True)

        with open(AUTORETRY_DEDUPE_JSON) as f:
            expected_result = json.load(f)

        assert (sorted(converted) == sorted(expected_result))
Exemplo n.º 3
0
    def test_ids_are_unique(self):
        with open(BEHAVE_JSON) as f:
            converted = behave2cucumber.convert(json.load(f))
            ids = []
            for feature in converted:
                ids.append(feature['id'])
                for element in feature['elements']:
                    ids.append(element['id'])

        assert (len(set(ids)) == 5)
Exemplo n.º 4
0
def after_all(context):
    # context.dr.close()
    file = r'/src/features/reports/jsonDumps/testResult.json'
    with open(file) as behave_json:
        cucumberJson = behave2cucumber.convert(json.load(behave_json))
        jsonStr = json.dumps(cucumberJson)

    jsonReport = open(r'/src/features/reports/jsonReports/jsonReport.json',
                      'w')
    jsonReport.write(jsonStr)
    jsonReport.close()
Exemplo n.º 5
0
def tranforma_cucumber(path_arquivo, novo):
    nome = path_arquivo.replace("\\", "/")
    with open(nome) as behave_json:
        cucumber_json = behave2cucumber.convert(json.load(behave_json))
        for element in cucumber_json:
            elemento = element["elements"]
            for lista in elemento:
                listaa = lista["steps"]
                for lis in listaa:
                    li = lis["result"]["duration"]
                    lis["result"]["duration"] = int(li * 1000000000)
        arquivo = open(novo, 'w')
        conteudo = json.loads(str(cucumber_json).replace("'", '"'))
        conteudo = json.dumps(conteudo, indent=4)
        arquivo.write(conteudo)
        arquivo.close()
Exemplo n.º 6
0
def after_all(context):
    """
    所有测试完成之后执行
    注意:behave1.2.6生成的json没法正常转换为cucumber兼容的json报告,建议降级为:1.2.5
    :param context:
    :return:
    """

    # 转换
    with open('./test_report.json',encoding='utf-8') as behave_json:
        # 格式转换
        cucumberJson = behave2cucumber.convert(json.load(behave_json))

    jsonStr = json.dumps(cucumberJson)

    # 写入
    jsonReport = open(r'./report/jsonReport.json', 'w',encoding='utf-8')
    jsonReport.write(jsonStr)
    jsonReport.close()
Exemplo n.º 7
0
def convert_behave_to_cucumber_json(behave_filename,
                                    cucumber_filename,
                                    encoding="UTF-8",
                                    pretty=True):
    """Convert behave JSON dialect into cucumber JSON dialect.

    .. param behave_filename:       Input filename with behave JSON data.
    .. param cucumber_filename:     Output filename with cucumber JSON data.
    """
    dump_kwargs = {"encoding": encoding}
    if pretty:
        dump_kwargs.update(indent=2, sort_keys=True)

    with open(behave_filename, "r") as behave_json:
        with open(cucumber_filename, "w+") as output_file:
            behave_json = json.load(behave_json, encoding)
            cucumber_json = behave2cucumber.convert(behave_json)
            # cucumber_text = json.dumps(cucumber_json, **dump_kwargs)
            # output_file.write(cucumber_text)
            json.dump(cucumber_json, output_file, **dump_kwargs)
    return 0
Exemplo n.º 8
0
            '/data', '{}/../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

    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)

    execute([
        'json_to_junit',
        '{}/../reports/blackbox-tests/cucumber/results.json'.format(cwd),
        '{}/../reports/blackbox-tests/junit/results.xml'.format(cwd)
    ])

    sys.exit(exit_code)
Exemplo n.º 9
0
#!/usr/bin/python3
import os
import sys
sys.path.insert(1, './lib/')
import wcommon as wc
wc.jenkins_header()
# load inputs from Jenkinsfile

import json
import behave2cucumber
raw = wc.read_file(sys.argv[1])
behave_json = json.loads(raw)
cucumber_json = behave2cucumber.convert(behave_json)
wc.rmf(sys.argv[2])
wc.post_fname(json.dumps(cucumber_json), sys.argv[2])
exit(0)
import json
import behave2cucumber
import sys


fPath=str(sys.argv[1])
with open(fPath) as behave_json:
    cucumber_json = behave2cucumber.convert(json.load(behave_json))


with open(fPath, "w") as of:
    json.dump(cucumber_json, of)
Exemplo n.º 11
0
import json

import behave2cucumber
from behave.__main__ import main as behave_main

code = behave_main([
    "features/", "-t @partners", '-k', '-o',
    'target/cucumber-reports/behave.json', '-f', 'json'
])
cucumber_json = behave2cucumber.convert(
    json.load(open("target/cucumber-reports/behave.json")))
with open('target/cucumber-reports/Cucumber.json', 'w') as report:
    report.write(json.dumps(cucumber_json))
    report.flush()
    report.close()

exit(code)
Exemplo n.º 12
0
def after_all(context):
    with open('./report/report.json') as behave_json:
        cucumber_json = behave2cucumber.convert(json.load(behave_json))
        arquivo = open('resultado-teste.json', 'w')
        arquivo.write(str(cucumber_json).replace("'", '"'))
        arquivo.close()