Commit graph

57 commits

Author SHA1 Message Date
Jelle van der Waa
ad4176e4ca treewide: Enable strict equality everywhere
Making test-functions strict required some test adjustments where we
incorrectly expected an number while we receive in fact a string. As
getAttribute() returns either a string or null.
2026-11-03 17:37:17 +01:00
Martin Pitt
f812b8b9e2 test: Clarify Browser.go()
This is supposed to behave similar to `cockpit.location.go()`. Our tests
always call this with either a hash or a path, and these are the only
two cases we support. Make that explicit with assertions, error
messages, and documentation.

Also clean up the test-functions.js backend: Replace `ph_go()` (which
covered both cases) with `ph_jump()` which only switches between pages
(like `cockpit.jump()` does, i.e. like clicking in the shell menu). Lift
the handling of hashes into `Browser.go()` directly; keep the current
implementation for now.
2026-05-20 11:31:11 +02:00
Jelle van der Waa
ec72eec5b4 test: fix scrollIntoView parameter name 'behaviour'
The option takes the US spelling of the name, not British.
2026-05-12 07:10:39 +02:00
Jelle van der Waa
26700ce29f test: replace flatten() with Array.prototype.flat()
This is baseline available.
2026-05-12 07:10:39 +02:00
Jelle van der Waa
ec71c58da8 test: allow special characters in quotes in :contains()
In cockpit-machines there are selectors like `.pf-v6-c-menu
button:contains('Serial (serial0)')` which previously weren't matched.
2026-01-14 11:35:34 +01:00
Jelle van der Waa
f8a4c75ec1 test: implement a simple :contains() match
With a simple :contains() implementation cockpit-files and
subscription-manager can run their tests without requiring sizzle in
node_modules.

Note that this still allows passing elements after contains() such as
for example `:contains() input`, but it won't support them. This is
needed to support `b.click()` which appends `:not(:disabled)` CSS
selectors. A future addition would be supporting selectors after
`:contains()` so cockpit-machines can be supported.
2025-11-03 14:31:37 +01:00
Freya Gustavsson
af90a9f09b test: Get computed style for element
This changes the behaviour from checking the visibility and display for
the element itself to checking if the element is inherently or directly
hidden by using `Window.getComputedStyle()`.

If a parent of the element we're checking has `visibility=hidden` our
previous check would have failed if not for our custom CSS that made
`hidden` elements get `display=none` applied. As we removed that in a
prior commit we now found the bug and need to correct it.

`Window.getComputedStyle()` will take all the values that the browser
itself would inherit. This coincidentally also means we are testing
closer to what users would experience in their own browser.

See-also: https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
Related-to: e89892b11185529721b2c0ad7f5ee4a4b558a29a
Signed-off-by: Freya Gustavsson <freya@venefilyn.se>
2025-08-28 10:53:16 +02:00
tomasmatus
505dc4b3f7 tests: don't count finished animations in ph_count_animations 2025-07-28 18:17:15 +02:00
Freya Gustavsson
8db6565337 lib: Update to Patternfly v6
Huge team-effort to redesign Cockpit with Patternfly v6 in mind and to
reduce the amount of hacks and legacy code we have. This also paves the
way to further improve Patternfly itself by keeping up-to-date with
their latest releases.

Commit includes codemod changes, updated tests, improved layout for
desktop and mobile, as well as inline-comments here and there for what
we need to fix.

Co-authored-by: Garrett LeSage <garrett@redhat.com>
Co-authored-by: Tomas Matus <tomatus777@gmail.com>
Co-authored-by: Martin Pitt <mpitt@redhat.com>
Relates-to: #21651, #20973

https://issues.redhat.com/browse/COCKPIT-1266
2025-03-24 12:12:46 +01:00
Martin Pitt
6e3d5118f1 test: Add support for querying shadow DOM
Add a `querySelectorAll()` variant which can transparently pierce and
traverse shadow DOMs without having to know their structure (i.e. doing
selectors piece-wise and iterating on their `.shadowRoot` attribute).

As this is more expensive than standard querySelector()`, only  use it
if the page actually contains any shadow root.

This makes it a lot more convenient to write tests for pages which use
web components, like https://patternflyelements.org.
2024-11-19 08:13:44 +01:00
Martin Pitt
c50bf49ff0 test: Use real mouse events in tests on Firefox
Our years-old `ph_mouse()` helper is cheating: It completely side-steps
the browser UI and directly synthesizes `MouseEvent`s in JavaScript.
This allowed funny things like clicking on a main page element while a
dialog is open (which you can't normally do as the dialog is modal),
clicking an element which is disabled in some non-standard way, or
clicking through a tooltip.

Make this more realistic by using the BiDi API for synthesizing mouse
events. This works fine with Firefox, but is unfortunately completely
broken in iframes with Chromium:
https://issues.chromium.org/issues/359616812

Specifying precise coordinates is not currently implemented.
`ph_mouse()` always clicks on the top left corner, while webdriver's
`pointerMove` puts (0,0) in the center of the element. This can be done
with a little extra calculation of the `getBoundingRect()`, but only
very few tests like `TestStorageLvm2.testMaxLayoutGrowth` rely on that.
For these tests, continue to use `ph_mouse()`.

https://issues.redhat.com/browse/COCKPIT-1158
2024-08-20 10:04:50 +02:00
Martin Pitt
3e87757dcc test: Fix error reporting in ph_select()
This code was pointless -- it just short-circuited the "no sizzle
available" error message.
2024-08-11 20:26:03 +02:00
Martin Pitt
a882545ca5 test: Put test-functions.js helpers on window object
webdriver's and BiDi's functions for preloading a script only supports
declaring and calling a function. This can't define globals.

So do what sizzle does and put the helper functions on the `window`
global object.

Drop the long-obsolete jQuery comment.
2024-08-06 18:05:29 +03:00
Marius Vollmer
b0a4483996 test: More careful mocking 2023-09-01 17:37:31 +02:00
Jelle van der Waa
063d7c24cd Only use Sizzle when required 2023-07-31 15:34:14 +02:00
Jelle van der Waa
ea5817462f test: make loading sizzle optional for tests 2023-06-07 10:26:18 +02:00
Marius Vollmer
b7707db652 test: Don't use CSS to replace DOM elements with arbitrary text
The tricky CSS tricks turned out to be a bit too tricky in the case
where the production CSS already uses ::after or ::before pseudo
elements.  Our ListingTable component uses those alot for handling the
mobile layout, for example.

Let's use to most straightforward way: setting the text of an element
via injected JavaScript.

This might fail when React decided to render inbetween the call to
set_mock and capturing of the actual screenshot.  But the tests keep
the pages quiet during pixel testing anyway, so hopefully this will
not happen in practice.

Another way this might fail is that React gets confused the next time
it renders after the call to set_mock because the DOM has changed too
much.  This can hopefully be prevented by only replacing the text of
elements, and not their children.
2023-05-25 11:04:17 +03:00
Katerina Koukiou
097f93cfe1 Bump eslint version
Autofix warnings: Expected property shorthand
2023-02-27 23:53:02 +01:00
Matej Marusak
d661eb9080 firewall: Show additional ports even when no service is defined
Fixes #16444
2023-01-18 14:19:19 +01:00
Katerina Koukiou
56dddcc3c6 tests: pixel-testing: introduce a scenario for RTL
This commit introduces a new pixel test scenario for RTL (Right to Left). This
scenario keeps using English for language but changes the direction of the language
to be RTL.

The reasoning behind this choice is that pixel tests take screenshots in the
middle of tests execution, by dynamically adopting the theme, browser
size etc for the different scenarios.
However in order to change the UI language one needs to reload the
page, which effectively means losing the application state. For this
reason, we would need to set the language at the very beginning of
each test if we wanted to properly test RTL with a language like Hebrew.

Since this means making a whole test run in another language, we decided
that we will for the time being test RTL with English.
This is obviously an unrealistic scenario but allows us to view spacing
issues at least.
2023-01-10 09:44:07 +01:00
Matej Marusak
627645914e test: Lint fix
I just ran `npm run eslint:fix` and this happened.
2022-12-08 12:15:06 +01:00
Martin Pitt
336aa73de3 Fix incomplete string replacements
Some code, like in user accounts dialogs, were using
`replace("\n", " ")`. This only replaces the first match.

Consistently use replaceAll() for all cases that replace static strings.
A lot of places were using `/haystack/g` which works correctly, but
replaceAll() with a static string is faster.

Spotted by CodeQL "Incomplete string escaping or encoding" alerts.
2022-11-17 13:57:40 +01:00
Martin Pitt
b55398428b test: Fix ESLint errors in test-functions.js
Disable `no-unused-vars` rule for this file; ESLint complains about all
of our API, like:

    error  'ph_count_check' is defined but never used             no-unused-vars

As this is not an ESM module, we can't use `export`.

Throw proper Error objects instead of literals:

    error  Expected an error object to be thrown                  no-throw-literal
2022-03-01 11:55:29 +01:00
Martin Pitt
0b28830807 test: Auto-fix JS code style in test-functions.js
One round of `eslint --fix test/common/test-functions.js` to fix missing
semicolons, whitespace, and constify values where possible.
2022-03-01 11:55:29 +01:00
Marius Vollmer
8284618023 test: Allow exceptions while waiting
ph_wait now allows all exceptions and keeps trying.  If the last try
has an exception, it will be reported.  This means that we don't lose
any exceptions that happen consistently, but we always have to wait
for the timeout.

Browser.wait_js_cond retries when the execution context is not found
or disappears in the middle.  To support this, getFrameExecId never
raises an exception itself but returns -1 so that Runtime.evaluate
raises an error that causes Browser.wait_js_cond to retry.

Together these changes mean that calls to functions like
Browser.wait_in_text can now survive a page reload in their middle.

Consequently, all calls to expect_load and expect_load_frame have been
removed.

Specifically, this fixes a race in the TestKeys.testAuthorizedKeys
test case.  That test case experiences a page reload that is triggered
asynchronously and can therefore not be reliably waited for with
expect_load_frame.  (The call to enter_page was essentially a no-op.)
2022-02-21 16:50:10 +02:00
Marius Vollmer
254dfff9b8 test: Rework pixel testing and mobile layout logic
test/common/testlib.py has a set of layouts and test code can switch a
Browser into one via Browser.set_layout.  Right now there is only
"desktop" and "mobile", but more can be easily added.

Browser.assert_pixels cycles through all the defined layouts and does
a pixel test for each.

TEST_MOBILE and cdp.mobile have been removed.
2022-01-28 14:21:45 +01:00
Marius Vollmer
12d9851f5c test: Allow assert_pixels ignore selectors to match multiple elements
This makes it easier to ignore whole table columns with
"td:nth-child(3)", for example.
2022-01-08 09:40:53 +01:00
Marius Vollmer
7d6ae00580 test: Give content iframes a fixed size when pixel testing
This isolates pixel tests for the pages from changes in the shell
layout.
2022-01-05 15:11:54 +02:00
Marius Vollmer
d221a04aea test: Blur the focused input element before pixel texting
The cursor is animated and we don't want that.
2021-12-14 10:37:43 +01:00
Marius Vollmer
dcf93270a4 test: Wait for animations to finish before pixel testing 2021-12-14 10:37:43 +01:00
Marius Vollmer
ad264c31fe test: Put actual text into output when wait_text or wait_in_text fail
This allows for more specific naughty patterns, and helps with
debugging of flakey tests.
2021-08-25 10:55:55 +02:00
Allison Karlitskaya
06f0e8acb5 testlib: add wait_text_matches()
Similar in spirit to wait_text_in(), but accepts a regexp.
2021-08-17 14:53:12 +02:00
Katerina Koukiou
1d4a934ebc pixel-tests: scroll element into view before taking a screenshot 2021-06-22 13:24:43 +02:00
Marius Vollmer
b0c8efbd3e test: Add support for pixel tests 2021-05-06 11:24:25 +02:00
Katerina Koukiou
6e25915971 test: make b.mouse work with SVGs 2021-03-12 09:14:12 +01:00
Garrett LeSage
a2c3bd2aa9
Fix spelling issues detected by codespell
Closes #14282
2020-06-30 16:20:51 +02:00
Martin Pitt
525b379efd test: Fix Browser.wait_attr_contains to get along with nonexisting attributes
It's useful to wait for an attribute to exist. In that case,
`ph_attr_contains()` previously failed with

    TypeError: Cannot read property 'indexOf' of null

So additionally wait for the attribute to exist in the first place.
2019-12-17 08:56:11 +01:00
Matej Marusak
9b580e9003 test: ph_count_check should return boolean
Others checks just return `true` or `false` so lets keep it consistent.
2019-11-08 10:23:51 +01:00
Simon Kobyda
8f03aa6823 test: Implement get_checked getter for checkbox 2019-10-02 12:43:48 +03:00
Matej Marušák
f00ff7d9d0 services: Redesign details page
Closes #12265
2019-07-19 16:33:57 +02:00
Matej Marusak
f3294bb3c7 tests: Stop allowing to click on invisible buttons
`mouse` function had option `force` which made it possible to click on
invisible buttons. However this is a bad practice.

This was in the code mostly because in `check-active-pages` the dropdown
menu was needed to be opened while holding `alt` key down.

This commit teaches the mouse function to also simulate holding down
special keys.

In three other tests `force` was used pointlessly.

Closes #11812
2019-05-14 12:03:07 +02:00
Matej Marusak
0dac14df64 pcp: Disable switch while pmlogger is activating
Activating can take a bit of time or can be indefinite when pcpd is dead
and pmlogger tries to start.

Closes #11224
2019-02-27 10:15:17 +01:00
Marius Vollmer
f05e3c2a5f test: Make ph_mouse and ph_is_visible consistent re visibility
We consider an element visible when at least one of width or height is
non-zero.

We frequently seem to get elements with zero height that are
nevertheless fully functional.  For example, the "body" element itself
seems to be stuck at a zero height sometimes.
2019-02-20 10:32:02 +01:00
Matej Marusak
255417ba62 Do not use initEvent
InitEvent is deprecated, see https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent
2019-02-17 09:36:01 +01:00
Matej Marusak
8c6eed9dfe Do not use initMouseEvent
initMouseEvent is deprecated, see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
2019-02-17 09:36:01 +01:00
Matej Marusak
f4ae988ef2 test: Set 'detail' in MouseEvent
This field is counter of clicks in the same area. No-click related
events should set detail to 0, double-click to 2.
2019-02-15 08:18:46 +01:00
Marius Vollmer
f509d0664e test: Allow coordinates with Browser.mouse
Also, Browser.mouse now does all the extra checks that Browser.click
makes.  Consequently, we implement Browser.click with Browser.mouse
now.
2019-01-22 16:50:15 +01:00
Katerina Koukiou
c0cec1ab58 tests: ph_is_visible should check also display: none aside with visibility: hidden
Both `display: none` and `visibility: hidden` are valid ways to hide an
element and should be covered in ph_is_visible.
2019-01-04 12:11:00 +01:00
Marius Vollmer
18f54c1242 test: Ensure "change" event from input elements
By explicitly blurring them after typing into them.
2018-08-29 15:45:23 +02:00
Martin Pitt
9d3c17b631 test: Fail CDP commands on unhandled exceptions
Install a Chrome Devtools Protocol handler for unhandled exceptions, and
fail the next CDP command with it.  This got lost with the move from
PhantomJS to Chrome.

Some of our tests rely on failed ph_* function invocations, so we must
not log failures of ph_wait_cond(); these  are also technically
unhandled exceptions. So turn this into a proper `PhWaitCondTimeout`
error class, so that it can be identified reliably.

Handle cases where undefined value is passed to fail/success in
cdp-driver.js.

Adjust the naughty override for the XTerm.js crash (#9641) as this now
shows the actual underlying crash instead of just the followup element
wait timeout.

Closes #9639
2018-07-26 22:31:53 -04:00