Skip to content

Commit

Permalink
move resize to selenium hooks class
Browse files Browse the repository at this point in the history
  • Loading branch information
jessezach committed Jul 28, 2019
1 parent ae61fd8 commit dd1ee95
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 1 addition & 11 deletions RobotEyes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@ def open_eyes(self, lib='SeleniumLibrary'):
self.browser = SeleniumHooks(lib)
self.test_name = BuiltIn().replace_variables('${TEST NAME}')
test_name_folder = self.test_name.replace(' ', '_')

# delete if directory already exist. Fresh test
self._delete_folder_if_exists(test_name_folder)

# recreate deleted folder
self._create_empty_folder(test_name_folder)

# Captures full screen
def capture_full_screen(self, tolerance=None, blur=[], radius=50):
tolerance = float(tolerance) if tolerance else self.tolerance
tolerance = tolerance/100 if tolerance >= 1 else tolerance
count = self.browser.capture_full_screen(self.path)
self.browser.blur_regions(blur, radius, self.path) if blur else ''
count = self.browser.capture_full_screen(self.path, blur, radius)
self._resize(self.path + '/img' + str(count) + '.png')
key = 'img' + str(count) + '.png'
self.stats[key] = tolerance


# Captures a specific region in a mobile screen
def capture_mobile_element(self, selector, tolerance=None):
tolerance = float(tolerance) if tolerance else self.tolerance
Expand Down Expand Up @@ -79,10 +75,6 @@ def compare_images(self):

# compare actual and baseline images and save the diff image
for filename in os.listdir(actual_path):
a_path = ''
b_path = ''
d_path = ''

if filename.endswith('.png'):
b_path = os.path.join(baseline_path, filename)
a_path = os.path.join(actual_path, filename)
Expand All @@ -107,8 +99,6 @@ def compare_images(self):
output.close()
BuiltIn().run_keyword('Fail', 'Image dissimilarity exceeds tolerance') if self.fail else ''



def _delete_folder_if_exists(self, test_name_folder):
actual_image_test_folder = os.path.join(self.images_base_folder, ACTUAL_IMAGE_BASE_FOLDER, test_name_folder)
diff_image_test_folder = os.path.join(self.images_base_folder, DIFF_IMAGE_BASE_FOLDER, test_name_folder)
Expand Down
3 changes: 2 additions & 1 deletion RobotEyes/selenium_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def __init__(self, lib):
except RuntimeError:
raise Exception('%s instance not found' % lib)

def capture_full_screen(self, path):
def capture_full_screen(self, path, blur=[], radius=50):
self.count += 1
self.driver.save_screenshot(path + '/img' + str(self.count) + '.png')
self.blur_regions(blur, radius, path) if blur else ''
return self.count

def capture_element(self, path, locator, blur=[], radius=50):
Expand Down

0 comments on commit dd1ee95

Please sign in to comment.