예제 #1
0
        public async Task ShouldSendEventsWhenFramesAreManipulatedDynamically()
        {
            await Page.GoToAsync(TestConstants.EmptyPage);

            // validate frameattached events
            var attachedFrames = new List <Frame>();

            Page.FrameAttached += (sender, e) => attachedFrames.Add(e.Frame);

            await FrameUtils.AttachFrameAsync(Page, "frame1", "./Assets/frame.html");

            Assert.Single(attachedFrames);
            Assert.Contains("/Assets/frame.html", attachedFrames[0].Url);

            // validate framenavigated events
            var navigatedFrames = new List <Frame>();

            Page.FrameNavigated += (sender, e) => navigatedFrames.Add(e.Frame);

            await FrameUtils.NavigateFrameAsync(Page, "frame1", "./empty.html");

            Assert.Single(navigatedFrames);
            Assert.Equal(TestConstants.EmptyPage, navigatedFrames[0].Url);

            // validate framedetached events
            var detachedFrames = new List <Frame>();

            Page.FrameDetached += (sender, e) => detachedFrames.Add(e.Frame);

            await FrameUtils.DetachFrameAsync(Page, "frame1");

            Assert.Single(navigatedFrames);
            Assert.True(navigatedFrames[0].Detached);
        }
예제 #2
0
        public async Task ShouldSendEventsWhenFramesAreManipulatedDynamically()
        {
            await Page.GoToAsync(TestConstants.EmptyPage);

            // validate frameattached events
            var attachedFrames = new List <IFrame>();

            Page.FrameAttached += (sender, e) => attachedFrames.Add(e.Frame);
            await FrameUtils.AttachFrameAsync(Page, "frame1", "./assets/frame.html");

            Assert.Single(attachedFrames);
            Assert.Contains("/assets/frame.html", attachedFrames[0].Url);

            // validate framenavigated events
            var navigatedFrames = new List <IFrame>();

            Page.FrameNavigated += (sender, e) => navigatedFrames.Add(e.Frame);
            await Page.EvaluateAsync(@"() => {
                const frame = document.getElementById('frame1');
                frame.src = './empty.html';
                return new Promise(x => frame.onload = x);
            }");

            Assert.Single(navigatedFrames);
            Assert.Equal(TestConstants.EmptyPage, navigatedFrames[0].Url);

            // validate framedetached events
            var detachedFrames = new List <IFrame>();

            Page.FrameDetached += (sender, e) => detachedFrames.Add(e.Frame);
            await FrameUtils.DetachFrameAsync(Page, "frame1");

            Assert.Single(detachedFrames);
            Assert.True(detachedFrames[0].IsDetached);
        }
예제 #3
0
 public async Task ShouldThrowWhenFrameIsDetached()
 {
     await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);
     var frame = Page.FirstChildFrame();
     var waitPromise = frame.WaitForXPathAsync("//*[@class=\"box\"]");
     await FrameUtils.DetachFrameAsync(Page, "frame1");
     var exception = await Assert.ThrowsAnyAsync<Exception>(() => waitPromise);
     Assert.Contains("waitForFunction failed: frame got detached.", exception.Message);
 }
예제 #4
0
        public async Task ShouldThrowForDetachedFrames()
        {
            var frame1 = await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);

            await FrameUtils.DetachFrameAsync(Page, "frame1");

            var exception = await Assert.ThrowsAsync <PlaywrightSharpException>(() => frame1.EvaluateAsync("() => 7 * 8"));

            Assert.Contains("Execution Context is not available in detached frame", exception.Message);
        }
예제 #5
0
        public async Task ShouldThrowForDetachedFrames()
        {
            await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);

            var frame = Page.FirstChildFrame();
            await FrameUtils.DetachFrameAsync(Page, "frame1");

            var exception = await Assert.ThrowsAnyAsync <PuppeteerException>(
                () => frame.EvaluateExpressionAsync("5 * 8"));

            Assert.Contains("Execution Context is not available in detached frame", exception.Message);
        }
        public async Task ShouldThrowWhenFrameIsDetached()
        {
            await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);

            var frame    = Page.Frames.ElementAt(1);
            var waitTask = frame.WaitForSelectorAsync(".box").ContinueWith(task => task?.Exception?.InnerException);
            await FrameUtils.DetachFrameAsync(Page, "frame1");

            var waitException = await waitTask;

            Assert.NotNull(waitException);
            Assert.Contains("waitForSelector failed: frame got detached", waitException.Message);
        }