Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NoInternetBrowserFactory and describe setup instructions for local environment without internet access / Custom browsers like Yandex #206

Open
mialeska opened this issue Sep 16, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mialeska
Copy link
Contributor

Instruction example in case of our SpecFlow-based template:

  1. Add CustomBrowserFactory
  2. Add respective nuget package of driver e.g. Selenium.WebDriver.ChromeDriver
  3. Add hook to be executed before tests:
    [BeforeTestRun(Order = 0)]
    public static void ConfigureBrowserFactory()
    {
    AqualityServices.BrowserFactory = new CustomBrowserFactory(
    AqualityServices.Get(),
    AqualityServices.Get(),
    AqualityServices.Get(),
    AqualityServices.LocalizedLogger);
    }
@mialeska mialeska added the enhancement New feature or request label Sep 16, 2021
@mialeska
Copy link
Contributor Author

Example of CustomBrowserFactory was in tests for usecases
https://github.com/aquality-automation/aquality-selenium-dotnet/blob/master/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs
, but could look like that:

using Aquality.Selenium.Browsers;
using Aquality.Selenium.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Core.Utilities;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using System;
using System.IO;
using System.Reflection;

namespace Web.Autotests.Framework.BrowserUtilities
{
    public class CustomBrowserFactory : BrowserFactory
    {
        public CustomBrowserFactory(IActionRetrier actionRetrier, IBrowserProfile browserProfile, ITimeoutConfiguration timeoutConfiguration, ILocalizedLogger localizedLogger)
            : base(actionRetrier, browserProfile, timeoutConfiguration, localizedLogger)
        {
        }

        protected override RemoteWebDriver Driver
        {
            get
            {
                var commandTimeout = TimeoutConfiguration.Command;
                var browserName = BrowserProfile.BrowserName;
                var driverSettings = BrowserProfile.DriverSettings;
                RemoteWebDriver driver;
                switch (browserName)
                {
                    case BrowserName.IExplorer:
                        driver = GetDriver<InternetExplorerDriver>(InternetExplorerDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location)),
                            (InternetExplorerOptions)driverSettings.DriverOptions, commandTimeout);
                        break;
                    case BrowserName.Chrome:
                        driver = GetDriver<ChromeDriver>(ChromeDriverService.CreateDefaultService(),
                            (ChromeOptions)driverSettings.DriverOptions, commandTimeout);
                        break;
                    default:
                        throw new NotSupportedException($"Browser [{browserName}] is not supported.");
                }
                return driver;
            }
        }

        private RemoteWebDriver GetDriver<T>(DriverService driverService, DriverOptions driverOptions, TimeSpan commandTimeout) where T : RemoteWebDriver
        {
            return (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants