nozer
April 26, 2024, 5:46pm
1
Hello,
is there a way to save a screenshot of each session() created on the scenario after failing?
Feature("Testing");
Scenario("Screenshot multiple sessions", (I) => {
session("one", () => {
I.amOnPage('http://google.com');
I.dontSeeInCurrentUrl('http://google.com');
});
session("two", () => {
I.amOnPage('http://google.com');
I.dontSeeInCurrentUrl('http://google.com');
});
session("one", () => {
I.dontSeeInCurrentUrl('http://google.com');
});
});
I think we already had it. But only with Puppeteer and Playwright.
codeceptjs:3.x
â codeceptjs:feat/screenshot-for-all-sessions
opened 05:38AM - 27 Jun 23 UTC
## Motivation/Description of the PR
- Currently only screenshot of the active s⌠ession is saved, this PR aims to save the screenshot of every session for easy debugging
```
Feature('ShadowDom');
Scenario('Input a text in the input box and after search validate one of the book title', async ({ I }) => {
I.amOnPage('/')
I.fillField('#input', 'Science')
I.pressKey('Enter')
I.waitForElement('h2[class="title"]')
await I.seeElementInDOM('h2[class="title"]')
await session('new session', () => {
I.amOnPage('https://codecept.io');
I.see('123');
})
await session('another session', () => {
I.amOnPage('https://google.com');
I.see('123');
})
});
```
```
Artifacts:
- screenshot: /Users/thanh.nguyen/Desktop/codeceptjs-shadow-dom-fun/output/Input_a_text_in_the_input_box_and_after_search_validate_one_of_the_book_title.failed.png
- new session_screenshot: /Users/thanh.nguyen/Desktop/codeceptjs-shadow-dom-fun/output/new session_Input_a_text_in_the_input_box_and_after_search_validate_one_of_the_book_title.failed.png
- another session_screenshot: /Users/thanh.nguyen/Desktop/codeceptjs-shadow-dom-fun/output/another session_Input_a_text_in_the_input_box_and_after_search_validate_one_of_the_book_title.failed.png
```
![Screenshot 2023-06-27 at 07 37 02](https://github.com/codeceptjs/CodeceptJS/assets/7845001/714c075f-688b-403a-93cb-4ccb274c5774)
Applicable helpers:
- [x] Puppeteer
- [x] Playwright
Applicable plugins:
- [x] allure
- [x] screenshotOnFail
## Type of change
- [x] :bug: Bug fix
## Checklist:
- [ ] Lint checking (Run `npm run lint`)
- [ ] Local tests are passed (Run `npm test`)
nozer
April 28, 2024, 7:00am
4
Oh, Iâm working with selenium webdriverâŚ
I can create a custom helper and initialize a new webdriver on it and finally add the screenshot to the _failed(), but I donât think is the best approach, right?
Sessions are a way easier to work with.
Is it possible to have the same result with on webdriver? Or to have a work around?
I guess codeceptjs would offer this in their new release.
codeceptjs:3.x
â codeceptjs:feat/screenshot-for-all-sessions-webdriver
opened 09:08AM - 29 Apr 24 UTC
## Motivation/Description of the PR
- WD Helper: Currently only screenshot of t⌠he active session is saved, this PR aims to save the screenshot of every session for easy debugging
```
Scenario('should save screenshot for sessions @WebDriverIO @Puppeteer @Playwright', async ({ I }) => {
await I.amOnPage('/form/bug1467');
await I.saveScreenshot('original.png');
await I.amOnPage('/');
await I.saveScreenshot('main_session.png');
session('john', async () => {
await I.amOnPage('/form/bug1467');
event.dispatcher.emit(event.test.failed, this);
});
const fileName = clearString('should save screenshot for active session @WebDriverIO @Puppeteer @Playwright');
const [original, failed] = await I.getSHA256Digests([
`${output_dir}/original.png`,
`${output_dir}/john_${fileName}.failed.png`,
]);
// Assert that screenshots of same page in same session are equal
await I.expectEqual(original, failed);
// Assert that screenshots of sessions are created
const [main_original, session_failed] = await I.getSHA256Digests([
`${output_dir}/main_session.png`,
`${output_dir}/john_${fileName}.failed.png`,
]);
await I.expectNotEqual(main_original, session_failed);
});
```
![Screenshot 2024-04-29 at 11 07 47](https://github.com/codeceptjs/CodeceptJS/assets/7845001/5dddf85a-ed77-474b-adfd-2f208d3c16a8)
Applicable helpers:
- [ ] WebDriver
Applicable plugins:
- [ ] screenshotOnFail
## Type of change
- [ ] :rocket: New functionality
## Checklist:
- [ ] Tests have been added
- [ ] Documentation has been added (Run `npm run docs`)
- [ ] Lint checking (Run `npm run lint`)
- [ ] Local tests are passed (Run `npm test`)
1 Like
nozer
July 3, 2024, 8:18am
6
Hello again, after the new release i couldnât figure out how to have both screenshots after failing.
Feature("Testing sessions");
Scenario("Sessions 1 @level1", async function ({ I }) {
await I.amOnPage("/");
session("john", async () => {
await I.amOnPage("/");
await I.see("You");
});
});
Current codeceptjs version: 3.6.4
Output folder:
Please let me know if Iâm doing something wrong.
Maybe I understood incorrectly but seems like it works like it should be? the failure happens on your session, so only session screenshot is captured not the main session, as the failure is not happening there.
nozer
December 12, 2024, 10:30am
8
soo we shouldnât get the screenshot of all the browsers after fail? right after the PR i was getting all the screenshot but just a short period of time.
nozer
December 12, 2024, 10:39am
9
btw, if one session (ex: âjohnâ) fails i donât get the screenshot attached to the allure report.
I get the attached screenshot only if the test fails on the main session.
Report :
Code :
Feature('Session');
Scenario('should save screenshot for sessions @session', async ({ I }) => {
await I.amOnPage('/');
await I.amOnPage('/browsevideos');
await session('john', async () => {
await I.amOnPage('/browsevideos');
await I.see('Fake text');// Fails here
});
});