seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5k stars 944 forks source link

where are attributes of sb_config?like sb_config.browser.I try my best to find it ,but i can't find . #293

Closed adadale closed 5 years ago

adadale commented 5 years ago

I can't find the sb_config._brower,etc.where are they? I only find ad_block_list.py,proxy_list.py and settings.py,but i can't find these below. Thanks!
self.browser = sb_config.browser self.data = sb_config.data self.demo_mode = sb_config.demo_mode self.demo_sleep = sb_config.demo_sleep self.highlights = sb_config.highlights self.environment = sb_config.environment self.env = self.environment # Add a shortened version self.with_selenium = sb_config.with_selenium # Should be True self.headless = sb_config.headless self.headless_active = False self.log_path = sb_config.log_path self.with_testing_base = sb_config.with_testing_base self.with_basic_test_info = sb_config.with_basic_test_info self.with_screen_shots = sb_config.with_screen_shots self.with_page_source = sb_config.with_page_source self.with_db_reporting = sb_config.with_db_reporting self.with_s3_logging = sb_config.with_s3_logging self.servername = sb_config.servername self.port = sb_config.port self.proxy_string = sb_config.proxy_string self.user_agent = sb_config.user_agent self.cap_file = sb_config.cap_file

mdmintz commented 5 years ago

Hi @adadale The whole point of sb_config was to avoid the DeprecationWarning messages from the old pytest.config - See: https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.18.1 It's for passing command line parameters (such as "browser") into the test configuration. Of all of those parameters, the only ones you might ever want to use inside tests themselves is self.browser, self.headless, self.env, and self.data. For example, if you want your tests to perform a different action based on the browser you're using, you could do something like:

if self.browser == "chrome":
    ... # DO SOMETHING SPECIAL

You can use --data=ANYTHING on the command line so that you can pass any custom parameters into tests, which you can then access with self.data. Maybe you have a QA and a Production environment, so you can have tests run differently using --env=qa or --env=production by then modifying a login method in your tests with:

if self.env == "qa":
    ... # Login to the QA environment
elif self.env == "production":
    ... # Login to the Production environment

If you want to see what the tests have access too, just run print(dir(self)) inside the tests. That will print out all the methods and variables that tests have access to.

adadale commented 5 years ago

I will try it.Thank you very much!