How to run my serenity feature, providing command line options(login credentials) to the program? - cucumber-jvm

My serenity project feature is working perfectly, by running maven project by using
mvn clean verify
But our leadership is against keeping login credentials(userId, password) in the feature file or any external properties file. Only supplying them in the command line like
mvn exec:java -Dexec.mainClass="com.module.test.Main" -Dexec.args="arg0 arg1 arg2"
But in Serenity, there is no Main.java file with main() method. Then
how do I invoke my serenity feature file to run using Maven with the provided 2 arguments ?
Your suggestions are highly appreciated,

First off, your company is doing the right thing. Sensitive data should never be committed to code. If it is then anybody who has access to the code has access to everything.
Serenity allows parameters to be passed at runtime, e.g.
mvn clean verify -DUSERNAME=bob -DPASSWORD=mysupersecurepassword
This will pass the values into the serenity runner. Serenity then provides a utility to read in these values using SystemEnvironmentVariables.createEnvironmentVariables, e.g.
EnvironmentVariables envs = SystemEnvironmentVariables.createEnvironmentVariables();
String username = env.getProperty("USERNAME");
String password = env.getProperty("PASSWORD");

Related

How to pass data provider thread count parameter from build.gradle to testng.xml

I am looking to pass data provider thread count value from command line an then pick this parameter in build.gradle and use it inside useTestNg() inside the test task. Is this possible?
For example:
Command: gradle clean build test -Pdataproviderthreadcount=5
Can this be captured using systemPropeties and the value to be used in useTestNg()
Since dataproviderthreadcount is a VM option, I used this as below and it worked as expected. My project is a Cucumber, Gradle and testNG.
TEST_ENV=STG BROWSER=chrome ./gradlew clean build -Dorg.gradle.jvmargs=-Ddataproviderthreadcount=2
You can also refer How can I pass VM arguments to gradle from command line?

Validate that NUnit's ITestEventListener within Jenkins Pipeline for a netcoreapp3.1 assembly is called

Locally, I have successfully implemented the interface ITestEventListener within a C# netcoreapp3.1 csproj. However, when the tests are an within a Jenkins Pipeline, things appear to not be working(?).
I am using version 3.12.0 of NUnit.Engine.
By locally I am referring to using 1) Visual Studio Version 16.9.2 to run the tests and 2) command line dotnet test -c devint --test-adapter-path:. --logger:nunit to run the tests. I am getting successful test runs.
Success is my [Extension]public class ReportTestListener : ITestEventListener {...} generates an html file. I am to see the html file is created locally whereas from the Jenkins Pipeline the html file is not generated.
Within the Jenkins Pipeline, I am using the command sh "dotnet test -c ${env.TARGET_ENV} --test-adapter-path:. --logger:nunit" where env.TARGET_ENV resolves to devint. I know tests successfully run within the Jenkins Pipeline since the NUnit test results file is generated/published.
What I am not sure of is how to test/validate that the ReportTestListener is being called within the Jenkins Pipeline. I know that testing frameworks such as NUnit uses refection to identify test classes and methods. I am presuming that also happens with my implementation of [Extension]public class ReportTestListener : ITestEventListener {...}. Ideas/Suggestions on how to validate that ITestEventListener's method void OnTestEvent(string report) is being called besides writing out to disk?
Changed file writing text path to use / instead of \.

karate argLine arguments not picked up with 'mvn gatling:test' command

I have an existing suite of karate tests which can run on different environments (dev / qa) using the approach below:
mvn test -DargLine="-DauthUser=*** -DauthPassword=*** -Dkarate.env=qa"
Now i have added some gatling tests and when try to run the tests on 'qa' with the following command, the tests still run on my default environment which is 'dev' instead of 'qa'.
mvn gatling:test -DargLine="-DauthUser=*** -DauthPassword=*** -Dkarate.env=qa"
Seems like the argLine approach will not work with maven gatling plugin. If not, is there any other way of passing these arguments for gatling tests?
I came across previous post where its suggested to not use -DargLine when specifying arguments - I want to pass multiple arguments in karate-config.js through mvn command
Just pass the command line arguments like:
mvn gatling:test -DauthUser=*** -DauthPassword=*** -Dkarate.env=qa

How to pass parameter from jenkins to selenium

I'm using jenkins and selenium.
I need to send the testing url to selenium server from jenkins.
Under General Tab
Jenkins String parameter: Name = APP, Default Value = http://localhost/basecode/
Under Post-build Actions
Trigger parameterized build on other projects -> Predefined parameters -> Parameters -> SEL_APP=$APP
Above mentioned SEL_APP value needs to be written in the selenium bat file.
Suggestions are most welcome :-)
If you are using maven then you can pass the parameters through maven command.
mvn clean test -Duser=value1 -Dpass=value2
If you are building the Jenkins job with parameters then you can use jenkins parameters in maven command as
clean test -Duser=$jenkinsparam1 -Dpass=$jenkinsparam1
jenkinsparam1 - Jenkins parameter while building a job.
In the code you can use them as
String s1 = System.getProperty("user");
String s2 = System.getProperty("pass");
Use File Operations Plugin to create a bat file.
Add File Operations build step and with in it add File Create Operation. It creates the bat file with the contents provided in text area.
Use %parameter_name% in your bat file, it would directly pick it from Jenkins.

serenity jbehave multiple browsers

I am trying to setup a test project that uses serenity and jbehave
I am noticing that all examples use serenity.properties that define a browser in it
I would like to structure my tests in a way so that same test can be executed in IE/firefox/chrome etc
How do I do this?
You can pass in properties as command line properties, so you can rerun the same tests with different browsers by passing in different settings for webdriver.driver, e.g.
$ mvn verify -Dwebdriver.driver=firefox
$ mvn verify -Dwebdriver.driver=chrome
etc.
I think you are able to get this to work by creating multiple Junit test classes with each its own driver and execute them all in a single run.
Every test class should be able to assign a specific 'managed' driver (e.g. PhantomJS, Chrome, Firefox). This is documented here: http://www.thucydides.info/docs/serenity/#_serenity_webdriver_support_in_junit
I don't know what the impact this would have on the generated report, hopefully you are still able to identify the feature/driver combination.