1
import { test, expect } from "@gradio/tootils";
2
import { chromium } from "playwright";
4
test("test inputs", async ({ page }) => {
5
const browser = await chromium.launch();
6
const context = await browser.newContext({
7
permissions: ["camera"]
9
context.grantPermissions(["camera"]);
11
const textbox = await page.getByLabel("Textbox").nth(0);
12
await expect(textbox).toHaveValue("Lorem ipsum");
14
await textbox.fill("hello world");
15
await expect(textbox).toHaveValue("hello world");
17
const textbox2 = await page.getByLabel("Textbox 2");
18
await textbox2.fill("hello world");
19
await expect(textbox2).toHaveValue("hello world");
21
const number = await page.getByLabel("Number").first();
22
await expect(number).toHaveValue("42");
23
await number.fill("10");
24
await expect(number).toHaveValue("10");
27
const image = await page.locator("input").nth(10);
28
await image.setInputFiles("./test/files/cheetah1.jpg");
30
const uploaded_image = await page.locator("img").nth(0);
31
const image_data = await uploaded_image.getAttribute("src");
32
await expect(image_data).toBeTruthy();
34
// Image Input w/ Cropper
35
const image_cropper = await page.locator("input").nth(10);
36
await image_cropper.setInputFiles("./test/files/cheetah1.jpg");
38
const uploaded_image_cropper = await page.locator("img").nth(0);
39
const image_data_cropper = await uploaded_image_cropper.getAttribute("src");
40
await expect(image_data_cropper).toBeTruthy();
42
// Image Input w/ Webcam
43
await page.getByRole("button", { name: "Click to Access Webcam" }).click();
44
await page.getByRole("button", { name: "select input source" }).click();
45
expect(await page.getByText("fake_device_0")).toBeTruthy();
48
test("test outputs", async ({ page }) => {
49
const submit_button = await page.locator("button", { hasText: /Submit/ });
51
await submit_button.click();
53
const textbox = await page.getByLabel("Textbox").nth(2);
54
await expect(textbox).toHaveValue(", selected:foo, bar");
56
const label = await page.getByTestId("label");
57
await expect(label).toContainText(
58
` Label positive positive 74% negative 26% neutral 0%`
61
const highlight_text_color_map = await page
62
.getByTestId("highlighted-text")
64
const highlight_text_legend = await page
65
.getByTestId("highlighted-text")
67
await expect(highlight_text_color_map).toContainText(
68
" HighlightedText The art quick brown adj fox nn jumped vrb testing testing testing over prp the art testing lazy adj dogs nn . punc test 0 test 0 test 1 test 1 test 2 test 2 test 3 test 3 test 4 test 4 test 5 test 5 test 6 test 6 test 7 test 7 test 8 test 8 test 9 test 9"
70
await expect(highlight_text_legend).toContainText(
71
"The testing testing testing over the testing lazy dogs . test test test test test test test test test test test test test test test test test test test test"
74
const json = await page.locator("data-testid=json");
75
await expect(json).toContainText(`{
84
batter: expand 4 children
100
const image = page.locator("img").nth(0);
101
const image_data = await image.getAttribute("src");
102
expect(image_data).toBeTruthy();
104
const audio = page.getByTestId("unlabelled-audio");
105
expect(audio).toBeTruthy();
107
const controls = page.getByTestId("waveform-controls");
108
await expect(controls).toBeVisible();