Last active
September 25, 2019 15:01
-
-
Save YevgeniyShunevych/7709a3a5da9b997f25f4ee823899e662 to your computer and use it in GitHub Desktop.
WaitAndSwitchToNextWindowAttribute trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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