Skip to content

Commit

Permalink
detect playwright-webkit browser
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Mar 16, 2021
1 parent ed4bf54 commit de8e6c3
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ declare namespace Cypress {
(task: 'net', eventName: string, frame: any): Promise<void>
}

type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | 'edge' | string
type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | 'edge' | 'webkit' | string

type BrowserChannel = 'stable' | 'canary' | 'beta' | 'dev' | 'nightly' | string

type BrowserFamily = 'chromium' | 'firefox'
type BrowserFamily = 'chromium' | 'firefox' | 'webkit'

/**
* Describes a browser Cypress can control
Expand Down
10 changes: 10 additions & 0 deletions packages/launcher/lib/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ export const browsers: Browser[] = [
versionRegex: /Microsoft Edge Dev (\S+)/m,
binary: ['edge-dev', 'microsoft-edge-dev'],
},
{

This comment has been minimized.

Copy link
@vitmalina

vitmalina Mar 23, 2021

@flotwig, I am following your commits in cy-webkit branch and I see you added playwright-webkit. However, can you please help me figure out how to make cypress start this browser? I see when I go to launcher package and do node index.js playwright-webkit gets started but does not work.

This comment has been minimized.

Copy link
@flotwig

flotwig Mar 23, 2021

Author Contributor

This is part of an open PR, this is still a long long way away from being ready for public use: #15533

This comment has been minimized.

Copy link
@vitmalina

vitmalina Mar 23, 2021

Yes, I understand that, but I want to help with the effort. I do not know where/how I can contribute. I have been poking in the code for a few weeks and had some successes. If you can point me out to the right direction, I believe I could be useful. ))

This comment has been minimized.

Copy link
@flotwig

flotwig Mar 23, 2021

Author Contributor

The WebKit browser is launching, but it is not yet automated. The code in webkit.ts needs to be completed, to send the appropriate Playwright CDP commands to navigate and automate the browser, like chrome.ts and cdp_automation.ts do.

This comment has been minimized.

Copy link
@vitmalina

vitmalina Mar 23, 2021

I see, thank you. Yes, I saw webkit.ts file. However, I could not make Cypress start webkit browser. Did you forget to add playwright-webkit as a dependency? does it need to be? Can you please help me with the cli command how you test? Greatly appreciate it.

This comment has been minimized.

Copy link
@flotwig

flotwig Mar 23, 2021

Author Contributor

@vitmalina playwright-webkit needs to be installed in Cypress's require path currently because of how it is required. By the time this is released, it will be fixed, but that's how it is right now.

Try installing playwright-webkit from the root of this project and using yarn cypress:open to launch.

This comment has been minimized.

Copy link
@vitmalina

vitmalina Mar 23, 2021

@flotwig, got playwright-webkit installed. Thanks. However, when I do yarn cypress:open I see this

Screen Shot 2021-03-23 at 3 53 16 PM

I do not see webkit as a browser option. What am I missing?

This comment has been minimized.

Copy link
@flotwig

flotwig Mar 24, 2021

Author Contributor

@vitmalina this branch is still in a very early stage so I'm not sure I can offer you much in the way of support here. You can check packages/launcher for how the NPM package is detected and debug from there if you wish.

name: 'webkit',
family: 'webkit',
channel: 'dev',
displayName: 'WebKit',
// WebKitGTK 2.31.1 (r272495)
versionRegex: /WebKitGTK (\S+)/m,
module: 'playwright-webkit',
getBinaryPath: (pw) => pw.webkit.executablePath(),
},
]

/** starts a found browser and opens URL if given one */
Expand Down
10 changes: 10 additions & 0 deletions packages/launcher/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ function lookup (
* we don't use the `binary` field on Windows.
*/
function checkBrowser (browser: Browser): Bluebird<(boolean | FoundBrowser)[]> {
if (browser.module) {
try {
browser.binary = browser.getBinaryPath(require(browser.module))
} catch (e) {
log('error ', e)

return Bluebird.resolve([])
}
}

if (Array.isArray(browser.binary) && os.platform() !== 'win32') {
return Bluebird.map(browser.binary, (binary: string) => {
return checkOneBrowser(extend({}, browser, { binary }))
Expand Down
22 changes: 15 additions & 7 deletions packages/launcher/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as Bluebird from 'bluebird'

// TODO: some of these types can be combined with cli/types/index.d.ts

type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | string
type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | 'edge' | 'webkit' | string

type BrowserChannel = 'stable' | 'canary' | 'beta' | 'dev' | 'nightly' | string

type BrowserFamily = 'chromium' | 'firefox'
type BrowserFamily = 'chromium' | 'firefox' | 'webkit'

export type PlatformName = 'darwin' | 'linux' | 'win32'

Expand All @@ -31,22 +31,30 @@ export type Browser = {
* Human-readable browser name.
*/
displayName: string
/** RegExp to use to extract version from something like "Google Chrome 58.0.3029.110" */
versionRegex: RegExp
/** If set, this is the base path that will be used for setting userDataDir. Useful for creating profiles in snap confinement. */
profilePath?: string
/** A single binary name or array of binary names for this browser. Not used on Windows. */
binary: string | string[]
/** RegExp to use to extract version from something like "Google Chrome 58.0.3029.110" */
versionRegex: RegExp
/** optional warning that will be shown in the GUI */
warning?: string
/** optional info that will be shown in the GUI */
info?: string
} & (BrowserBinary | BrowserNpm)

type BrowserBinary = {
/** A single binary name or array of binary names for this browser. Not used on Windows. */
binary: string | string[]
}

type BrowserNpm = {
module: string
getBinaryPath: (module: any) => string
}

/**
* Represents a real browser that exists on the user's system.
*/
export type FoundBrowser = Omit<Browser, 'versionRegex' | 'binary'> & {
export type FoundBrowser = Omit<Browser, keyof BrowserBinary | keyof BrowserNpm> & {
path: string
version: string
majorVersion?: string
Expand Down
Loading

0 comments on commit de8e6c3

Please sign in to comment.