Exemplo n.º 1
0
 private void ValidateTarget(V100.Target.TargetInfo targetInfo)
 {
     Assert.That(targetInfo, Is.Not.Null);
     Assert.That(targetInfo.TargetId, Is.Not.Null);
     Assert.That(targetInfo.Title, Is.Not.Null);
     Assert.That(targetInfo.Type, Is.Not.Null);
     Assert.That(targetInfo.Url, Is.Not.Null);
 }
Exemplo n.º 2
0
        public async Task GetTargetAndSendMessageToTarget()
        {
            var domains = session.GetVersionSpecificDomains <V100.DevToolsSessionDomains>();

            V100.Target.TargetInfo[] allTargets = null;
            string sessionId = null;

            V100.Target.TargetInfo targetInfo = null;
            driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("devToolsConsoleTest.html");
            ManualResetEventSlim sync = new ManualResetEventSlim(false);

            domains.Target.ReceivedMessageFromTarget += (sender, e) =>
            {
                ValidateMessage(e);
                sync.Set();
            };
            var targetsResponse = await domains.Target.GetTargets();

            allTargets = targetsResponse.TargetInfos;
            ValidateTargetsInfos(allTargets);
            ValidateTarget(allTargets[0]);
            targetInfo = allTargets[0];
            await domains.Target.ActivateTarget(new V100.Target.ActivateTargetCommandSettings()
            {
                TargetId = targetInfo.TargetId
            });

            var attachResponse = await domains.Target.AttachToTarget(new V100.Target.AttachToTargetCommandSettings()
            {
                TargetId = targetInfo.TargetId,
                Flatten  = false
            });

            sessionId = attachResponse.SessionId;
            ValidateSession(sessionId);
            await domains.Target.SendMessageToTarget(new V100.Target.SendMessageToTargetCommandSettings()
            {
                Message   = "{\"id\":" + id + ",\"method\":\"Page.bringToFront\"}",
                SessionId = sessionId,
                TargetId  = targetInfo.TargetId
            });

            sync.Wait(TimeSpan.FromSeconds(5));
        }