Releases: seleniumbase/SeleniumBase
Fix issue with printing file paths that contain spaces
Fix issue with printing file paths that contain spaces
Fixes #1041
(This was discovered by running sbase mkrec new_file.py --url=wikipedia.org
from a directory that contained spaces within the file path. When the result file was being outputted using sbase print PATH_WITH_SPACES/new_file.py
, the path was being split into multiple arguments based on how many spaces it contained, which led to errors.)
Improve the Recorder and browser-launching
Improve the Recorder and browser-launching
- Recorder: If the element is a span of a button, use the button. (code-generation)
- Recorder: Add
\n
to input text on form-submit actions. (code-generation) - Optimize browser-launching:
-- (Now using the newer Selenium4 Service objects.)
Mostly Recorder Mode updates
Mostly Recorder Mode updates
- Recorder: Don't generate selectors with attributes containing
\n
. - Recorder: Include "data-content" attribute for selector-generation.
- Recorder: Skip 'aria-label' & 'for' attributes containing numbers.
- Recorder: Only use basic tags when unique to the page.
- Recorder: Make sure that new origins switch to new tabs.
- Recorder: Use a teal-colored border for Assert Text Mode.
- Recorder: Prevent duplicate "open()" calls during "codegen".
- Recorder: Add "--url=URL" & "--edge" as options to "mkrec" / "codegen".
- Dashboard: Fix bug where "Skipped" tests were displayed as "Passed".
Recorder Mode
🔴 SeleniumBase Recorder Mode lets you record & export browser actions into test automation scripts.
(This tutorial assumes you are using SeleniumBase version 2.0.8
or newer.)
🔴 To make a new recording with Recorder Mode, you can use sbase mkrec
or sbase codegen
):
sbase mkrec TEST_NAME.py --url=URL
If the file already exists, you'll get an error. If no URL is provided, you'll start on a blank page and will need to navigate somewhere for the Recorder to activate. (The Recorder captures events on URLs that start with https
, http
, or file
.) The command above runs an empty test that stops at a breakpoint so that you can perform manual browser actions for the Recorder. When you have finished recording, type "c
" on the command-line and press [ENTER]
to let the test continue from the breakpoint. The test will then complete and a file called TEST_NAME_rec.py
will be automatically created in the ./recordings
folder. That file will get copied back to the original folder with the name you gave it. (You can run with Edge instead of Chrome by adding --edge
to the command above.)
Example:
sbase mkrec new_test.py --url=wikipedia.org
* RECORDING initialized: new_test.py
pytest new_test.py --rec -q -s --url=wikipedia.org
> .../SeleniumBase/examples/new_test.py(7)test_recording()
5 def test_recording(self):
6 if self.recorder_ext and not self.xvfb:
----> 7 import ipdb; ipdb.set_trace()
ipdb> c
>>> RECORDING SAVED as: recordings/new_test_rec.py
**************************************************
*** RECORDING COPIED to: new_test.py
🔴 While a recording is in progress, you can press the [ESC]
key to pause the recording. To resume the recording, you can hit the [~`]
key, which is located directly below the [ESC]
key on most keyboards.
🔴 From within Recorder Mode there are two additional modes: "Assert Element Mode" and "Assert Text Mode". To switch into "Assert Element Mode", press the {^}-key (SHIFT+6)
: The border will become purple, and you'll be able to click on elements to assert from your test. To switch into "Assert Text Mode", press the {&}-key (SHIFT+7)
: The border will become teal, and you'll be able to click on elements for asserting text from your test. While using either of the two special Assertion Modes, certain actions such as clicking on links won't have any effect. This lets you make assertions on elements without navigating away from the page, etc. To return back to the original Recorder Mode, press any key other than SHIFT or BACKSPACE (Eg: Press CONTROL
, etc.). You can also press ESC once to leave the Assertion Modes, but if you press it again, it'll stop the Recorder.
🔴 For extra flexibility, you can break up the sbase mkrec
command into three separate commands so that you can pick & choose how you use the Recorder:
sbase mkfile TEST_NAME.py --rec
pytest TEST_NAME.py --rec -q -s
cp ./recordings/TEST_NAME_rec.py ./TEST_NAME.py
The first command creates a boilerplate test with a breakpoint; the second command runs the test with the Recorder activated; and the third command replaces the initial boilerplate with the full recorded test. If you're just experimenting with the Recorder, you can run the second command as many times as you want, and it'll override previous recordings saved to ./recordings/TEST_NAME_rec.py
. (Note that -s
is needed to allow breakpoints, unless you already have a pytest.ini
file present with addopts = --capture=no
in it. The -q
is optional, which shortens pytest
console output.)
🔴 You can also use the Recorder to add code to an existing test. To do that, you'll first need to create a breakpoint in your code where you want to insert manual browser actions:
import ipdb; ipdb.set_trace()
Now you'll be able to run your test with pytest
, and it will stop at the breakpoint for you to add in actions: (Press c
and ENTER
on the command-line to continue from the breakpoint.)
pytest TEST_NAME.py --rec -s
🔴 You can also set a breakpoint at the start of your test by adding --trace
as a pytest
command-line option: (This is useful when running Recorder Mode without any ipdb
breakpoints.)
pytest TEST_NAME.py --trace --rec -s
🔴 After the test completes, a file called TEST_NAME_rec.py
will be automatically created in the ./recordings
folder, which will include the actions performed by the test, and the manual actions that you added in.
🔴 Here's a command-line notification for a completed recording:
>>> RECORDING SAVED as: recordings/TEST_NAME_rec.py
***************************************************
🔴 When running additional tests from the same Python module, Recordings will get added to the file that was created from the first test:
>>> RECORDING ADDED to: recordings/TEST_NAME_rec.py
***************************************************
🔴 Recorder Mode works by saving your recorded actions into the browser's sessionStorage
. SeleniumBase then reads from the browser's sessionStorage
to take the raw data and generate a full test from it. Keep in mind that sessionStorage
is only present for a website while the browser tab remains on a web page of the same domain/origin. If you leave that domain/origin, the sessionStorage
of that tab will no longer have the raw data that SeleniumBase needs to create a full recording. To compensate for this, all links to web pages of a different domain/origin will automatically open a new tab for you while in Recorder Mode. Additionally, the SeleniumBase self.open(URL)
method will also open a new tab for you in Recorder Mode if the domain/origin is different from the current URL. When the recorded test completes, SeleniumBase will scan the sessionStorage
of all open browser tabs for the data it needs to generate the complete SeleniumBase automation script.
🔴 As an alternative to activating Recorder Mode with the --rec
command-line arg, you can also call self.activate_recorder()
from your tests. This is only useful for tests that stay on the same URL because the Recorder will turn off when leaving the page where you activated the Recorder. The reason for this is because the standard Recorder Mode functions as a Chrome extension (and persists wherever the browser goes), whereas the method call version of Recorder Mode only lives in the page where it was called.
🔴 (Note that same domain/origin is not the same as same URL. Example: https://xkcd.com/353/
and https://xkcd.com/1537/
are two different URLs with the same domain/origin. That means that both URLs will share the same sessionStorage
data, and that any changes to sessionStorage
from one URL will carry on to the sessionStorage
of a different URL when the domain/origin is the same. If you want to find out a website's origin during a test, just call: self.get_origin()
, which returns the value of window.location.origin
from the browser's console.)
🔴 Inside recorded tests, you might find the self.open_if_not_url(URL)
method, which opens the URL given if the browser is not currently on that page. This is used as a method in recorded scripts when SeleniumBase detects that a browser action (such as a click) has brought the test to that page. This method not only prevents an extra page load if not needed, but it also lets people know what page the test went to after a browser action was performed.
Some updates to Visual Testing
Some updates to Visual Testing
- Add the
full_diff
option to thecheck_window()
method:
def check_window(
self,
name="default",
level=0,
baseline=False,
check_domain=True,
full_diff=False,
):
"""*** Automated Visual Testing with SeleniumBase ***
...
If "full_diff" is set to False, the error output will only include the first differing element in the list comparison. Set "full_diff" to True if you want to see the full output.
- Add the
deferred
version of thecheck_window()
method:
def deferred_check_window(
self,
name="default",
level=0,
baseline=False,
check_domain=True,
full_diff=False,
)
This won't fail the test right away if the call fails.
Use with self.process_deferred_asserts()
to fail the test later.
See https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_deferred_asserts.py for examples of other deferred_assert_*
methods.
For more info on SeleniumBase Visual Testing in general, see: https://seleniumbase.io/examples/visual_testing/ReadMe/
(Watch the tutorial on YouTube)
Other changes include:
- Refactor and improve the Dashboard code
- Refresh Python dependencies:
--tomli>=1.2.2;python_version>="3.6"
--traitlets==5.1.1;python_version>="3.7"
Support Edge automation on Linux with msedgedriver
Support Edge automation on Linux with msedgedriver
Here's the full list of changes:
- Support Edge automation on Linux with msedgedriver.
- Automatically repair msedgedriver to match Edge version.
- Automatically repair chromedriver to match Chrome on Linux.
- Refresh Python dependencies:
--setuptools>=58.3.0;python_version>="3.6
--virtualenv>=20.9.0
Refresh Python dependencies
Refresh Python dependencies
pip>=21.3.1;python_version>="3.6"
prompt-toolkit==3.0.21;python_version>="3.6.2"
(Also includes updates to documentation and examples.)
Refresh Recorder Mode with "codegen" and more
Refresh Recorder Mode with "codegen" and more
🔴 SeleniumBase 2.0.4
lets you go back to regular Recorder Mode from Assert Mode by pressing [ESC] once. If you press it again, it will pause the Recorder. (Previously, pressing [ESC] would pause the Recorder right away if using Assert Mode). As before, pressing the {^}-key (SHIFT+6)
will switch the Recorder into Assert Element Mode and pressing the {&}-key (SHIFT+7)
will switch the Recorder into Assert Text Mode. You can switch back to regular Recorder Mode from Assert Mode by pressing any key other than [SHIFT] and [BACKSPACE]. Also, --codegen
can be used in place of --recorder
for Recorder initialization, and sbase codegen [FILE.py]
can be used in place of sbase mkrec [FILE.py]
, which calls attention to the code-generation abilities of the Recorder.
For the complete ReadMe on Recorder Mode, see: https://seleniumbase.io/help_docs/recorder_mode/
Optimize the proxy_helper for proxy with auth
Optimize the proxy_helper for proxy with auth
The proxy_helper is used to run tests on a proxy server that requires authentication.
To change the browser's proxy settings, use the following for a server with auth:
pytest --proxy=USERNAME:PASSWORD@IP_ADDRESS:PORT
If a proxy server has no auth, you can use:
pytest --proxy=IP_ADDRESS:PORT
Fix a bug with Recorder Mode
Fix a bug with Recorder Mode
🔴 SeleniumBase 2.0.2
fixes a bug with Recorder Mode that was preventing the last recorded assert on a domain from being saved unless it was followed by a non-assert recorded action on the same domain.
Also:
- Better error-handling.
- Optimize an import.
- Refresh Python dependencies:
--sniffio;python_version>="3.7"
- Update a lot of older docs.
Update Recorder Mode
Update Recorder Mode
🔴 SeleniumBase 2.0.1
adds the ability to preview selectors via the page title when hovering over elements. It also fixes an issue that may occur when opening up new URLs while in Recorder Mode.