Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get screenshot path during test execution specified as pathPattern in settings #7864

Closed
vasilyevi opened this issue Jul 6, 2023 · 6 comments
Labels
TYPE: enhancement The accepted proposal for future implementation.

Comments

@vasilyevi
Copy link

What is your Scenario?

Trying to integrate autotests with 3rd party service(test reporting solution) and need to upload screenshot. Need to get an exact screenshot path in the end of each test. The pathPattern is the following "${DATE}_${TIME}/${TEST}/${FILE_INDEX}_${QUARANTINE_ATTEMPT}.png"

What are you suggesting?

get from t?

What alternatives have you considered?

didn't find a good solution

Additional context

No response

@vasilyevi vasilyevi added the TYPE: enhancement The accepted proposal for future implementation. label Jul 6, 2023
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jul 6, 2023
@htho
Copy link
Contributor

htho commented Jul 7, 2023

I have a collection of undocumented TestCafe "functions".

// testcafe-undocumented.ts

export const screenshotPath = (t: TestController): string => (t as any).testRun.opts.screenshots.path;

Although they are undocumented and can change anytime - this did not change since TestCafe 1.x.

@Dmitry-Ostashev
Copy link
Contributor

@vasilyevi You can implement your own Reporter or wrap an existing one. The reporter plugin contains the reportTestDone method with the testRunInfo object argument. This object contains all captured screenshot paths.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Jul 10, 2023
@vasilyevi
Copy link
Author

@Dmitry-Ostashev is it possible to get access to that object from after test? From “t” or other object?

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 5, 2023
@AlexKamaev
Copy link
Contributor

You cannot access this object from the test using t testController. However, you can pass any information from the test (from t testController) to a custom reporter using the t.report action. Then, you can process this passed information in your custom reporter

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 6, 2023
@vasilyevi
Copy link
Author

vasilyevi commented Sep 6, 2023

@AlexKamaev I don't want to override the default reporter and implement own one, but I need the screenshots paths, what is the simplest way to get them?

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 6, 2023
@AlexKamaev
Copy link
Contributor

Alternatively, you can get your screenshot paths in reporter hook methods: https://testcafe.io/documentation/404388/guides/advanced-guides/modify-reporter-output.

Here is a basic example for screenshots:

function onBeforeWriteHook(writeInfo) {
    if (writeInfo.initiator === 'reportTestDone')
        writeInfo.formattedText += JSON.stringify(writeInfo.data.testRunInfo.screenshots.map(s => s.screenshotPath));
}

 module.exports = {
    hooks: {
        reporter: {
            onBeforeWrite: {
                'spec': onBeforeWriteHook,
            },
        },
    },
};

However, I still believe that you need to write your custom reporter to pass screenshots to your third-party service.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

5 participants