Skip to content

New Keyword 'Element Attriubte Should Contain' #1129

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

Closed
johanno opened this issue May 22, 2018 · 10 comments
Closed

New Keyword 'Element Attriubte Should Contain' #1129

johanno opened this issue May 22, 2018 · 10 comments

Comments

@johanno
Copy link

johanno commented May 22, 2018

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)
@aaltat
Copy link
Contributor

aaltat commented May 23, 2018

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.

@emanlove
Copy link
Member

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?

@aaltat
Copy link
Contributor

aaltat commented May 23, 2018

Thanks for reminding us from that, I always forget that part.

@johanno
Copy link
Author

johanno commented May 23, 2018

@johanno why not simply use that library?

Because it doesn't support Python3

@aaltat
Copy link
Contributor

aaltat commented May 23, 2018

I also think that having this type of general keywords or functionality in SL is useful.

@pekkaklarck
Copy link
Member

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.

@emanlove
Copy link
Member

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.

@pekkaklarck
Copy link
Member

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.

@rubygeek
Copy link
Contributor

rubygeek commented May 25, 2018 via email

@emanlove
Copy link
Member

In keeping with the desire to limit the number of keywords added to the library, including specialized assertions, this will not be implemented. There are existing methods to be get attributes or wait for an element to contain an attribute and then assert its value. Thank you all for suggestion this.

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

5 participants