Add the ability to set desired capabilities to local drivers in App.config
asrafiq opened this issue · 20 comments
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
Hi @asrafiq
We can't add desired caps from config now because IWebDriver constructors don't have caps as input params.
But I believe I can create some wrapper classes for Chrome, Firefox to handle it :)
Can you share me some examples of caps you wanna see?
As for now, I see it like:
<component name="ChromeSample" type="chrome, type" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="arguments" value="--window-size=1024,1024;--headless" />
<item key="mobileEmulation" value="iPhone6" />
<item key="userProfilePreference1" value="intl.accept_languages=nl" />
<item key="userProfilePreference2" value="download.default_directory=D:\workspace" />
</dictionary>
</parameter>
</parameters>
</component>
awesome thanks, I'll try it out and report back.
I updated logic in 1.1.1-beta2, because generated WebDrivers couldn't implement selenium interfaces.
Hi @unickq ,
I'm getting this error when i try and regenerate the feature files.
Custom tool error: Generation error: SpecFlow configuration error -> Unrecognized attribute 'markFeaturesParallelizable'. Note that attribute names are case-sensitive.
Any Ideas? also noticed the build failed.
@unickq I'm using v2.2.1 see the main part of my app.config below. Just to add that I've moved to stable 1.1.1 version and now get his error:
#error: 'Generation error: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
This looks like a different feature file generation issue. My app.config has stayed the same for both versions.
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
<section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration" />
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<unitTestProvider name="Unickq.SpecFlow.Selenium" />
<generator allowDebugGeneratedFiles="true" markFeaturesParallelizable="true" />
<plugins>
<!-- <add name="Unickq.SpecFlow.Selenium"/>-->
<add name="Unickq.SpecFlow.Selenium" path="..\Automation\bin\Debug" />
</plugins>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<stepAssemblies>
<!-- This attribute is required in order to use StepArgument Transformation as described here;
https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Step-argument-transformations -->
<stepAssembly assembly="SpecFlow.Assist.Dynamic" /></stepAssemblies>
</specFlow>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.8.1.0" newVersion="5.8.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="TechTalk.SpecFlow.Generator" publicKeyToken="0778194805d6db41" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="TechTalk.SpecFlow.Utils" publicKeyToken="0778194805d6db41" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="TechTalk.SpecFlow" publicKeyToken="0778194805d6db41" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="2638cd05610744eb" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.9.0.0" newVersion="3.9.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
It's kind of SpecFlow issue SpecFlowOSS/SpecFlow#857
According to your config, everything looks correct. You also can remove path from plugin because specflow used to find plugins in default build dir.
I'll build a new version with fixed nuget dependencies.
My config for 1.1.1-beta2 in net461 project using VS2017:
<specFlow>
<unitTestProvider name="Unickq.SpecFlow.Selenium" />
<generator allowDebugGeneratedFiles="true" markFeaturesParallelizable="true" />
<plugins>
<add name="Unickq.SpecFlow.Selenium" />
</plugins>
<stepAssemblies>
<stepAssembly assembly="SpecFlow.Assist.Dynamic" />
</stepAssemblies>
</specFlow>
What are your VS and .NET versions?
@unickq I'm using 4.6.01055 and VS 2017. It does seem like a specflow generation issue on the stable version but when I use the beta2 version I always get the error below which seems quite specific.
Custom tool error: Generation error: SpecFlow configuration error -> Unrecognized attribute 'markFeaturesParallelizable'. Note that attribute names are case-sensitive.
Reach me on nicktestqa@yahoo.com I'll try to help you
Hi @unickq ,
I've managed to get past the specflow generation issues by reverting back to VS 2015.
I'm now trying to get the local driver configuration correct for Firefox to start up but when i try the following in app.config:
<component name="Firefox" type="Unickq.SpecFlow.Selenium.Local.FirefoxDriver, Unickq.SpecFlow.Selenium.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="capabilities" value="acceptInsecureCerts=true" />
</dictionary>
</parameter>
</parameters>
</component>
</components>
or
<component name="Firefox" type="Unickq.SpecFlow.Selenium.Local.FirefoxDriver, Unickq.SpecFlow.Selenium.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="acceptInsecureCerts" value="true" />
</dictionary>
</parameter>
</parameters>
</component>
or
<component name="Firefox" type="Unickq.SpecFlow.Selenium.Local.FirefoxDriver, Unickq.SpecFlow.Selenium.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="acceptInsecureCerts" value="true" />
<item key="moz:firefoxOptions.binary" value="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" />
</dictionary>
</parameter>
</parameters>
</component>
I always get this error when i try and run a test:
An exception was thrown while invoking the constructor 'Void .ctor(System.Collections.Generic.Dictionary`2[System.String,System.Object])' on type 'FirefoxDriver'. ---> Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line (See inner exception for details.)
Any ideas how i can get this working?
@asrafiq
You're right, that's a bug. I forgot to initialize FirefoxOptions instance :(
Built new one - https://www.nuget.org/packages/Unickq.SpecFlow.Selenium/1.1.1-beta3 and tested with
<component name="FirefoxDebug" type="Unickq.SpecFlow.Selenium.Local.FirefoxDriver, Unickq.SpecFlow.Selenium.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="AcceptUntrustedCertificates" value="true" />
<item key="Binary" value="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" />
</dictionary>
</parameter>
</parameters>
</component>
Did get moz:firefoxOptions.binary work . Can you show me the raw code for it? I mean FF initialization with it.
@unickq thanks for the quick fix that's working now. However, I still cant get it to accept insecure certs.
I get this:
{System.InvalidOperationException: Invalid moz:firefoxOptions field acceptInsecureCerts}
when I try:
<component name="Firefox" type="Unickq.SpecFlow.Selenium.Local.FirefoxDriver, Unickq.SpecFlow.Selenium.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="Capability" value="acceptInsecureCerts=true" />
<item key="Binary" value="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" />
</dictionary>
</parameter>
</parameters>
</component>`
I am trying to set this based on what it says here https://github.com/mozilla/geckodriver#webdriver-capabilities with no joy at the moment. Does the above config look correct?
So I think the raw code on the new version should look like this for AcceptInsecureCertificates:
var options = new FirefoxOptions {AcceptInsecureCertificates = true};
var driver = new FirefoxDriver(options);
I don't know where exactly acceptInsecureCerts should be added - in Capabilities/Arguments/Preference
I expected that FirefoxProfile.AcceptUntrustedCertificates and FirefoxOptions.AcceptInsecureCertificates do the same job
Anyway I've added additional AcceptInsecureCertificates property as now we have for Chrome in beta4
@unickq Thanks for your help. I got it working by using my default profile. I had already added an exception to the untrusted insecure self signed cert in the firefox browser manually when i first navigated to the site. However, the GeckoDriver creates a new profile each time it spins up firefox and therefore never recorded the exception i had added.
In the end my App.config looked like this for the firefox local driver:
<!-- Using a local Webdriver:-->
<component name="Firefox" type="Unickq.SpecFlow.Selenium.Local.FirefoxDriver, Unickq.SpecFlow.Selenium.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="capabilities">
<dictionary>
<item key="Binary" value="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" />
<item key="FirefoxProfile" value="default" />
</dictionary>
</parameter>
</parameters>
</component>
I'll try the IE and Chrome local drivers next.
@unickq Tested the other drivers and they work as expected. Thanks.
Although it should be highlighted that if you don't want to use additional params then you have to revert back to the old config. e.g. for IE local with no params:
<component name="IE" type="OpenQA.Selenium.IE.InternetExplorerDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency"/>
When are you planning on releasing this?
Didn't get what you want to highlight :)
OpenQA.Selenium.Firefox.FirefoxDriver
and Unickq.SpecFlow.Selenium.Local.FirefoxDriver
are different types 💯
You use original FirefoxDriver if you want to run FF without params and Local.FirefoxDriver wrapper if you need to pass params.
I'll release 1.2.0 version as soon as fix NuGet dependencies issue .
I don't really understand the bug but I hope it's fixed soon and I look forward to the release 👍