-
Notifications
You must be signed in to change notification settings - Fork 1.4k
IntelliSense confusion for a noob #3402
-
As a reasonably new python developer I have some confusion about something...
Using Basecase with Seleniumbase allows me to do what I think is called 'intellisense' with self like:
- self.assert_true
- self.open
- self.download_file
This is really helpful and has the "choices list" and instructions on hover.
For example:
image
But when you do the other approach and use "with SB() as sb:" I cannot get it to work with sb like:
- sb.asset_true
- sb.open
- sb.download_file
For example:
image
My guess is that Basecase is a pytest thing but is there a way to use it through "Seleniumbase" directly so I get intellisense for "sb" ?
Also I am only using it this way because it seems that the Basecase approach only works with pytest and to use python to run it like "python ./main.py" you seem to need to do the "with SB() as sb:" statement.
In summary my questions are:
-
Can I use intellisense on 'sb' somehow the same way as 'self' allows?
-
Is there any way to run python main.py for the Basecase version? (it works fine for me with pytest but not python)
Thanks in advance to anyone that can help.
Beta Was this translation helpful? Give feedback.
All reactions
The BaseCase.main(__name__, __file__)
lets you kick off pytest
when calling the script with pure python
.
Here's the most basic example of that:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__) class NullTests(BaseCase): def test_null(self): pass
To get autocomplete working from SB()
scripts, use a breakpoint()
. Then all methods will appear from the debugger.
The reason SB()
methods don't appear with IntelliSense
is because the methods get defined at runtime because different modes have different methods. (Eg. UC Mode and CDP Mode add different methods into SB()
.) Different methods based on the mode.
Inside help_docs/method_summary.md you'll find regular met...
Replies: 3 comments 5 replies
-
The BaseCase.main(__name__, __file__)
lets you kick off pytest
when calling the script with pure python
.
Here's the most basic example of that:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__) class NullTests(BaseCase): def test_null(self): pass
To get autocomplete working from SB()
scripts, use a breakpoint()
. Then all methods will appear from the debugger.
The reason SB()
methods don't appear with IntelliSense
is because the methods get defined at runtime because different modes have different methods. (Eg. UC Mode and CDP Mode add different methods into SB()
.) Different methods based on the mode.
Inside help_docs/method_summary.md you'll find regular methods at the top and middle. The UC Mode method list is at the bottom. And CDP Mode methods can be found in the second half of examples/cdp_mode/ReadMe.md.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm totally new to development maybe this is a bad idea but found that marking sb as BaseCase could do the trick. This looks like the thing the OP was asking for.
Screenshot 2025年03月15日 at 01 49 10
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 2
-
Thank you! This is all I wanted. So helpful. : )
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Here the the Syntax Formats to stick to: SeleniumBase/help_docs/syntax_formats.md
Beta Was this translation helpful? Give feedback.
All reactions
-
Even with the link you provided here's what I am having trouble doing all together at the same time.
- Using python not pytest like: python main.py --gui
- Not needing pytest function naming like test_example()
- Getting intellisense as previously mentioned
Things work great with pytest but using python seems to complicate it a bit. The examples I've found from your site allow a solution to all 3 but not at the same time. What is an example of code that would allow all three for someone that just wants to use seleniumbase with python only and not have to name things test_ (pytest style) and still have intellisense?
Beta Was this translation helpful? Give feedback.
All reactions
-
pytest
has an arg parser. You can pass arguments easily from the command-line. With regular Python formats, args are passed in during theSB()
call, for example.- The
test_
naming is specific topytest
so that tests can be collected automatically. There are no naming requirements for non-pytest scripts, as they would just be called viapython
. - Unless Intellisense has ESP (to see the future), it's not going to know what the methods are until at runtime because different modes come with different methods. The mode is set at initialization (eg.
uc=True
). The mode can also be changed at runtime (eg.sb.activate_cdp_mode()
).
The debugger sees all methods. For example:
python -m pdbp raw_login_driver.py
The methods that exist in the SB()
and Driver()
formats aren't defined until runtime.
For example, if using UC Mode, new driver
methods are added.
Since methods aren't set until runtime, the IDE wouldn't know what to list for methods yet.
But the good news is that the BaseCase
format will probably display methods in an IDE:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__) class TestSimpleLogin(BaseCase): def test_simple_login(self): self.open("seleniumbase.io/simple/login") self.type("#username", "demo_user") self.type("#password", "secret_pass") self.click('a:contains("Sign in")') self.assert_exact_text("Welcome!", "h1") self.assert_element("img#image1") self.highlight("#image1") self.click_link("Sign out") self.assert_text("signed out", "#top_message")
Beta Was this translation helpful? Give feedback.
All reactions
-
I think we have a misunderstanding still and I'm probably just going to frustrate you if I try to understand it further so I'll give up.
Beta Was this translation helpful? Give feedback.