Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

IntelliSense confusion for a noob #3402

Answered by mdmintz
tylerdurden4285 asked this question in Q&A
Discussion options

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:

  1. Can I use intellisense on 'sb' somehow the same way as 'self' allows?

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

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
2 replies
Comment options

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

Comment options

Thank you! This is all I wanted. So helpful. : )

Answer selected by mdmintz
Comment options

I did this: ``` from seleniumbase import BaseCase BaseCase.main(__name__, __file__) ``` So then to use sb I do it like this? ![image](https://github.com/user-attachments/assets/f218af79-3d36-468e-b4ee-ff109bcced80) perhaps like this or similar is better? ![image](https://github.com/user-attachments/assets/2fb46776-f910-446d-9190-b689bcdc1aac)
You must be logged in to vote
1 reply
Comment options

Here the the Syntax Formats to stick to: SeleniumBase/help_docs/syntax_formats.md

Comment options

Even with the link you provided here's what I am having trouble doing all together at the same time.

  1. Using python not pytest like: python main.py --gui
  2. Not needing pytest function naming like test_example()
  3. 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?

You must be logged in to vote
2 replies
Comment options

  1. pytest has an arg parser. You can pass arguments easily from the command-line. With regular Python formats, args are passed in during the SB() call, for example.
  2. The test_ naming is specific to pytest so that tests can be collected automatically. There are no naming requirements for non-pytest scripts, as they would just be called via python.
  3. 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
Screenshot 2024年02月27日 at 2 32 58 PM

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")
Comment options

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /