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

Why can i use pycharm to run my_first_test.py? #292

Closed
adadale opened this issue Mar 10, 2019 · 3 comments
Closed

Why can i use pycharm to run my_first_test.py? #292

adadale opened this issue Mar 10, 2019 · 3 comments
Labels
question Someone is looking for answers

Comments

@adadale
Copy link

adadale commented Mar 10, 2019

Terminal to run my_first_test.py is running well .but when i use Pycharm to run it ,it goes wrong.Logging is here.It may be about setUp method in base_case.py.But I doubt why i can run it in terminal successfully?Thanks!
F
examples/my_first_test.py:9 (MyTestClass.test_basic)
self = <examples.my_first_test.MyTestClass testMethod=test_basic>

def setUp(self):
    """
        Be careful if a subclass of BaseCase overrides setUp()
        You'll need to add the following line to the subclass setUp() method:
        super(SubClassOfBaseCase, self).setUp()
        """
    self.is_pytest = None
    try:
        # This raises an exception if the test is not coming from pytest
        self.is_pytest = sb_config.is_pytest
    except Exception:
        # Not using pytest (probably nosetests)
        self.is_pytest = False
    if self.is_pytest:
        # pytest-specific code
        test_id = "%s.%s.%s" % (self.__class__.__module__,
                                self.__class__.__name__,
                                self._testMethodName)
        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
        self.database_env = sb_config.database_env
        self.message_duration = sb_config.message_duration
        self.js_checking_on = sb_config.js_checking_on
        self.ad_block_on = sb_config.ad_block_on
        self.verify_delay = sb_config.verify_delay
        self.timeout_multiplier = sb_config.timeout_multiplier
        self.use_grid = False
        if self.servername != "localhost":
            # Use Selenium Grid (Use --server=127.0.0.1 for localhost Grid)
            self.use_grid = True
        if self.with_db_reporting:
            from seleniumbase.core.application_manager import (
                ApplicationManager)
            from seleniumbase.core.testcase_manager import (
                ExecutionQueryPayload)
            import getpass
            self.execution_guid = str(uuid.uuid4())
            self.testcase_guid = None
            self.execution_start_time = 0
            self.case_start_time = 0
            self.application = None
            self.testcase_manager = None
            self.error_handled = False
            self.testcase_manager = TestcaseManager(self.database_env)
            #
            exec_payload = ExecutionQueryPayload()
            exec_payload.execution_start_time = int(time.time() * 1000)
            self.execution_start_time = exec_payload.execution_start_time
            exec_payload.guid = self.execution_guid
            exec_payload.username = getpass.getuser()
            self.testcase_manager.insert_execution_data(exec_payload)
            #
            data_payload = TestcaseDataPayload()
            self.testcase_guid = str(uuid.uuid4())
            data_payload.guid = self.testcase_guid
            data_payload.execution_guid = self.execution_guid
            if self.with_selenium:
                data_payload.browser = self.browser
            else:
                data_payload.browser = "N/A"
            data_payload.test_address = test_id
            application = ApplicationManager.generate_application_string(
                self._testMethodName)
            data_payload.env = application.split('.')[0]
            data_payload.start_time = application.split('.')[1]
            data_payload.state = constants.State.NOTRUN
            self.testcase_manager.insert_testcase_data(data_payload)
            self.case_start_time = int(time.time() * 1000)
        if self.headless:
            try:
                from pyvirtualdisplay import Display
                self.display = Display(visible=0, size=(1440, 1080))
                self.display.start()
                self.headless_active = True
            except Exception:
                # pyvirtualdisplay might not be necessary anymore because
                # Chrome and Firefox now have built-in headless displays
                pass

    # Launch WebDriver for both Pytest and Nosetests
    if not hasattr(self, "browser"):
      raise Exception("""SeleniumBase plugins did not load! """
                        """Please reinstall using:\n"""
                        """ >>> "python setup.py install" <<< """)

E Exception: SeleniumBase plugins did not load! Please reinstall using:
E >>> "python setup.py install" <<<

../seleniumbase/fixtures/base_case.py:2860: Exception

@mdmintz
Copy link
Member

mdmintz commented Mar 10, 2019

Hi @adadale , when you run seleniumbase in pycharm, you need to install the requirements inside there first. There is a requirements.txt file at the top level. I tested with PyCharm CE... an alert message popped up in the editor asking if I wanted to install the requirements, and then I did. If PyCharm isn't giving you the alert, there should be a command in there somewhere to let you install the requirements.

@adadale
Copy link
Author

adadale commented Mar 11, 2019

I made it successfully.Thank you very much.I want to ask another question.Because my ability of writing code is very poor,I don't know what's the meaning of database_env and message_duration,etc which are in the setUp method.I want to learn your project,but i don't know how to do it efficiently.
def setUp(self):
if self.is_pytest:
self.database_env = sb_config.database_env
self.message_duration = sb_config.message_duration
self.js_checking_on = sb_config.js_checking_on
self.ad_block_on = sb_config.ad_block_on
self.verify_delay = sb_config.verify_delay
self.timeout_multiplier = sb_config.timeout_multiplier
self.use_grid = False

@mdmintz
Copy link
Member

mdmintz commented Mar 11, 2019

@adadale You can set message_duration to change the default time for pop-up messages to appear (in seconds), such as during demo_mode. Example:

pytest my_first_test.py --demo_mode --message_duration=2

"database_env" is for marking a row in a table when using the MySQL functionality to save test results to a MySQL DB at the end of tests. That way you can tell apart the environment where you decided to run your tests. It's not necessary.

@mdmintz mdmintz closed this as completed Mar 12, 2019
@mdmintz mdmintz added the question Someone is looking for answers label Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers
Projects
None yet
Development

No branches or pull requests

2 participants