Skip to content

Commit 07d0cd1

Browse files
committed
fix(regression-test): finish cross-platform stabilization
Signed-off-by: kangfenmao <kangfenmao@qq.com>
1 parent 0260ad2 commit 07d0cd1

4 files changed

Lines changed: 36 additions & 40 deletions

File tree

scripts/cherry-regression-test/system-automation.ts

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -101,43 +101,18 @@ export function openExternalText(platform: Platform, paths: RunPaths, candidateP
101101
} else {
102102
const script = [
103103
`Start-Process notepad.exe -ArgumentList '${escapePowerShell(filePath)}'`,
104-
'Add-Type -AssemblyName UIAutomationClient',
105-
'Add-Type -AssemblyName UIAutomationTypes',
106-
`$expected = (Get-Content -Raw -LiteralPath '${escapePowerShell(filePath)}').Trim()`,
107-
'$root = [System.Windows.Automation.AutomationElement]::RootElement',
108-
'$documentCondition = [System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::Document)',
109-
'$editCondition = [System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::Edit)',
104+
`$filename = '${escapePowerShell(basename(filePath))}'`,
110105
'$deadline = [DateTime]::UtcNow.AddSeconds(10)',
111-
'$document = $null',
112-
'$range = $null',
106+
'$notepad = $null',
113107
'do {',
114-
' $documents = @($root.FindAll([System.Windows.Automation.TreeScope]::Descendants, $documentCondition))',
115-
' $edits = @($root.FindAll([System.Windows.Automation.TreeScope]::Descendants, $editCondition))',
116-
' foreach ($candidate in (@($documents) + @($edits))) {',
117-
' $candidateRange = $null',
118-
' $candidateText = $null',
119-
' try {',
120-
' $candidateRange = $candidate.GetCurrentPattern([System.Windows.Automation.TextPattern]::Pattern).DocumentRange',
121-
' $candidateText = $candidateRange.GetText(-1)',
122-
' } catch {',
123-
' try {',
124-
' $candidateValue = $candidate.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)',
125-
' $candidateText = $candidateValue.Current.Value',
126-
' } catch {}',
127-
' }',
128-
' if ($candidateText -and $candidateText.Trim().Contains($expected)) {',
129-
' $document = $candidate',
130-
' $range = $candidateRange',
131-
' break',
132-
' }',
133-
' }',
134-
' if (-not $document) { Start-Sleep -Milliseconds 200 }',
135-
'} while (-not $document -and [DateTime]::UtcNow -lt $deadline)',
136-
'if (-not $document) { throw "Notepad document was not found" }',
108+
' $notepad = Get-Process -Name notepad -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowTitle.Contains($filename) } | Sort-Object StartTime -Descending | Select-Object -First 1',
109+
' if (-not $notepad) { Start-Sleep -Milliseconds 200 }',
110+
'} while (-not $notepad -and [DateTime]::UtcNow -lt $deadline)',
111+
'if (-not $notepad) { throw "Notepad window was not found" }',
137112
'$shell = New-Object -ComObject WScript.Shell',
138-
'if (-not $shell.AppActivate($document.Current.ProcessId)) { throw "Notepad window could not be activated" }',
139-
'$document.SetFocus()',
140-
'if ($range) { $range.Select() } else { $shell.SendKeys("^a") }',
113+
'if (-not $shell.AppActivate($notepad.Id)) { throw "Notepad window could not be activated" }',
114+
'Start-Sleep -Milliseconds 300',
115+
'$shell.SendKeys("^a")',
141116
'Start-Sleep -Milliseconds 500'
142117
].join('\n')
143118
execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
@@ -205,7 +180,8 @@ export function chooseNativeFile(platform: Platform, paths: RunPaths, candidateP
205180
'$acceptCondition = [System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::AutomationIdProperty, "1")',
206181
'$acceptButton = $dialog.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $acceptCondition)',
207182
'if (-not $acceptButton) { throw "Native folder accept button was not found" }',
208-
'$acceptButton.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern).Invoke()',
183+
'$acceptButton.SetFocus()',
184+
'[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")',
209185
'Start-Sleep -Milliseconds 500'
210186
]
211187
: [

tests/e2e/cherry-regression/05-desktop-assistants.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function invokeQuickAssistant(
5252
await input.fill(markerPrompt)
5353
await input.press('Enter')
5454
await expect(quick.getByText('QUICK_ASSISTANT_PASS', { exact: true }).last()).toBeVisible({ timeout: 2 * 60_000 })
55-
await quick.keyboard.press('Escape')
55+
await quick.getByRole('button', { name: 'ESC to return', exact: true }).click()
5656
await expect(quick.getByText('Answer this question', { exact: true })).toBeVisible()
5757
}
5858

@@ -104,8 +104,21 @@ test('[C-03] 使用划词助手处理跨应用选中文本 @selection-assistant'
104104
const readLabel = selection.getByRole('button', { name: 'Read validation label', exact: true })
105105
await expect(readLabel).toBeVisible()
106106
openExternalText(app.record.platform, app.paths, join(app.paths.fixtures, 'selection.txt'))
107-
sendSystemHotkey(app.record.platform, [app.record.platform === 'macos' ? 'Meta' : 'Control', 'Alt', 'Shift', 'k'])
108-
await expect.poll(() => selection.evaluate(() => document.visibilityState)).toBe('visible')
107+
await expect
108+
.poll(
109+
async () => {
110+
sendSystemHotkey(app.record.platform, [
111+
app.record.platform === 'macos' ? 'Meta' : 'Control',
112+
'Alt',
113+
'Shift',
114+
'k'
115+
])
116+
await selection.waitForTimeout(1_000)
117+
return selection.evaluate(() => document.visibilityState)
118+
},
119+
{ timeout: 15_000 }
120+
)
121+
.toBe('visible')
109122
await readLabel.click()
110123
const action = await app.window('/windows/selection/action/')
111124
await expect(action.locator('body')).toContainText('SELECTION_ASSISTANT_PASS', { timeout: 2 * 60_000 })

tests/e2e/cherry-regression/09-cherryin-and-images.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ async function generateAndSaveImage(
4040
}
4141
await page.locator('[contenteditable="true"]').fill(IMAGE_PROMPT)
4242
await page.getByRole('button', { name: 'Send', exact: true }).click()
43+
const generation = page.getByRole('status', {
44+
name: /Drawing in progress\. Please do not leave this page\.|Revealing generated image/
45+
})
4346
const image = page.getByTestId('artboard-image-transform').last()
44-
await expect(image).toBeVisible({ timeout: 3 * 60_000 })
47+
await expect(generation).toBeVisible()
48+
await expect(generation).toBeHidden({ timeout: 3 * 60_000 })
49+
await expect(image).toBeVisible()
4550

4651
await image.click({ button: 'right' })
4752
await page.getByText('Save As', { exact: true }).click()

tests/e2e/cherry-regression/models.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export async function selectVisibleModel(page: Page, model: string): Promise<voi
1212
const modelName = model.split('/').at(-1) ?? model
1313
const search = selector.getByTestId('model-selector-search')
1414
await search.fill(modelName)
15-
const option = selector.locator(`[role="option"][data-testid$="::${model}"]`).first()
15+
const option = selector
16+
.locator(`[role="option"][data-testid$="::${model}"], [role="option"][data-testid$="::${modelName}"]`)
17+
.first()
1618
await expect(option).toBeVisible()
1719
await option.click()
1820
}

0 commit comments

Comments
 (0)