Skip to content

Commit 3a57476

Browse files
committed
ci: add action for setting display resolution for all platform
1 parent b40653e commit 3a57476

6 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'vscode-webdriverio Set screen resolution'
2+
description: 'Set screen resolution'
3+
inputs:
4+
width:
5+
description: 'screen width'
6+
default: '1920'
7+
height:
8+
description: 'screen height'
9+
default: '1080'
10+
runs:
11+
using: 'composite'
12+
steps:
13+
# https://github.com/actions/runner-images/issues/2935
14+
- name: Set display resolution on Windows
15+
if: runner.os == 'Windows'
16+
shell: pwsh
17+
run: |
18+
Set-DisplayResolution -Width ${{ inputs.width }} -Height ${{ inputs.height }} -Force
19+
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.
26+
- name: Set display resolution on Linux
27+
if: runner.os == 'Linux'
28+
shell: bash
29+
run: |
30+
pnpm --filter @vscode-wdio/xvfb-patch run patch -w ${{ inputs.width }} -h ${{ inputs.height }}
31+
echo "::group::apt install -y xdotool"
32+
sudo apt install -y xdotool
33+
echo "::endgroup::"
34+
35+
# already use FHD resolution
36+
- name: Set display resolution on MacOS
37+
if: runner.os == 'macOS'
38+
shell: bash
39+
run: |
40+
brew install displayplacer
41+
displayplacer list

e2e/wdio.conf.ts

Lines changed: 9 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'
@@ -76,6 +77,14 @@ export function createBaseConfig(workspacePath: string, userSettings = {}): Webd
7677
timeout: 6000000,
7778
require: ['assertions/index.ts'],
7879
},
80+
before: async function (_capabilities, _specs, _browser) {
81+
if (process.platform === 'linux') {
82+
const result = shell.exec('xdotool search --onlyvisible --name code')
83+
const windowId = result.stdout.trim()
84+
shell.exec(`xdotool windowmove ${windowId} 0 0`)
85+
shell.exec(`xdotool windowsize ${windowId} 100% 100%`)
86+
}
87+
},
7988
afterTest: async function (_test: unknown, _context: unknown, result: Frameworks.TestResult) {
8089
if (!result.passed) {
8190
await browser.saveScreenshot(path.join(outputDir, `screenshot-${screenshotCount++}.png`))

infra/xvfb-patch/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@vscode-wdio/xvfb-patch",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"patch": "tsx ./src/index.ts"
7+
}
8+
}

infra/xvfb-patch/src/index.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from 'node:fs'
2+
import * as path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import { parseArgs } from 'node:util'
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
7+
const rootDir = path.resolve(__dirname, '../../..')
8+
const filePath = path.join(rootDir, 'node_modules', 'xvfb-maybe', 'src', 'xvfb-maybe.js')
9+
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}`)
27+
28+
const insertBefore = "const dblDashPos = args.indexOf('--'),"
29+
const codeToInsert = ` args.unshift('--server-args=-screen 0 ${options.width}x${options.height}x24', '--');`
30+
31+
const sourceCode = fs.readFileSync(filePath, 'utf-8')
32+
33+
if (sourceCode.includes(codeToInsert)) {
34+
console.log('🔧 xvfb-maybe is already patched')
35+
process.exit(0)
36+
}
37+
38+
const lines = sourceCode.split('\n')
39+
const index = lines.findIndex((line) => line.includes(insertBefore))
40+
41+
if (index !== -1) {
42+
lines.splice(index, 0, codeToInsert)
43+
const newCode = lines.join('\n')
44+
fs.writeFileSync(filePath, newCode, 'utf-8')
45+
console.log('\n✅ xvfb-maybe is patched successfully\n\n')
46+
} else {
47+
console.log('\n💥 could not find the target line.\n\n')
48+
}

infra/xvfb-patch/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"resolveJsonModule": true
5+
}
6+
}

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)