robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
173 stars 14 forks source link

[QUESTION] Discovery of python keywords in a selenium plugin #147

Closed johngeorgewright closed 1 year ago

johngeorgewright commented 1 year ago

I have a lot of keywords in a selenium plugin. For example:

# lib/MyPlugin.py

from SeleniumLibrary.base import keyword

class MyPlugin:
  @keyword()
  def assert_something(self, something):
    return some_assertion()

Then I use it in my case file:

*** Settings ***
Library    SeleniumLibrary    plugins=MyPlugin

*** Test Cases ***
Expect Something
    Assert Something    something

I current receive errors, in my case file, telling me that the Assert Something keyword does not exist. Is there anything I can do to remedy that? (Just to clarify, running this test works fine).

Desktop (please complete the following information):

d-biehl commented 1 year ago

Hi @johngeorgewright,

RobotCode caches the information about the keywords in a library when it first finds them, because normally keywords don't change. However, this is quite a challenge with dynamic libraries. The possibility to extend the Selenium library with plugins makes it a dynamic library. Try to delete the cache of RobotCode, as long as the SeleniumLibrary is always included in your project in the same way, i.e. with always the same parameters, this can be a solution. Search in VSCode with F1 for the command Robot Code: Clear Cache and Restart Language Servers and execute it.

You can also exclude libraries completely from the cache mechanism, then the information for each robot file is always read in again. This might take a little longer at startup, but if it's just one library, it shouldn't matter too much.

Excluding libraries is done with the setting robotcode.analysis.cache.ignoredLibraries (just search in Settings, but aware of the User and Workspace/Folder settings, in most cases it is enough to use the User settings), just add SeleniumLibrary there.

johngeorgewright commented 1 year ago

Amazing. This works! Thanks for your help @d-biehl .