python-needle / needle

Automated tests for your CSS.
https://needle.readthedocs.io/
Other
590 stars 50 forks source link

added whitelist #49

Open andreabisello opened 8 years ago

andreabisello commented 8 years ago

Now you can pass a whitelist of css selector. If css selectors matches somethings, those elements visibility will be set to "hidden" in order to avoid screenshot comparison failures on elements that can, by nature, change.

jphalip commented 8 years ago

Nice, I really like this feature. Thanks for the suggestion.

Here are a few comments:

Thanks!

andreabisello commented 8 years ago

@jphalip

How i can set css properties or alter visibility of WebElement using WebElement api? in documentation http://selenium-python.readthedocs.io/api.html?highlight=javascript#module-selenium.webdriver.remote.webelement i find only getter method and in stack overflow everyone use execute_script api, so i used execute_script api to make element hidden using javascript.

any suggestion?

thanks.

jphalip commented 8 years ago

My recommendation is specifically to use find_elements_by_css_selector() to retrieve the elements, since querySelector() has some limited support in old browsers like IE 8 (granted, that's not a huge deal).

Then to set a CSS property on a WebElement you should be able to reference it with arguments[0] when running execute_script. Something like: driver.execute_script('arguments[0].style.visibility="hidden";')

andreabisello commented 8 years ago

@jphalip i updated the code and now i think your bullets suggestions 1,2,3 are fine with https://github.com/bfirsh/needle/pull/49/commits/8887618cc61864c3407c22fc3a13b90cc6dde33b .

i never created a unit test. any suggestion for this use case?

thanks

jphalip commented 8 years ago

Thanks for the updates. First, one small comment: I think we should assume that the provided CSS selectors might potentially return multiple elements. So, could you use find_elements_by_css_selector() (note the plural) instead of find_element_by_css_selector() and then loop through the resulting list of elements?

Also, a note about the ignore parameter's default value. You have it as a list, which is a common pitfall in Python programming. See this article for more information: http://effbot.org/zone/default-values.htm Instead you should give it a default value of None and then follow the same approach as described in the article.

Regarding the tests. You could have the tests create a page with two elements in it, then take a screenshot while ignoring one of them, and then compare the resulting screenshot with a pre-generated control image. You should take a look at the existing tests for some inspiration.

andreabisello commented 8 years ago

@jphalip thanks for the suggestions :-) :+1: