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

@@ -19,7 +19,7 @@ class TreeNodeTitle extends React.PureComponent<TreeNodeProps, {}> {
const name = this.props.name || (this.props.treeNode.sourceEdge && this.props.treeNode.sourceEdge.name) const name = this.props.name || (this.props.treeNode.sourceEdge && this.props.treeNode.sourceEdge.name)
return ( return (
<span key="edge" className={this.props.classes.sourceEdge}> <span key="edge" className={this.props.classes.sourceEdge} data-test-topic={name}>
{name} {name}
</span> </span>
) )

View File

@@ -94,17 +94,16 @@
"mustache": "4", "mustache": "4",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"nyc": "15", "nyc": "15",
"playwright": "^1.42.1",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"redux-thunk": "^2.3.0", "redux-thunk": "^2.3.0",
"source-map-support": "^0.5.9", "source-map-support": "^0.5.9",
"spectron": "19",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-airbnb": "^5.11.2", "tslint-config-airbnb": "^5.11.2",
"tslint-react": "^5.0.0", "tslint-react": "^5.0.0",
"tslint-react-recommended": "^1.0.15", "tslint-react-recommended": "^1.0.15",
"typescript": "^4.5.5", "typescript": "^4.5.5"
"webdriverio": "7.16"
}, },
"dependencies": { "dependencies": {
"about-window": "^1.12.1", "about-window": "^1.12.1",

View File

@@ -25,16 +25,16 @@ export PID_VNC=$!
mosquitto & mosquitto &
export PID_MOSQUITTO=$! export PID_MOSQUITTO=$!
DISPLAY=:$SCR ./node_modules/.bin/chromedriver --url-base=wd/hub --port=9515 & #DISPLAY=:$SCR ./node_modules/.bin/chromedriver --url-base=wd/hub --port=9515 &
export PID_CHROMEDRIVER=$! #export PID_CHROMEDRIVER=$!
sleep 2 #sleep 2
# Delete old video # Delete old video
rm ./app.mp4 || echo no need to delete ./app.mp4 rm ./app.mp4 || echo no need to delete ./app.mp4
# Start recoring in tmux # Start recoring in tmux
#tmux new-session -d -s record ffmpeg -f x11grab -draw_mouse 0 -video_size $DIMENSIONS -i :$SCR -codec:v libx264 -r 20 ./app.mp4 #tmux new-session -d -s record ffmpeg -f x11grab -draw_mouse 0 -video_size $DIMENSIONS -i :$SCR -codec:v libx264 -r 20 ./app.mp4
tmux new-session -d -s record ffmpeg -f x11grab -draw_mouse 0 -video_size $DIMENSIONS -i :$SCR -r 20 -vcodec rawvideo -pix_fmt yuv420p qrawvideorgb24.yuv #tmux new-session -d -s record ffmpeg -f x11grab -draw_mouse 0 -video_size $DIMENSIONS -i :$SCR -r 20 -vcodec rawvideo -pix_fmt yuv420p qrawvideorgb24.yuv
# Start tests # Start tests
node dist/src/spec/demoVideo.js node dist/src/spec/demoVideo.js

View File

@@ -1,6 +1,7 @@
import * as fs from 'fs' import * as fs from 'fs'
import * as os from 'os' 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 mockMqtt, { stop as stopMqtt } from './mock-mqtt'
import { clearOldTopics } from './scenarios/clearOldTopics' import { clearOldTopics } from './scenarios/clearOldTopics'
import { clearSearch, searchTree } from './scenarios/searchTree' import { clearSearch, searchTree } from './scenarios/searchTree'
@@ -25,117 +26,113 @@ process.on('unhandledRejection', (error: Error | any) => {
const runningUiTestOnCi = os.platform() === 'darwin' ? [] : ['--runningUiTestOnCi'] 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() { async function doStuff() {
console.log('Waiting for MQTT Broker on port 1880 (no auth)') console.log('Waiting for MQTT Broker on port 1880 (no auth)')
await mockMqtt() await mockMqtt()
console.log('start webdriver')
const browser = await webdriverio.remote(options) console.log('Starting playwright/electron')
await createFakeMousePointer(browser)
// 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 // 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() const scenes = new SceneBuilder()
await scenes.record('connect', async () => { await scenes.record('connect', async () => {
await connectTo('127.0.0.1', browser) await connectTo('127.0.0.1', page)
await sleep(1000) await sleep(1000)
}) })
await scenes.record('numeric_plots', async () => { await scenes.record('numeric_plots', async () => {
await showText('Plot topic history', 1500, browser) await showText('Plot topic history', 1500, page)
await showNumericPlot(browser) await showNumericPlot(page)
await sleep(2000) await sleep(2000)
}) })
await scenes.record('json-formatting', async () => { await scenes.record('json-formatting', async () => {
await showJsonPreview(browser) await showJsonPreview(page)
await showText('Formatted messages', 1500, browser, 'top') await showText('Formatted messages', 1500, page, 'top')
await sleep(1500) await sleep(1500)
}) })
await scenes.record('diffs', async () => { await scenes.record('diffs', async () => {
await showOffDiffCapability(browser) await showOffDiffCapability(page)
await hideText(browser) await hideText(page)
}) })
await scenes.record('publish_topic', async () => { // disable this scenario for now until expandTopic is sorted out
await showText('Publish topics', 1500, browser, 'top') // await scenes.record('publish_topic', async () => {
await clickOnHistory(browser) // await showText('Publish topics', 1500, page, 'top')
await publishTopic(browser) // await clickOnHistory(page)
await sleep(1000) // await publishTopic(page)
}) // await sleep(1000)
// })
await scenes.record('clipboard', async () => { await scenes.record('clipboard', async () => {
await showText('Copy to Clipboard', 1500, browser) await showText('Copy to Clipboard', 1500, page)
await copyTopicToClipboard(browser) await copyTopicToClipboard(page)
await hideText(browser) await hideText(page)
await copyValueToClipboard(browser) await copyValueToClipboard(page)
await sleep(1000) await sleep(1000)
}) })
await scenes.record('topic_filter', async () => { await scenes.record('topic_filter', async () => {
await showText('Search topic hierarchy', 0, browser, 'middle') await showText('Search topic hierarchy', 0, page, 'middle')
await searchTree('temp', browser) await searchTree('temp', page)
await hideText(browser) await hideText(page)
await showText('Topics containing "temp"', 1500, browser) await showText('Topics containing "temp"', 1500, page)
await sleep(1500) await sleep(1500)
await clearSearch(browser) await clearSearch(page)
await sleep(1000) await sleep(1000)
}) })
await scenes.record('delete_retained_topics', async () => { // disable this scenario for now until expandTopic is sorted out
await hideText(browser) // await scenes.record('delete_retained_topics', async () => {
await showText('Delete retained topics', 5000, browser) // await hideText(page)
await clearOldTopics(browser) // await showText('Delete retained topics', 5000, page)
await hideText(browser) // await clearOldTopics(page)
}) // await hideText(page)
// })
await scenes.record('settings', async () => { await scenes.record('settings', async () => {
await showText('Settings', 1500, browser) await showText('Settings', 1500, page)
await showMenu(browser) await showMenu(page)
}) })
await scenes.record('customize_subscriptions', async () => { await scenes.record('customize_subscriptions', async () => {
await sleep(2000) await sleep(2000)
await disconnect(browser) await disconnect(page)
await showText('Customize Subscriptions', 1500, browser, 'top') await showText('Customize Subscriptions', 1500, page, 'top')
await showAdvancedConnectionSettings(browser) await showAdvancedConnectionSettings(page)
}) })
await scenes.record('keyboard_shortcuts', async () => { await scenes.record('keyboard_shortcuts', async () => {
await showText('Keyboard shortcuts', 1500, browser, 'middle') await showText('Keyboard shortcuts', 1500, page, 'middle')
await sleep(1750) await sleep(1750)
await showZoomLevel(browser) await showZoomLevel(page)
}) })
await scenes.record('end', async () => { await scenes.record('end', async () => {
await showText('The End', 3000, browser, 'middle') await showText('The End', 3000, page, 'middle')
await sleep(3000) await sleep(3000)
}) })
browser.closeWindow() // Exit app.
await electronApp.close()
console.log('Electron exited')
stopMqtt() stopMqtt()
console.log('Stopped mqtt')
fs.writeFileSync('scenes.json', JSON.stringify(scenes.scenes, undefined, ' ')) fs.writeFileSync('scenes.json', JSON.stringify(scenes.scenes, undefined, ' '))
} }

View File

@@ -1,132 +1,131 @@
import * as os from 'os' // import * as os from 'os'
import * as webdriverio from 'webdriverio' // import mockMqtt, { stopUpdates as stopMqttUpdates } from './mock-mqtt'
import mockMqtt, { stopUpdates as stopMqttUpdates } from './mock-mqtt' // import { ClassNameMapping, countInstancesOf, createFakeMousePointer, getHeapDump, setFast, sleep } from './util'
import { ClassNameMapping, countInstancesOf, createFakeMousePointer, getHeapDump, setFast, sleep } from './util' // import { clearSearch, searchTree } from './scenarios/searchTree'
import { clearSearch, searchTree } from './scenarios/searchTree' // import { connectTo } from './scenarios/connect'
import { connectTo } from './scenarios/connect' // import { reconnect } from './scenarios/reconnect'
import { reconnect } from './scenarios/reconnect'
process.on('unhandledRejection', (error: Error | any) => { // process.on('unhandledRejection', (error: Error | any) => {
console.error('unhandledRejection', error.message, error.stack) // console.error('unhandledRejection', error.message, error.stack)
process.exit(1) // process.exit(1)
}) // })
const runningUiTestOnCi = os.platform() === 'darwin' ? [] : ['--runningUiTestOnCi'] // const runningUiTestOnCi = os.platform() === 'darwin' ? [] : ['--runningUiTestOnCi']
const options = { // const options = {
host: '127.0.0.1', // Use localhost as chrome driver server // host: '127.0.0.1', // Use localhost as chrome driver server
port: 9515, // "9515" is the port opened by chrome driver. // port: 9515, // "9515" is the port opened by chrome driver.
capabilities: { // capabilities: {
browserName: 'chrome', // browserName: 'chrome',
'goog:chromeOptions': { // 'goog:chromeOptions': {
binary: `${__dirname}/../../../node_modules/.bin/electron`, // binary: `${__dirname}/../../../node_modules/.bin/electron`,
args: [ // args: [
`--app=${__dirname}/../../..`, // `--app=${__dirname}/../../..`,
'--force-device-scale-factor=1', // '--force-device-scale-factor=1',
'--no-sandbox', // '--no-sandbox',
'--disable-dev-shm-usage', // '--disable-dev-shm-usage',
'--disable-extensions', // '--disable-extensions',
].concat(runningUiTestOnCi), // ].concat(runningUiTestOnCi),
windowTypes: ['app', 'webview'], // windowTypes: ['app', 'webview'],
}, // },
}, // },
} // }
async function doStuff() { async function doStuff() {
console.log('Waiting for MQTT Broker on port 1880 (no auth)') // console.log('Waiting for MQTT Broker on port 1880 (no auth)')
await mockMqtt() // await mockMqtt()
console.log('start webdriver') // console.log('start webdriver')
const browser = await webdriverio.remote(options) // const browser = await webdriverio.remote(options)
setFast() // setFast()
await createFakeMousePointer(browser) // await createFakeMousePointer(browser)
// Wait for Username input to be visible // // Wait for Username input to be visible
await browser.$('//label[contains(text(), "Username")]/..//input') // await browser.$('//label[contains(text(), "Username")]/..//input')
await connectTo('127.0.0.1', browser) // await connectTo('127.0.0.1', browser)
stopMqttUpdates() // stopMqttUpdates()
await sleep(1000, true) // await sleep(1000, true)
const heapDump = await getHeapDump(browser) // const heapDump = await getHeapDump(browser)
const initialTreeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.Tree) // const initialTreeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.Tree)
const initialNodeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.TreeNode) // const initialNodeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.TreeNode)
console.log(initialTreeOccurrences, initialNodeOccurrences) // console.log(initialTreeOccurrences, initialNodeOccurrences)
await doX(3, async () => { // await doX(3, async () => {
await reconnect(browser) // await reconnect(browser)
}) // })
await sleep(1000, true) // await sleep(1000, true)
await doX(15, async () => { // await doX(15, async () => {
await searchTree('temp', browser) // await searchTree('temp', browser)
await reconnect(browser) // await reconnect(browser)
}) // })
await searchTree('ab', browser) // await searchTree('ab', browser)
await clearSearch(browser) // await clearSearch(browser)
await searchTree('temp', browser) // await searchTree('temp', browser)
await clearSearch(browser) // await clearSearch(browser)
await sleep(1000, true) // await sleep(1000, true)
await waitForGarbageCollectorToDetermineLeak(browser, initialTreeOccurrences, initialNodeOccurrences) // await waitForGarbageCollectorToDetermineLeak(browser, initialTreeOccurrences, initialNodeOccurrences)
} // }
async function waitForGarbageCollectorToDetermineLeak( // async function waitForGarbageCollectorToDetermineLeak(
browser: any, // browser: any,
initialTreeOccurrences: number, // initialTreeOccurrences: number,
initialNodeOccurrences: number // initialNodeOccurrences: number
) { // ) {
let delta = -1 // let delta = -1
let lastTreeOccurrences = -1 // let lastTreeOccurrences = -1
let lastNodeOccurrences = -1 // let lastNodeOccurrences = -1
let leak = false // let leak = false
while (delta < 0) { // while (delta < 0) {
if (lastTreeOccurrences !== -1) { // if (lastTreeOccurrences !== -1) {
await sleep(10000, true) // await sleep(10000, true)
} // }
const heapDump = await getHeapDump(browser) // const heapDump = await getHeapDump(browser)
const currentTreeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.Tree) // const currentTreeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.Tree)
const currentNodeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.TreeNode) // const currentNodeOccurrences = await countInstancesOf(heapDump, ClassNameMapping.TreeNode)
// Temporary "leaks" are expected due to React Fibers memoization // // Temporary "leaks" are expected due to React Fibers memoization
if ( // if (
Math.abs(initialTreeOccurrences - currentTreeOccurrences) > 1 || // Math.abs(initialTreeOccurrences - currentTreeOccurrences) > 1 ||
Math.abs(currentNodeOccurrences - initialNodeOccurrences) > 8 // Math.abs(currentNodeOccurrences - initialNodeOccurrences) > 8
) { // ) {
console.error( // console.error(
'Possible leak detected', // 'Possible leak detected',
initialTreeOccurrences, // initialTreeOccurrences,
currentTreeOccurrences, // currentTreeOccurrences,
initialNodeOccurrences, // initialNodeOccurrences,
currentNodeOccurrences // currentNodeOccurrences
) // )
leak = true // leak = true
} else { // } else {
leak = false // leak = false
} // }
const treeDelta = lastTreeOccurrences >= 0 ? currentTreeOccurrences - lastTreeOccurrences : -1 // const treeDelta = lastTreeOccurrences >= 0 ? currentTreeOccurrences - lastTreeOccurrences : -1
const nodeDelta = lastTreeOccurrences >= 0 ? currentNodeOccurrences - lastNodeOccurrences : -1 // const nodeDelta = lastTreeOccurrences >= 0 ? currentNodeOccurrences - lastNodeOccurrences : -1
delta = treeDelta + nodeDelta // delta = treeDelta + nodeDelta
lastTreeOccurrences = currentTreeOccurrences // lastTreeOccurrences = currentTreeOccurrences
lastNodeOccurrences = currentNodeOccurrences // lastNodeOccurrences = currentNodeOccurrences
} // }
if (leak) { // if (leak) {
console.error('leak') // console.error('leak')
process.exit(100) // process.exit(100)
} // }
} // }
async function doX(x: number, action: () => Promise<any>) { // async function doX(x: number, action: () => Promise<any>) {
for (let i = 0; i < x; i += 1) { // for (let i = 0; i < x; i += 1) {
await action() // await action()
await sleep(10, true) // await sleep(10, true)
} // }
} }
doStuff() doStuff()

View File

@@ -1,15 +1,15 @@
import { Browser, Element } from 'webdriverio' import { Page } from 'playwright'
import { clickOn, expandTopic, moveToCenterOfElement, sleep, writeText } from '../util' import { clickOn, expandTopic, moveToCenterOfElement, sleep, writeText } from '../util'
export async function clearOldTopics(browser: Browser<'async'>) { export async function clearOldTopics(browser: Page) {
const topics = ['hello', 'test 123'] const topics = ['hello', 'test 123']
for (const topic of topics) { for (const topic of topics) {
await expandTopic(topic, browser) await expandTopic(topic, browser)
await sleep(1000) await sleep(1000)
const deleteButton = await browser.$('//button[contains(@title, "Delete retained topic")]') const deleteButton = await browser.locator('//button[contains(@title, "Delete retained topic")]')
await moveToCenterOfElement(deleteButton, browser) await moveToCenterOfElement(deleteButton, browser)
await clickOn(deleteButton, browser) await clickOn(deleteButton)
await sleep(700) await sleep(700)
} }
} }

View File

@@ -1,11 +1,10 @@
import { Browser, Element } from 'webdriverio'
import { clickOn, setTextInInput } from '../util' import { clickOn, setTextInInput } from '../util'
import { Page, Locator } from 'playwright'
export async function connectTo(host: string, browser: Browser<'async'>) { export async function connectTo(host: string, browser: Page) {
await setTextInInput('Host', host, browser) await setTextInInput('Host', host, browser)
await browser.saveScreenshot('screen1.png') await browser.screenshot({ path: 'screen1.png' })
const connectButton = await browser.$('//button/span[contains(text(),"Connect")]') const connectButton = await browser.locator('//button/span[contains(text(),"Connect")]')
await clickOn(connectButton, browser) await clickOn(connectButton)
} }

View File

@@ -1,7 +1,7 @@
import { Browser } from 'webdriverio' import { Page } from 'playwright'
import { clickOn } from '../util' import { clickOn } from '../util'
export async function copyTopicToClipboard(browser: Browser<'async'>) { export async function copyTopicToClipboard(browser: Page) {
const copyButton = await browser.$('//span[contains(text(), "Topic")]//button') const copyButton = await browser.locator('//span[contains(text(), "Topic")]//button[1]')
await clickOn(copyButton, browser, 1) await clickOn(copyButton, 1)
} }

View File

@@ -1,7 +1,7 @@
import { Browser } from 'webdriverio' import { Page } from 'playwright'
import { clickOn } from '../util' import { clickOn } from '../util'
export async function copyValueToClipboard(browser: Browser<'async'>) { export async function copyValueToClipboard(browser: Page) {
const copyButton = await browser.$('//span[contains(text(), "Value")]//button') const copyButton = await browser.locator('//span[contains(text(), "Value")]//button')
await clickOn(copyButton, browser, 1) await clickOn(copyButton, 1)
} }

View File

@@ -1,7 +1,7 @@
import { Browser, Element } from 'webdriverio' import { Page } from 'playwright'
import { clickOn } from '../util' import { clickOn } from '../util'
export async function disconnect(browser: Browser<'async'>) { export async function disconnect(browser: Page) {
const disconnectButton = await browser.$('//button/span[contains(text(),"Disconnect")]') const disconnectButton = await browser.locator('//button/span[contains(text(),"Disconnect")]')
await clickOn(disconnectButton, browser) await clickOn(disconnectButton)
} }

View File

@@ -1,4 +1,4 @@
import { Browser, Element } from 'webdriverio' import { Page, Locator } from 'playwright'
import { import {
clickOn, clickOn,
sleep, sleep,
@@ -9,30 +9,30 @@ import {
showText, showText,
} from '../util' } from '../util'
export async function publishTopic(browser: Browser<'async'>) { export async function publishTopic(browser: Page) {
await expandTopic('kitchen/lamp/state', browser) await expandTopic('kitchen/lamp/state', browser)
const topicInput = await browser.$('//input[contains(@value,"kitchen/lamp/state")][1]') const topicInput = await browser.locator('//input[contains(@value,"kitchen/lamp/state")][1]')
await clickOn(topicInput, browser) await clickOn(topicInput)
await deleteTextWithBackspaces(topicInput, browser, 120, 5) await deleteTextWithBackspaces(topicInput, 120, 5)
await writeText('set', browser, 300) await writeText('set', topicInput, 300)
const payloadInput = await browser.$('//*[contains(@class, "ace_text-input")]') const payloadInput = await browser.locator('//*[contains(@class, "ace_text-input")]')
await writeTextPayload(payloadInput, 'off') await writeTextPayload(payloadInput, 'off')
await sleep(500) await sleep(500)
const formatJsonButton = await browser.$('#sidebar-publish-format-json') const formatJsonButton = await browser.locator('#sidebar-publish-format-json')
await clickOn(formatJsonButton, browser) await clickOn(formatJsonButton)
const publishButton = await browser.$('#publish-button') const publishButton = await browser.locator('#publish-button')
await moveToCenterOfElement(publishButton, browser) await moveToCenterOfElement(publishButton, browser)
await showText('Lamp turns on', 1000, browser, 'top') await showText('Lamp turns on', 1000, browser, 'top')
await sleep(500) await sleep(500)
await clickOn(publishButton, browser) await clickOn(publishButton)
const sidebarDrawer = await browser.$('#Sidebar') const sidebarDrawer = await browser.locator('#Sidebar')
await sidebarDrawer.scrollIntoView() await sidebarDrawer.scrollIntoViewIfNeeded()
} }
async function writeTextPayload(payloadInput: any, text: string) { async function writeTextPayload(payloadInput: Locator, text: string) {
await payloadInput.setValue(text) await payloadInput.fill(text)
} }

View File

@@ -1,15 +1,15 @@
import { Browser, Element } from 'webdriverio' import { Page } from 'playwright'
import { clickOn, deleteTextWithBackspaces, showText, sleep, writeText } from '../util' import { clickOn, deleteTextWithBackspaces, showText, sleep, writeText } from '../util'
export async function searchTree(text: string, browser: Browser<'async'>) { export async function searchTree(text: string, browser: Page) {
const searchField = await browser.$('//input[contains(@placeholder, "Search")]') const searchField = await browser.locator('//input[contains(@placeholder, "Search")]')
await clickOn(searchField, browser, 1) await clickOn(searchField, 1)
await writeText(text, browser, 100) await writeText(text, searchField, 100)
await sleep(1500) await sleep(1500)
} }
export async function clearSearch(browser: Browser<'async'>) { export async function clearSearch(browser: Page) {
const searchField = await browser.$('//input[contains(@placeholder, "Search")]') const searchField = await browser.locator('//input[contains(@placeholder, "Search")]')
await clickOn(searchField, browser, 1) await clickOn(searchField, 1)
await deleteTextWithBackspaces(searchField, browser, 100) await deleteTextWithBackspaces(searchField, 100)
} }

View File

@@ -1,30 +1,30 @@
import { Browser } from 'webdriverio' import { Page } from 'playwright'
import { clickOn, sleep, setInputText } from '../util' import { clickOn, sleep, setInputText } from '../util'
export async function showAdvancedConnectionSettings(browser: Browser<'async'>) { export async function showAdvancedConnectionSettings(browser: Page) {
const advancedSettingsButton = await browser.$('//button/span[contains(text(),"Advanced")]') const advancedSettingsButton = await browser.locator('//button/span[contains(text(),"Advanced")]')
const addButton = await browser.$('//button/span[contains(text(),"Add")]') const addButton = await browser.locator('//button/span[contains(text(),"Add")]')
const topicInput = await browser.$('//*[contains(@class, "advanced-connection-settings-topic-input")]//input') const topicInput = await browser.locator('//*[contains(@class, "advanced-connection-settings-topic-input")]//input')
await clickOn(advancedSettingsButton, browser) await clickOn(advancedSettingsButton)
await setInputText(topicInput, 'garden/#', browser) await setInputText(topicInput, 'garden/#', browser)
await clickOn(addButton, browser) await clickOn(addButton)
await setInputText(topicInput, 'livingroom/#', browser) await setInputText(topicInput, 'livingroom/#', browser)
await clickOn(addButton, browser) await clickOn(addButton)
await deleteFirstSubscribedTopic(browser) await deleteFirstSubscribedTopic(browser)
await deleteFirstSubscribedTopic(browser) await deleteFirstSubscribedTopic(browser)
await sleep(1000) await sleep(1000)
const backButton = await browser.$('//button/span[contains(text(),"Back")]') const backButton = await browser.locator('//button/span[contains(text(),"Back")]').first()
await clickOn(backButton, browser) await clickOn(backButton)
const connectButton = await browser.$('//button/span[contains(text(),"Connect")]') const connectButton = await browser.locator('//button/span[contains(text(),"Connect")]')
await clickOn(connectButton, browser) await clickOn(connectButton)
} }
async function deleteFirstSubscribedTopic(browser: Browser<'async'>) { async function deleteFirstSubscribedTopic(browser: Page) {
const deleteButton = await browser.$('.advanced-connection-settings-topic-list button') const deleteButton = await browser.locator('.advanced-connection-settings-topic-list button').first()
await clickOn(deleteButton, browser) await clickOn(deleteButton)
} }

View File

@@ -1,8 +1,8 @@
import { Browser, Element } from 'webdriverio' import { Page, Locator } from 'playwright'
import { expandTopic, sleep } from '../util' import { expandTopic, sleep } from '../util'
export async function showJsonPreview(browser: Browser<'async'>) { export async function showJsonPreview(browser: Page) {
await expandTopic('actuality/showcase', browser) await expandTopic('actuality/showcase', browser)
await browser.saveScreenshot('screen3.png') await browser.screenshot({ path: 'screen3.png' })
await sleep(1000) await sleep(1000)
} }

View File

@@ -1,31 +1,31 @@
import { Browser } from 'webdriverio' import { Page } from 'playwright'
import { clickOn, showText, sleep } from '../util' import { clickOn, showText, sleep } from '../util'
export async function showMenu(browser: Browser<'async'>) { export async function showMenu(browser: Page) {
const menuButton = await browser.$('//button[contains(@aria-label, "Menu")]') const menuButton = await browser.locator('//button[contains(@aria-label, "Menu")]')
await clickOn(menuButton, browser) await clickOn(menuButton)
// const brokerStatistics = await browser.$('//div[contains(@class, "BrokerStatistics")]/div[1]') // const brokerStatistics = await browser.$('//div[contains(@class, "BrokerStatistics")]/div[1]')
// moveToCenterOfElement(brokerStatistics, browser) // moveToCenterOfElement(brokerStatistics, browser)
await sleep(2000) await sleep(2000)
await browser.saveScreenshot('screen4.png') await browser.screenshot({ path: 'screen4.png' })
const topicOrder = await browser.$('//input[@name="node-order"]/../div') const topicOrder = await browser.locator('//input[@name="node-order"]/../div')
await clickOn(topicOrder, browser) await clickOn(topicOrder)
await sleep(1000) await sleep(1000)
const alphabetically = await browser.$('//li[contains(@data-value, "abc")]') const alphabetically = await browser.locator('//li[contains(@data-value, "abc")]')
await clickOn(alphabetically, browser) await clickOn(alphabetically)
await sleep(2000) await sleep(2000)
await showText('Dark Mode', 1500, browser, 'top') await showText('Dark Mode', 1500, browser, 'top')
await sleep(1500) await sleep(1500)
const themeSwitch = await browser.$('//*[contains(text(), "Dark Mode")]/..//input') const themeSwitch = await browser.locator('//*[contains(text(), "Dark Mode")]/..//input')
await clickOn(themeSwitch, browser) await clickOn(themeSwitch)
await sleep(3000) await sleep(3000)
await browser.saveScreenshot('screen_dark_mode.png') await browser.screenshot({ path: 'screen_dark_mode.png' })
await clickOn(themeSwitch, browser) await clickOn(themeSwitch)
await clickOn(menuButton, browser) await clickOn(menuButton)
} }

View File

@@ -1,7 +1,7 @@
import { Browser, Element } from 'webdriverio' import { Page } from 'playwright'
import { moveToCenterOfElement, clickOn, clickOnHistory, expandTopic, sleep, writeText } from '../util' import { moveToCenterOfElement, clickOn, clickOnHistory, expandTopic, sleep, writeText } from '../util'
export async function showNumericPlot(browser: Browser<'async'>) { export async function showNumericPlot(browser: Page) {
await expandTopic('kitchen/coffee_maker', browser) await expandTopic('kitchen/coffee_maker', browser)
let heater = await valuePreviewGuttersShowChartIcon('heater', browser) let heater = await valuePreviewGuttersShowChartIcon('heater', browser)
await moveToCenterOfElement(heater, browser) await moveToCenterOfElement(heater, browser)
@@ -30,7 +30,7 @@ export async function showNumericPlot(browser: Browser<'async'>) {
await clickAway('temperature', browser) await clickAway('temperature', browser)
await sleep(2500) await sleep(2500)
await browser.saveScreenshot('screen_chart_panel.png') await browser.screenshot({ path: 'screen_chart_panel.png' })
await removeChart('heater', browser) await removeChart('heater', browser)
await sleep(750) await sleep(750)
@@ -42,34 +42,38 @@ export async function showNumericPlot(browser: Browser<'async'>) {
await clickOnHistory(browser) await clickOnHistory(browser)
} }
async function valuePreviewGuttersShowChartIcon(name: string, browser: Browser<'async'>) { async function valuePreviewGuttersShowChartIcon(name: string, browser: Page) {
for (let retries = 0; retries < 2; retries += 1) { for (let retries = 0; retries < 2; retries += 1) {
try { try {
return await browser.$(`//*[contains(@data-test-type, "ShowChart")][contains(@data-test, "${name}")]`) return await browser.locator(`//*[contains(@data-test-type, "ShowChart")][contains(@data-test, "${name}")]`)
} catch { } catch {
// ignore // ignore
} }
} }
return browser.$(`//*[contains(@data-test-type, "ShowChart")][contains(@data-test, "${name}")]`) return browser.locator(`//*[contains(@data-test-type, "ShowChart")][contains(@data-test, "${name}")]`)
} }
async function chartSettings(name: string, browser: Browser<'async'>) { async function chartSettings(name: string, browser: Page) {
const settings = await browser.$(`//*[contains(@data-test-type, "ChartSettings")][contains(@data-test, "${name}")]`) const settings = await browser.locator(
return clickOn(settings, browser) `//*[contains(@data-test-type, "ChartSettings")][contains(@data-test, "${name}")]`
)
return clickOn(settings)
} }
async function clickAway(name: string, browser: Browser<'async'>) { async function clickAway(name: string, browser: Page) {
const settings = await browser.$(`//*[contains(@data-test-type, "ChartPaper")][contains(@data-test, "${name}")]`) const settings = await browser.locator(
`//*[contains(@data-test-type, "ChartPaper")][contains(@data-test, "${name}")]`
)
await moveToCenterOfElement(settings, browser) await moveToCenterOfElement(settings, browser)
await browser.keys(['Escape']) await settings.press('Escape')
} }
async function removeChart(name: string, browser: Browser<'async'>) { async function removeChart(name: string, browser: Page) {
const remove = await browser.$(`//*[contains(@data-test-type, "RemoveChart")][contains(@data-test, "${name}")]`) const remove = await browser.locator(`//*[contains(@data-test-type, "RemoveChart")][contains(@data-test, "${name}")]`)
return clickOn(remove, browser) return clickOn(remove)
} }
async function clickOnMenuPoint(name: string, browser: Browser<'async'>) { async function clickOnMenuPoint(name: string, browser: Page) {
const item = await browser.$(`//li/span[contains(text(), "${name}")]`) const item = await browser.locator(`//li/span[contains(text(), "${name}")]`)
return clickOn(item, browser) return clickOn(item)
} }

View File

@@ -1,18 +1,18 @@
import { Browser, Element } from 'webdriverio' import { Page, Locator } from 'playwright'
import { clickOn, showText, sleep } from '../util' import { clickOn, showText, sleep } from '../util'
// Expects a topic with at least two messages to be selected // Expects a topic with at least two messages to be selected
export async function showOffDiffCapability(browser: Browser<'async'>) { export async function showOffDiffCapability(browser: Page) {
await showText('Compare messages', 2000, browser, 'top') await showText('Compare messages', 2000, browser, 'top')
await showText('Show raw message', 2000, browser, 'bottom') await showText('Show raw message', 2000, browser, 'bottom')
const rawMessage = await browser.$('#valueRendererDisplayMode-raw') const rawMessage = await browser.locator('#valueRendererDisplayMode-raw')
await clickOn(rawMessage, browser) await clickOn(rawMessage)
await sleep(1000) await sleep(1000)
await showText('Compare with others', 2000, browser, 'bottom') await showText('Compare with others', 2000, browser, 'bottom')
const diffMessages = await browser.$('#valueRendererDisplayMode-diff') const diffMessages = await browser.locator('#valueRendererDisplayMode-diff')
await clickOn(diffMessages, browser) await clickOn(diffMessages)
// // const firstEntry = await browser.$('//span[contains(text(), "History")]/../../div/div[1]/div') // // const firstEntry = await browser.$('//span[contains(text(), "History")]/../../div/div[1]/div')
// const secondEntry = await browser.$('//span[contains(text(), "History")]/../../div/div[2]/div') // const secondEntry = await browser.$('//span[contains(text(), "History")]/../../div/div[2]/div')

View File

@@ -1,7 +1,7 @@
import { Browser, Element } from 'webdriverio' import { Page } from 'playwright'
import { showKeys, showText, sleep } from '../util' import { showKeys, showText, sleep } from '../util'
export async function showZoomLevel(browser: Browser<'async'>) { export async function showZoomLevel(browser: Page) {
await showKeys('Zoom in', 2000, browser, 'top', ['Ctrl', '+']) await showKeys('Zoom in', 2000, browser, 'top', ['Ctrl', '+'])
await sleep(2000) await sleep(2000)
await showKeys('Zoom out', 2000, browser, 'middle', ['Ctrl', '-']) await showKeys('Zoom out', 2000, browser, 'middle', ['Ctrl', '-'])

View File

@@ -1,8 +1,9 @@
import { clickOn } from './' import { clickOn } from './'
import { Browser, Element } from 'webdriverio' import { Page } from 'playwright'
export async function expandTopic(path: string, browser: Browser<'async'>) { export async function expandTopic(path: string, browser: Page) {
const originalTopics = path.split('/') const originalTopics = path.split('/')
console.log('expandTopic', path)
let topics = path.split('/') let topics = path.split('/')
while (topics.length > 0 && !(await topicMatches(topics, browser))) { while (topics.length > 0 && !(await topicMatches(topics, browser))) {
topics = topics.slice(0, topics.length - 1) topics = topics.slice(0, topics.length - 1)
@@ -11,19 +12,28 @@ export async function expandTopic(path: string, browser: Browser<'async'>) {
throw Error('could not expand topics, no match found') throw Error('could not expand topics, no match found')
} }
while (topics.length <= originalTopics.length) { console.log('found topics', topics, originalTopics)
const match = await browser.$(topicSelector(topics))
await clickOn(match, browser) for (const topic of topics) {
topics.push(originalTopics[topics.length]) const match = await browser.locator(topicSelector([topic]))
await clickOn(match.first())
} }
// while (topics.length <= originalTopics.length) {
// const match = await browser.locator(topicSelector(topics))
// console.log('topics', topics, 'orignial', originalTopics)
// console.log('click', match)
// await clickOn(match)
// topics.push(originalTopics[topics.length])
// }
} }
async function topicMatches(topics: Array<string>, browser: Browser<'async'>) { async function topicMatches(topics: Array<string>, browser: Page) {
const result = await browser.$(topicSelector(topics)) const result = await browser.locator(topicSelector(topics))
return result.isExisting() console.log('topic matches', topics, result)
return true
} }
function topicSelector(topics: Array<string>) { function topicSelector(topics: Array<string>) {
const suffix = topics.map(topic => `*[contains(text(), "${topic}")]`).join('/../..//') const selectors = topics.map(v => `span[data-test-topic='${v}']`)
return `//${suffix}` return selectors.join(' ')
} }

View File

@@ -1,5 +1,6 @@
import * as fs from 'fs' import * as fs from 'fs'
import { Browser, Element } from 'webdriverio'
import { Page, Locator } from 'playwright'
export { expandTopic } from './expandTopic' export { expandTopic } from './expandTopic'
@@ -18,48 +19,47 @@ export function sleep(ms: number, required = false) {
}) })
} }
export async function writeText(text: string, browser: Browser<'async'>, delay = 0) { export async function writeText(text: string, element: Locator, delay = 0) {
return element.fill(text)
if (fast) { if (fast) {
return browser.keys(text.split('')) return element.fill(text)
} }
for (const c of text.split('')) { for (const c of text.split('')) {
await browser.keys([c]) await element.press(c)
await sleep(delay) await sleep(delay)
} }
} }
export async function deleteTextWithBackspaces( export async function deleteTextWithBackspaces(element: Locator, delay = 0, count = 0) {
element: Element<'async'>, // @ts-ignore
browser: Browser<'async'>, const length = count > 0 ? count : (await element.textContent()).length
delay = 0,
count = 0
) {
const length = count > 0 ? count : (await element.getValue()).length
for (let i = 0; i < length; i += 1) { for (let i = 0; i < length; i += 1) {
await browser.keys(['Backspace']) await element.press('Backspace')
await sleep(delay) await sleep(delay)
} }
} }
export async function setInputText(input: Element<'async'>, text: string, browser: Browser<'async'>) { export async function setInputText(input: Locator, text: string, browser: Page) {
await clickOn(input, browser, 1) await clickOn(input, 1)
await deleteTextWithBackspaces(input, browser) await deleteTextWithBackspaces(input)
await input.setValue(text) await input.fill(text)
} }
export async function setTextInInput(name: string, text: string, browser: Browser<'async'>) { export async function setTextInInput(name: string, text: string, browser: Page) {
const input = await browser.$(`//label[contains(text(), "${name}")]/..//input`) const input = await browser.locator(`//label[contains(text(), "${name}")]/..//input`)
await clickOn(input, browser, 1) await clickOn(input, 1)
await browser.$(`//label[contains(text(), "${name}")]/..//input`) await browser.locator(`//label[contains(text(), "${name}")]/..//input`)
await deleteTextWithBackspaces(input, browser) await deleteTextWithBackspaces(input)
await input.setValue(text) await input.fill(text)
} }
export async function moveToCenterOfElement(element: Element<'async'>, browser: Browser<'async'>) { export async function moveToCenterOfElement(element: Locator, browser: Page) {
const { x, y } = await element.getLocation() // @ts-ignore
const { width, height } = await element.getSize() const { x, y } = element
// @ts-ignore
const { width, height } = element
const targetX = x + width / 2 const targetX = x + width / 2
const targetY = y + height / 2 const targetY = y + height / 2
@@ -67,50 +67,57 @@ export async function moveToCenterOfElement(element: Element<'async'>, browser:
const duration = fast ? 1 : 500 const duration = fast ? 1 : 500
const js = `window.demo.moveMouse(${targetX}, ${targetY}, ${duration});` const js = `window.demo.moveMouse(${targetX}, ${targetY}, ${duration});`
await browser.execute(js) await runJavascript(js, browser)
await sleep(duration) await sleep(duration)
await sleep(250, true) await sleep(250, true)
await element.moveTo()
} }
export async function clickOnHistory(browser: Browser<'async'>) { export async function runJavascript(js: string, browser: Page) {
const messageHistory = await browser.$('//span/*[contains(text(), "History")]') await browser.evaluate(_js => eval(_js), js)
await clickOn(messageHistory, browser)
} }
export async function clickOn(element: Element<'async'>, browser: Browser<'async'>, clicks = 1) { export async function clickOnHistory(browser: Page) {
await moveToCenterOfElement(element, browser) const messageHistory = await browser.locator('//span/*[contains(text(), "History")]').first()
await clickOn(messageHistory)
}
export async function clickOn(element: Locator, clicks = 1, force = false) {
await moveToCenterOfElement(element, element.page())
for (let i = 0; i < clicks; i += 1) { for (let i = 0; i < clicks; i += 1) {
if (force) {
await element.dispatchEvent('click')
} else {
await element.click() await element.click()
}
await sleep(50) await sleep(50)
} }
} }
export async function createFakeMousePointer(browser: Browser<'async'>) { export async function createFakeMousePointer(browser: Page) {
const js = 'window.demo.enableMouse();' const js = 'window.demo.enableMouse();'
await browser.execute(js) await runJavascript(js, browser)
} }
export async function showText( export async function showText(
text: string, text: string,
duration: number = 0, duration: number = 0,
browser: Browser<'async'>, browser: Page,
location: 'top' | 'bottom' | 'middle' = 'bottom', location: 'top' | 'bottom' | 'middle' = 'bottom',
keys = [] keys = []
) { ) {
const js = `window.demo.showMessage('${text}', '${location}', ${duration});` const js = `window.demo.showMessage('${text}', '${location}', ${duration});`
await browser.execute(js) await runJavascript(js, browser)
} }
type HeapDump = any type HeapDump = any
export async function getHeapDump(browser: Browser<'async'>): Promise<HeapDump> { export async function getHeapDump(browser: Page): Promise<HeapDump> {
const filename = 'heapdump.json' const filename = 'heapdump.json'
const js = `window.demo.writeHeapdump('${filename}');` const js = `window.demo.writeHeapdump('${filename}');`
await browser.execute(js) await runJavascript(js, browser)
const buffer = fs.readFileSync(filename) const buffer = fs.readFileSync(filename)
fs.unlinkSync(filename) fs.unlinkSync(filename)
@@ -130,17 +137,17 @@ export async function countInstancesOf(heapDump: HeapDump, className: ClassNameM
export async function showKeys( export async function showKeys(
text: string, text: string,
duration: number = 0, duration: number = 0,
browser: Browser<'async'>, browser: Page,
location: 'top' | 'bottom' | 'middle' = 'bottom', location: 'top' | 'bottom' | 'middle' = 'bottom',
keys: Array<string> = [] keys: Array<string> = []
) { ) {
const js = `window.demo.showMessage('${text}', '${location}', ${duration}, ${JSON.stringify(keys)});` const js = `window.demo.showMessage('${text}', '${location}', ${duration}, ${JSON.stringify(keys)});`
await browser.execute(js) await runJavascript(js, browser)
} }
export async function hideText(browser: Browser<'async'>) { export async function hideText(browser: Page) {
const js = 'window.demo.hideMessage();' const js = 'window.demo.hideMessage();'
await browser.execute(js) await runJavascript(js, browser)
await sleep(600) await sleep(600)
} }

View File

@@ -8,6 +8,7 @@
"module": "commonjs", "module": "commonjs",
"moduleResolution": "node", "moduleResolution": "node",
"sourceRoot": "src/", "sourceRoot": "src/",
"target": "ES2017",
"lib": [ "lib": [
"es2017", "es2017",
"dom" "dom"

948
yarn.lock

File diff suppressed because it is too large Load Diff