Skip to content
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

Class variables not recognized and don't autofill #63

Open
tchumannity opened this issue Dec 7, 2023 · 1 comment
Open

Class variables not recognized and don't autofill #63

tchumannity opened this issue Dec 7, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@tchumannity
Copy link

Variables that are defined in a class aren't recognized or autofilled when writing test cases in robot. I created multiple files with various classes to organize my locator variables but they are all unrecognized in robot files. Everything runs fine and tests pass, its just much harder to write and figure if a variable actually does not exist.

Test.robot:

Testing
	[Documentation]    Testing Stuff
	Open Test Application
	Tap Element    ${WelcomeScreen.iAgree_button}
	Tap Element    ${LetsGetStartedScreen.setupNow_button}
Locators.py:

class WelcomeScreen:
    EULAPrivacy_link = "//android.view.ViewGroup/android.widget.TextView[2]"
    iAgree_button = "IAgreeButton"
    debugSettings_button = "//android.view.ViewGroup/android.view.ViewGroup/android.widget.ImageButton"

class LetsGetStartedScreen:
    setupNow_button = "SetupButton"
    tutorial_button = "TutorialButton"

In this case ${WelcomeScreen.iAgree_button} and ${LetsGetStartedScreen.setupNow_button} won't autofill and display an unknown variable in the editor.

@jnhyperion
Copy link
Owner

jnhyperion commented Dec 8, 2023

For now, plugin does not support variable parsing with syntax like ${class_name.var_name}, the workaround is:

from dataclasses import dataclass, asdict


@dataclass
class Foo:
    foo_int_var: int = 1
    foo_str_var: str = "1"


@dataclass
class Bar:
    bar_int_var: int = 1
    bar_str_var: str = "1"


def get_variables():
    return {**asdict(Foo()), **asdict(Bar())}

then you can use the variable by name directly, but the limitation is this will be conflict if there're same name var in different var class.

@jnhyperion jnhyperion added the enhancement New feature or request label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants