Skip to content

Commit

Permalink
[dotnet] Added TargetAttached datastructure to DevTools Target (Selen…
Browse files Browse the repository at this point in the history
…iumHQ#13175)

* Added TargetAttached to DevTools Target.

* Fixed wrong file name in license. Made setters on TargetAttachedEventArgs internal.

---------

Co-authored-by: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com>
  • Loading branch information
EdwinVanVliet and nvborisenko authored Nov 23, 2023
1 parent cd67d04 commit 7763c5b
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dotnet/src/webdriver/DevTools/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public abstract class Target
/// </summary>
public event EventHandler<TargetDetachedEventArgs> TargetDetached;

/// <summary>
/// Occurs when a target is attached.
/// </summary>
public event EventHandler<TargetAttachedEventArgs> TargetAttached;

/// <summary>
/// Asynchronously gets the targets available for this session.
/// </summary>
Expand Down Expand Up @@ -79,5 +84,17 @@ protected virtual void OnTargetDetached(TargetDetachedEventArgs e)
this.TargetDetached(this, e);
}
}

/// <summary>
/// Raises the TargetAttached event.
/// </summary>
/// <param name="e"></param>
protected virtual void OnTargetAttached(TargetAttachedEventArgs e)
{
if (this.TargetAttached != null)
{
this.TargetAttached(this, e);
}
}
}
}
41 changes: 41 additions & 0 deletions dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// <copyright file="TargetAttachedEventArgs.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Event arguments present when the TargetAttached event is raised.
/// </summary>
public class TargetAttachedEventArgs : EventArgs
{
/// <summary>
/// Gets the ID of the session of the target attached.
/// </summary>
public string SessionId { get; internal set; }
/// <summary>
/// Gets the target which is attached.
/// </summary>
public TargetInfo TargetInfo { get; internal set; }
/// <summary>
/// Gets if the target is waiting on the debugger. Target continues after invoking Runtime.runIfWaitingForDebugger.
/// </summary>
public bool WaitingForDebugger { get; internal set; }
}
}
20 changes: 20 additions & 0 deletions dotnet/src/webdriver/DevTools/v117/V117Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public V117Target(TargetAdapter adapter)
{
this.adapter = adapter;
adapter.DetachedFromTarget += OnDetachedFromTarget;
adapter.AttachedToTarget += OnAttachedToTarget;
}

/// <summary>
Expand Down Expand Up @@ -120,5 +121,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
{
this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId });
}

private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
{
this.OnTargetAttached(new TargetAttachedEventArgs()
{
SessionId = e.SessionId,
TargetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
},
WaitingForDebugger = e.WaitingForDebugger
});
}
}
}
20 changes: 20 additions & 0 deletions dotnet/src/webdriver/DevTools/v118/V118Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public V118Target(TargetAdapter adapter)
{
this.adapter = adapter;
adapter.DetachedFromTarget += OnDetachedFromTarget;
adapter.AttachedToTarget += OnAttachedToTarget;
}

/// <summary>
Expand Down Expand Up @@ -120,5 +121,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
{
this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId });
}

private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
{
this.OnTargetAttached(new TargetAttachedEventArgs()
{
SessionId = e.SessionId,
TargetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
},
WaitingForDebugger = e.WaitingForDebugger
});
}
}
}
20 changes: 20 additions & 0 deletions dotnet/src/webdriver/DevTools/v119/V119Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public V119Target(TargetAdapter adapter)
{
this.adapter = adapter;
adapter.DetachedFromTarget += OnDetachedFromTarget;
adapter.AttachedToTarget += OnAttachedToTarget;
}

/// <summary>
Expand Down Expand Up @@ -120,5 +121,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
{
this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId });
}

private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
{
this.OnTargetAttached(new TargetAttachedEventArgs()
{
SessionId = e.SessionId,
TargetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
},
WaitingForDebugger = e.WaitingForDebugger
});
}
}
}
20 changes: 20 additions & 0 deletions dotnet/src/webdriver/DevTools/v85/V85Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public V85Target(TargetAdapter adapter)
{
this.adapter = adapter;
adapter.DetachedFromTarget += OnDetachedFromTarget;
adapter.AttachedToTarget += OnAttachedToTarget;
}

/// <summary>
Expand Down Expand Up @@ -115,5 +116,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
{
this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId });
}

private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
{
this.OnTargetAttached(new TargetAttachedEventArgs()
{
SessionId = e.SessionId,
TargetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
},
WaitingForDebugger = e.WaitingForDebugger
});
}
}
}

0 comments on commit 7763c5b

Please sign in to comment.