wtorek, 12 marca 2019

SpecFlow with Selenium IWebDriver manager

Specflow-webdriver-manager template uses Selenium IWebDriver for running browsers.

Template

Template you will find on GitHub:
https://github.com/bazylMN/specflow-webdriver-manager

WebDriverManager for browsers

Choice between browsers is managed by 'GetDriver()' method in WebDriverManager class:

public IWebDriver GetDriver()
        {
            var browserType = TestContext.Parameters["BROWSER"];
            switch (browserType)
            {
                case "CHROME":
                    webDriver = new ChromeDriver();
                    break;

                case "CHROMEHEADLESS":
                    ChromeOptions chromeOptions = new ChromeOptions();
                    chromeOptions.AddArguments("headless");
                    webDriver = new ChromeDriver(chromeOptions);
                    break;

                case "INTERNETEXPLORER":
                    webDriver = new InternetExplorerDriver();
                    break;

                case "FIREFOX":
                    webDriver = new FirefoxDriver();
                    break;

                case "FFHEADLESS":
                    FirefoxOptions firefoxOptions = new FirefoxOptions();
                    firefoxOptions.AddArguments("--headless");
                    webDriver = new FirefoxDriver(firefoxOptions);
                    break;

                default:
                    webDriver = new ChromeDriver();
                    break;
            }
            return webDriver;
        }

Commands for running particular browser

Default browser is Chrome, but you can choose Firefox, Internet Explorer or headless mode for Chrome and Firefox, using commands:

nunit3-console specflow-webdriver-manager\bin\Debug\specflow-webdriver-manager.dll --params:BROWSER=FIREFOX --work=NUnitTestResult --out=NUnitTestResult.txt --result=NUnitTestResult.xml

nunit3-console specflow-webdriver-manager\bin\Debug\specflow-webdriver-manager.dll --params:BROWSER=INTERNETEXPLORER --work=NUnitTestResult --out=NUnitTestResult.txt --result=NUnitTestResult.xml

nunit3-console specflow-webdriver-manager\bin\Debug\specflow-webdriver-manager.dll --params:BROWSER=CHROMEHEADLESS --work=NUnitTestResult --out=NUnitTestResult.txt --result=NUnitTestResult.xml

nunit3-console specflow-webdriver-manager\bin\Debug\specflow-webdriver-manager.dll --params:BROWSER=FFHEADLESS --work=NUnitTestResult --out=NUnitTestResult.txt --result=NUnitTestResult.xml

Instruction

Instruction of usage specflow-webdriver-manager template is placed in README.md file.

Brak komentarzy:

Prześlij komentarz