حفظ لقطة الشاشة
حفظ لقطة شاشة لسياق التصفح الحالي كملف PNG على نظام التشغيل الخاص بك. كن على دراية بأن بعض متصفحات السائق تأخذ لقطات شاشة للمستند بأكمله (مثل Geckodriver مع Firefox) والبعض الآخر يأخذ لقطة للعرض الحالي فقط (مثل Chromedriver مع Chrome).
الاستخدام
browser.saveScreenshot(filepath, { fullPage, format, quality, clip })
المعلمات
الاسم | النوع | التفاصيل |
---|---|---|
filepath | String | المسار إلى الصورة التي تم إنشاؤها (لاحقة .png مطلوبة) بالنسبة إلى دليل التنفيذ |
options | Object | خيارات لقطة الشاشة |
options.fullPage=false اختياري | Boolean | ما إذا كان سيتم التقاط لقطة شاشة للصفحة بأكملها أو العرض الحالي فقط |
options.format='png' اختياري | String | تنسيق لقطة الشاشة (إما png أو jpeg ) |
options.quality=100 اختيا ري | Number | جودة لقطة الشاشة في حالة تنسيق JPEG في نطاق 0-100 بالمائة |
options.clip اختياري | Object | قص مستطيل من لقطة الشاشة |
أمثلة
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');
}
العائدات
- <Buffer>
return
: مخزن لقطة الشاشة