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
4.45k stars 908 forks source link

Recording and saving #2833

Closed kitsune0n closed 3 weeks ago

kitsune0n commented 3 weeks ago

When using seleniumbase in my python app as from seleniumbase import SB i understand have two options for using recording in my code recorder_ext=True with extension and activate_recorder() without extension

how i can stop recording and save?

trying to use import pdb; pdb.set_trace() after activate_recorder() but this only works with pytest ? or save_recorded_actions() after activate_recorder() and have only msg Recorder Mode ACTIVE. [ESC]: Pause. [~]: Resume.`

Of course, in my case, extension would have approached more, it works when i add recorder_ext=True SB(uc=True, disable_js=False, headless=False, recorder_ext=True, extension_dir=MY_EXTENSION_PATH, locale_code="en") but with driver.quit () I do not see any saved records, do I need to execute additional commands to complete the recording and saving the file?

mdmintz commented 3 weeks ago

A SeleniumBase script must end naturally for the recording to be created from recorded actions when using Recorder Mode. Don't quit the driver before that. The recorded script is finalized during the tearDown() phase.

See the Recorder Mode ReadMe for full instructions.

kitsune0n commented 3 weeks ago

Thx @mdmintz tearDown() help's. But have troubles with sessionStorage url open by self.open() like in readme trying with and without uc mode Error:

`Traceback (most recent call last):
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\plugins\sb_manager.py", line 944, in SB
    yield sb
  File "C:\Users\mrsta\PycharmProjects\CryptoBot\main.py", line 100, in <module>
    sb.tearDown()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 15857, in tearDown
    self.__process_recorded_actions()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 4651, in __process_recorded_actions
    tab_actions = self.__get_recorded_actions_on_active_tab()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 4632, in __get_recorded_actions_on_active_tab
    actions = self.get_session_storage_item("recorded_actions")
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 8519, in get_session_storage_item
    raise WebDriverException("Session Storage is not available here!")
selenium.common.exceptions.WebDriverException: Message: Session Storage is not available here!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\plugins\sb_manager.py", line 971, in SB
    sb.tearDown()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 15857, in tearDown
    self.__process_recorded_actions()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 4649, in __process_recorded_actions
    for window in self.driver.window_handles:
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 494, in window_handles
    return self.execute(Command.W3C_GET_WINDOW_HANDLES)["value"]
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: disconnected: Unable to receive message from renderer
  (failed to check if window was closed: disconnected: not connected to DevTools)
  (Session info: chrome=125.0.6422.142)
Stacktrace:
        GetHandleVerifier [0x00007FF695D91F52+60322]
        (No symbol) [0x00007FF695D0CEC9]
        (No symbol) [0x00007FF695BC7EBA]
        (No symbol) [0x00007FF695BB070D]
        (No symbol) [0x00007FF695BAE39D]
        (No symbol) [0x00007FF695BAEBAF]
        (No symbol) [0x00007FF695BC84E3]
        (No symbol) [0x00007FF695B9D08C]
        (No symbol) [0x00007FF695C4B697]
        (No symbol) [0x00007FF695C3C1E0]
        (No symbol) [0x00007FF695C09617]
        (No symbol) [0x00007FF695C0A211]
        GetHandleVerifier [0x00007FF6960A94AD+3301629]
        GetHandleVerifier [0x00007FF6960F36D3+3605283]
        GetHandleVerifier [0x00007FF6960E9450+3563680]
        GetHandleVerifier [0x00007FF695E44326+790390]
        (No symbol) [0x00007FF695D1750F]
        (No symbol) [0x00007FF695D13404]
        (No symbol) [0x00007FF695D13592]
        (No symbol) [0x00007FF695D02F9F]
        BaseThreadInitThunk [0x00007FFB1BC4257D+29]
        RtlUserThreadStart [0x00007FFB1D08AA48+40]
Traceback (most recent call last):
  File "C:\Users\mrsta\PycharmProjects\CryptoBot\main.py", line 100, in <module>
    sb.tearDown()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 15857, in tearDown
    self.__process_recorded_actions()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 4651, in __process_recorded_actions
    tab_actions = self.__get_recorded_actions_on_active_tab()
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 4632, in __get_recorded_actions_on_active_tab
    actions = self.get_session_storage_item("recorded_actions")
  File "C:\Users\mrsta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py", line 8519, in get_session_storage_item
    raise WebDriverException("Session Storage is not available here!")
selenium.common.exceptions.WebDriverException: Message: Session Storage is not available here!`
mdmintz commented 3 weeks ago

Session Storage is only available on http and https URLs.

kitsune0n commented 3 weeks ago

Session Storage is only available on http and https URLs.

Yes. I open https url @mdmintz step by step:

  1. I import selenium base into my project from seleniumbase import SB
  2. then use selenium base with recorder extension with SB(uc=False, disable_js=False, headless=False, recorder_ext=True, extension_dir=MY_EXTENSION_PATH, locale_code="en") as sb:
  3. Open https website sb.open(URL)
  4. after delay call tearDown sb.tearDown() ps: adding sb.save_recorded_actions() don't give any result
mdmintz commented 3 weeks ago

Here's an example of using it from SB():

from seleniumbase import SB

with SB(recorder_ext=True) as sb:
    sb.open("seleniumbase.io/simple/login")
    sb.type("#username", "demo_user")
    sb.type("#password", "secret_pass")
    sb.click('a:contains("Sign in")')
    sb.assert_exact_text("Welcome!", "h1")
    sb.assert_element("img#image1")
    sb.highlight("#image1")
    sb.click_link("Sign out")
    sb.assert_text("signed out", "#top_message")

Call a breakpoint() on a line where you want to insert manual actions to record. Type c on the command-line and press Enter/Return to continue from the breakpoint(). At the end of the script, the recording will be generated automatically.

kitsune0n commented 3 weeks ago

Here's an example of using it from SB():

from seleniumbase import SB

with SB(recorder_ext=True) as sb:
    sb.open("seleniumbase.io/simple/login")
    sb.type("#username", "demo_user")
    sb.type("#password", "secret_pass")
    sb.click('a:contains("Sign in")')
    sb.assert_exact_text("Welcome!", "h1")
    sb.assert_element("img#image1")
    sb.highlight("#image1")
    sb.click_link("Sign out")
    sb.assert_text("signed out", "#top_message")

Call a breakpoint() on a line where you want to insert manual actions to record. Type c on the command-line and press Enter/Return to continue from the breakpoint(). At the end of the script, the recording will be generated automatically.

thx I find what is the problem I added by the plugin of Extense_Dir = Metamask_Extance_path open its web page that interferes with record. Is there anyway to ignore this with record extension ? or only use activate_recorder() for 1 page record ? can i make custom name of the records ?