SkipKent
SkipKent

Reputation: 457

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. For libraries imported directly code completion is working fine, but in this case I'm importing the Selenium2Library indirectly via a method:

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. 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

Upvotes: 0

Views: 1522

Answers (1)

ombre42
ombre42

Reputation: 2384

Try adding a docstring to your function to help 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

Upvotes: 1

Related Questions