How to use PreviewUpdatedEventArgs class of Microsoft.Playwright.Transport.Channels package

Best Playwright-dotnet code snippet using Microsoft.Playwright.Transport.Channels.PreviewUpdatedEventArgs

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

PreviewUpdatedEventArgs.cs

Source: PreviewUpdatedEventArgs.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) Microsoft Corporation.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25using System;
26
27namespace Microsoft.Playwright.Transport.Channels
28{
29    internal class PreviewUpdatedEventArgs : EventArgs
30    {
31        public string Preview { get; set; }
32    }
33}
34
Full Screen

ElementHandleChannel.cs

Source: ElementHandleChannel.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) 2020 Darío Kondratiuk
5 * Modifications copyright (c) Microsoft Corporation.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25using System;
26using System.Collections.Generic;
27using System.Linq;
28using System.Text.Json;
29using System.Threading.Tasks;
30using Microsoft.Playwright.Core;
31using Microsoft.Playwright.Helpers;
32using Microsoft.Playwright.Transport.Protocol;
33
34namespace Microsoft.Playwright.Transport.Channels
35{
36    internal class ElementHandleChannel : JSHandleChannel, IChannel<ElementHandle>
37    {
38        public ElementHandleChannel(string guid, Connection connection, ElementHandle owner) : base(guid, connection, owner)
39        {
40            Object = owner;
41        }
42
43        internal event EventHandler<PreviewUpdatedEventArgs> PreviewUpdated;
44
45        public new ElementHandle Object { get; set; }
46
47        internal override void OnMessage(string method, JsonElement? serverParams)
48        {
49            switch (method)
50            {
51                case "previewUpdated":
52                    PreviewUpdated?.Invoke(this, new() { Preview = serverParams.Value.GetProperty("preview").ToString() });
53                    break;
54            }
55        }
56
57        internal Task<ElementHandleChannel> WaitForSelectorAsync(string selector, WaitForSelectorState? state, float? timeout, bool? strict)
58        {
59            var args = new Dictionary<string, object>
60            {
61                ["selector"] = selector,
62                ["timeout"] = timeout,
63                ["state"] = state,
64                ["strict"] = strict,
65            };
66
67            return Connection.SendMessageToServerAsync<ElementHandleChannel>(
68                Guid,
69                "waitForSelector",
70                args);
71        }
72
73        internal Task<ElementHandleChannel> QuerySelectorAsync(string selector)
74            => Connection.SendMessageToServerAsync<ElementHandleChannel>(
75                Guid,
76                "querySelector",
77                new Dictionary<string, object>
78                {
79                    ["selector"] = selector,
80                });
81
82        internal Task WaitForElementStateAsync(ElementState state, float? timeout)
83        {
84            var args = new Dictionary<string, object>
85            {
86                ["state"] = state,
87                ["timeout"] = timeout,
88            };
89
90            return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "waitForElementState", args);
91        }
92
93        internal Task<ChannelBase[]> QuerySelectorAllAsync(string selector)
94            => Connection.SendMessageToServerAsync<ChannelBase[]>(
95                Guid,
96                "querySelectorAll",
97                new Dictionary<string, object>
98                {
99                    ["selector"] = selector,
100                });
101
102        internal async Task<byte[]> ScreenshotAsync(string path, bool? omitBackground, ScreenshotType? type, int? quality, IEnumerable<ILocator> mask, ScreenshotAnimations? animations, ScreenshotCaret? caret, ScreenshotScale? scale, float? timeout)
103        {
104            var args = new Dictionary<string, object>
105            {
106                ["type"] = type,
107                ["omitBackground"] = omitBackground,
108                ["path"] = path,
109                ["timeout"] = timeout,
110                ["animations"] = animations,
111                ["caret"] = caret,
112                ["scale"] = scale,
113                ["quality"] = quality,
114            };
115            if (mask != null)
116            {
117                args["mask"] = mask.Select(locator => new Dictionary<string, object>
118                {
119                    ["frame"] = ((Locator)locator)._frame._channel,
120                    ["selector"] = ((Locator)locator)._selector,
121                }).ToArray();
122            }
123
124            return (await Connection.SendMessageToServerAsync(Guid, "screenshot", args).ConfigureAwait(false))?.GetProperty("binary").GetBytesFromBase64();
125        }
126
127        internal Task<JsonElement?> EvalOnSelectorAsync(string selector, string script, object arg)
128            => Connection.SendMessageToServerAsync<JsonElement?>(
129                Guid,
130                "evalOnSelector",
131                new Dictionary<string, object>
132                {
133                    ["selector"] = selector,
134                    ["expression"] = script,
135                    ["arg"] = arg,
136                });
137
138        internal Task<JsonElement?> EvalOnSelectorAllAsync(string selector, string script, object arg)
139            => Connection.SendMessageToServerAsync<JsonElement?>(
140                Guid,
141                "evalOnSelectorAll",
142                new Dictionary<string, object>
143                {
144                    ["selector"] = selector,
145                    ["expression"] = script,
146                    ["arg"] = arg,
147                });
148
149        internal Task<FrameChannel> ContentFrameAsync() => Connection.SendMessageToServerAsync<FrameChannel>(Guid, "contentFrame", null);
150
151        internal Task<FrameChannel> OwnerFrameAsync() => Connection.SendMessageToServerAsync<FrameChannel>(Guid, "ownerFrame", null);
152
153        internal Task HoverAsync(
154            IEnumerable<KeyboardModifier> modifiers,
155            Position position,
156            float? timeout,
157            bool? force,
158            bool? trial)
159        {
160            var args = new Dictionary<string, object>
161            {
162                ["force"] = force,
163                ["position"] = position,
164                ["timeout"] = timeout,
165                ["trial"] = trial,
166                ["modifiers"] = modifiers?.Select(m => m.ToValueString()),
167            };
168
169            return Connection.SendMessageToServerAsync<JsonElement?>(Guid, "hover", args);
170        }
171
172        internal Task FocusAsync() => Connection.SendMessageToServerAsync(Guid, "focus", null);
173
174        internal Task ClickAsync(
175            float? delay,
176            MouseButton? button,
177            int? clickCount,
178            IEnumerable<KeyboardModifier> modifiers,
179            Position position,
180            float? timeout,
181            bool? force,
182            bool? noWaitAfter,
183            bool? trial)
184        {
185            var args = new Dictionary<string, object>
186            {
187                ["delay"] = delay,
188                ["button"] = button,
189                ["clickCount"] = clickCount,
190                ["force"] = force,
191                ["noWaitAfter"] = noWaitAfter,
192                ["timeout"] = timeout,
193                ["trial"] = trial,
194                ["position"] = position,
195                ["modifiers"] = modifiers?.Select(m => m.ToValueString()),
196            };
197
198            return Connection.SendMessageToServerAsync(Guid, "click", args);
199        }
200
201        internal Task DblClickAsync(
202            float? delay,
203            MouseButton? button,
204            IEnumerable<KeyboardModifier> modifiers,
205            Position position,
206            float? timeout,
207            bool? force,
208            bool? noWaitAfter,
209            bool? trial)
210        {
211            var args = new Dictionary<string, object>
212            {
213                ["delay"] = delay,
214                ["button"] = button,
215                ["force"] = force,
216                ["noWaitAfter"] = noWaitAfter,
217                ["timeout"] = timeout,
218                ["trial"] = trial,
219                ["position"] = position,
220                ["modifiers"] = modifiers?.Select(m => m.ToValueString()),
221            };
222
223            return Connection.SendMessageToServerAsync(Guid, "dblclick", args);
224        }
225
226        internal async Task<ElementHandleBoundingBoxResult> BoundingBoxAsync()
227        {
228            var result = (await Connection.SendMessageToServerAsync(Guid, "boundingBox", null).ConfigureAwait(false)).Value;
229
230            if (result.TryGetProperty("value", out var value))
231            {
232                return value.ToObject<ElementHandleBoundingBoxResult>();
233            }
234
235            return null;
236        }
237
238        internal Task ScrollIntoViewIfNeededAsync(float? timeout)
239        {
240            var args = new Dictionary<string, object>
241            {
242                ["timeout"] = timeout,
243            };
244
245            return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "scrollIntoViewIfNeeded", args);
246        }
247
248        internal Task FillAsync(string value, bool? noWaitAfter, bool? force, float? timeout)
249        {
250            var args = new Dictionary<string, object>
251            {
252                ["value"] = value,
253                ["timeout"] = timeout,
254                ["force"] = force,
255                ["noWaitAfter"] = noWaitAfter,
256            };
257
258            return Connection.SendMessageToServerAsync(Guid, "fill", args);
259        }
260
261        internal Task DispatchEventAsync(string type, object eventInit)
262        {
263            var args = new Dictionary<string, object>
264            {
265                ["type"] = type,
266                ["eventInit"] = eventInit,
267            };
268
269            return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "dispatchEvent", args);
270        }
271
272        internal Task SetInputFilesAsync(IEnumerable<InputFilesList> files, bool? noWaitAfter, float? timeout)
273        {
274            var args = new Dictionary<string, object>
275            {
276                ["files"] = files,
277                ["timeout"] = timeout,
278                ["noWaitAfter"] = noWaitAfter,
279            };
280
281            return Connection.SendMessageToServerAsync(Guid, "setInputFiles", args);
282        }
283
284        internal Task SetInputFilePathsAsync(IEnumerable<string> localPaths, IEnumerable<WritableStream> streams, bool? noWaitAfter, float? timeout)
285        {
286            var args = new Dictionary<string, object>
287            {
288                ["localPaths"] = localPaths,
289                ["streams"] = streams,
290                ["timeout"] = timeout,
291                ["noWaitAfter"] = noWaitAfter,
292            };
293
294            return Connection.SendMessageToServerAsync(Guid, "setInputFilePaths", args);
295        }
296
297        internal async Task<string> GetAttributeAsync(string name)
298        {
299            var args = new Dictionary<string, object>
300            {
301                ["name"] = name,
302            };
303
304            return (await Connection.SendMessageToServerAsync(Guid, "getAttribute", args).ConfigureAwait(false))?.GetProperty("value").ToString();
305        }
306
307        internal async Task<string> InnerHTMLAsync()
308            => (await Connection.SendMessageToServerAsync(Guid, "innerHTML").ConfigureAwait(false))?.GetProperty("value").ToString();
309
310        internal async Task<string> InnerTextAsync()
311            => (await Connection.SendMessageToServerAsync(Guid, "innerText").ConfigureAwait(false))?.GetProperty("value").ToString();
312
313        internal async Task<string> TextContentAsync()
314            => (await Connection.SendMessageToServerAsync(Guid, "textContent").ConfigureAwait(false))?.GetProperty("value").ToString();
315
316        internal Task SelectTextAsync(bool? force = null, float? timeout = null)
317        {
318            var args = new Dictionary<string, object>
319            {
320                ["force"] = force,
321                ["timeout"] = timeout,
322            };
323
324            return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "selectText", args);
325        }
326
327        internal async Task<IReadOnlyList<string>> SelectOptionAsync(object values, bool? noWaitAfter = null, bool? force = null, float? timeout = null)
328        {
329            var args = new Dictionary<string, object>();
330
331            if (values is IElementHandle[])
332            {
333                args["elements"] = values;
334            }
335            else
336            {
337                args["options"] = values;
338            }
339
340            args["force"] = force;
341            args["timeout"] = timeout;
342            args["noWaitAfter"] = noWaitAfter;
343
344            return (await Connection.SendMessageToServerAsync(Guid, "selectOption", args).ConfigureAwait(false))?.GetProperty("values").ToObject<List<string>>().AsReadOnly();
345        }
346
347        internal async Task<bool> IsVisibleAsync()
348            => (await Connection.SendMessageToServerAsync(Guid, "isVisible", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;
349
350        internal async Task<bool> IsHiddenAsync()
351            => (await Connection.SendMessageToServerAsync(Guid, "isHidden", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;
352
353        internal async Task<bool> IsEnabledAsync()
354            => (await Connection.SendMessageToServerAsync(Guid, "isEnabled", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;
355
356        internal async Task<bool> IsEditableAsync()
357            => (await Connection.SendMessageToServerAsync(Guid, "isEditable", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;
358
359        internal async Task<bool> IsDisabledAsync()
360            => (await Connection.SendMessageToServerAsync(Guid, "isDisabled", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;
361
362        internal async Task<string> InputValueAsync(float? timeout)
363        {
364            var args = new Dictionary<string, object>()
365            {
366                { "timeout", timeout },
367            };
368
369            return (await Connection.SendMessageToServerAsync(Guid, "inputValue", args).ConfigureAwait(false))?.GetProperty("value").GetString();
370        }
371
372        internal async Task<bool> IsCheckedAsync()
373            => (await Connection.SendMessageToServerAsync(Guid, "isChecked", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;
374
375        internal Task CheckAsync(Position position, float? timeout, bool? force, bool? noWaitAfter, bool? trial)
376        {
377            var args = new Dictionary<string, object>
378            {
379                ["force"] = force,
380                ["position"] = position,
381                ["trial"] = trial,
382                ["timeout"] = timeout,
383                ["noWaitAfter"] = noWaitAfter,
384            };
385
386            return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "check", args);
387        }
388
389        internal Task UncheckAsync(Position position, float? timeout, bool? force, bool? noWaitAfter, bool? trial)
390        {
391            var args = new Dictionary<string, object>
392            {
393                ["force"] = force,
394                ["position"] = position,
395                ["trial"] = trial,
396                ["timeout"] = timeout,
397                ["noWaitAfter"] = noWaitAfter,
398            };
399
400            return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "uncheck", args);
401        }
402
403        internal Task TypeAsync(string text, float? delay, float? timeout, bool? noWaitAfter)
404        {
405            var args = new Dictionary<string, object>
406            {
407                ["text"] = text,
408                ["delay"] = delay,
409                ["timeout"] = timeout,
410                ["noWaitAfter"] = noWaitAfter,
411            };
412
413            return Connection.SendMessageToServerAsync(Guid, "type", args);
414        }
415
416        internal Task PressAsync(string key, float? delay, float? timeout, bool? noWaitAfter)
417        {
418            var args = new Dictionary<string, object>
419            {
420                ["key"] = key,
421                ["delay"] = delay,
422                ["timeout"] = timeout,
423                ["noWaitAfter"] = noWaitAfter,
424            };
425
426            return Connection.SendMessageToServerAsync(Guid, "press", args);
427        }
428
429        internal Task TapAsync(
430            Position position,
431            IEnumerable<KeyboardModifier> modifiers,
432            float? timeout,
433            bool? force,
434            bool? noWaitAfter,
435            bool? trial)
436        {
437            var args = new Dictionary<string, object>
438            {
439                ["force"] = force,
440                ["noWaitAfter"] = noWaitAfter,
441                ["position"] = position,
442                ["modifiers"] = modifiers?.Select(m => m.ToValueString()),
443                ["trial"] = trial,
444                ["timeout"] = timeout,
445            };
446
447            return Connection.SendMessageToServerAsync(Guid, "tap", args);
448        }
449    }
450}
451
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 methods in PreviewUpdatedEventArgs

    No methods found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)