Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"BAUTH_LOGIN": "",
"BAUTH_PASSWORD": "",
"BAUTH_IGNORE": "true",
"BROWSER_BINARY_LOCATION" : ""
"BROWSER_BINARY_LOCATION" : "",
"UNHANDLED_PROMPT_BEHAVIOR" : ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Selenium.Support" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="Selenium.Support" Version="4.3.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.3.0" />
<PackageReference Include="SpecFlow" Version="3.9.69" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The whole automation code is divided into the following parts:
- UI structure descriptive code
- Supportive code</Description>
<Copyright>Quantori Inc.</Copyright>
<PackageVersion>1.13.0</PackageVersion>
<PackageVersion>1.14.0</PackageVersion>
<RepositoryUrl>https://github.com/quantori/Behavioral.Automation</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -36,8 +36,8 @@ The whole automation code is divided into the following parts:
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="Selenium.Support" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="Selenium.Support" Version="4.3.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.3.0" />
<PackageReference Include="SpecFlow" Version="3.9.69" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public void OpenChrome(ChromeOptions options = null)
{
options.BinaryLocation = Environment.ExpandEnvironmentVariables(ConfigServiceBase.BrowserBinaryLocation);
}
if (!string.IsNullOrWhiteSpace(ConfigServiceBase.UnhandledPromptBehavior))
{
options.UnhandledPromptBehavior = ConfigServiceBase.UnhandledPromptBehavior switch
{
"Accept" => UnhandledPromptBehavior.Accept,
"Dismiss" => UnhandledPromptBehavior.Dismiss,
"Ignore" => UnhandledPromptBehavior.Ignore,
_ => options.UnhandledPromptBehavior
};
}
}

var driver = new ChromeDriver(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public static class ConfigServiceBase
private const string AccessClipboardString = "ACCESS_CLIPBOARD";

private const string BrowserBinaryLocationString = "BROWSER_BINARY_LOCATION";

private const string UnhandledPromptBehaviorString = "UNHANDLED_PROMPT_BEHAVIOR";

public static string UnhandledPromptBehavior => ConfigRoot[UnhandledPromptBehaviorString];

public static string BaseUrl => ConfigRoot[BaseUrlString];

public static string BrowserParameters => ConfigRoot[BrowserParametersString];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ public void SwitchToTheFirstWindow()
var handle = Driver.WindowHandles.First();
Driver.SwitchTo().Window(handle);
}

/// <summary>
/// Close inactive windows
/// </summary>
public void CloseInactiveWindows()
{
var currentWindowHandle = Driver.CurrentWindowHandle;
var windowHandles = Driver.WindowHandles;

foreach (var windowHandle in windowHandles)
{
if (!windowHandle.Equals(currentWindowHandle))
{
Driver.SwitchTo().Window(windowHandle);
Driver.Close();
}
}

Driver.SwitchTo().Window(currentWindowHandle);
}

/// <summary>
/// Get URI from relative URL
Expand Down Expand Up @@ -229,23 +249,15 @@ public void Navigate(string url)
var uri = new Uri(url);
_scopeContextManager.SwitchPage(uri);
}

/// <summary>
/// Switch to the last opened window
/// </summary>
public void SwitchToLastWindow()
{
Driver.SwitchTo().Window(Driver.WindowHandles.Last());
}

/// <summary>
/// Change size of opened browser window
/// </summary>
/// <param name="Height">Desired height</param>
/// <param name="Width">Desired width</param>
public void ResizeWindow(int Height, int Width)
/// <param name="height">Desired height</param>
/// <param name="width">Desired width</param>
public void ResizeWindow(int height, int width)
{
Driver.Manage().Window.Size = new Size(Width, Height);
Driver.Manage().Window.Size = new Size(width, height);
}

/// <summary>
Expand Down Expand Up @@ -295,5 +307,11 @@ public string SaveBrowserLog()

return fileName;
}

public void ClearCache()
{
Driver.Manage().Cookies.DeleteAllCookies();
ExecuteScript("javascript: localStorage.clear()");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.ObjectModel;
using JetBrains.Annotations;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace Behavioral.Automation.Services
{
Expand Down Expand Up @@ -114,9 +113,9 @@ public interface IDriverService
/// <summary>
/// Change size of opened browser window
/// </summary>
/// <param name="Height">Desired height</param>
/// <param name="Width">Desired width</param>
void ResizeWindow(int Height, int Width);
/// <param name="height">Desired height</param>
/// <param name="width">Desired width</param>
void ResizeWindow(int height, int width);

/// <summary>
/// Make screenshot
Expand All @@ -136,5 +135,15 @@ public interface IDriverService
/// </summary>
/// <returns>Path to saved log</returns>
string SaveBrowserLog();

/// <summary>
/// Clears browser cache
/// </summary>
void ClearCache();

/// <summary>
/// Close inactive windows
/// </summary>
public void CloseInactiveWindows();
}
}
6 changes: 4 additions & 2 deletions Behavioral.Automation.Selenium/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[1.13.0] - 2022-06-03
[1.14.0] - 2022-07-27
### Added
- Changed folder structure to separate Selenium and Playwright versions of the framework
- Added method to clear browser data
- Added method to close inactive windows
- Small fixes