| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import { By } from 'selenium-webdriver'
- import fs from 'fs'
- import { expect } from 'chai'
- import { Condition } from 'selenium-webdriver'
- export async function getActionButtons () {
- // Currently, only the active dashboard's contents are rendered,
- // so we don't need to scope the selector by dashboard title.
- return await webdriver.findElements(By.css('.action-button button'))
- }
- export async function getExecutionDialogOutput() {
- await webdriver.wait(new Condition('Dialog with long int is visible', async () => {
- const dialog = await webdriver.findElement({ id: 'execution-results-popup' })
- return await dialog.isDisplayed()
- }));
-
- const ret = await webdriver.executeScript('return window.logEntries.get(window.executionDialog.executionTrackingId).output')
- return ret
- }
- export async function closeExecutionDialog() {
- const btnClose = await webdriver.findElements(By.css('[title="Close"]'))
- await btnClose[0].click()
- }
- export function takeScreenshotOnFailure (test, webdriver) {
- if (test.state === 'failed') {
- const title = test.fullTitle();
- console.log(`Test failed, taking screenshot: ${title}`);
- takeScreenshot(webdriver, title);
- }
- }
- export function takeScreenshot (webdriver, title) {
- return webdriver.takeScreenshot().then((img) => {
- fs.mkdirSync('screenshots', { recursive: true });
- title = title.replaceAll('config: ', '')
- title = title.replaceAll(/[\(\)\|\*\<\>\:]/g, "_")
- title = title + '.failed-test'
- fs.writeFileSync('screenshots/' + title + '.png', img, 'base64')
- })
- }
- export async function getRootAndWait() {
- await webdriver.get(runner.baseUrl())
- await webdriver.wait(new Condition('wait for loaded-dashboard', async function() {
- const body = await webdriver.findElement(By.tagName('body'))
- const attr = await body.getAttribute('loaded-dashboard')
- console.log('loaded-dashboard: ', attr)
- if (attr) {
- return true
- } else {
- return false
- }
- }))
- }
- export async function closeSidebar() {
- await webdriver.findElement(By.id('sidebar-toggler-button')).click()
- const sidebar = await webdriver.findElement(By.id('mainnav'))
- const neededLeft = '-250px' // Assuming sidebar is closed at this position
- let lastLeft = ''
- await webdriver.wait(new Condition('wait for sidebar to close', async function() {
- const left = await sidebar.getCssValue('left')
- if (left !== lastLeft) {
- lastLeft = left
- console.log('Sidebar left changed to: ', left)
- return false
- } else {
- console.log('Sidebar closed, left is: *' + left, left === neededLeft ? ' (as expected)' : '')
- return left === neededLeft
- }
- }), 10000); // Wait up to 10 seconds for the sidebar to close
- }
- export async function openSidebar() {
- await webdriver.findElement(By.id('sidebar-toggler-button')).click()
- const sidebar = await webdriver.findElement(By.id('mainnav'))
- let lastLeft = 0
- await webdriver.wait(new Condition('wait for sidebar to open', async function() {
- const left = await sidebar.getCssValue('left')
- if (left !== lastLeft) {
- lastLeft = left
- console.log('Sidebar left changed to: ', left)
- return false
- } else {
- console.log('Sidebar opened, left is: ', left)
- return true
- }
- }));
- }
- export async function getNavigationLinks() {
- const navigationLinks = await webdriver.findElements(By.css('.navigation-links li'))
- return navigationLinks
- }
- export async function requireExecutionDialogStatus (webdriver, expected) {
- await webdriver.wait(new Condition('wait for action to be running', async function () {
- const dialogStatus = await webdriver.findElement(By.id('execution-dialog-status'))
- const actual = await dialogStatus.getText()
- if (actual === expected) {
- return true
- } else {
- console.log('Waiting for domStatus text to be: ', expected, ', it is currently: ', actual)
- return false
- }
- }))
- }
- export async function findExecutionDialog (webdriver) {
- return webdriver.findElement(By.id('execution-results-popup'))
- }
- export async function getActionButton (webdriver, title) {
- const buttons = await webdriver.findElements(By.css('[title="' + title + '"]'))
- expect(buttons).to.have.length(1)
- return buttons[0]
- }
- export async function getTerminalBuffer() {
- try {
- const output = await webdriver.executeScript(`
- if (window.terminal && window.terminal.getBufferAsString) {
- return window.terminal.getBufferAsString();
- }
- return null;
- `)
- return output
- } catch (e) {
- console.log('[getTerminalBuffer] Error:', e.message)
- return null
- }
- }
|