saveScreenshot
Zapisz zrzut ekranu bieżącego kontekstu przeglądania jako plik PNG w swoim systemie operacyjnym. Miej świadomość, że niektóre sterowniki przeglądarek wykonują zrzuty ekranu całego dokumentu (np. Geckodriver z Firefoksem), a inne tylko bieżącego obszaru widocznego (np. Chromedriver z Chrome).
Usage
browser.saveScreenshot(filepath, { fullPage, format, quality, clip })
Parameters
| Name | Type | Details |
|---|---|---|
filepath | String | ścieżka do wygenerowanego obrazu (wymagane rozszerzenie .png) względem katalogu wykonania |
options | Object | opcje zrzutu ekranu |
options.fullPage=falseoptional | Boolean | czy zrobić zrzut ekranu całej strony czy tylko bieżącego obszaru widocznego |
options.format='png'optional | String | format zrzutu ekranu (albo png albo jpeg) |
options.quality=100optional | Number | jakość zrzutu ekranu w przypadku formatu JPEG w zakresie 0-100 procent |
options.clipoptional | Object | przycinanie prostokąta zrzutu ekranu |
Examples
saveScreenshot.js
it('should save a screenshot of the browser viewport', async () => {
await browser.saveScreenshot('./some/path/screenshot.png');
});
it('should save a screenshot of the full page', async () => {
await browser.saveScreenshot('./some/path/screenshot.png', { fullPage: true });
});
it('should save a screenshot of a specific rectangle', async () => {
await browser.saveScreenshot('./some/path/screenshot.png', { clip: { x: 0, y: 0, width: 100, height: 100 } });
});
it('should save a screenshot of the full page in JPEG format', async () => {
await browser.saveScreenshot('./some/path/screenshot.jpeg', { fullPage: true, format: 'jpeg' });
});
it('should save a screenshot of the full page in JPEG format with quality 50', async () => {
await browser.saveScreenshot('./some/path/screenshot.jpeg', { fullPage: true, format: 'jpeg', quality: 50 });
});
running from a hook, make sure to explicitly define the hook as async:
wdio.conf.js
afterTest: async function(test) {
await browser.saveScreenshot('./some/path/screenshot.png');
}
Returns
- <Buffer>
return: bufor zrzutu ekranu