Skip to content

Commit ebd298a

Browse files
Merge pull request #270 from q2ebanking/update-switching-to-frames
Update Switching to Frames
2 parents 7954b87 + 85b9594 commit ebd298a

File tree

3 files changed

+64
-22
lines changed

3 files changed

+64
-22
lines changed

Boa.Constrictor.Selenium/Boa.Constrictor.Selenium.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5-
<Version>4.0.0</Version>
5+
<Version>4.1.0</Version>
66
<Authors>Pandy Knight and the PrecisionLender SETs</Authors>
77
<Company>Q2</Company>
88
<Title>Boa.Constrictor.Selenium</Title>
99
<Product>Boa.Constrictor.Selenium</Product>
1010
<Description>Boa Constrictor is the .NET Screenplay Pattern! This package is the Selenium WebDriver interaction library.</Description>
11-
<Copyright>Copyright © 2020-2023 Q2 Holdings Inc.</Copyright>
11+
<Copyright>Copyright © 2020-2024 Q2 Holdings Inc.</Copyright>
1212
<RepositoryUrl>https://github.com/q2ebanking/boa-constrictor</RepositoryUrl>
1313
<RepositoryType>git</RepositoryType>
1414
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

Boa.Constrictor.Selenium/CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
(none)
2121

2222

23+
## [4.1.0] - 2024-01-29
24+
25+
### Added
26+
- Added `SwitchFrames` property to control switching to DefaultContent first
27+
- Added functionality to switch into nested frames in `SwitchFrames`
28+
29+
### Changed
30+
- `SwitchFrames` `Locator` property is now a list
31+
32+
2333
## [4.0.0] - 2023-05-29
2434

2535
### Added
2636

2737
- Added `SwitchFrame` Task with automatic waiting
28-
- Addd commented code for a potential `PerformInFrame` Task
38+
- Add commented code for a potential `PerformInFrame` Task
2939
- This one is currently exhibiting flaky errors
3040
- We must investigate further before releasing it officially
3141

Boa.Constrictor.Selenium/Tasks/SwitchFrame.cs

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using System;
2-
using Boa.Constrictor.Screenplay;
1+
using Boa.Constrictor.Screenplay;
32
using OpenQA.Selenium;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
46

57
namespace Boa.Constrictor.Selenium
68
{
79
/// <summary>
810
/// Switches the frame.
11+
/// Start from DefaultContent by default.
912
/// </summary>
1013
public class SwitchFrame : AbstractWebTask
1114
{
@@ -15,11 +18,12 @@ public class SwitchFrame : AbstractWebTask
1518
/// Private constructor.
1619
/// (Use static builder methods to construct.)
1720
/// </summary>
18-
/// <param name="locator">The locator.</param>
19-
/// <param name="useDefaultContent">If true use DefaultContent instead of the locator.</param>
20-
private SwitchFrame(IWebLocator locator, bool useDefaultContent)
21+
/// <param name="locators">The list of locators.</param>
22+
/// <param name="useDefaultContent">If true use DefaultContent instead of the locators.</param>
23+
private SwitchFrame(List<IWebLocator> locators, bool useDefaultContent)
2124
{
22-
Locator = locator;
25+
Locators = locators;
26+
StartFromCurrentLocation = false;
2327
UseDefaultContent = useDefaultContent;
2428
}
2529

@@ -28,12 +32,17 @@ private SwitchFrame(IWebLocator locator, bool useDefaultContent)
2832
#region Properties
2933

3034
/// <summary>
31-
/// The target Web element's locator.
35+
/// The list of target Web element locators.
36+
/// </summary>
37+
public List<IWebLocator> Locators { get; }
38+
39+
/// <summary>
40+
/// Start from current location instead of switching to DefaultContent first.
3241
/// </summary>
33-
public IWebLocator Locator { get; }
42+
public bool StartFromCurrentLocation { get; set; }
3443

3544
/// <summary>
36-
/// The DefaultContent is used.
45+
/// Switch to DefaultContent instead of a target frame.
3746
/// </summary>
3847
public bool UseDefaultContent { get; }
3948

@@ -46,13 +55,31 @@ private SwitchFrame(IWebLocator locator, bool useDefaultContent)
4655
/// </summary>
4756
/// <param name="locator">The locator.</param>
4857
/// <returns></returns>
49-
public static SwitchFrame To(IWebLocator locator) => new SwitchFrame(locator, false);
58+
public static SwitchFrame To(IWebLocator locator) =>
59+
new SwitchFrame(new List<IWebLocator> { locator }, false);
5060

5161
/// <summary>
5262
/// Constructs the Task object for DefaultContent.
5363
/// </summary>
5464
/// <returns></returns>
55-
public static SwitchFrame ToDefaultContent() => new SwitchFrame(null, true);
65+
public static SwitchFrame ToDefaultContent() => new SwitchFrame(new List<IWebLocator>(), true);
66+
67+
/// <summary>
68+
/// Constructs the Task object for the given locator list.
69+
/// </summary>
70+
/// <param name="locators">The list of locators.</param>
71+
/// <returns></returns>
72+
public static SwitchFrame ToNested(List<IWebLocator> locators) => new SwitchFrame(locators, false);
73+
74+
/// <summary>
75+
/// Sets the Task to start from current location instead of DefaultContent.
76+
/// </summary>
77+
/// <returns></returns>
78+
public SwitchFrame AndStartFromCurrentLocation()
79+
{
80+
StartFromCurrentLocation = true;
81+
return this;
82+
}
5683

5784
#endregion
5885

@@ -65,12 +92,16 @@ private SwitchFrame(IWebLocator locator, bool useDefaultContent)
6592
/// <param name="driver">The WebDriver.</param>
6693
public override void PerformAs(IActor actor, IWebDriver driver)
6794
{
68-
driver.SwitchTo().DefaultContent();
95+
if (UseDefaultContent || !StartFromCurrentLocation)
96+
driver.SwitchTo().DefaultContent();
6997

7098
if (!UseDefaultContent)
7199
{
72-
actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True());
73-
driver.SwitchTo().Frame(Locator.FindElement(driver));
100+
foreach (IWebLocator locator in Locators)
101+
{
102+
actor.WaitsUntil(Existence.Of(locator), IsEqualTo.True());
103+
driver.SwitchTo().Frame(locator.FindElement(driver));
104+
}
74105
}
75106
}
76107

@@ -80,24 +111,25 @@ public override void PerformAs(IActor actor, IWebDriver driver)
80111
/// <param name="obj">The other object.</param>
81112
public override bool Equals(object obj) =>
82113
obj is SwitchFrame frame &&
83-
Locator.Equals(frame.Locator) &&
114+
Locators.SequenceEqual(frame.Locators) &&
115+
StartFromCurrentLocation == frame.StartFromCurrentLocation &&
84116
UseDefaultContent == frame.UseDefaultContent;
85117

86118
/// <summary>
87119
/// Gets a unique hash code for this interaction.
88120
/// </summary>
89121
/// <returns></returns>
90122
public override int GetHashCode() =>
91-
HashCode.Combine(GetType(), Locator, UseDefaultContent);
123+
HashCode.Combine(GetType(), Locators, StartFromCurrentLocation, UseDefaultContent);
92124

93125
/// <summary>
94126
/// Returns a description of the Task.
95127
/// </summary>
96128
/// <returns></returns>
97-
public override string ToString() =>
98-
UseDefaultContent
129+
public override string ToString() =>
130+
UseDefaultContent
99131
? "switch frame to DefaultContent"
100-
: $"switch frame to '{Locator.Description}'";
132+
: $"switch frame to '{Locators.Last().Description}'";
101133

102134
#endregion
103135
}

0 commit comments

Comments
 (0)