Spec Run command line - Execute tests per environments or per targets (Filter by Targets in srprofile file)

331 views
Skip to first unread message

Vishnu Priya

unread,
Feb 14, 2017, 6:50:30 AM2/14/17
to SpecRun
Hi,

I have configured spec run in my project with custom.srprofile file to add three different targets for configuring three different test environments.  I have added configuration transformations to the targets to pick up right URL depending on the environment from app.config app settings like below:

<Targets>
    <Target name = "Integration">
      <DeploymentTransformationSteps>
        <ConfigFileTransformation configFile="app.config">
          <Transformation>
            <![CDATA[<?xml version="1.0" encoding="utf-8"?>
                <appSettings>
                      <add key="BaseUri" value="https://INTEGRATIONURL.com/" xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" />
                </appSettings>
</configuration>
]]>
          </Transformation>
        </ConfigFileTransformation>
      </DeploymentTransformationSteps>
    </Target>
   
   <Target name = "Staging">
     <DeploymentTransformationSteps>
         <ConfigFileTransformation configFile="app.config">
           <Transformation>
             <![CDATA[<?xml version="1.0" encoding="utf-8"?>
                <appSettings>
                    <add key="BaseUri" value="https://STAGINGURL.com/" xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" />
                 </appSettings>
</configuration>
]]>
           </Transformation>
         </ConfigFileTransformation>
     </DeploymentTransformationSteps>
   </Target>
   
   <Target name = "PreProduction">
     <DeploymentTransformationSteps>
         <ConfigFileTransformation configFile="app.config">
           <Transformation>
             <![CDATA[<?xml version="1.0" encoding="utf-8"?>
                <appSettings>
                  <add key="BaseUri" value="https://PREPRODURL.com" xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" />
               </appSettings>
</configuration>
]]>
           </Transformation>
         </ConfigFileTransformation>
     </DeploymentTransformationSteps>
   </Target>
  </Targets>


Now, If I run my tests, my tests are running for all three targets(all environments). Could you please let me know if there is a way I can pass the value to the srprofile file (from team city or from command line or using filter tags or some where) so, it will run tests only for the environment I require? 
I am stuck here at the moment and I dont know how to proceed. Your help is much appreciated. Thank You.

Vishnu

Stephen McCafferty

unread,
Feb 17, 2017, 9:45:50 AM2/17/17
to SpecRun
If you have defined tags for your tests (e.g. @Integration, @Staging etc.), you can use those tags to filter the tests very easily from the command line. Simply start SpecRun.exe with the /filter: option and specify the filter you want to use. Note that this will override the global filter defined in your profile (but if you define filters for your targets, the filters for the targets are retained).

You could also use separate profiles for each of the environment, and specify the profile from the command line. You can specify a profile when running tests from the command line. This would allow you to run tests for any combination of environments simply by chaining together a series of command lines with different profiles specified each time. It does largely defeat the points of defining targets in a single profile though.

Reading between the lines, I take it what you really want is to be able to run tests from the command line just for a specific target, rather than all your targets. Would that be your ideal scenario?

chak...@googlemail.com

unread,
Jan 10, 2018, 12:58:09 PM1/10/18
to SpecRun
Hi Stephen

I have the same issue and question here, but i would like to run my tests just for a specific environment and browser from command line is this possible:
Which was possible in Cucumber, like from command prompt we could run selected tests with tags on a specific browser and environment, like cucumber BROWSER=Chrome ENVIRONMENT=UAT @regression ----- which runs all the tests with tag regression on Chrome browser and UAT environment.

Stephen McCafferty

unread,
Jan 12, 2018, 7:35:56 AM1/12/18
to SpecRun
You can define filters from the command line using the /filter:option. Note that these filters override any filters you may have defined in your profile.

To run tests in different environments, you will need to define an profile for each environment. You can then specify the desired profile from the command line (e.g. "SpecRun Chrome_UAT.srprofile"). This should only be problematic if you require a lot of different combinations, in which case defining a separate profile for each combination could be tedious.

If you haven't already, I suggest taking a look at targets. There is a sample project that demonstrates how to use targets to run the same tests on different browsers (using Selenium).

Let us know if these options don't handle your use cases and where the problems are.
Reply all
Reply to author
Forward
0 new messages