|
| 1 | +""" The main purpose of this file is to demonstrate running SeleniumBase |
| 2 | + scripts without the use of Pytest by calling the script directly |
| 3 | + with Python or from a Python interactive interpreter. Based on |
| 4 | + whether relative imports work or don't work, it will autodetect |
| 5 | + how this file was run. With pure Python, it will need to initialize |
| 6 | + all the variables that would've been automatically initialized |
| 7 | + by the Pytest plugin. The same thing is required for the setUp() |
| 8 | + and tearDown() methods, which are now called from the script itself. |
| 9 | +
|
| 10 | + One big advantage to running tests with Pytest is that most of this |
| 11 | + is done for you automatically, with the option to update any of the |
| 12 | + parameters through command line parsing. Pytest also provides you |
| 13 | + with other plugins, such as ones for generating test reports, |
| 14 | + handling multithreading, and parametrized tests. Depending on your |
| 15 | + specific needs, you may need to call SeleniumBase commands without |
| 16 | + using Pytest, and this example shows you how. """ |
| 17 | + |
| 18 | +try: |
| 19 | + # Running with Pytest / (Finds test methods to run using autodiscovery) |
| 20 | + # Example run command: "pytest raw_parameter_script.py" |
| 21 | + from .my_first_test import MyTestClass # (relative imports work: ".~") |
| 22 | + |
| 23 | +except (ImportError, ValueError): |
| 24 | + # Running with pure Python OR from a Python interactive interpreter |
| 25 | + # Example run command: "python raw_parameter_script.py" |
| 26 | + from my_first_test import MyTestClass # (relative imports DON'T work) |
| 27 | + |
| 28 | + b = MyTestClass("test_basic") |
| 29 | + b.browser = "chrome" |
| 30 | + b.headless = False |
| 31 | + b.servername = "localhost" |
| 32 | + b.port = 4444 |
| 33 | + b.data = None |
| 34 | + b.environment = "test" |
| 35 | + b.database_env = "test" |
| 36 | + b.log_path = "latest_logs/" |
| 37 | + b.timeout_multiplier = None |
| 38 | + b.with_db_reporting = False |
| 39 | + b.with_s3_logging = False |
| 40 | + b.js_checking_on = False |
| 41 | + b.is_pytest = False |
| 42 | + b.demo_mode = False |
| 43 | + b.demo_sleep = 1 |
| 44 | + b.message_duration = 2 |
| 45 | + b.proxy_string = None |
| 46 | + b.ad_block_on = False |
| 47 | + b.highlights = None |
| 48 | + b.check_js = False |
| 49 | + b.cap_file = None |
| 50 | + |
| 51 | + b.setUp() |
| 52 | + try: |
| 53 | + b.test_basic() |
| 54 | + finally: |
| 55 | + b.tearDown() |
| 56 | + del b |
0 commit comments