File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use chromiumoxide::{Browser, BrowserConfig};
44use futures:: { FutureExt , StreamExt } ;
55
66mod basic;
7+ mod page;
78
89pub async fn test < T > ( test : T )
910where
Original file line number Diff line number Diff line change 1+ use crate :: test;
2+
3+ #[ tokio:: test]
4+ async fn test_evaluate_on_new_document ( ) {
5+ test ( async |browser| {
6+ let page = browser
7+ . new_page ( "about:blank" )
8+ . await
9+ . expect ( "should create new page" ) ;
10+
11+ page. evaluate_on_new_document ( "window.testValue = 42;" )
12+ . await
13+ . expect ( "should evaluate script on new document" ) ;
14+
15+ page. goto ( "https://www.google.com" )
16+ . await
17+ . expect ( "should navigate to www.google.com" ) ;
18+
19+ let result: i32 = page
20+ . evaluate ( "window.testValue" )
21+ . await
22+ . expect ( "should evaluate window.testValue" )
23+ . into_value ( )
24+ . expect ( "should convert to i32" ) ;
25+
26+ assert_eq ! ( result, 42 ) ;
27+ } )
28+ . await ;
29+ }
30+
31+ #[ tokio:: test]
32+ async fn test_add_init_script ( ) {
33+ test ( async |browser| {
34+ let page = browser
35+ . new_page ( "about:blank" )
36+ . await
37+ . expect ( "should create new page" ) ;
38+
39+ page. add_init_script ( "window.testValue = 42;" )
40+ . await
41+ . expect ( "should add init script" ) ;
42+
43+ page. goto ( "https://www.google.com" )
44+ . await
45+ . expect ( "should navigate to www.google.com" ) ;
46+
47+ let result: i32 = page
48+ . evaluate ( "window.testValue" )
49+ . await
50+ . expect ( "should evaluate window.testValue" )
51+ . into_value ( )
52+ . expect ( "should convert to i32" ) ;
53+
54+ assert_eq ! ( result, 42 ) ;
55+ } )
56+ . await ;
57+ }
You can’t perform that action at this time.
0 commit comments