(@wdio/globals): fix getPuppeteer()#10804
(@wdio/globals): fix getPuppeteer()#10804christian-bromann merged 3 commits intowebdriverio:mainfrom
Conversation
christian-bromann
left a comment
There was a problem hiding this comment.
@jan-molak thanks for raising the PR.
I never stumbled upon this problem. Can we add a unit test to ensure this doesn't fail us again?
|
Hey @christian-bromann, sure thing, I was looking for a good place to do it but struggled to find it. Are there any existing specs in this area that I could extend, or should I make something new? |
|
I think |
|
Looks like For example, this test works with and without the patch: it('should work', async () => {
browser = await remote({
baseUrl: 'http://foobar.com',
capabilities: {
browserName: 'chrome',
},
})
const pptr = await browser.getPuppeteer()
expect(typeof pptr).toBe('object')
})Are there any tests specifically around |
|
I recommend adding a smoke test then. It runs a "fake" session but allows you to import the browser via |
|
Hey @christian-bromann, it looks like adding tests in this area might be a bit challenging, so I'd be grateful if you could suggest a way to proceed. Adding a testI started by adding a simple test to it('should provide access to Puppeteer', async () => {
const puppeteer = await global.browser.getPuppeteer()
expect(puppeteer).toBeDefined()
})This failed with: 🐛 #2 Mock config issueI tracked it down to this line, which defines the browser version as I changed that as follows: - browserVersion: 64.0,
+ browserVersion: '79.0',This is to avoid triggering this clause that prevents using Puppeteer with anything older than v79.0: webdriverio/packages/webdriverio/src/commands/browser/getPuppeteer.ts Lines 98 to 104 in caa2302 This allowed me to get further, but resulted in the following error message: 🐛 #3 Error message issueSetting 🐛 #4 Can't use Puppeteer with mock WebdriverIOSetting Next steps?I suppose we could reuse Nock instance in to pretend to be a debugger URL, but I'm not sure what requests/responses we'd need to mock out for that, and if it's even a good idea.The mock might need to be quite involved to fool |
|
Dang .. I guess testing that |
|
@christian-bromann - I've added a new e2e test file as modifying Anyway, hope the test is OK. |
christian-bromann
left a comment
There was a problem hiding this comment.
Let's import Browser directly if possible
Proposed changes
At the moment,
proxyHandlerfrom@wdio/globalsreturns fields from global objects without binding them to their receivers:webdriverio/packages/wdio-globals/src/index.ts
Lines 20 to 30 in bd86d69
This means that when the field happens to be a method referencing
this(like thegetPuppeteermethod), it loses the context of its receiver object and doesn't work:webdriverio/packages/webdriverio/src/commands/browser/getPuppeteer.ts
Lines 45 to 68 in caa2302
For example, the following code sample DOESN'T WORK as
getPuppeteer()is not bound tobrowserand returns anundefined.Types of changes
This pull request addresses the issue by binding method calls to their respective receiver objects.
Checklist
Further comments
Reviewers: @webdriverio/project-committers