2
votes

Am new to allure report. I am using testng and Java8. Everytime i run the tests, I need to do "allure serve allure-results". Is there a way by which the results get automatically updated instead of starting the command everytime?

2

2 Answers

1
votes

Step 1: Add dependencies of AllureReportBuilder from Maven repository

Step 2: Add below code for generate allure Report.

This will generate the Allure Report folder.

new AllureReportBuilder("1.5.4", new File("target/allure-report")).unpackFace(); 
new AllureReportBuilder("1.5.4", new File("target/allure-report")).processResults(new File("target/allure-results"));

Note- Above code belongs to allure1

0
votes

I faced the same issue in python. So, what I came up with is to run the terminal command through python script in pytest's conftest.py.

    import subprocess
    def pytest_sessionfinish(session, exitstatus):
        """
        Run command to set allure path and generate allure report after the test run is over
        """
        # Running pytest can result in six different exit codes:
        # Exit code 0:  All tests were collected and passed successfully
        # Exit code 1:  Tests were collected and run but some of the tests failed
        # Exit code 2:  Test execution was interrupted by the user
        # Exit code 3:  Internal error happened while executing tests
        # Exit code 4:  pytest command line usage error
        # Exit code 5:  No tests were collected
        print '\nrun status code:', exitstatus
        if (exitstatus != 2 or exitstatus != 3 or exitstatus!= 4 or exitstatus != 5):
            command_to_export_allure_path= ['export PATH=$PATH:/usr/local/bin:/usr/local/bin/allure-commandline/allure-2.7.0/bin/']
            command_generate_allure_report= ['allure generate --clean -o %s/Allure/ %s'%(allure_report_dir, allure_report_dir)]
            print command_to_export_allure_path
            print command_generate_allure_report
            subprocess.call(command_to_export_allure_path, shell=True)
            subprocess.call(command_generate_allure_report, shell=True)

I am sure there should be someway to run terminal command through java code as well