Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Put test-functions.js helpers on window object #20833

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

martinpitt
Copy link
Member

@martinpitt martinpitt commented Aug 2, 2024

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.


cockpit-project/bots#6688 already landed for not breaking naughty patterns.

This is a prerequisite for #20832

@@ -193,7 +193,7 @@ def dialog_set_val(self, field, val):

def dialog_combobox_choices(self, field):
return self.browser.call_js_func("""(function (sel) {
var lis = ph_find(sel).querySelectorAll('li');
var lis = window.ph_find(sel).querySelectorAll('li');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window is the global object, so do we really need to change all the code like this? Or do you prefer it for clarity?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a testrun with all changes to testlib.py reverted: https://cockpit-logs.us-east-1.linodeobjects.com/pull-20843-be1fb85d-20240806-133921-arch-storage/log.html

Looks pretty green.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in other words, this isn't actually a API break.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a prerequisite for the BiDi conversion in #20832. Exporting globals only works with CDP, you can't do it with webdriver or bidi. So that reversion only proves that main isn't broken, but there was never any doubt about that 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not for clarity, it's the core of this change: You cannot export globals if all you have is "you define a function and the browser calls it". We have to attach it to an existing global, like sizzle does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have to say window.ph_select = function () { }, but do we also have to say window.ph_select() everywhere? Is window not the global object when evaluating JavaScript via bidi?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Sorry, I misunderstood you there. Testing..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works! TIL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yippie!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah, testing this without bidi was bogus, urks.

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.
@martinpitt martinpitt changed the title test: Put test-functions.js helpers on window object [API break] test: Put test-functions.js helpers on window object Aug 6, 2024
@martinpitt
Copy link
Member Author

@mvollmer Thanks! This is much nicer indeed. I wasn't aware that you don't have to write window.. Magic..

Copy link
Member

@mvollmer mvollmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mvollmer mvollmer merged commit a882545 into cockpit-project:main Aug 6, 2024
77 checks passed
@martinpitt martinpitt deleted the test-functions-window branch August 6, 2024 15:10
martinpitt added a commit to martinpitt/bots that referenced this pull request Aug 11, 2024
…lper functions"

This wasn't necessary after all, things on `window.` are available in
the global namespace. See the final version of
cockpit-project/cockpit#20833

This reverts commit b8aae7b.
martinpitt added a commit to cockpit-project/bots that referenced this pull request Aug 11, 2024
…lper functions"

This wasn't necessary after all, things on `window.` are available in
the global namespace. See the final version of
cockpit-project/cockpit#20833

This reverts commit b8aae7b.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants