renatoathaydes / spock-reports

This project creates a global extension to Spock to create test reports.
Apache License 2.0
273 stars 68 forks source link

Custom properties in spockReports #230

Closed ivtm86 closed 2 years ago

ivtm86 commented 2 years ago

Hi, thanks for jour great Spock Extension. The option to use SpockConfig.groovy instad of IReportCreator.properties is very helpful for me. I works without IDE , just Notepad and GroovyConsole and i use every reduction of artefacts like META-INF... Actually i can not define custom properties in SpockConfig.

set 'com.athaydes.spockframework.report.build':'1.1.0'
set 'com.athaydes.spockframework.report.projectName':'My Testproject'
set 'com.athaydes.spockframework.report.projectVersion':'1.1.5'
set 'projectName':'My Testproject'

All this tries is not working. Why ? What is my mistake? Sorry and thanks vor answers. kiwiman

renatoathaydes commented 2 years ago

It's Spock itself that looks at this file. Do the Spock config options work in this file? If not, I suggest you ask on the Spock project.

ivtm86 commented 2 years ago

Hi Renato, i can see my Properties in console log before Test runs.
But not after Testrun. console before run: [Thread-5] INFO com.athaydes.spockframework.report.SpockReportExtension - Got configuration from Spock: com.athaydes.spockframework.report.internal.SpockReportsConfiguration([com.athaydes.spockframework.report.outputDir:/temp/SeleniumReports, com.athaydes.spockframework.report.showCodeBlocks:false, com.athaydes.spockframework.report.IReportCreator:com.athaydes.spockframework.report.template.TemplateReportCreator, com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension:html, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName:summary.html, com.athaydes.spockframework.report.template.TemplateReportCreator.enabled:true, com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile:/report_template/bwi-spec-template.html, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile:/report_template/bwi-summary-template.html, com.athaydes.spockframework.report.internal.HtmlReportCreator.inlineCss:true, com.athaydes.spockframework.report.internal.HtmlReportCreator.specSummaryNameOption:class_name, com.athaydes.spockframework.report.build:1.1.0, com.athaydes.spockframework.report.projectName:Project1, com.athaydes.spockframework.report.projectVersion:1.1.5, projectName:Project1]) Test started MS-Edge Browser started Open StartPage ... After TestRun:

[Thread-5] INFO com.athaydes.spockframework.report.internal.ConfigLoader - SpockReports config loaded: {com.athaydes.spockframework.report.aggregatedJsonReportDir=, com.athaydes.spockframework.report.showCodeBlocks=false, com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=md, com.athaydes.spockframework.report.testSourceRoots=src/test/groovy, com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.internal.HtmlReportCreator, com.athaydes.spockframework.report.outputDir=build/spock-reports, com.athaydes.spockframework.report.internal.HtmlReportCreator.inlineCss=true, com.athaydes.spockframework.report.internal.HtmlReportCreator.featureReportCss=spock-feature-report.css, com.athaydes.spockframework.report.hideEmptyBlocks=false, com.athaydes.spockframework.report.internal.HtmlReportCreator.summaryReportCss=spock-summary-report.css, com.athaydes.spockframework.report.projectVersion=Unknown, com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/templateReportCreator/spec-template.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.specSummaryNameOption=class_name_and_title, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/templateReportCreator/summary-template.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.excludeToc=false, com.athaydes.spockframework.report.template.TemplateReportCreator.enabled=true, com.athaydes.spockframework.report.projectName=, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.printThrowableStackTrace=false, com.athaydes.spockframework.report.internal.HtmlReportCreator.enabled=true} [Thread-5] INFO com.athaydes.spockframework.report.template.TemplateReportAggregator - Writing summary report to C:\temp\SeleniumReports\summary.html [Thread-5] INFO com.athaydes.spockframework.report.internal.ConfigLoader - SpockReports config loaded: {com.athaydes.spockframework.report.aggregatedJsonReportDir=, com.athaydes.spockframework.report.showCodeBlocks=false, com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=md, com.athaydes.spockframework.report.testSourceRoots=src/test/groovy, com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.internal.HtmlReportCreator, com.athaydes.spockframework.report.outputDir=build/spock-reports, com.athaydes.spockframework.report.internal.HtmlReportCreator.inlineCss=true, com.athaydes.spockframework.report.internal.HtmlReportCreator.featureReportCss=spock-feature-report.css, com.athaydes.spockframework.report.hideEmptyBlocks=false, com.athaydes.spockframework.report.internal.HtmlReportCreator.summaryReportCss=spock-summary-report.css, com.athaydes.spockframework.report.projectVersion=Unknown, com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/templateReportCreator/spec-template.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.specSummaryNameOption=class_name_and_title, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/templateReportCreator/summary-template.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.excludeToc=false, com.athaydes.spockframework.report.template.TemplateReportCreator.enabled=true, com.athaydes.spockframework.report.projectName=, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.printThrowableStackTrace=false, com.athaydes.spockframework.report.internal.HtmlReportCreator.enabled=true}

secondary Hint: Property: com.athaydes.spockframework.report.internal.HtmlReportCreator.specSummaryNameOption=class_name_and_title not working completly (not in SpockConfig and not in .properties )

renatoathaydes commented 2 years ago

I don't get it. Why is spock printing this twice? What do you mean by "before" and "after" your tests run? This should print only once, right before when your tests start.

ivtm86 commented 2 years ago

Why spock printing twice. I don't know. Before and after. Well. Itry to explane.

  1. This is a peace of my Test Specification:

    @Slf4j
    @Stepwise
    //@StepThrough
    class DEV_Spock_Features extends Specification{
    @Shared b
    @Shared dm = new LazyMap()
    def setupSpec(){
        println("MSEdge Browser started")
        println("Open StartPage")
    }
    def cleanupSpec(){  
    }
    def "feature-1"(){
        given: "Startpage is opened"
    .....

    Both println i can see in console log between booth reporting peaces. Thats it.

  2. I try to build my Test Environment as simple as possible.

    • Tools: Groovy (GroovyConsole vor DEV and GroovyShell vor execute) No IDE like Eclipse, Intellij...
      • Notepad++
        • GEB-SeleniumFramework
        • Spock BDD Framework.
    • Folder Structure:
      • Projectname (this is my System.getProperty(user.dir))
        • resources (.groovy with GEB pageobject and GEB modules)
        • tests (.groovy Testscripts ans Spock Specifications)
          • SpockConfig.groovy unter C:\Users\user1.spock
          • Modified startGroovy.bat Now i can start my Spock Test from diferent TestManagement Tools. like MF ALM / AQUA /Excel ... and after testrun import Spock-Report (exclude Excel)back.
renatoathaydes commented 2 years ago

Why spock printing twice. I don't know.

You need to find out because that should not happen.

Can you show me the exact command you use to run the tests, or even better, make a GitHub project that uses your way of working and reproduces the issue (please remove Selenium and everything that's not required to show the problem)?

renatoathaydes commented 2 years ago

I have just tried the following:

Create SpockConfig.groovy

spockReports {
    set 'com.athaydes.spockframework.report.build':'1.1.0'
    set 'com.athaydes.spockframework.report.projectName':'My Testproject'
    set 'com.athaydes.spockframework.report.projectVersion':'1.1.5'
    set 'projectName':'My Testproject'
}

Create Groovy Specification tmp.groovy:

@Grab(group='com.athaydes', module='spock-reports', version='2.3.0-groovy-3.0')
@GrabExclude(group = 'org.codehaus.groovy', module='groovy')
@GrabExclude(group = 'org.codehaus.groovy', module='groovy-xml')
@GrabExclude(group = 'org.codehaus.groovy', module='groovy-json')
@GrabExclude(group = 'org.codehaus.groovy', module='groovy-templates')
class Groovy extends spock.lang.Specification {

    def 'Should run ok'() {
        when:
        def x = 1
        def y = 2

        then:
        x + y == 3
    }

}

Install recent Groovy 3 (4 is not fully supported) then run the test:

$ sdk install groovy 3.0.11
$ groovy tmp.groovy

Result:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
JUnit5 launcher: passed=1, aborted=0, failed=0, skipped=0, time=355ms

And the report looks fine:

Screen Shot 2022-06-10 at 18 42 22

You can see this is all I've got in my working directory:

$ ls
SpockConfig.groovy build              tmp.groovy
ivtm86 commented 2 years ago

Ok. I find the reason Why is spock printing this twice. -> I start spock-report loadConfiguration() in summary.html template. Thats my MISTAKE.

Here is my commandline to start one spock test: C:\opt\groovy\bin\groovy.bat -Duser.dir=C:\Users\User1\project1 C:\Users\User1\project1\test\Spock_Simple.groovy I can use Properties:

For any other Custom Properties. for example build:

i get following Messages: [main] WARN com.athaydes.spockframework.report.internal.ConfigLoader - Invalid property value for property 'testSourceRoots' [main] WARN com.athaydes.spockframework.report.internal.ConfigLoader - Property [build] not acceptable by IReportCreator of type com.athaydes.spockframework.report.template.TemplateReportCreator

But this is ok for me if i known this.

renatoathaydes commented 2 years ago

I didn't know you were using a template report creator. That explains it. This type just doesn't support those properties right now. You can easily find other ways to pass this information down to the template, though. For example, by setting a system property when running the test (like groovy ... -DmyReportProjectName=Project I think, at least in Java this works) and then in the template itself, grab the property with System.getProperty('myReportProjectName').

Do you have any concerns left or should we close this ticket?