qase-tms / qase-javascript

Qase TMS JavaScript SDK
https://developers.qase.io
49 stars 43 forks source link

[qase-playwright] User cannot customize what should be uploaded to TMS #378

Closed DzmitryMaretski closed 1 year ago

DzmitryMaretski commented 1 year ago

Hi there. I have prepared changes for you to make more flexible qase-playwright library. Currently playwright support 3 different types of files: screenshot, video, trace When user want to run not a small test - qase upload can failed due to file size. We can provide customization for user to select specific file to upload. I can't upload changes by myself, so I will show you here all changes.

qase-playwright/src/index.ts

  1. Need to add additional field to QaseOptions
interface QaseOptions {
    ...
    attachmentOptions?: Record<string, boolean>;
}
  1. In constructor need to add initialization. It's mean that it will be true by the default
    this.options.attachmentOptions = {
            uploadTrace: _options?.attachmentOptions?.uploadTrace ?? true,
            uploadScreenshot: _options?.attachmentOptions?.uploadScreenshot ?? true,
            uploadVideo: _options?.attachmentOptions?.uploadVideo ?? true,
        };
  2. uploadAttachments function should be rewritten. So, we will check: do we need to upload Video? Is this attachment is video? If yes - we will prepare readstream and it will be uploaded

    private async uploadAttachments(testResult: TestResult) {
        return await Promise.all(
            testResult.attachments.map(async (attachment) => {
                let dataToUpload;
                if(this.options?.attachmentOptions?.uploadVideo && attachment?.name === 'video') {
                    dataToUpload = createReadStream(attachment?.path as string);
                }
                if(this.options?.attachmentOptions?.uploadTrace && attachment?.name === 'trace') {
                    dataToUpload = createReadStream(attachment?.path as string);
                }
                if(this.options?.attachmentOptions?.uploadScreenshot && attachment?.name === 'screenshot') {
                    dataToUpload = createReadStream(attachment?.path as string);
                }
    
                if (dataToUpload) {
                    const options = {
                        headers: {
                            'Content-Type': 'multipart/form-data; boundary=' + customBoundary,
                        },
                    };
    
                    const response = await this.api.attachments.uploadAttachment(
                        this.options.projectCode,
                        [dataToUpload],
                        options
                    );
    
                    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
                    return (response.data.result?.[0].hash as string);
                }
                return null;
            })
        );
    }
  3. onTestEnd function should have .filter function to delete all nulls.
    return this.prepareCaseResult(test, testResult, attachmentsArray.filter((value) => value));

After that we can add to qase-playwright/examples/playwright.config.ts additional parameter:

    reporter: [
        ['list'],
        ['playwright-qase-reporter',
            {
                ...
                attachmentOptions: {
                    uploadScreenshot: true,
                    uploadTrace: false,
                    uploadVideo: false,
                },
            }],
    ],

To show how it works.

Also need to provide additional field parameter in README.md file in Reporter options (* - required): section

It would be great to see this feature in the nearest future

n3r commented 1 year ago

Hello @DzmitryMaretski!

Thanks for your issue and post. Right now, we are preparing a new major update and we will use your idea with options for attachments.

DzmitryMaretski commented 1 year ago

Hi, @n3r . Thanks for sharing. Could you please provide ETA for this new major update? Thanks in advance

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.