Skip to content

Investigate removing unreleased non-native selectors #376

Closed

Description

@just-be-dev

@IlfirinPL Added location support for SmartClient and SmartGWT in the (currently pending) 1.7 version. Being that I've added the ability to create custom locators, this may be a candidate for removal/refactoring before release.

I have similar goals of integrating ExtJS and I was able to accomplish that using a custom locator. I'll publish it in a new repository for you to compare with soon.

@IlfirinPL @emanlove Any thoughts?

Activity

  1. IlfirinPL commented on Apr 15, 2015

    @IlfirinPL
    Contributor

    It what way removing custom locators would improve you solution ?
    For my point of view its better to have more, both custom locators and having integrated ExtJS

  2. just-be-dev commented on Apr 15, 2015

    @just-be-dev
    ContributorAuthor

    I think you've misunderstood me.

    I've added the ability to create a custom locator through keywords (see #365). With this ability, the SmartClient selector isn't necessary to have in the core. You could create a keyword SmartClient Locator and register it in the selectors list by doing Add Locator Strategy | scLocator | SmartClient Locator

  3. IlfirinPL commented on Apr 16, 2015

    @IlfirinPL
    Contributor

    I your example "Click Element custom[example=true]" you have to pass argument in different way then the rest of locators custom=something, second you have to remember to add to all test suites both keyword Smart client locator and later register it , in current solution everything is out of the box, I like possibility of adding custom locator but I would like to most of commonly used to work out of the box.

  4. just-be-dev commented on Apr 16, 2015

    @just-be-dev
    ContributorAuthor

    That was a typo, I've updated the original post.

    This is straight from the docs:

    Custom locator keyword example:

    | Custom Locator Strategy | [Arguments] | ${browser} | ${criteria} | ${tag} | ${constraints} |
    |   | ${retVal}= | Execute Javascript | return window.document.getElementById('${criteria}'); |
    |   | [Return] | ${retVal} |

    Usage example:

    | Add Location Strategy | custom | Custom Locator Strategy |
    | Page Should Contain Element | custom=my_id |

    Currently, you only have to register it once and it will stay registered for the entire duration of the test execution. So, you register it in the setup of your top level suite and then all suites can use it from there on in.

  5. IlfirinPL commented on Apr 20, 2015

    @IlfirinPL
    Contributor

    I tried to check your solution but I have some problems
    in suite setup
    Add Location Strategy scLocate2 Custom Locator Strategy ScLocate

    Custom Locator Strategy ScLocate
    [Arguments] ${browser} ${criteria} ${tag} ${constraints}
    ${criteria} Replace String ${criteria} ' \'
    ${retVal}= Execute Javascript return isc.AutoTest.getElement('${criteria}');
    [Return] ${retVal}

    Step executed
    Wait Until Element Is Visible scLocate2=//VLayout[ID="mainSection"]/member[Class=ListGrid||index=1||classIndex=0||classLength=1||roleIndex=0||roleLength=1||scRole=list]/filterEditor/editRowForm/item[name=name||title=Name||index=0||Class=TextItem]/element

    20150420 13:39:12.709 : INFO : ${criteria} = //VLayout[ID="mainSection"]/member[Class=ListGrid||index=1||classIndex=0||classLength=1||roleIndex=0||roleLength=1||scRole=list]/filterEditor/editRowForm/item[name=name||title=Name||index=0||Class=Tex...
    20150420 13:39:12.711 : INFO :
    Executing JavaScript:
    return isc.AutoTest.getElement('//VLayout[ID="mainSection"]/member[Class=ListGrid||index=1||classIndex=0||classLength=1||roleIndex=0||roleLength=1||scRole=list]/filterEditor/editRowForm/item[name=name||title=Name||index=0||Class=TextItem]/element');
    20150420 13:39:14.936 : INFO : ${retVal} = None
    20150420 13:39:15.150 : INFO : ${criteria} = //VLayout[ID="mainSection"]/member[Class=ListGrid||index=1||classIndex=0||classLength=1||roleIndex=0||roleLength=1||scRole=list]/filterEditor/editRowForm/item[name=name||title=Name||index=0||Class=Tex...
    20150420 13:39:15.153 : INFO :
    Executing JavaScript:
    return isc.AutoTest.getElement('//VLayout[ID="mainSection"]/member[Class=ListGrid||index=1||classIndex=0||classLength=1||roleIndex=0||roleLength=1||scRole=list]/filterEditor/editRowForm/item[name=name||title=Name||index=0||Class=TextItem]/element');
    20150420 13:39:18.772 : INFO : ${retVal} = <selenium.webdriver.remote.webelement.WebElement object at 0x000000000494EF60>
    20150420 13:39:18.969 : INFO :
    Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 212, in _send_socket
    self.streamhandler.dump(packet)
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 436, in dump
    s = self._json_encoder(obj)
    File "C:\Python27\lib\json\encoder.py", line 209, in encode
    chunks = list(chunks)
    File "C:\Python27\lib\json\encoder.py", line 431, in _iterencode
    for chunk in _iterencode_list(o, _current_indent_level):
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 442, in _iterencode
    o = _default(o)
    File "C:\Python27\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
    TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004778710> is not JSON serializable
    Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 212, in _send_socket
    self.streamhandler.dump(packet)
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 436, in dump
    s = self._json_encoder(obj)
    File "C:\Python27\lib\json\encoder.py", line 209, in encode
    chunks = list(chunks)
    File "C:\Python27\lib\json\encoder.py", line 431, in _iterencode
    for chunk in _iterencode_list(o, _current_indent_level):
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 442, in _iterencode
    o = _default(o)
    File "C:\Python27\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
    TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004778710> is not JSON serializable
    Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 212, in _send_socket
    self.streamhandler.dump(packet)
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 436, in dump
    s = self._json_encoder(obj)
    File "C:\Python27\lib\json\encoder.py", line 209, in encode
    chunks = list(chunks)
    File "C:\Python27\lib\json\encoder.py", line 431, in _iterencode
    for chunk in _iterencode_list(o, _current_indent_level):
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 442, in _iterencode
    o = _default(o)
    File "C:\Python27\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
    TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004778710> is not JSON serializable
    Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 212, in _send_socket
    self.streamhandler.dump(packet)
    File "C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py", line 436, in dump
    s = self._json_encoder(obj)
    File "C:\Python27\lib\json\encoder.py", line 209, in encode
    chunks = list(chunks)
    File "C:\Python27\lib\json\encoder.py", line 431, in _iterencode
    for chunk in _iterencode_list(o, _current_indent_level):
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 442, in _iterencode
    o = _default(o)
    File "C:\Python27\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
    TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004778710> is not JSON serializable

  6. just-be-dev commented on Apr 20, 2015

    @just-be-dev
    ContributorAuthor

    Why are you replacing ${criteria} with \\? You might want to Log your arguments to make sure you're getting everything you expect to get.

    Also, are you sure you're actually accessing the isc object? With Execute Javascript you have to explicitly use window if you want to access something in the global scope. That should probably be window.isc.AutoTest.getElement(...);. I assume that's what's happening. If that doesn't help, let me know and we can dive deeper into it.

  7. IlfirinPL commented on Apr 21, 2015

    @IlfirinPL
    Contributor

    keyword "Custom Locator Strategy ScLocate" its equivalent of code below of python implementation
    additional \ are to escape RF masking , code below its working correctly. Standard \ are required to mask / in java script

    def _find_by_sc_locator(self, browser, criteria, tag, constraints):
        js = "return isc.AutoTest.getElement('%s')" % criteria.replace("'", "\\'")
        return self._filter_elements([browser.execute_script(js)], tag, constraints)
    
  8. just-be-dev commented on Apr 21, 2015

    @just-be-dev
    ContributorAuthor

    Do you happen to have a test written for this against one of the SmartClient examples? If not, I'll try to write one at some point today.

  9. IlfirinPL commented on Apr 22, 2015

    @IlfirinPL
    Contributor

    example use
    open , wait for element , type single char

    Open Browser | http://www.smartclient.com/smartgwt/showcase/#featured_tile_filtering
    Wait Until Page Contains Element | scLocator=//testRoot[]?/member[Class=VStack||index=0||length=1||classIndex=0||classLength=1]/member[Class=DynamicForm||index=1||length=4||classIndex=0||classLength=2]/item[name=commonName||title=Animal||value=a||index=0||Class=TextItem]/element
    Input Text | scLocator=//testRoot[]/member[Class=VStack||index=0||length=1||classIndex=0||classLength=1]/member[Class=DynamicForm||index=1||length=4||classIndex=0||classLength=2]/item[name=commonName||title=Animal||value=a||index=0||Class=TextItem]/element | a

  10. just-be-dev commented on Apr 22, 2015

    @just-be-dev
    ContributorAuthor

    So I've implemented a test case to test what you gave me above and I found that both methods work.

    I just commited a test that covers this in my custom-smartclient-locator branch.

    You can try it out yourself by running:

    python run_tests.py python firefox --suite smartclient
    

    You can change firefox to the browser of your choice. Regardless that shows that the custom locator does indeed function correctly. I believe it didn't work for you because you weren't using window.isc.

  11. IlfirinPL commented on Apr 24, 2015

    @IlfirinPL
    Contributor

    I tried your solution it raised some errors but over all steps were executed correctly
    [ ERROR ] Calling listener method 'start_keyword' of listener 'C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004623940> is not JSON serializable

    [ ERROR ] Calling listener method 'end_keyword' of listener 'C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004623940> is not JSON serializable
    [ ERROR ] Calling listener method 'start_keyword' of listener 'C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004623940> is not JSON serializable

    [ ERROR ] Calling listener method 'end_keyword' of listener 'C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.firefox.webdriver.WebDriver object at 0x0000000004623940> is not JSON serializable

  12. just-be-dev commented on Apr 24, 2015

    @just-be-dev
    ContributorAuthor

    That appears to be some issue with RIDE. I run my tests directly from the command-line so I don't have a whole lot of experience with that. You might try reporting that as an issue on the RIDE repo, but it seems like it isn't really actively maintained anymore so you mileage may vary. All I can tell you from looking at ride code is that it's trying to serialize some data to send across a socket (for whatever reason) and that process is failing.

    @pekkaklarck, is there anyone still around who knows anything about RIDE? I'm not sure what's causing @IlfirinPL error, but my guess is it may be choking on a javascript string.

    @IlfirinPL Are you okay with me removing the baked in SmartClient support in favor of using a custom locator?

  13. IlfirinPL commented on Apr 24, 2015

    @IlfirinPL
    Contributor

    No, I want to have support of smart client as part of selenium, and as you see method using Custom Locator rise errors, over all i don't know why you want to remove it, where is advantage of it ?
    In current solution you can use smart client out of the box.

  14. just-be-dev commented on Apr 24, 2015

    @just-be-dev
    ContributorAuthor

    It's more of an argument of separation of concerns. Having a SmartClient locator (or any custom locator) baked in means that knowledge of the SmartClient library is needed to maintain and support that locator. If SmartClient updates to change it's querying scheme then the Selenium2Library will have to update as well to mark that change. If you're still using the old query scheme after the library is updated then you'll be forced to use an old version of the Selenium2Library because your location strategy is out of date.

    The advantage of it is that you get to customize the locator however you want without requiring a change to the core Selenium2Library. It makes long-term maintenance simpler for both of us.

    I'm not touching any of the other locators currently for the purpose of backwards compatibility. The only reason this locator is up for discussion is because it hasn't yet been released. With that being said, @emanlove approved it so I'll keep it in if you're really dead set against it.

    As for the errors you're seeing, as I've stated that's an issue in RIDE. I'll look into it though, maybe there's something I can do to alleviate the issue.

  15. just-be-dev commented on Apr 27, 2015

    @just-be-dev
    ContributorAuthor

    I'll leave your solution in. In the future though, I want to avoid baking in locators.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions