Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locators to be blurred should ignore NoSuchElementException error in Capture Screenshot keywords #45

Closed
AllanMedeiros opened this issue Jan 8, 2020 · 5 comments
Assignees

Comments

@AllanMedeiros
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I have a single array of many fields to be blurred in the screenshot, but not all of them appears in every page of the application, so eventually I get NoSuchElementException error because one of these fields is not present in the current page.
I'm using a test case template to perform the same set of actions in many pages, would not be pratical to create a locator array for each page.

Describe the solution you'd like
Capture Screenshot kws could ignore NoSuchElementException error and proceed to next locator in the array.

Describe alternatives you've considered
I could create an array variable for each page, but that would kill the purpose of re-usability of code.

Additional context
Add any other context or screenshots about the feature request here.

@jessezach
Copy link
Owner

@AllanMedeiros Makes sense. This would help avoid creating multiple blur variable arrays. Will push the change for this as part of the upcoming release.

@jessezach jessezach self-assigned this Jan 9, 2020
@AllanMedeiros
Copy link
Contributor Author

Added this import in selenium_hooks.py
from selenium.common.exceptions import NoSuchElementException

And changed this method like this.

def blur_regions(self, selectors, radius, path):
        selectors = selectors if isinstance(selectors, list) else [selectors]

        for region in selectors:
            try:
                prefix, locator, element = self.find_element(region)
            except NoSuchElementException:
                continue

            area_coordinates = self._get_coordinates(prefix, locator, element)
            left, right = math.ceil(area_coordinates['left']), math.ceil(area_coordinates['right'])
            top, bottom = math.ceil(area_coordinates['top']), math.ceil(area_coordinates['bottom'])
            left, right, top, bottom = self._update_coordinates(left, right, top, bottom)
            im = Image.open(path + '/img' + str(self.count) + '.png')
            cropped_image = im.crop((left, top, right, bottom))
            blurred_image = cropped_image.filter(ImageFilter.GaussianBlur(radius=int(radius)))
            im.paste(blurred_image, (left, top, right, bottom))
            im.save(path + '/img' + str(self.count) + '.png')

Let me know if you thought something different than that.
But after a few runs, seems to be working fine.

@jessezach
Copy link
Owner

@AllanMedeiros This is exactly how I was planning to fix it. Could you raise a pull request with this code please?

@AllanMedeiros
Copy link
Contributor Author

ok, done!

@jessezach
Copy link
Owner

Released in v1.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants