简体   繁体   English

PyCharm中的Selenium2Library代码完成

[英]Selenium2Library code completion in PyCharm

I'm experimenting with creating a basic library extension for Robot Framework using Python, and I'm using PyCharm as the editor. 我正在尝试使用Python创建用于Robot Framework的基本库扩展,并且正在使用PyCharm作为编辑器。 For libraries imported directly code completion is working fine, but in this case I'm importing the Selenium2Library indirectly via a method: 对于直接导入的库,代码完成工作正常,但是在这种情况下,我通过一种方法间接导入Selenium2Library:

def get_current_browser():
    browser = BuiltIn().get_library_instance('Selenium2Library')._current_browser()
    return browser

Which I call from other methods with something like 我从其他方法调用类似于

driver = get_current_browser()

This successfully grabs the webdriver browser instance from Robot Framework and lets me do as I please, but I don't get code hints when I go to edit a 'driver' variable. 这成功地从Robot Framework中获取了webdriver浏览器实例,并让我随心所欲,但是当我去编辑一个'driver'变量时却没有代码提示。 Is there way I can get hints in this scenario? 在这种情况下,有什么办法可以得到提示?

Here's the code in full: 这是完整的代码:

from robot.libraries.BuiltIn import BuiltIn
from Selenium2Library.keywords.keywordgroup import KeywordGroup
import logging


def get_current_browser():
    browser = BuiltIn().get_library_instance('Selenium2Library')._current_browser()
    return browser


class MyLibrary(KeywordGroup):

    def get_title_via_python(self):
        driver = get_current_browser()
        title = driver.title
        logging.warn("checking title %s" % title)
        return title

Try adding a docstring to your function to help PyCharm. 尝试在函数中添加文档字符串以帮助PyCharm。

from selenium.webdriver import Remote # Remote imported only for code completion


def get_current_browser():
    """
    :rtype: Remote
    """
    browser = BuiltIn().get_library_instance('Selenium2Library')._current_browser()
    return browser

More at http://www.jetbrains.com/pycharm/webhelp/type-hinting-in-pycharm.html 有关更多信息, 请访问http://www.jetbrains.com/pycharm/webhelp/type-hinting-in-pycharm.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM