2023-06-20 04:02:03 +08:00
import { test , expect } from "@gradio/tootils" ;
2024-02-07 03:20:20 +08:00
import { chromium } from "playwright" ;
2022-07-01 13:27:47 +08:00
2024-01-05 07:39:16 +08:00
test ( "test inputs" , async ( { page } ) = > {
2024-02-07 03:20:20 +08:00
const browser = await chromium . launch ( ) ;
const context = await browser . newContext ( {
permissions : [ "camera" ]
} ) ;
context . grantPermissions ( [ "camera" ] ) ;
2022-10-13 00:30:42 +08:00
const textbox = await page . getByLabel ( "Textbox" ) . nth ( 0 ) ;
2022-07-01 13:27:47 +08:00
await expect ( textbox ) . toHaveValue ( "Lorem ipsum" ) ;
await textbox . fill ( "hello world" ) ;
await expect ( textbox ) . toHaveValue ( "hello world" ) ;
2022-10-13 00:30:42 +08:00
const textbox2 = await page . getByLabel ( "Textbox 2" ) ;
2022-07-01 13:27:47 +08:00
await textbox2 . fill ( "hello world" ) ;
await expect ( textbox2 ) . toHaveValue ( "hello world" ) ;
2023-09-22 20:12:26 +08:00
const number = await page . getByLabel ( "Number" ) . first ( ) ;
2022-07-01 13:27:47 +08:00
await expect ( number ) . toHaveValue ( "42" ) ;
await number . fill ( "10" ) ;
await expect ( number ) . toHaveValue ( "10" ) ;
// Image Input
const image = await page . locator ( "input" ) . nth ( 10 ) ;
await image . setInputFiles ( "./test/files/cheetah1.jpg" ) ;
const uploaded_image = await page . locator ( "img" ) . nth ( 0 ) ;
const image_data = await uploaded_image . getAttribute ( "src" ) ;
2024-02-07 22:57:52 +08:00
await expect ( image_data ) . toBeTruthy ( ) ;
2022-07-01 13:27:47 +08:00
// Image Input w/ Cropper
const image_cropper = await page . locator ( "input" ) . nth ( 10 ) ;
await image_cropper . setInputFiles ( "./test/files/cheetah1.jpg" ) ;
const uploaded_image_cropper = await page . locator ( "img" ) . nth ( 0 ) ;
const image_data_cropper = await uploaded_image_cropper . getAttribute ( "src" ) ;
2024-02-07 22:57:52 +08:00
await expect ( image_data_cropper ) . toBeTruthy ( ) ;
2024-02-07 03:20:20 +08:00
// Image Input w/ Webcam
await page . getByRole ( "button" , { name : "Click to Access Webcam" } ) . click ( ) ;
await page . getByRole ( "button" , { name : "select input source" } ) . click ( ) ;
expect ( await page . getByText ( "fake_device_0" ) ) . toBeTruthy ( ) ;
2022-07-01 13:27:47 +08:00
} ) ;
2024-01-05 07:39:16 +08:00
test ( "test outputs" , async ( { page } ) = > {
2022-07-01 13:27:47 +08:00
const submit_button = await page . locator ( "button" , { hasText : /Submit/ } ) ;
2024-01-05 07:39:16 +08:00
await submit_button . click ( ) ;
2022-07-01 13:27:47 +08:00
2022-10-13 00:30:42 +08:00
const textbox = await page . getByLabel ( "Textbox" ) . nth ( 2 ) ;
2023-06-20 04:02:03 +08:00
await expect ( textbox ) . toHaveValue ( ", selected:foo, bar" ) ;
2022-07-01 13:27:47 +08:00
2022-10-13 00:30:42 +08:00
const label = await page . getByTestId ( "label" ) ;
2023-06-20 04:02:03 +08:00
await expect ( label ) . toContainText (
` Label positive positive 74% negative 26% neutral 0% `
) ;
2022-07-01 13:27:47 +08:00
const highlight_text_color_map = await page
2022-10-13 00:30:42 +08:00
. getByTestId ( "highlighted-text" )
2022-07-01 13:27:47 +08:00
. nth ( 0 ) ;
const highlight_text_legend = await page
2022-10-13 00:30:42 +08:00
. getByTestId ( "highlighted-text" )
2022-07-01 13:27:47 +08:00
. nth ( 1 ) ;
await expect ( highlight_text_color_map ) . toContainText (
" 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"
) ;
await expect ( highlight_text_legend ) . toContainText (
"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"
) ;
const json = await page . locator ( "data-testid=json" ) ;
await expect ( json ) . toContainText ( ` {
items : {
item : [
0 : {
id : "0001" ,
type : null ,
is_good : false ,
ppu : 0.55 ,
batters : {
batter : expand 4 children
} ,
topping : [
0 : { + 2 items } ,
1 : { + 2 items } ,
2 : { + 2 items } ,
3 : { + 2 items } ,
4 : { + 2 items } ,
5 : { + 2 items } ,
6 : { + 2 items }
]
}
]
}
} ` );
2024-02-07 22:57:52 +08:00
const image = page . locator ( "img" ) . nth ( 0 ) ;
2022-07-01 13:27:47 +08:00
const image_data = await image . getAttribute ( "src" ) ;
2024-02-07 22:57:52 +08:00
expect ( image_data ) . toBeTruthy ( ) ;
2022-07-01 13:27:47 +08:00
2024-02-07 22:57:52 +08:00
const audio = page . getByTestId ( "unlabelled-audio" ) ;
2023-10-31 12:46:02 +08:00
expect ( audio ) . toBeTruthy ( ) ;
2023-06-20 04:02:03 +08:00
2024-02-07 22:57:52 +08:00
const controls = page . getByTestId ( "waveform-controls" ) ;
await expect ( controls ) . toBeVisible ( ) ;
2022-07-01 13:27:47 +08:00
} ) ;