-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bypass login with browser profiles (#87)
Improves performance by allowing the use of Chrome and Firefox profiles for test users. +semver: minor
- Loading branch information
Showing
16 changed files
with
411 additions
and
40 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
...rc/Capgemini.PowerApps.SpecFlowBindings/Configuration/BrowserOptionsWithProfileSupport.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
namespace Capgemini.PowerApps.SpecFlowBindings.Configuration | ||
{ | ||
using System; | ||
using System.IO; | ||
using Microsoft.Dynamics365.UIAutomation.Browser; | ||
using OpenQA.Selenium.Chrome; | ||
using OpenQA.Selenium.Firefox; | ||
|
||
/// <summary> | ||
/// Extends the EasyRepro <see cref="BrowserOptions"/> class with additonal support for chrome profiles. | ||
/// </summary> | ||
public class BrowserOptionsWithProfileSupport : BrowserOptions, ICloneable | ||
{ | ||
/// <summary> | ||
/// Gets or sets the directory to use as the user profile. | ||
/// </summary> | ||
public string ProfileDirectory { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public object Clone() | ||
{ | ||
return this.MemberwiseClone(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override ChromeOptions ToChrome() | ||
{ | ||
var options = base.ToChrome(); | ||
|
||
if (!string.IsNullOrEmpty(this.ProfileDirectory)) | ||
{ | ||
options.AddArgument($"--user-data-dir={this.ProfileDirectory}"); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override FirefoxOptions ToFireFox() | ||
{ | ||
var options = base.ToFireFox(); | ||
|
||
if (!string.IsNullOrEmpty(this.ProfileDirectory)) | ||
{ | ||
this.ProfileDirectory = this.ProfileDirectory.EndsWith("firefox") ? this.ProfileDirectory : Path.Combine(this.ProfileDirectory, "firefox"); | ||
options.AddArgument($"-profile \"{this.ProfileDirectory}\""); | ||
} | ||
|
||
return options; | ||
} | ||
} | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
bindings/src/Capgemini.PowerApps.SpecFlowBindings/Extensions/BrowserTypeExtensions.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Capgemini.PowerApps.SpecFlowBindings.Extensions | ||
{ | ||
using Microsoft.Dynamics365.UIAutomation.Browser; | ||
|
||
/// <summary> | ||
/// Provides extension methods on <see cref="BrowserType"/>. | ||
/// </summary> | ||
public static class BrowserTypeExtensions | ||
{ | ||
/// <summary> | ||
/// Determines if the given browser type supports profiles. | ||
/// </summary> | ||
/// <param name="type">The <see cref="BrowserType"/> to check.</param> | ||
/// <returns>true if the browser supports profiles otherwise false.</returns> | ||
public static bool SupportsProfiles(this BrowserType type) | ||
{ | ||
switch (type) | ||
{ | ||
case BrowserType.IE: | ||
return false; | ||
case BrowserType.Chrome: | ||
return true; | ||
case BrowserType.Firefox: | ||
return true; | ||
case BrowserType.Edge: | ||
return false; | ||
case BrowserType.Remote: | ||
return false; | ||
default: | ||
return false; | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bindings/src/Capgemini.PowerApps.SpecFlowBindings/Extensions/DirectoryInfoExtensions.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Capgemini.PowerApps.SpecFlowBindings.Extensions | ||
{ | ||
using System.IO; | ||
|
||
/// <summary> | ||
/// Extensions to the <see cref="DirectoryInfo"/> class. | ||
/// </summary> | ||
public static class DirectoryInfoExtensions | ||
{ | ||
/// <summary> | ||
/// Copies the directory recursively to the target directory. | ||
/// </summary> | ||
/// <param name="source">The source directory.</param> | ||
/// <param name="target">The target directory.</param> | ||
public static void CopyTo(this DirectoryInfo source, DirectoryInfo target) | ||
{ | ||
Directory.CreateDirectory(target.FullName); | ||
|
||
foreach (var fileInfo in source.GetFiles()) | ||
{ | ||
fileInfo.CopyTo(Path.Combine(target.FullName, fileInfo.Name), true); | ||
} | ||
|
||
foreach (var subdirectory in source.GetDirectories()) | ||
{ | ||
subdirectory.CopyTo(target.CreateSubdirectory(subdirectory.Name)); | ||
} | ||
} | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
bindings/src/Capgemini.PowerApps.SpecFlowBindings/Hooks/BeforeRunHooks.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Capgemini.PowerApps.SpecFlowBindings.Hooks | ||
{ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Capgemini.PowerApps.SpecFlowBindings.Configuration; | ||
using Capgemini.PowerApps.SpecFlowBindings.Steps; | ||
using Microsoft.Dynamics365.UIAutomation.Api.UCI; | ||
using Microsoft.Dynamics365.UIAutomation.Browser; | ||
using TechTalk.SpecFlow; | ||
|
||
/// <summary> | ||
/// Hooks that run before the start of each run. | ||
/// </summary> | ||
[Binding] | ||
public class BeforeRunHooks : PowerAppsStepDefiner | ||
{ | ||
/// <summary> | ||
/// Creates a new folder for the scenario and copies the session/cookies information from previous runs. | ||
/// </summary> | ||
[BeforeTestRun] | ||
public static void BaseProfileSetup() | ||
{ | ||
if (!TestConfig.UseProfiles) | ||
{ | ||
return; | ||
} | ||
|
||
Parallel.ForEach(UserProfileDirectories.Keys, (username) => | ||
{ | ||
var profileDirectory = UserProfileDirectories[username]; | ||
var baseDirectory = Path.Combine(profileDirectory, "base"); | ||
|
||
Directory.CreateDirectory(baseDirectory); | ||
|
||
var userBrowserOptions = (BrowserOptionsWithProfileSupport)TestConfig.BrowserOptions.Clone(); | ||
userBrowserOptions.ProfileDirectory = baseDirectory; | ||
userBrowserOptions.Headless = true; | ||
|
||
var webClient = new WebClient(userBrowserOptions); | ||
using (new XrmApp(webClient)) | ||
{ | ||
var user = TestConfig.Users.First(u => u.Username == username); | ||
LoginSteps.Login(webClient.Browser.Driver, TestConfig.GetTestUrl(), user.Username, user.Password); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.