replace deprecated spectron with playwright

This commit is contained in:
Björn Dalfors
2024-04-05 14:35:18 +02:00
parent 4626df0bf7
commit 6e5e2e0dd7
22 changed files with 396 additions and 1242 deletions

View File

@@ -1,6 +1,7 @@
import * as fs from 'fs'
import * as os from 'os'
import * as webdriverio from 'webdriverio'
import { ElectronApplication, Page, _electron as electron } from 'playwright'
import mockMqtt, { stop as stopMqtt } from './mock-mqtt'
import { clearOldTopics } from './scenarios/clearOldTopics'
import { clearSearch, searchTree } from './scenarios/searchTree'
@@ -25,117 +26,113 @@ process.on('unhandledRejection', (error: Error | any) => {
const runningUiTestOnCi = os.platform() === 'darwin' ? [] : ['--runningUiTestOnCi']
const options = {
host: '127.0.0.1', // Use localhost as chrome driver server
port: 9515, // "9515" is the port opened by chrome driver.
path: '/wd/hub',
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
binary: `${__dirname}/../../../node_modules/.bin/electron`,
args: [
`--app=${__dirname}/../../..`,
'--force-device-scale-factor=1',
'--no-sandbox',
'--disable-dev-shm-usage',
'--disable-extensions',
].concat(runningUiTestOnCi),
windowTypes: ['app', 'webview'],
},
},
}
async function doStuff() {
console.log('Waiting for MQTT Broker on port 1880 (no auth)')
await mockMqtt()
console.log('start webdriver')
const browser = await webdriverio.remote(options)
await createFakeMousePointer(browser)
console.log('Starting playwright/electron')
// Launch Electron app.
const electronApp: ElectronApplication = await electron.launch({ args: [`${__dirname}/../../..`] })
// Get the first window that the app opens, wait if necessary.
const page = await electronApp.firstWindow({ timeout: 3000 })
// Print the title.
console.log(await page.title())
// Capture a screenshot.
await page.screenshot({ path: 'intro.png' })
// Direct Electron console to Node terminal.
page.on('console', console.log)
// Wait for Username input to be visible
await browser.$('//label[contains(text(), "Username")]/..//input')
await page.locator('//label[contains(text(), "Username")]/..//input')
const scenes = new SceneBuilder()
await scenes.record('connect', async () => {
await connectTo('127.0.0.1', browser)
await connectTo('127.0.0.1', page)
await sleep(1000)
})
await scenes.record('numeric_plots', async () => {
await showText('Plot topic history', 1500, browser)
await showNumericPlot(browser)
await showText('Plot topic history', 1500, page)
await showNumericPlot(page)
await sleep(2000)
})
await scenes.record('json-formatting', async () => {
await showJsonPreview(browser)
await showText('Formatted messages', 1500, browser, 'top')
await showJsonPreview(page)
await showText('Formatted messages', 1500, page, 'top')
await sleep(1500)
})
await scenes.record('diffs', async () => {
await showOffDiffCapability(browser)
await hideText(browser)
await showOffDiffCapability(page)
await hideText(page)
})
await scenes.record('publish_topic', async () => {
await showText('Publish topics', 1500, browser, 'top')
await clickOnHistory(browser)
await publishTopic(browser)
await sleep(1000)
})
// disable this scenario for now until expandTopic is sorted out
// await scenes.record('publish_topic', async () => {
// await showText('Publish topics', 1500, page, 'top')
// await clickOnHistory(page)
// await publishTopic(page)
// await sleep(1000)
// })
await scenes.record('clipboard', async () => {
await showText('Copy to Clipboard', 1500, browser)
await copyTopicToClipboard(browser)
await hideText(browser)
await copyValueToClipboard(browser)
await showText('Copy to Clipboard', 1500, page)
await copyTopicToClipboard(page)
await hideText(page)
await copyValueToClipboard(page)
await sleep(1000)
})
await scenes.record('topic_filter', async () => {
await showText('Search topic hierarchy', 0, browser, 'middle')
await searchTree('temp', browser)
await hideText(browser)
await showText('Topics containing "temp"', 1500, browser)
await showText('Search topic hierarchy', 0, page, 'middle')
await searchTree('temp', page)
await hideText(page)
await showText('Topics containing "temp"', 1500, page)
await sleep(1500)
await clearSearch(browser)
await clearSearch(page)
await sleep(1000)
})
await scenes.record('delete_retained_topics', async () => {
await hideText(browser)
await showText('Delete retained topics', 5000, browser)
await clearOldTopics(browser)
await hideText(browser)
})
// disable this scenario for now until expandTopic is sorted out
// await scenes.record('delete_retained_topics', async () => {
// await hideText(page)
// await showText('Delete retained topics', 5000, page)
// await clearOldTopics(page)
// await hideText(page)
// })
await scenes.record('settings', async () => {
await showText('Settings', 1500, browser)
await showMenu(browser)
await showText('Settings', 1500, page)
await showMenu(page)
})
await scenes.record('customize_subscriptions', async () => {
await sleep(2000)
await disconnect(browser)
await showText('Customize Subscriptions', 1500, browser, 'top')
await showAdvancedConnectionSettings(browser)
await disconnect(page)
await showText('Customize Subscriptions', 1500, page, 'top')
await showAdvancedConnectionSettings(page)
})
await scenes.record('keyboard_shortcuts', async () => {
await showText('Keyboard shortcuts', 1500, browser, 'middle')
await showText('Keyboard shortcuts', 1500, page, 'middle')
await sleep(1750)
await showZoomLevel(browser)
await showZoomLevel(page)
})
await scenes.record('end', async () => {
await showText('The End', 3000, browser, 'middle')
await showText('The End', 3000, page, 'middle')
await sleep(3000)
})
browser.closeWindow()
// Exit app.
await electronApp.close()
console.log('Electron exited')
stopMqtt()
console.log('Stopped mqtt')
fs.writeFileSync('scenes.json', JSON.stringify(scenes.scenes, undefined, ' '))
}