Example #1
0
        internal WaitTask(Frame frame, string predicateBody, WaitForFunctionPollingOption polling, int?pollingInterval, int timeout, object[] args)
        {
            if (string.IsNullOrEmpty(predicateBody))
            {
                throw new ArgumentNullException(nameof(predicateBody));
            }
            if (pollingInterval <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pollingInterval), "Cannot poll with non-positive interval");
            }

            _frame           = frame;
            _predicateBody   = $"return ( {predicateBody} )(...args)";
            _polling         = polling;
            _pollingInterval = pollingInterval;
            _timeout         = timeout;
            _args            = args;

            frame.WaitTasks.Add(this);
            _taskCompletion = new TaskCompletionSource <JSHandle>();

            _cts = new CancellationTokenSource();

            _timeoutTimer = System.Threading.Tasks.Task.Delay(timeout, _cts.Token).ContinueWith(_
                                                                                                => Termiante(new PuppeteerException($"waiting failed: timeout {timeout}ms exceeded")));

            Rerun();
        }
Example #2
0
        internal WaitTask(
            DOMWorld world,
            string predicateBody,
            bool isExpression,
            string title,
            WaitForFunctionPollingOption polling,
            int?pollingInterval,
            int timeout,
            object[] args = null)
        {
            if (string.IsNullOrEmpty(predicateBody))
            {
                throw new ArgumentNullException(nameof(predicateBody));
            }
            if (pollingInterval <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pollingInterval), "Cannot poll with non-positive interval");
            }

            _world           = world;
            _predicateBody   = isExpression ? $"return ({predicateBody})" : $"return ({predicateBody})(...args)";
            _polling         = polling;
            _pollingInterval = pollingInterval;
            _timeout         = timeout;
            _args            = args ?? Array.Empty <object>();
            _title           = title;

            _cts = new CancellationTokenSource();

            _taskCompletion = new TaskCompletionSource <JSHandle>(TaskCreationOptions.RunContinuationsAsynchronously);

            _world.WaitTasks.Add(this);

            if (timeout > 0)
            {
                _timeoutTimer = System.Threading.Tasks.Task.Delay(timeout, _cts.Token)
                                .ContinueWith(
                    _ => Terminate(new WaitTaskTimeoutException(timeout, title)),
                    TaskScheduler.Default);
            }

            _ = Rerun();
        }
Example #3
0
        internal WaitTask(
            Frame frame,
            string predicateBody,
            bool isExpression,
            string title,
            WaitForFunctionPollingOption polling,
            int?pollingInterval,
            int timeout,
            object[] args = null)
        {
            if (string.IsNullOrEmpty(predicateBody))
            {
                throw new ArgumentNullException(nameof(predicateBody));
            }
            if (pollingInterval <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pollingInterval), "Cannot poll with non-positive interval");
            }

            _frame           = frame;
            _predicateBody   = isExpression ? $"return {predicateBody}" : $"return ( {predicateBody} )(...args)";
            _polling         = polling;
            _pollingInterval = pollingInterval;
            _timeout         = timeout;
            _args            = args ?? new object[] { };
            _title           = title;

            frame.WaitTasks.Add(this);
            _taskCompletion = new TaskCompletionSource <JSHandle>();

            _cts = new CancellationTokenSource();

            if (timeout > 0)
            {
                _timeoutTimer = System.Threading.Tasks.Task.Delay(timeout, _cts.Token).ContinueWith(_
                                                                                                    => Termiante(new WaitTaskTimeoutException(timeout, title)));
            }

            Rerun();
        }