Coder Social home page Coder Social logo

unickq / specflow.selenium.plugin Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 4.0 160 KB

SpecFlow WebDriver instances generator plugin. Annotate scenario with @Browser:Chrome and run you tests!

License: MIT License

C# 97.85% Gherkin 2.15%
automation nunit selenium specflow test-automation testing-tools webdriver webdrivermanager

specflow.selenium.plugin's Introduction

Hi, I'm Nick ๐Ÿ‘‹

Software Engineer in Test, who makes automated tests, scrapers, bots, and tunes CI and digs into logs to find the truth ๐Ÿ™Œ

Linkedin Add GitHub followers Nuget

specflow.selenium.plugin's People

Contributors

unickq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

specflow.selenium.plugin's Issues

RemoteWebDriver Grid

Hi Nick,

Very good job. I am trying to use it with RemoteWebDriver Grid. I don't see a real example in the example solution. I am getting

System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'

when trying to use a remote web driver. He is my config:

  <component name="RemoteWebDriver"
       type="Unickq.SeleniumHelper.RemoteWebDriver, Unickq.SeleniumHelper.SpecFlowPlugin"
       service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
    <parameters>
      <parameter name="url" value="http://192.168.207.202:4444/" />
      <parameter name="browser" value="Chrome" />
      <parameter name="capabilities">
        <dictionary>
          <item key="CapabilityType.BrowserName" value="chrome" />
        </dictionary>
      </parameter>
    </parameters>
  </component>

I have a working solution with RemoteWebDriver and now I am trying to integrate your job. This is what I need to have working with your solution:

  			capabilities = DesiredCapabilities.Chrome();
  			capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
  			capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));

Can you help me with this?

Specflow AfterScenario runs after Nunit Teardown

Hi @unickq,

Thanks again for your help before on the enhancement.

I am facing a new issue where when a test fails the browser is closed down as part of the NUnit Teardown before the Specflow AfterScenario is run, which is where I take a screenshot of the browser to help diagnose the issue.

When I manually comment out the driver.quit like below in the generated code then the after scenario takes a screenshot as expected.

        [NUnit.Framework.TearDownAttribute()]
        public virtual void ScenarioTearDown()
        {
            try
            {
                ((Unickq.SpecFlow.Selenium.WebDriverGrid.PaidWebDriver) driver).UpdateTestResult();
            }
            catch (System.Exception)
            {
            }
            //try {System.Threading.Thread.Sleep(50); driver.Quit(); } catch (System.Exception) {}
            driver = null;
            try
            {
                testRunner.ScenarioContext.Remove("Driver");
            }
            catch (System.NullReferenceException)
            {
            }
            testRunner.OnScenarioEnd();
        }

Code to create the screenshot in the specflow after scenario:
driver.TakeScreenshot().SaveAsFile(path, ScreenshotImageFormat.Jpeg);

I think in the previous base class version, the browser closing was not in the teardown but I'm not certain of this.

Any ideas how I can solve or work around this?

Thanks,
Adil

No test matches the given testcase filter " not able run the tests

[10/31/2018 3:18:49 PM Warning] No test matches the given testcase filter " not able run the tests

I am using 2017 Visual Studio
TechTalk.SpecFlow version 2.4.0
Unickq.SpecFlow.Selenium.SpecFlowPlugin version 1.3.0.0
WebDriver version is 3.14.0.0

When trying run in debug mode getting below exception

'testhost.x86.exe' (CLR v4.0.30319: Dependency finder domain): Unloaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll'
The thread 0x34c0 has exited with code 0 (0x0).
The thread 0x18d4 has exited with code 0 (0x0).
The program '[16712] testhost.x86.exe: Program Trace' has exited with code 0 (0x0).
The program '[16712] testhost.x86.exe' has exited with code 0 (0x0)

SpecFlow.Selenium.Plugin with Visual Studio 2017

Hi Nick,

I created a C# Unit Test Project (.NET Framework) on Visual Studio 2017 community edition and added the latest versions (as of 3/10/2018) of these following .Nuget packages

  • Autofac, Autofac.configuration, NUnit, MSTest, Specflow.Assist.Dynamic, TechTalk.Specflow and
    Unickq.Specflow.Selenium.SpecFlowPlugin

In the App.config file , I set the test provider to NUnit and set the component name to ChromeDebug as shown below
















.....

I then created a feature file called GoogleSearch

Feature: GoogleSearch
Feature to test Google search functionality
We will test auto-search as well as navigationg to search results

@browser:ChromeDebug
Scenario: Google search for Execute Automation term
Given I have navigated to Google page
And I see the Google page fully loaded
When I type the following Keyword
| Keyword |
| Execute Automation |
Then I should see the results for the keyword
| Keyword |
| Execute Automation |

There are some issues with the generated GoogleSearch.feature.cs file

  1. It does not like the parameter 'GoogleSearchFeature' as shown below
    [NUnit.Framework.ParallelizableAttribute("GoogleSearchFeature")]
    public partial class GoogleSearchFeature
    {
    It shows this error when you mouse over 'GoogleSearchFeature'
    (Argument1: cannot convert from 'string' to type 'NUnit.Framework.ParallelScope' )

Why is this happening?

  1. In your Unickq.SpecFlow.Selenium.Example project's F1.feature,cs file, you have the following code that is missing from my GoogleSearch.feature.cs

    using Autofac; // missing from mine
    using Autofac.Configuration; // missing from mine

private OpenQA.Selenium.IWebDriver driver; // missing from mine, and all the code referring to driver is missing

private IContainer container; // missing from mine and all the code referring to container is missing

Your file
[NUnit.Framework.TestCaseAttribute("ChromeDebug", etc..]
public virtual void CheckWebsiteTitle(string browser, etc..)
{
InitializeSeleniumBrowser(browser);

versus mine

[NUnit.Framework.CategoryAttribute("Browser:ChromeDebug")]
public virtual void GoogleSearchForExecuteAutomationTerm()
{
// string browser and InitializeSeleniumBrowser(browser); are missing from mine
// also, mine does not have an [NUnit.Framework.TestCaseAttribute it has an
[NUnit.Framework.CategoryAttribute( "Browser:ChromeDebug")

private void InitializeSeleniumBrowser(string browser) // this function is missing from mine
{
driver = container.ResolveNamed<OpenQA.Selenium.IWebDriver>(browser);
}

Because of all the missing code, the following code in the step file is giving errors

if (scenarioContext == null) throw new ArgumentNullException(nameof(scenarioContext));
ScenarioContext = scenarioContext;
Browser = scenarioContext.GetWebDriver();

How can we fix this issue?

Thanks. :)

Burak

Using POM within this framework

Hello,

I cloned this project and started using it for a proof of concept I am working on for automation. What I found is that when I started to create Page classes POM (Page Object Model) implementation, I started running into issues. It dawned on me that maybe this plugin is NOT POM-friendly. Is that the case? What I am finding is that when I try to use the IWebElement and scenario context within the Page Class files, I get errors/issues. Here is an example of an error I am facing:

error with base page

unickq.seleniumhelper throwing errors while compiling

trying to run it locally for two browsers.
Made changes to app.config but while building it is throwing errors:

Could not find schema information for the element 'unitTestProvider'.
Could not find schema information for the attribute 'allowDebugGeneratedFiles'.

my app.config file:

App.config error

Build error with VS2019 - unitTestProvider not recognized by SpecFlow
SpecFlowError

Add the ability to set desired capabilities to local drivers in App.config

Hi Nick,

Great work here.
Would it be possible to add the ability to set the desired capabilities for local drivers? Allowing the option to set a firefox profile on start up would be very helpful.

Just to add that what i'm specifically trying to accomplish with this is to have the ability to set settings such as 'AcceptUntrustedCertificates' on the FF Profile and 'acceptInsecureCerts' as a desired capability.

Thanks for your help

Tagging at feature

Hi Nick, this is great that you've made the original usable with the latest versions of NUnit/Selenium/Specflow.

Any possibility of tagging at the feature level? If a feature has many scenarios it may be easier just to tag once instead for each scenario.

To take take it one step further it would be nice to these browsers globally (somewhere) so the user doesn't have to worry about tagging individually.

I've been working on my own custom plugin and the TestFixture attribute that accepts an argument could be a possibility for feature tagging. Also the TextFixtureSource attribute seems to be powerful.

Sorry for the lengthy post but what you have so far is something I have waiting for and will definitely be using. Thanks, Prab

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.