How to use KillingState method of PuppeteerSharp.States.KillingState class

Best Puppeteer-sharp code snippet using PuppeteerSharp.States.KillingState.KillingState

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

KillingState.cs

Source: KillingState.cs Github

copy
1using System;
2using System.Threading.Tasks;
3
4namespace PuppeteerSharp.States
5{
6    internal class KillingState : State
7    {
8        public KillingState(StateManager stateManager) : base(stateManager)
9        {
10        }
11
12        public override async Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)
13        {
14            if (!StateManager.TryEnter(p, fromState, this))
15            {
16                // Delegate KillAsync to current state, because it has already changed since
17                // transition to this state was initiated.
18                await StateManager.CurrentState.KillAsync(p).ConfigureAwait(false);
19            }
20
21            try
22            {
23                if (!p.Process.HasExited)
24                {
25                    p.Process.Kill();
26                }
27            }
28            catch (InvalidOperationException)
29            {
30                // Ignore
31                return;
32            }
33
34            await WaitForExitAsync(p).ConfigureAwait(false);
35        }
36
37        public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => WaitForExitAsync(p);
38
39        public override Task KillAsync(LauncherBase p) => WaitForExitAsync(p);
40    }
41}
42
Full Screen

StartedState.cs

Source: StartedState.cs Github

copy
1using System;
2using System.Threading.Tasks;
3
4namespace PuppeteerSharp.States
5{
6    internal class StartedState : State
7    {
8        public StartedState(StateManager stateManager) : base(stateManager)
9        {
10        }
11
12        public override Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)
13        {
14            StateManager.TryEnter(p, fromState, this);
15            return Task.CompletedTask;
16        }
17
18        public override Task StartAsync(LauncherBase p) => Task.CompletedTask;
19
20        public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => new ExitingState(StateManager).EnterFromAsync(p, this, timeout);
21
22        public override Task KillAsync(LauncherBase p) => new KillingState(StateManager).EnterFromAsync(p, this);
23    }
24}
25
Full Screen

StateManager.cs

Source: StateManager.cs Github

copy
1using System;
2using System.Threading;
3
4namespace PuppeteerSharp.States
5{
6    internal class StateManager
7    {
8        private State _currentState;
9
10        public StateManager()
11        {
12            Initial = new InitialState(this);
13            Starting = new ChromiumStartingState(this);
14            Started = new StartedState(this);
15            Exiting = new ExitingState(this);
16            Killing = new KillingState(this);
17            Exited = new ExitedState(this);
18            Disposed = new DisposedState(this);
19            CurrentState = Initial;
20        }
21
22        public State CurrentState
23        {
24            get => _currentState;
25            set => _currentState = value;
26        }
27
28        internal State Initial { get; set; }
29
30        internal State Starting { get; set; }
31
32        internal StartedState Started { get; set; }
33
34        internal State Exiting { get; set; }
35
36        internal State Killing { get; set; }
37
38        internal ExitedState Exited { get; set; }
39
40        internal State Disposed { get; set; }
41
42        public bool TryEnter(LauncherBase p, State fromState, State toState)
43        {
44            if (Interlocked.CompareExchange(ref _currentState, toState, fromState) == fromState)
45            {
46                fromState.Leave(p);
47                return true;
48            }
49
50            return false;
51        }
52    }
53}
54
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in KillingState

Trigger KillingState code on LambdaTest Cloud Grid

Execute automation tests with KillingState on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)