wtorek, 12 marca 2019

SpecFlow with Coypu and Coypu BrowserSession manager

SpecFlow UI tests might be run with Selenium IWebDriver or, you might use Coypu framework (https://github.com/featurist/coypu).
With Coypu you can manage browsers and interact with elements on page. After Coypu description:
"If your tests are littered with sleeps, retries, complex XPath expressions and IDs dug out of the source with browser developer tools then Coypu might help."

Template

Specflow-coypu template with Coypu BrowserSession manager you will find on GitHub:

Coypu configuration for browsers

Choice between browsers is managed by 'GetBrowser()' method in BrowserSessionManager class:

public BrowserSession GetBrowser()
        {
            if (browser != null)
                return browser;

            var sessionConfiguration = new SessionConfiguration()
            {
                Browser = GetBrowserName(),
                AppHost = "https://specflow.org/", // whatever url you want
                Timeout = TimeSpan.FromSeconds(2)
            };
            browser = new BrowserSession(sessionConfiguration);
            browser.MaximiseWindow();

            return browser;
        }

private Browser GetBrowserName()
        {
            var browserType = TestContext.Parameters["BROWSER"];
            switch (browserType)
            {
                case "CHROME":
                    browserName = Coypu.Drivers.Browser.Chrome;
                    break;

                case "INTERNETEXPLORER":
                    browserName = Coypu.Drivers.Browser.InternetExplorer;
                    break;

                case "FIREFOX":
                    browserName = Coypu.Drivers.Browser.Firefox;
                    break;

                default:
                    browserName = Coypu.Drivers.Browser.Chrome;
                    break;
            }
            return browserName;
        }

Comands for running particular browser

Default browser in template is Chrome, but you can choose Firefox or Internet Explorer, using command:

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

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

Instruction

Instruction of usage is placed in README.md file.

Brak komentarzy:

Prześlij komentarz