|
| 1 | +import { Page, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Wait until shinylive terminal shows the three >>>'s indicating that it's |
| 5 | + * ready to go |
| 6 | + * @param page Page object available from inside playwright tests |
| 7 | + */ |
| 8 | +export async function wait_until_initialized(page: Page) { |
| 9 | + await page.waitForSelector(`text=">>>"`, { timeout: 10000 }); |
| 10 | +} |
| 11 | + |
| 12 | +/** |
| 13 | + * Click the run app button in the upper right of the editor |
| 14 | + * @param page Page object available from inside playwright tests |
| 15 | + */ |
| 16 | +export async function click_run_app_button(page: Page) { |
| 17 | + // This is a bit of an intense selector for the run button but right now I |
| 18 | + // can't figure out a better way |
| 19 | + await page.locator(`[aria-label="Re-run code (Ctrl)-Shift-Enter"]`).click(); |
| 20 | +} |
| 21 | + |
| 22 | +async function expect_pane_has_text( |
| 23 | + page: Page, |
| 24 | + pane_selector: string, |
| 25 | + text: string |
| 26 | +) { |
| 27 | + await expect(page.locator(pane_selector, { hasText: text })).toBeVisible(); |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Test that some text exists in the editor pane |
| 32 | + * @param page Page object available from inside playwright tests |
| 33 | + * @param text Text to search for in the editor panel |
| 34 | + */ |
| 35 | +export async function expect_editor_has_text(page: Page, text: string) { |
| 36 | + await expect_pane_has_text(page, `.shinylive-editor`, text); |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Test that some text exists in the terminal pane |
| 41 | + * @param page Page object available from inside playwright tests |
| 42 | + * @param text Text to search for in the terminal panel |
| 43 | + */ |
| 44 | +export async function expect_terminal_has_text(page: Page, text: string) { |
| 45 | + await expect_pane_has_text(page, `.shinylive-terminal`, text); |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * Test that some text exists in the app viewer pane |
| 50 | + * @param page Page object available from inside playwright tests |
| 51 | + * @param text Text to search for in the terminal panel |
| 52 | + * @param selector Element to search for text in. Defaults to h1 tag |
| 53 | + */ |
| 54 | +export async function expect_app_has_text( |
| 55 | + page: Page, |
| 56 | + text: string, |
| 57 | + selector: string = "h1" |
| 58 | +) { |
| 59 | + // For some reason there needs to be an await for the frame locator but not |
| 60 | + // for the other normal locators |
| 61 | + await expect( |
| 62 | + page.frameLocator(".app-frame").locator(selector, { hasText: text }) |
| 63 | + ).toBeVisible(); |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * A URL data-hash containing the following app: |
| 68 | + * |
| 69 | + * ``` |
| 70 | + * from shiny import App, render, ui |
| 71 | + * |
| 72 | + * app_ui = ui.page_fluid( |
| 73 | + * ui.h1("Code from a url") |
| 74 | + * ) |
| 75 | + * |
| 76 | + * def server(input, output, session): |
| 77 | + * pass |
| 78 | + * |
| 79 | + * app = App(app_ui, server) |
| 80 | + * ``` |
| 81 | + * |
| 82 | + */ |
| 83 | +export const app_url_encoding = |
| 84 | + "code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMAMwCdiYACAZwAsBLCbJjmVYnTJMAgujxM6lACZw6EgK4cAOhFVpUAfSVMAvEyVYoAcziaaAGyXSAFKqYODHDGwCMdsAGFispvUZMUAZ0FspgAJSqkWoQsjSscgBucjZcqApkEsQZ6ZkJLCwcpOGI9o6oUAVlDuroeqLoNhraHBIsSXLRYAC+ALpAA"; |
0 commit comments