Run Playwright-dotnet automation tests on LambdaTest cloud grid
Perform automation testing on 3000+ real desktop and mobile devices online.
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Playwright.Core;
using Microsoft.Playwright.Helpers;
namespace Microsoft.Playwright.Transport.Channels
{
internal class JsonPipeChannel : Channel<JsonPipe>
{
public JsonPipeChannel(string guid, Connection connection, JsonPipe owner) : base(guid, connection, owner)
{
}
public event EventHandler<PlaywrightServerMessage> Message;
public event EventHandler<SerializedError> Closed;
internal override void OnMessage(string method, JsonElement? serverParams)
{
switch (method)
{
case "closed":
if (serverParams.Value.TryGetProperty("error", out var error))
{
Closed?.Invoke(this, error.ToObject<SerializedError>(Connection.DefaultJsonSerializerOptions));
}
else
{
Closed?.Invoke(this, null);
}
break;
case "message":
Message?.Invoke(this, serverParams?.GetProperty("message").ToObject<PlaywrightServerMessage>(Connection.DefaultJsonSerializerOptions));
break;
}
}
internal Task SendAsync(object message) =>
Connection.SendMessageToServerAsync(Guid, "send", new Dictionary<string, object>
{
{ "message", message },
});
internal Task CloseAsync() =>
Connection.SendMessageToServerAsync(Guid, "close");
}
}
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Threading.Tasks;
using Microsoft.Playwright.Transport;
using Microsoft.Playwright.Transport.Channels;
using Microsoft.Playwright.Transport.Protocol;
namespace Microsoft.Playwright.Core
{
internal class JsonPipe : ChannelOwnerBase, IChannelOwner<JsonPipe>
{
private readonly JsonPipeChannel _channel;
private readonly JsonPipeInitializer _initializer;
public JsonPipe(IChannelOwner parent, string guid, JsonPipeInitializer initializer) : base(parent, guid)
{
_channel = new(guid, parent.Connection, this);
_initializer = initializer;
_channel.Closed += (_, e) => Closed.Invoke(this, e);
_channel.Message += (_, e) => Message.Invoke(this, e);
}
public event EventHandler<PlaywrightServerMessage> Message;
public event EventHandler<SerializedError> Closed;
ChannelBase IChannelOwner.Channel => _channel;
IChannel<JsonPipe> IChannelOwner<JsonPipe>.Channel => _channel;
public Task CloseAsync() => _channel.CloseAsync();
public Task SendAsync(object message) => _channel.SendAsync(message);
}
}
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Microsoft.Playwright.Transport.Channels
{
internal class SerializedError
{
private string _message;
/// <summary>
/// Error name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Error Message.
/// </summary>
public string Message
{
get => _message ?? Value;
set => _message = value;
}
/// <summary>
/// Error Value.
/// </summary>
public string Value { get; set; }
/// <summary>
/// Error stack.
/// </summary>
public string Stack { get; set; }
public override string ToString()
{
if (!string.IsNullOrEmpty(Stack))
{
return $"{Stack}";
}
return $"{Name}: {Message}";
}
}
}
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.