Exemplo n.º 1
0
        public async Task CloseSession(ChromeSessionInfo sessionInfo)
        {
            using (var webClient = GetDebuggerClient())
            {
                var result = await webClient.PostAsync("/json/close/" + sessionInfo.Id, null);

                var contents = await result.Content.ReadAsStringAsync();

                //Assert contents == "Target is closing"
            }
        }
Exemplo n.º 2
0
        public async Task <string> NavigateToPageInNewSession(ChromeSessionInfo sessionInfo, string address)
        {
            TestContext.WriteLine($"ThreadId: {Thread.CurrentThread.ManagedThreadId}");

            var    s         = new SemaphoreSlim(0, 1);
            string body      = null;
            string requestId = null;

            using (var session = new ChromeSession(sessionInfo.WebSocketDebuggerUrl))
            {
                await session.Page.Enable();

                await session.Network.Enable(new Network.EnableCommand()
                {
                });

                session.Network.SubscribeToResponseReceivedEvent((e2) =>
                {
                    if (e2.Response.Url != address)
                    {
                        return;
                    }

                    requestId = e2.RequestId;
                });

                session.Page.SubscribeToLoadEventFiredEvent(async(e) =>
                {
                    if (String.IsNullOrWhiteSpace(requestId))
                    {
                        throw new InvalidOperationException("RequestId not set");
                    }

                    var response = await session.Network.GetResponseBody(new Network.GetResponseBodyCommand()
                    {
                        RequestId = requestId
                    });

                    body = response.Body;
                    s.Release();
                });

                var navigateResult = await session.Page.Navigate(new Page.NavigateCommand
                {
                    Url = address
                });

                await s.WaitAsync();

                return(body);
            }
        }
Exemplo n.º 3
0
        public async Task AssertParallelNavigationTasksSucceed()
        {
            int sessionCount = 10;

            var sessions = new ChromeSessionInfo[sessionCount];
            var tasks    = new Task <string> [sessionCount];

            for (int i = 0; i < sessionCount; i++)
            {
                var session = await RuntimeTestSetup.Chrome.CreateNewSession();

                sessions[i] = session;
                tasks[i]    = NavigateToPageInNewSession(session, "https://www.google.com/?q=foo" + i);
            }

            Task.WaitAll(tasks, 30000);
            for (int i = 0; i < sessionCount; i++)
            {
                Assert.IsTrue(tasks[i].Result.Contains($"value=\"foo{i}\""));
                await RuntimeTestSetup.Chrome.CloseSession(sessions[i]);
            }
        }
Exemplo n.º 4
0
        public async Task CleanupChromeSession()
        {
            await RuntimeTestSetup.Chrome.CloseSession(m_currentChromeSessionInfo);

            m_currentChromeSessionInfo = null;
        }
Exemplo n.º 5
0
 public async Task GetNewChromeSession()
 {
     m_currentChromeSessionInfo = await RuntimeTestSetup.Chrome.CreateNewSession();
 }