Beispiel #1
0
        public TPage CreatePage <TPage>(string?baseUrl = null) where TPage : IPage
        {
            if (_webDriver == null)
            {
                _webDriver = WebDriverManager.CreateDriver(_driverType);
                _webDriver.Manage().Window.Maximize();
            }

            var page = PageBase.Create <TPage>(_webDriver, baseUrl);

            page.Load();
            return(page);
        }
Beispiel #2
0
        public virtual async Task InitializeAsync(Type?contextType = null)
        {
            contextType ??= GetType();

            Task?waitForInitialization = null;

            lock (@lock)
            {
                if (_status == ContextStatus.Initialized)
                {
                    return;
                }

                else if (_status == ContextStatus.Initializing)
                {
                    waitForInitialization = _initializeEvent.ToTask((int)BarrierManager.WaitHandleTimeout.TotalMilliseconds);
                }
                else
                {
                    _status = ContextStatus.Initializing;
                }
            }

            if (waitForInitialization != null)
            {
                await waitForInitialization;
                return;
            }

            DriverContextAttribute?useDriverAttr = contextType.GetCustomAttribute <DriverContextAttribute>(true);

            if (useDriverAttr != null)
            {
                _driverName = useDriverAttr.DriverName;
                _navigate   = !useDriverAttr.DisableNavigation;
                if (useDriverAttr.WaitForBarrier)
                {
                    _webDriver = await WebDriverManager.Instance.WaitForDriver(_driverName);
                }
                else
                {
                    int references = useDriverAttr.MaxReference <= 0 ? GetDriverReferences(_driverName, contextType) : useDriverAttr.MaxReference;
                    _webDriver        = WebDriverManager.Instance.CreateDriver(_driverType, _driverName, references);
                    _useDriverBarrier = true;
                    _webDriver.Manage().Window.Maximize();
                }
            }
            else
            {
                _webDriver = WebDriverManager.CreateDriver(_driverType);
                _webDriver.Manage().Window.Maximize();
            }

            var barrierDefAttr = contextType.GetCustomAttribute <BarrierAttribute>();

            if (barrierDefAttr != null)
            {
                _barrier = BarrierManager.Manager.GetWaitHandler(barrierDefAttr.BarrierName ?? contextType.Name);
            }

            var barriersAttr = contextType.GetCustomAttributes <WaitForBarrierAttribute>();

            if (barriersAttr != null && barriersAttr.Any())
            {
                await Task.WhenAll(barriersAttr.Select(x => BarrierManager.Manager.Wait(x.BarrierName)));
            }

            _status = ContextStatus.Initialized;
            _initializeEvent.Set();
        }