Implement the frameLocator.getBy* methods#5135
Conversation
inancgumus
left a comment
There was a problem hiding this comment.
It's a lovely idea to move the boilerplate testing code into testBrowser 👏. Not related to this PR, but I wonder why we need to load IFrames using an HTTP server when we could do it with a simple iframe srcdoc... I've only added some minor suggestions.
|
|
||
| // withIFrameContent sets up a handler for /iframe that serves a page embedding | ||
| // an iframe with the given content. | ||
| func (tb *testBrowser) withIframeContent(iframeHTML string) { |
There was a problem hiding this comment.
IFrame instead of Iframe?
Should this method and withIFrameURL be options that are passed to newTestBrowser, as with other options, for consistency?
tb := newTestBrowser(t, withHTTPServer(), withIFrameContent(...))There was a problem hiding this comment.
Good idea! withIFrameURL can't be an option because the URL is sometimes known after the testBrowser gets initialized (see https://github.com/grafana/k6/pull/5135/files#diff-7ec25e41d5b272a1ab43d25bb03d48bdd68072ac9632c3295c27f14ce4370011R572-R573) but I refactored withIFrameContent to be an option as it simplifies a bit the locator tests (in 62090aa).
There was a problem hiding this comment.
👍 Hmm, don't we already initialize testBrowser before applying the options? The only issue is with withIFrameURL, we'd need to pass that after withHTTPServer.
k6/internal/js/modules/k6/browser/tests/test_browser.go
Lines 76 to 83 in 62090aa
| <html> | ||
| <head></head> | ||
| <body> | ||
| <iframe id="frameB" src="%s"></iframe> |
There was a problem hiding this comment.
Do we need the frameB id?
There was a problem hiding this comment.
Yes, it's used in the tests with the Locator function to retrieve the iframe.
There was a problem hiding this comment.
I'd explicitly pass the frame ID to that helper then, as it creates a temporal coupling issue. We'd have to look at that helper code to see why frameB is used in the test every time.
| "page": any(p).(T), | ||
| "frame": any(p.MainFrame()).(T), | ||
| "locator": any(p.Locator(":root", nil)).(T), | ||
| pageImpl: any(p).(T), |
There was a problem hiding this comment.
Not related to this PR, but I wonder why we use generics here when we could do the same with interfaces, or use a much simpler approach. A task for another time, I guess.
62090aa
I've tested this approach and I like how it simplifies the tests but, I'm not sure why, it makes one test ( |
Adding the |
Might have misunderstood the question, but the reason why we're working with a HTTP server is to mimic a different origin i.e. CORS. Anything in injected_script.js can read from an |
What?
Implement the following
frameLocator.getBy*APIs which are the preferred way of working with selectors:Why?
Because we have already implemented all those methods for
page,frame, andlocator, and we want to implement them as well forframeLocatoras a way to increase our compatibility with Playwright, as described in #5036.Checklist
make check) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)
Closes #5036