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

Make path pattern smarter for errors screenshots #7014

Closed
fmancardi opened this issue May 7, 2022 · 11 comments
Closed

Make path pattern smarter for errors screenshots #7014

fmancardi opened this issue May 7, 2022 · 11 comments
Assignees
Labels

Comments

@fmancardi
Copy link

What is your Scenario?

I would like that screenshots on failure generate a file name with the testcase name + a progressive.
Probably this a non-sense because when test script fails it can not take more than one screenshot.

This is my .testcaferc.json

{
  "selectorTimeout": 2000,
  "skipJsErrors": true,

  "screenshots": {
    "takeOnFails": true,
    "pathPattern": "${DATE}_${TIME}/test-${TEST}/${USERAGENT}/${TEST}-${FILE_INDEX}.png"
  }
}

What is the Current behavior?

for the screenshots taken usin .takeScreenshot() it work as expected generating
tcf01

inside the TCF-004-errors folder, file name is the standard

2022-05-07 11_04_13-{C__development_testautomation_end-to-end_screenshots_2022-05-07_10-56-27_test-T

What is the Expected behavior?

inside the TCF-004-errors folder, file name respect the mask

${TEST}-${FILE_INDEX}.png

What is your public website URL? (or attach your complete example)

You can access our test site

This is the example

What is your TestCafe test code?

import { Selector } from 'testcafe';

fixture `New Fixture`
    .page `https://platform70-at.tesisquare.com/core/framework/login.cfm`;

test
.meta({'TCID': 'TCF-004',
          'WKFSTATUS': 'ready',
          '6.3': 'yes',
          '6.4': 'yes',
          '7.0': 'yes'})
('TCF-004', async t => {
    await t
        .click('#cookieChoiceDismiss')
        .typeText('#userlogin', 'admin')
        .typeText('#password', 'qqq')
        .click('#login')
        .click('#btn-toggle-menu')
        .click(Selector('#A_ADMIN_SYS-GESANAG_AN span').withText('ANAGRAFICHE'))
        .click('#A_ADMIN_SYS-GESANAG_AN_1')
        .click('#inserisci')
        .switchToIframe('#frame-for-tab')
        .typeText('#IdAnag', 'qazwsxedcrfvtgbyhnuj')
        .takeScreenshot()
        .typeText('#DescIndirizzoPF', 'qq')
        .typeText('#DescCittaPF', 'qq')
        .takeScreenshot()
        .typeText('#DescRagSocPF', 'qq')
        .typeText('#CapPF', 'qq')
        .typeText('#IdProvinciaPF', 'qq')
        .takeScreenshot()
        .click('#select2-Stato-container')
        .typeText('#fieldset_g1 .select2-search__field', 'Valido')
        .pressKey('enter')
        .click('#select2-idlingua-container')
        .typeText('#fieldset_g1 .select2-search__field', 'Italiano')
        .pressKey('enter')
        .click('#select2-IdNazionePF-container')
        .typeText('#fieldset_g1 .select2-search__field', 'ITALY')
        .pressKey('enter')
        .click('#inserisci')
        .expect(Selector('#pagecontainer div')
        	     .withText('Error ID: PLATFORM_STANDARD')
        	     .exists).eql(false)
        .expect(Selector('#pagecontainer a')
        	      .withText('Return to the Homepage')
        	      .exists).eql(false)
        .debug();
});


Your complete configuration file

{
  "selectorTimeout": 2000,
  "skipJsErrors": true,

  "screenshots": {
    "takeOnFails": true,
    "pathPattern": "${DATE}_${TIME}/test-${TEST}/${USERAGENT}/${TEST}-${FILE_INDEX}.png"
  }
}

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

N.A.

TestCafe version

1.18.2

Node.js version

v14.15.5

Command-line arguments

testcafe 'chrome --start-fullscreen' --test-meta WKFSTATUS=ready,6.4=yes --cfg=at-7.0.json ./test/testcafe/TCF-006-multiple-sshots.js

Browser name(s) and version(s)

No response

Platform(s) and version(s)

Windows 10, using Gitbash to run the script

Other

No response

@fmancardi fmancardi added the TYPE: bug The described behavior is considered as wrong (bug). label May 7, 2022
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 7, 2022
@Aleksey28
Copy link
Collaborator

Hi @fmancardi,

This behavior is expected. TestCafe replaces any ${FILE_INDEX} for the error with ${ERRORS_FOLDER}/${FILE_INDEX}. This decision was made because a file can contain a lot of tests with errors. If you want to screenshot only an error and you have only one test in the file, you can use ${TEST_INDEX} instead of ${FILE_INDEX}

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

I'm going to provide a more detailed explanation, because IMHO replace is not working as expected for errors

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 16, 2022
@Aleksey28
Copy link
Collaborator

Fine, please share more details, but before you do that, take a look at this paragraph. In the example with the default path pattern, you can see that the errors/string is put before ${FILE_INDEX}. Testcafe works with custom patterns in the same way.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label May 17, 2022
@fmancardi
Copy link
Author

Please give a look to my first explanation, the errors folder does not exist anymore, it's name is changed to TC-004-errors.
This is not the expectation.
folder name must remain errors
file name inside the folder have to have TC-004 as prefix then the progressive.

regards

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 17, 2022
@Aleksey28
Copy link
Collaborator

Thank you for the explanation. It happens because you separate ${TEST} and ${FILE_INDEX} with -. Thus, Testcafe doesn't handle your case and just replaces ${FILE_INDEX} with the errors/${FILE_INDEX}. We will think about ways to improve this behavior and update this thread once we have any news.

@Aleksey28 Aleksey28 reopened this May 18, 2022
@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label May 18, 2022
@Aleksey28 Aleksey28 added TYPE: enhancement The accepted proposal for future implementation. and removed TYPE: bug The described behavior is considered as wrong (bug). labels May 18, 2022
@Aleksey28 Aleksey28 changed the title Screenshots - using .testcaferc.json - pathPattern substitution for screenshots->takeOnFails Make path pattern smarter for errors screenshots May 18, 2022
@fmancardi
Copy link
Author

I've tried with
"pathPattern": "${DATE}_${TIME}/test-${TEST}/${USERAGENT}/${TEST}${FILE_INDEX}.png"

same effect
errors folder is renamed but images inside no

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 19, 2022
@Aleksey28
Copy link
Collaborator

It doesn't change anything. In case of errors, testcafe replaces part of the {FILE_INDEX} pattern with errors/${FILE_INDEX} each time. It doesn't matter what you put before or after.
I have an idea. You can swap {FILE_INDEX} and ${TEST} if it's appropriate to you like this: ${DATE}_${TIME}/test-${TEST}/${USERAGENT}/${FILE_INDEX}-${TEST}.png. The names of the files with errors will be changed.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label May 20, 2022
@fmancardi
Copy link
Author

fmancardi commented May 21, 2022

Using your suggestions things work as expected.
We can consider this a workaround.
It will be great if in the future using the mask ${TEST}-${FILE_INDEX}.png things also work.
I understand this is not a critic issue, but having fixed will be great.

May be a more flexible approach can be to have two pathPatters:

  • 'pathPattern'
  • 'errorsPathPattern' or 'pathPatternOnFails'
"pathPattern": "${DATE}_${TIME}/test-${TEST}/${USERAGENT}/${TEST}-${FILE_INDEX}.png"
"pathPatternOnFails": "${DATE}_${TIME}/test-${TEST}/${USERAGENT}/MyErrorsFolder/myPrefix-${TEST}-${FILE_INDEX}.png"

Best regards

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 21, 2022
@Aleksey28
Copy link
Collaborator

Thank you for the suggestion. We will consider ways to improve this behavior and update this thread once we have news.

Copy link

Release v3.5.0-rc.1 addresses this.

1 similar comment
Copy link

Release v3.5.0-rc.1 addresses this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants