czwartek, 14 marca 2019

SpecFlow with Coypu and custom IWebDriver for Coypu SessionConfiguration

Using Coypu with SpecFlow might have some limitations. Sometimes there is need to use driver with options or capabilities. Coypu gives possibility to customise web drivers with SessionConfiguration class.

Template

Example of Coypu custom web driver configurations is prepared in specflow-coypu-custom-webdriver template:

Custom Coypu driver configuration

To customise, for example, chrome driver, create class like below:

public class CustomChromeWebDriver : SeleniumWebDriver
    {
        public CustomChromeWebDriver(Browser browser) : base(CustomProfile(), browser)
        {
        }

        private static IWebDriver CustomProfile()
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.AddArguments("test-type");
            chromeOptions.AddArguments("--disable-extensions");

            return new ChromeDriver(chromeOptions);
        }
    }

Use name of created class for 'Driver' declaration in Coypu session configuration like below:

var sessionConfigurationForChrome = new SessionConfiguration()
{
Driver = typeof(CustomChromeWebDriver),
Browser = Coypu.Drivers.Browser.Chrome,
AppHost = "https://specflow.org/", // whatever url you want
Timeout = TimeSpan.FromSeconds(2)
};
browser = new BrowserSession(sessionConfigurationForChrome);
browser.MaximiseWindow();

Specflow-coypu-custom-webdriver template has BrowserSessionManager class to manage custom drivers for chrome, firefox, internet explorer and headless mode for chrome and firefox.

Custom RemoteWebDriver configuration

If you need to use RemoteWebDriver for running tests, in custom web driver classes replace IWebDriver to RemoteWebDriver (there might be also necessity to add option for running tests locally).

Brak komentarzy:

Prześlij komentarz