-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathE10_screenshotselenium.py
More file actions
43 lines (35 loc) · 1.48 KB
/
E10_screenshotselenium.py
File metadata and controls
43 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import cv2
class usando_unittest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox(executable_path = "./geckodriver")
def test_usando_opencv(self):
driver = self.driver
driver.get("https://www.google.com")
driver.save_screenshot('img2.png')
sleep(3)
def test_comparando_imagenes(self):
img1 = cv2.imread('img1.png')
img2 = cv2.imread('img2.png')
diferencia = cv2.absdiff(img1, img2)
imagen_gris = cv2.cvtColor(diferencia, cv2.COLOR_BGR2GRAY)
contours,_ = cv2.findContours(imagen_gris,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
for i in contours:
if cv2.contourArea(i) >= 10000:
posicion_x,posicion_y,ancho,alto = cv2.boundingRect(i)
cv2.rectangle(img1,(posicion_x,posicion_y),(posicion_x+ancho,posicion_y+alto),(0,0,255),2)
while(1):
cv2.imshow('Imagen1', img1)
cv2.imshow('Imagen2', img2)
cv2.imshow('Diferencias detectadas', diferencia)
teclado = cv2.waitKey(5) & 0xFF
if teclado == 27:
break
cv2.destroyAllWindows()
if __name__ == "__main__":
unittest.main()