11import * as path from 'node:path'
22import * as url from 'node:url'
33
4+ import * as core from '@actions/core'
45import { minVersion } from 'semver'
56import shell from 'shelljs'
67
@@ -10,6 +11,7 @@ import type { Frameworks } from '@wdio/types'
1011type TestTargets = 'workspace' | 'mocha' | 'jasmine' | 'cucumber'
1112
1213const __dirname = path . dirname ( url . fileURLToPath ( import . meta. url ) )
14+ const prjRoot = path . resolve ( __dirname , '..' )
1315const target = ( process . env . VSCODE_WDIO_E2E_SCENARIO || 'mocha' ) as TestTargets
1416
1517const minimumVersion = minVersion ( pkg . engines . vscode ) ?. version || 'stable'
@@ -34,7 +36,28 @@ function defineSpecs(target: TestTargets) {
3436}
3537
3638const specs = defineSpecs ( target )
37- let screenshotCount = 0
39+
40+ class ScreenshotNameGenerator {
41+ private readonly _counterMap = new Map < string , number >
42+
43+ private _generateMapId ( file :string , title :string ) {
44+ return `${ file } -${ title } `
45+ }
46+
47+ getFilename ( file :string , title :string ) {
48+ const mapId = this . _generateMapId ( file , title )
49+ const counter = this . _counterMap . get ( mapId )
50+ const newCounter = typeof counter === 'undefined' ? 0 : counter + 1
51+ this . _counterMap . set ( mapId , newCounter )
52+ const _title = title
53+ . split ( ' ' )
54+ . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
55+ . join ( '' )
56+ return `screenshot-${ path . basename ( file ) } -${ _title } -${ newCounter } .png`
57+ }
58+ }
59+
60+ const ssNameGenerator = new ScreenshotNameGenerator ( )
3861
3962export function createBaseConfig ( workspacePath : string , userSettings = { } ) : WebdriverIO . Config {
4063 const resolvedUserSettings = Object . assign (
@@ -80,16 +103,24 @@ export function createBaseConfig(workspacePath: string, userSettings = {}): Webd
80103 require : [ 'assertions/index.ts' ] ,
81104 } ,
82105 before : async function ( _capabilities , _specs , _browser ) {
83- if ( process . platform === 'linux' ) {
84- const result = shell . exec ( 'xdotool search --onlyvisible --name code' )
106+ // For Github Actions on Linux, Maximize the screen by GUI approach
107+ // See also .github/actions/set-screen-resolution/action.yml
108+ if ( process . env . GITHUB_ACTIONS === 'true' && process . platform === 'linux' ) {
109+ const result = shell . exec ( 'xdotool search --onlyvisible --name code' , { silent : true } )
85110 const windowId = result . stdout . trim ( )
86111 shell . exec ( `xdotool windowmove ${ windowId } 0 0` , { silent : true } )
87112 shell . exec ( `xdotool windowsize ${ windowId } 100% 100%` , { silent : true } )
88113 }
89114 } ,
90- afterTest : async function ( _test : unknown , _context : unknown , result : Frameworks . TestResult ) {
115+ afterTest : async function ( test : Frameworks . Test , _context : unknown , result : Frameworks . TestResult ) {
91116 if ( ! result . passed ) {
92- await browser . saveScreenshot ( path . join ( outputDir , `screenshot-${ screenshotCount ++ } .png` ) )
117+ await browser . saveScreenshot ( path . join ( outputDir , ssNameGenerator . getFilename ( test . file , test . title ) ) )
118+ }
119+ if ( process . env . GITHUB_ACTIONS === 'true' && result . retries . attempts === 1 ) {
120+ core . warning ( `Retried: ${ test . title } ` , {
121+ title : 'Test was retried.' ,
122+ file : path . relative ( prjRoot , test . file ) ,
123+ } )
93124 }
94125 } ,
95126 }
0 commit comments