File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+ using Xunit ;
7+
8+ namespace PuppeteerSharp . Tests . Frame
9+ {
10+ [ Collection ( "PuppeteerLoaderFixture collection" ) ]
11+ public class EvaluateTests : PuppeteerPageBaseTest
12+ {
13+ [ Fact ]
14+ public async Task ShouldHaveDifferentExecutionContexts ( )
15+ {
16+ await Page . GoToAsync ( TestConstants . EmptyPage ) ;
17+ await FrameUtils . AttachFrame ( Page , "frame1" , TestConstants . EmptyPage ) ;
18+ Assert . Equal ( 2 , Page . Frames . Count ( ) ) ;
19+
20+ var frame1 = Page . Frames . ElementAt ( 0 ) ;
21+ var frame2 = Page . Frames . ElementAt ( 1 ) ;
22+
23+ await frame1 . EvaluateExpressionAsync ( "window.FOO = 'foo'" ) ;
24+ await frame2 . EvaluateExpressionAsync ( "window.FOO = 'bar'" ) ;
25+
26+ Assert . Equal ( "foo" , await frame1 . EvaluateExpressionAsync < string > ( "window.FOO" ) ) ;
27+ Assert . Equal ( "bar" , await frame2 . EvaluateExpressionAsync < string > ( "window.FOO" ) ) ;
28+ }
29+
30+ [ Fact ]
31+ public async Task ShouldExecuteAfterCrossSiteNavigation ( )
32+ {
33+ await Page . GoToAsync ( TestConstants . EmptyPage ) ;
34+ var mainFrame = Page . MainFrame ;
35+ Assert . Contains ( "localhost" , await mainFrame . EvaluateExpressionAsync < string > ( "window.location.href" ) ) ;
36+
37+ await Page . GoToAsync ( TestConstants . CrossProcessHttpPrefix + "/empty.html" ) ;
38+ Assert . Contains ( "127" , await mainFrame . EvaluateExpressionAsync < string > ( "window.location.href" ) ) ;
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ await page.EvaluateFunctionAsync(@"(frameId, url) => {
1717 }" , frameId , url ) ;
1818 }
1919
20- public static string DumpFrames ( Frame frame , string indentation = "" )
20+ public static string DumpFrames ( PuppeteerSharp . Frame frame , string indentation = "" )
2121 {
2222 var result = indentation + Regex . Replace ( frame . Url , @":\d{4}" , ":<PORT>" ) ;
2323 foreach ( var child in frame . ChildFrames )
You can’t perform that action at this time.
0 commit comments