SeleniumLibrary
SeleniumLibrary copied to clipboard
New Keyword 'Element Attriubte Should Contain'
Copied from ExtendeSelenium2Library:
@keyword
def element_attribute_should_contain(self, attribute_locator, expected, message=''):
"""Verifies element attribute identified by ``attribute_locator`` contains ``expected``.
Arguments:
- ``attribute_locator``: The locator to find requested element attribute. It consists of
element locator followed by an @ sign and attribute name,
for example "element_id@class".
- ``expected``: The expected element attribute value.
- ``message``: The value that would be use to override the default error message.
Examples:
| Element Attribute Should Contain | css=div.class@class | value |
"""
actual = self.get_element_attribute(attribute_locator)
if expected not in actual:
if not message:
message = "Element attribute '%s' should have contained '%s'" \
" but its value was '%s'." % (attribute_locator, expected, actual)
raise AssertionError(message)
#And the negation:
@keyword
def element_attribute_should_not_contain(self, attribute_locator, unexpected, message=''):
"""Verifies element attribute identified by ``attribute_locator``
does not contain ``unexpected``.
Arguments:
- ``attribute_locator``: The locator to find requested element attribute. It consists of
element locator followed by an @ sign and attribute name,
for example "element_id@class".
- ``unexpected``: The unexpected element attribute value.
- ``message``: The value that would be use to override the default error message.
Examples:
| Element Attribute Should Not Contain | css=div.class@class | value |
"""
actual = self.get_element_attribute(attribute_locator)
if unexpected in actual:
if not message:
message = "Element attribute '%s' should not contain '%s'" \
" but it did." % (attribute_locator, unexpected)
raise AssertionError(message)
Generally the idea sounds reasonable. Instead of making direct assertions, I would prefer Wait... type of keywords. Would you be willing to provide the PR? Also remember that changes must be backed up with tests.
I should note that @rickypc has outlined a very specific licensing and contributor agreement with his library, robotframework-extendedselenium2library, and simply cutting and pasting code into the SeleniumLibrary should be done with this under serious consideration!
@johanno why not simply use that library?
Thanks for reminding us from that, I always forget that part.
@johanno why not simply use that library?
Because it doesn't support Python3
I also think that having this type of general keywords or functionality in SL is useful.
FWIW, I don't think it's a good idea to add all new assert functionality as Wait ... keywords. I know web is very dynamic nowadays and you often need to wait, but it still looks a bit strange if you need to use Wait Something Is Foo instead of Something Should Be Foo. Adding an optional timeout to asserts like
Something Should Be Foo timeout=5s
would allow using simpler keyword names and would avoid the need to have both Wait and Should variants. Obviously adding this to all Should keywords would be a big task, but it might be possible to implement it automatically by utilizing the dynamic API SeleniumLibrary nowadays uses.
Also, it's a good point we cannot directly copy code from a project using AGPL. Luckily this kind of keywords are easy to implement from scratch and ES2L code wouldn't even be fully compatible with the current SL code anyway.
It also doesn't support SeleniumLibrary. It would seem best to first see if we can add some updates to the ExtendSelenium2Library. I know of a couple developers in NYC that also use this library and could benefit from the upgrade. We had talked about mini conferences and mini sprints, online, so this would be a great candidate.
I can see ES2L supporting the latest SL being useful to many, but, to be honest, if the reason E2SL exists is to just add new generic functionality to SL, I don't see the point of the library in general. Much better concentrating efforts to SL only.
The situation with AngularLibrary is different because it is designed to a specific domain and adds non-generic functionality on top of SL. Having a way such functionality could be added to SL via plugins might be even better, but that would first require designing and implementing the plugin API.
Plus, my team has already added Element Attribute Value Should Be -
https://github.com/robotframework/SeleniumLibrary/blob/master/src/SeleniumLibrary/keywords/element.py#L387
On Fri, May 25, 2018 at 3:39 AM, Pekka Klärck [email protected] wrote:
I can see ES2L supporting the latest SL being useful to many, but, to be honest, if the reason E2SL exists is to just add new generic functionality to SL, I don't see the point of the library in general. Much better concentrating efforts to SL only.
The situation with AngularLibrary is different because it is designed to a specific domain and adds non-generic functionality on top of SL. Having a way such functionality could be added to SL via plugins might be even better, but that would first require designing and implementing the plugin API.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/robotframework/SeleniumLibrary/issues/1129#issuecomment-391983835, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAoXSkoBXeGhnAk2jHAXvZsFklxHw41ks5t18M5gaJpZM4UI8TP .
-- Ruby: http://blog.rubygeek.com - http://www.twitter.com/rubygeek http://www.linkedin.com/in/nolastowe - my linkedin profile http://github.com/rubygeek - my code