SeleniumBase
SeleniumBase copied to clipboard
Does seleniumBase support recording electron applications?
Does seleniumIDE support recording electron applications?
I want to use seleniumIDE to record automation scripts for electron applications. If so, what should I modify in the source code to replace our electron application path?
If anyone also working on the recording of automated test scripts for electron applications, please contact me:[email protected]
SeleniumBase has its own Recorder tool: https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/recorder_mode.md https://seleniumbase.io/help_docs/recorder_mode/ It's an alternative to SeleniumIDE. It will work on all types of applications, including Electron ones.
To activate the GUI for it, type seleniumbase recorder on the command-line. Set your parameters, and then record the actions you want to generate a Python script from. When done recording actions, type c on the command-line and press Enter to leave the breakpoint, which then calls the tearDown() method that completes the script generation. There's a video here: https://www.youtube.com/watch?v=eKN5nq7YbdM
SeleniumBase has its own Recorder tool: https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/recorder_mode.md https://seleniumbase.io/help_docs/recorder_mode/ It's an alternative to SeleniumIDE. It will work on all types of applications, including Electron ones.
To activate the GUI for it, type
seleniumbase recorderon the command-line. Set your parameters, and then record the actions you want to generate a Python script from. When done recording actions, typecon the command-line and press Enter to leave the breakpoint, which then calls thetearDown()method that completes the script generation. There's a video here: https://www.youtube.com/watch?v=eKN5nq7YbdM
Thanks for answer. I have seen this video, but it seems that SeleniumBase Recorder only supports url.:( I want to know where should I modify it to support starting a local Electron application? Just like: Enter the path of the executable program in the input box that originally entered the url , and then start the program(Electron application) when recording . How can I modify it? Thanks for answer again!
@GuiStarF There needs to be a URL. Data is saved to sessionStorage, which is linked to URLs. The Python script than scans the sessionStorage to get the recorded actions for generating a test script. Maybe try loading your Electron App on a page that does have a URL?
@mdmintz My idea is that maybe I can replace the browser that the recording tool should start with my own electron program. In fact, the electron program is a desktop program that encapsulates the browser and web applications, So I would like to ask Which code or which file does SeleniumBase work to start the browser? And then I would like to try to modify it.Maybe it can be worked.
This file has the code that launches browsers: https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/core/browser_launcher.py This file has the Recorder code: https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/js_code/recorder_js.py
@mdmintz Thanks for answer, I will try to modify. If I have any problem, I would ask you again.
=================================================================== FAILURES ===================================================================
_________________________________________________________ RecorderTests.test_recording _________________________________________________________
seleniumbase\fixtures\base_case.py:13425: in tearDown
self.__process_recorded_actions()
seleniumbase\fixtures\base_case.py:3737: in __process_recorded_actions
for window in self.driver.window_handles:
C:\Users\GuiStar\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py:591: in window_handles
return self.execute(Command.W3C_GET_WINDOW_HANDLES)['value']
C:\Users\GuiStar\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py:435: in execute
self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x000001DE11F9DAB0>
response = {'status': 500, 'value': '{"value":{"error":"chrome not reachable","message":"chrome not reachable\\n (Session info: ...unk [0x758A6739+25]\\n\\tRtlGetFullPathName_UEx [0x77008FEF+1215]\\n\\tRtlGetFullPathName_UEx [0x77008FBD+1165]\\n"}}'}
E selenium.common.exceptions.WebDriverException: Message: chrome not reachable
E (Session info: chrome=103.0.5060.114)
E Stacktrace:
E Backtrace:
E Ordinal0 [0x00FB5FD3+2187219]
E Ordinal0 [0x00F4E6D1+1763025]
E Ordinal0 [0x00E63D40+802112]
E Ordinal0 [0x00E58A12+756242]
E Ordinal0 [0x00E4C2F0+705264]
E Ordinal0 [0x00F59895+1808533]
E Ordinal0 [0x00F626C1+1844929]
E BaseThreadInitThunk [0x758A6739+25]
E RtlGetFullPathName_UEx [0x77008FEF+1215]
E RtlGetFullPathName_UEx [0x77008FBD+1165]
C:\Users\GuiStar\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py:247: WebDriverException
=========================================================== short test summary info ============================================================
FAILED new_recording.py::RecorderTests::test_recording - selenium.common.exceptions.WebDriverException: Message: chrome not reachable
1 failed in 44.42s
-------
1
-------
*** RECORDING COPIED to: new_recording.py
@mdmintz
I use 'sbase recorder',and then I got the above error. How should I solve it pls?
Since it's happening in the tearDown area, it means you closed the Chrome browser before reaching tearDown. SeleniumBase automatically spins up and spins down web browsers on its own. If you try manually closing the browser in the test, then the Recorder won't be able to extract the recorded actions from the sessionStorage of the browser in the tearDown in order to generate the test script.
Since it's happening in the
tearDownarea, it means you closed the Chrome browser before reachingtearDown. SeleniumBase automatically spins up and spins down web browsers on its own. If you try manually closing the browser in the test, then the Recorder won't be able to extract the recorded actions from thesessionStorageof the browser in thetearDownin order to generate the test script.
yep,when I enter url,it worked.But I changed seleniumbase\fixtures\base_case.py(--->) :
def open(self, url):
"""Navigates the current browser window to the specified page."""
self.__check_scope()
self.__check_browser()
pre_action_url = None
try:
pre_action_url = self.driver.current_url
except Exception:
pass
url = str(url).strip() # Remove leading and trailing whitespace
if not self.__looks_like_a_page_url(url):
# url should start with one of the following:
# "http:", "https:", "://", "data:", "file:",
# "about:", "chrome:", "opera:", or "edge:".
if page_utils.is_valid_url("https://" + url):
url = "https://" + url
else:
# start electron
--------->self.get_electron(url)
return
# raise Exception('Invalid URL: "%s"!' % url)
def get_electron:
def get_electron(self, path):
# local chromedirver.exe
driver_path = r'D:/WorkRoom/WebDriver/chromedriver.exe'
self.service = webdriver.chrome.service.Service(driver_path)
self.service.start()
# start electron app:postman.exe
self.driver = webdriver.remote.webdriver.WebDriver(
command_executor=self.service.service_url,
desired_capabilities={
'browserName': 'chrome',
'goog:chromeOptions': {
'args': [],
'binary': r'C:/Users/GuiStar/AppData/Local/Postman/Postman.exe', # postman.exe
'extensions': [],
'windowTypes': ['webview']
},
'platform': 'ANY',
'version': ''
},
browser_profile=None,
proxy=None,
keep_alive=False
)
and then,I run to start POSTMAN.exe and it worked,but I still get the above error, the reason may be because the browser is not started, How can I modify the code to make the recorder collect the sessionStorage from the electron application in the tearDown in order to generate the test script?
You'll have to set self.driver to be the driver of the Electron App. The Recorder saves actions to the main browser's sessionStorage. That's the driver seen by self.driver. At the end of the test, in the tearDown area, SeleniumBase reads the sessionStorage of self.driver, and uses that data to generate the automation script.
Now after I replace the browser with the electron app, the recorder can't get the sessionstorage from the browser. I'm wondering how can I get the recorder to get the sessionstorage from the electron app I started? What is the loading mechanism of recorder_js code? Can you tell me where the Recorder calls recorder_js?
Through the Chrome extension: https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/extensions/recorder.zip
The reading of sessionStorage is done in “def __get_recorded_actions_on_active_tab” in base_case. https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py
Thank you.I'll try to modify again~Have a nice weekend:)
@mdmintz Hey, bro. Now I can start the electron application with seleniumBase, but I don't know where a detection function exists that keeps the app starting two or three times as it runs.. Can you tell me what is the function that detects whether a page is open and where it is referenced? Another challenge is Do you know how to manually invoke the recorder when switching pages in my electron application?
I await your reply.
Do you know how to manually invoke the recorder when switching pages in my electron application?
self.activate_recorder()
Can you tell me what is the function that detects whether a page is open and where it is referenced?
I'm not sure what you mean exactly. If you want to know the current URL, use self.get_current_url(). The browser should always be open during a test. It is closed automatically during tearDown().