Esempio n. 1
0
        public object Post(NewSessionRequest request)
        {
            if (request.RequiredCapabilities != null)
            {
                // TODO: verify that required capabilities can be supported, otherwise return session_not_created
            }

            if (request.DesiredCapabilities != null)
            {
                // TODO: verify that app exists, otherwise return session_not_created

                // TODO: support more desired capabilities, rather than just ignoring them
                var capabilities = new Capabilities(request.DesiredCapabilities);
                var session = _sessionRepository.Create(capabilities);

                return new HttpResult
                {
                    StatusCode = HttpStatusCode.RedirectMethod,
                    Headers =
                    {
                        { HttpHeaders.Location, RequestContext.AbsoluteUri.WithTrailingSlash() + session.SessionId.ToString("N") }
                    }
                };
            }

            throw new MissingCommandParameterException();
        }
Esempio n. 2
0
        public Session Create(Capabilities capabilities)
        {
            var session = new Session(capabilities);

            _cache.Add(
                session.SessionId.ToString("N"),
                session,
                new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(5) });

            return session;
        }
Esempio n. 3
0
        public Session(Capabilities capabilities)
        {
            _capabilities = capabilities;
            _sessionId = Guid.NewGuid();

            // TODO: inject this somehow

            if (Capabilities.App != null)
            {
                // TODO: Not sure why this works, but Process.Start will throw COMExceptions once automation is used...
                var app = Application.Launch(Capabilities.App);

                while (app.GetWindows().Count == 0)
                {
                    Thread.Sleep(500);
                }

                app.WaitWhileBusy();

                _process = app.Process;
            }

            _timeouts = new Timeouts();
        }