Skip to content

Commit 2b56269

Browse files
committed
ci: window maximize on linux
1 parent 32bc9d0 commit 2b56269

3 files changed

Lines changed: 42 additions & 7 deletions

File tree

.github/workflows/actions/set-screen-resolution/action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ runs:
1717
run: |
1818
Set-DisplayResolution -Width ${{ inputs.width }} -Height ${{ inputs.height }} -Force
1919
20+
# I don't know the details, but it appears that it needs to be maximized at the Webdriver level
21+
# because it does not launch in full screen on Linux.
22+
# However, as the following Issue states, Electron(base of vscode) can not be muximize by webdriver protocol.
23+
# https://github.com/electron/electron/issues/33942
24+
# Therefore, GUI-based methods are used to maximize the screen.
25+
# The process of maximizing screen size using xdotool is done in the before hook of wdio.conf.ts.
2026
- name: Set display resolution on Linux
2127
if: runner.os == 'Linux'
2228
shell: bash
2329
run: |
24-
pnpm --filter @vscode-wdio/xvfb-patch run patch
30+
pnpm --filter @vscode-wdio/xvfb-patch run patch -w ${{ inputs.width }} -h ${{ inputs.height }}
31+
sudo apt install -y xdotool
2532
2633
# already use FHD resolution
2734
- name: Set display resolution on MacOS

e2e/wdio.conf.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'node:path'
22
import * as url from 'node:url'
33

44
import { minVersion } from 'semver'
5+
import shell from 'shelljs'
56

67
import pkg from '../packages/vscode-webdriverio/package.json' with { type: 'json' }
78
import type { Frameworks } from '@wdio/types'
@@ -59,6 +60,9 @@ export function createBaseConfig(workspacePath: string, userSettings = {}): Webd
5960
workspacePath: path.resolve(workspacePath),
6061
},
6162
'wdio:enforceWebDriverClassic': true,
63+
'goog:chromeOptions': {
64+
args: ['window-size=1920,1080'],
65+
},
6266
},
6367
],
6468

@@ -76,6 +80,14 @@ export function createBaseConfig(workspacePath: string, userSettings = {}): Webd
7680
timeout: 6000000,
7781
require: ['assertions/index.ts'],
7882
},
83+
before: async function (_capabilities, _specs, _browser) {
84+
if (process.platform === 'linux') {
85+
const result = shell.exec('xdotool search --onlyvisible --name code')
86+
const windowId = result.stdout.trim()
87+
shell.exec(`xdotool windowmove ${windowId} 0 0`)
88+
shell.exec(`xdotool windowsize ${windowId} 100% 100%`)
89+
}
90+
},
7991
afterTest: async function (_test: unknown, _context: unknown, _result: Frameworks.TestResult) {
8092
// if (!result.passed) {
8193
await browser.saveScreenshot(path.join(outputDir, `screenshot-${screenshotCount++}.png`))

infra/xvfb-patch/src/index.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
import * as fs from 'node:fs'
22
import * as path from 'node:path'
33
import { fileURLToPath } from 'node:url'
4+
import { parseArgs } from 'node:util'
45

56
const __dirname = path.dirname(fileURLToPath(import.meta.url))
67
const rootDir = path.resolve(__dirname, '../../..')
78
const filePath = path.join(rootDir, 'node_modules', 'xvfb-maybe', 'src', 'xvfb-maybe.js')
89

9-
const width = 1920
10-
const height = 1920
10+
const args = process.argv.slice(2)
11+
const optionsDef = {
12+
width: {
13+
type: 'string',
14+
short: 'w',
15+
},
16+
height: {
17+
type: 'string',
18+
short: 'h',
19+
},
20+
} as const
21+
22+
const { values: options } = parseArgs({ args, options: optionsDef })
23+
24+
console.log('Adjust screen resolution')
25+
console.log(` Width : ${options.width}`)
26+
console.log(` Height: ${options.height}`)
1127

1228
const insertBefore = "const dblDashPos = args.indexOf('--'),"
13-
const codeToInsert = ` args.unshift('--server-args="'-screen 0 ${width}x${height}x24'"', '--');`
29+
const codeToInsert = ` args.unshift('--server-args=-screen 0 ${options.width}x${options.height}x24', '--');`
1430

1531
const sourceCode = fs.readFileSync(filePath, 'utf-8')
1632

@@ -23,10 +39,10 @@ const lines = sourceCode.split('\n')
2339
const index = lines.findIndex((line) => line.includes(insertBefore))
2440

2541
if (index !== -1) {
26-
lines.splice(index, 0, codeToInsert) // 挿入
42+
lines.splice(index, 0, codeToInsert)
2743
const newCode = lines.join('\n')
2844
fs.writeFileSync(filePath, newCode, 'utf-8')
29-
console.log('✅ xvfb-maybe is patched successfully')
45+
console.log('\n✅ xvfb-maybe is patched successfully')
3046
} else {
31-
console.log('💥 could not find the target line.')
47+
console.log('\n💥 could not find the target line.')
3248
}

0 commit comments

Comments
 (0)