Skip to content

Instantly share code, notes, and snippets.

@YevgeniyShunevych
Last active September 25, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YevgeniyShunevych/7709a3a5da9b997f25f4ee823899e662 to your computer and use it in GitHub Desktop.
Save YevgeniyShunevych/7709a3a5da9b997f25f4ee823899e662 to your computer and use it in GitHub Desktop.
WaitAndSwitchToNextWindowAttribute trigger
using System.Linq;
namespace Atata
{
public class WaitAndSwitchToNextWindowAttribute : TriggerAttribute
{
public WaitAndSwitchToNextWindowAttribute(TriggerEvents on = TriggerEvents.AfterClick, TriggerPriority priority = TriggerPriority.Medium)
: base(on, priority)
{
}
protected override void Execute<TOwner>(TriggerContext<TOwner> context)
{
context.Log.Start("Wait and switch to next window", LogLevel.Trace);
string currentWindowHandle = context.Driver.CurrentWindowHandle;
string switchToWindowHandle = context.Driver.Try().Until(
driver => driver.WindowHandles.SkipWhile(x => x != currentWindowHandle).Skip(1).FirstOrDefault(),
AtataContext.Current.WaitingTimeout,
AtataContext.Current.WaitingRetryInterval);
context.Driver.SwitchTo().Window(switchToWindowHandle);
context.Log.Trace($"Switched to \"{switchToWindowHandle}\" window");
context.Log.EndSection();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment