chore: Create screenshot of multiple instances on test fail (#273)
#271
This commit is contained in:
parent
b35b2d5e7c
commit
2e7d110fd3
|
@ -6,10 +6,8 @@ import pytest
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
|
|
||||||
import configs
|
import configs
|
||||||
import driver
|
|
||||||
from configs.system import IS_LIN
|
from configs.system import IS_LIN
|
||||||
from fixtures.path import generate_test_info
|
from fixtures.path import generate_test_info
|
||||||
from scripts.utils import local_system
|
|
||||||
from scripts.utils.system_path import SystemPath
|
from scripts.utils.system_path import SystemPath
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
|
@ -2,6 +2,8 @@ import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import allure
|
import allure
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
import squish
|
import squish
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
|
|
||||||
|
@ -10,6 +12,7 @@ import driver
|
||||||
from configs.system import IS_LIN
|
from configs.system import IS_LIN
|
||||||
from driver import context
|
from driver import context
|
||||||
from driver.server import SquishServer
|
from driver.server import SquishServer
|
||||||
|
from gui.objects_map import statusDesktop_mainWindow
|
||||||
from scripts.utils import system_path, local_system
|
from scripts.utils import system_path, local_system
|
||||||
from scripts.utils.system_path import SystemPath
|
from scripts.utils.system_path import SystemPath
|
||||||
|
|
||||||
|
@ -42,10 +45,26 @@ class AUT:
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
if exc_type:
|
if exc_type:
|
||||||
screenshot = configs.testpath.RUN / f'{self.aut_id}.png'
|
try:
|
||||||
ImageGrab.grab(xdisplay=configs.system.DISPLAY if IS_LIN else None).save(screenshot)
|
self.attach()
|
||||||
allure.attach(
|
driver.waitForObjectExists(statusDesktop_mainWindow).setVisible(True)
|
||||||
name=f'Screenshot on fail for multiple instance: {self.aut_id}', body=screenshot.read_bytes(), attachment_type=allure.attachment_type.PNG)
|
configs.testpath.TEST.mkdir(parents=True, exist_ok=True)
|
||||||
|
screenshot = configs.testpath.TEST / f'{self.aut_id}.png'
|
||||||
|
|
||||||
|
rect = driver.object.globalBounds(driver.waitForObject(statusDesktop_mainWindow))
|
||||||
|
img = ImageGrab.grab(
|
||||||
|
bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height),
|
||||||
|
xdisplay=configs.system.DISPLAY if IS_LIN else None)
|
||||||
|
view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
|
||||||
|
cv2.imwrite(str(screenshot), view)
|
||||||
|
|
||||||
|
allure.attach(
|
||||||
|
name=f'Screenshot on fail: {self.aut_id}',
|
||||||
|
body=screenshot.read_bytes(),
|
||||||
|
attachment_type=allure.attachment_type.PNG)
|
||||||
|
except Exception as err:
|
||||||
|
_logger.info(err)
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
@allure.step('Attach Squish to Test Application')
|
@allure.step('Attach Squish to Test Application')
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Image:
|
||||||
rect = driver.object.globalBounds(driver.waitForObject(self.object_name))
|
rect = driver.object.globalBounds(driver.waitForObject(self.object_name))
|
||||||
img = ImageGrab.grab(
|
img = ImageGrab.grab(
|
||||||
bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height),
|
bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height),
|
||||||
xdisplay=":0" if IS_LIN else None
|
xdisplay=configs.system.DISPLAY if IS_LIN else None
|
||||||
)
|
)
|
||||||
self._view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
|
self._view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue