Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize script command logs #8165

Merged
merged 1 commit into from Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/wdio-utils/src/utils.ts
Expand Up @@ -5,6 +5,7 @@ import type { Services, Clients } from '@wdio/types'

const SCREENSHOT_REPLACEMENT = '"<Screenshot[base64]>"'
const SCRIPT_PLACEHOLDER = '"<Script[base64]>"'
const REGEX_SCRIPT_NAME = /return \(function (\w+)/

/**
* overwrite native element commands with user defined
Expand Down Expand Up @@ -97,6 +98,9 @@ export function transformCommandLogResult (result: { file?: string, script?: str
return SCREENSHOT_REPLACEMENT
} else if (typeof result.script === 'string' && isBase64(result.script)) {
return SCRIPT_PLACEHOLDER
} else if (typeof result.script === 'string' && result.script.match(REGEX_SCRIPT_NAME)) {
const newScript = result.script.match(REGEX_SCRIPT_NAME)![1]
return { ...result, script: `${newScript}(...) [${Buffer.byteLength(result.script, 'utf-8')} bytes]` }
}

return result
Expand Down
4 changes: 4 additions & 0 deletions packages/wdio-utils/tests/utils.test.ts
Expand Up @@ -46,6 +46,10 @@ describe('utils', () => {
expect(transformCommandLogResult({ script: 'foo' })).toEqual({ script: 'foo' })
expect(transformCommandLogResult({ script: (Buffer.from('some script payload')).toString('base64') }))
.toBe('"<Script[base64]>"')

expect(transformCommandLogResult({ script: 'return foobar' })).toEqual({ script: 'return foobar' })
expect(transformCommandLogResult({ script: 'return (function isElementDisplayed(element) {\n...' }))
.toEqual({ script: 'isElementDisplayed(...) [50 bytes]' })
})

describe('overwriteElementCommands', () => {
Expand Down