Skip to content

Commit

Permalink
Merge pull request #5 from RohitM-IN/dev
Browse files Browse the repository at this point in the history
Update to 4th alpha
  • Loading branch information
RohitM-IN authored Aug 6, 2023
2 parents d3cdadc + 2a3248c commit 5fef3c1
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 28 deletions.
2 changes: 1 addition & 1 deletion SeleniumManager.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static void Main(string[] args)
{
string jarName = "selenium-server-4.9.1.jar"; // Name of your JAR file
string jarPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), jarName); // Path to your JAR file
string arguments = $" -jar {jarPath} standalone ";//--driver-implementation \"Chrome\"";
string arguments = $@" -jar {jarPath} standalone ";// --config D:\dev\C#\SeleniumManager\SeleniumManager.ConsoleApp\myconfig.toml";//--driver-implementation \"Chrome\"";
ProcessStartInfo psi = new ProcessStartInfo("java", arguments);
psi.CreateNoWindow = false; // Hide the console window
psi.UseShellExecute = false; // Do not use the operating system shell to start the process
Expand Down
17 changes: 17 additions & 0 deletions SeleniumManager.Core/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ namespace SeleniumManager.Core
{
public class ConfigManager
{
#region Declaration

public readonly ConfigurationSettings configSettings;

#endregion

#region Public Functions

/// <summary>
/// This function sets the config required for the Selenium Manager
/// </summary>
/// <param name="configFilePath"></param>
public ConfigManager(string? configFilePath = null)
{
if (string.IsNullOrEmpty(configFilePath))
Expand All @@ -28,6 +38,10 @@ public ConfigManager(string? configFilePath = null)
}
}

#endregion

#region Private Functions

private ConfigurationSettings LoadConfigSettingsFromResource(string resourceName)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Expand Down Expand Up @@ -68,5 +82,8 @@ private ConfigurationSettings LoadConfigSettingsFromFile(string configFilePath)
return LoadConfigSettingsFromResource("SeleniumManager.Core.Configuration.config.json");
}
}

#endregion

}
}
5 changes: 3 additions & 2 deletions SeleniumManager.Core/DataContract/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Options
public EdgeOptions edgeOptions { get; set; } = GetEdgeOptions();
public InternetExplorerOptions internetExplorerOptions { get; set; } = GetInternetExplorerOptions();
public SafariOptions safariOptions { get; set; } = GetSafariOptions();
public ChromeOptions operaOptions { get; set; } = GetChromeOptions();

public static ChromeOptions GetChromeOptions()
{
Expand All @@ -39,8 +40,8 @@ public static FirefoxOptions GetFirefoxOptions()
#if !DEBUG
firefoxOptions.AddArgument("headless");
#endif
firefoxOptions.AddArgument("disable-gpu");
firefoxOptions.AddArgument("no-sandbox");
//firefoxOptions.AddArgument("disable-gpu");
//firefoxOptions.AddArgument("no-sandbox");
firefoxOptions.AddArgument("--blink-settings=imagesEnabled=false");
return firefoxOptions;
}
Expand Down
17 changes: 17 additions & 0 deletions SeleniumManager.Core/Enum/AdjustType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SeleniumManager.Core.Enum
{
/// <summary>
/// Tells the selenium manager to Create or destroy a instance
/// </summary>
public enum AdjustType
{
Create = 1,
Destroy = 2
}
}
28 changes: 28 additions & 0 deletions SeleniumManager.Core/Enum/WebDriverType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SeleniumManager.Core.Enum
{
public enum WebDriverType
{
None = 0,
[Description("Chrome")]
Chrome = 1,
[Description("Microsoft Edge")]
Microsoft_Edge = 2,
[Description("Firefox")]
Firefox = 3,
[Description("Safari")]
Safari = 4,
[Description("InternetExplorer")]
InternetExplorer = 5,
[Description("Opera")]
Opera = 6,
[Description("Custom")]
Custom = 7,
}
}
117 changes: 117 additions & 0 deletions SeleniumManager.Core/Interface/ISeleniumManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenQA.Selenium;
using SeleniumManager.Core.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -9,6 +10,122 @@ namespace SeleniumManager.Core.Interface
{
public interface ISeleniumManager
{
#region Properties
/// <summary>
/// Gets Max Session available
/// </summary>
int MaxSessions { get; }

/// <summary>
/// Gets Free Session available
/// </summary>
int FreeSessions { get; }

/// <summary>
/// Gets total count of session available
/// </summary>
int TotalSessions { get; }

/// <summary>
/// Gets Total count of available sessions
/// </summary>
int AvailableSessions { get; }

/// <summary>
/// Gets Total count of concurrent sessions which are in use
/// </summary>
int ConcurrentSessions { get; }

/// <summary>
/// Gets When Last Hartbeat was taken.
/// </summary>
/// <value>the <c>string</c> represents <c>browser's name</c> and <c>long</c> represents the <c>count</c></value>
DateTime LastSessionDetails { get; }

/// <summary>
/// This dictionary has list of browsers with max count of instance available
/// </summary>
/// <value>the <c>string</c> represents <c>browser's name</c> and <c>long</c> represents the <c>count</c></value>
Dictionary<string, long> MaxStereotypes { get; }

/// <summary>
/// This dictionary has list of browsers with available instances.
/// </summary>
/// <value>the <c>string</c> represents <c>browser's name</c> and <c>long</c> represents the <c>count</c></value>
Dictionary<string, long> AvailableStereotypes { get; }

/// <summary>
/// This dictionary has list of browsers with parallel count of instance running
/// </summary>
/// <value>the <c>string</c> represents <c>browser's name</c> and <c>long</c> represents the <c>count</c></value>
Dictionary<string, long> ConcurrentStereotypes { get; }

#endregion

#region Methods

/// <summary>
/// This function will try to execute next in line of queue
/// </summary>
/// <exception cref="Exception"></exception>
void TryExecuteNext();

/// <summary>
/// This function returns complete data of the status available from grid
/// the endpoint is mostly example.com/status
/// </summary>
/// <returns>task of dynamic</returns>
Task<dynamic?> GetHeartBeat();

/// <summary>
/// This function returns number of available instance in a Task
/// </summary>
/// <returns>Task of int</returns>
Task<int> GetAvailableInstances();

/// <summary>
/// <para>
/// This overridable function returns the webdriver from the given browser name.
/// By default it will try to get best available browser from the configured statistics.
/// </para>
/// </summary>
/// <param name="browserName">Name of the browser</param>
/// <returns>IWebDriver</returns>
/// <exception cref="ArgumentException"></exception>
IWebDriver CreateDriverInstance(string? browserName);

/// <summary>
/// This Function Enqueues an function
/// in which has the first parameter supports IWebDriver
/// </summary>
/// <param name="action">Action</param>
/// <code>
/// manager = new SeleniumManager();
/// manager.EnqueueAction(SomeFunction);
/// string SomeFunction(IWebDriver driver) { }
/// </code>
/// <returns>TaskCompletionSource string</returns>
/// <exception cref="Exception"></exception>
Task<string> EnqueueAction(Func<IWebDriver, string> action);

/// <summary>
/// This function checks if the browser is available or not.
/// </summary>
/// <param name="browserName">Name of the browser</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
string GetAvailableDriverName(string? browserName);

/// <summary>
/// This Function override Enqueues an function
/// in which has the first parameter supports IWebDriver and the other is the brousername you want
/// </summary>
/// <param name="action"></param>
/// <param name="browserName">Name of the brouser for example check WebDriverType enum</param>
/// <seealso cref="WebDriverType"/>
/// <returns></returns>
Task<string> EnqueueAction(Func<IWebDriver, string> action, string browserName);
#endregion

}
}
11 changes: 6 additions & 5 deletions SeleniumManager.Core/SeleniumManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
This include managing Queues, Parallel Tests, etc.</Description>
<Copyright>MIT License</Copyright>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<AssemblyVersion>0.0.0.3</AssemblyVersion>
<Version>0.0.0.3-alpha</Version>
<AssemblyVersion>0.0.0.4</AssemblyVersion>
<Version>0.0.0.4-alpha</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;8618</NoWarn>
<NoWarn>1701;1702;8618;1591</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;8618</NoWarn>
<NoWarn>1701;1702;8618;1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -50,7 +51,7 @@ This include managing Queues, Parallel Tests, etc.</Description>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Selenium.WebDriver" Version="4.9.1" />
<PackageReference Include="Selenium.WebDriver" Version="4.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 5fef3c1

Please sign in to comment.