I want to run many SOAPUI project xmls using Gradle script, in Linux - gradle

I want to run the SOAPUI project xmls using Gradle script. The GRADLE script should read the project xmls from soapuiInputs.properties file and run automatically all. Please guide me step by step how to create Gradle script to run the SOAPUI projects in Linux server.
Note: We use SOAPUI version 5.1.2.

Probably the simple way is to call the SOAPUI testrunner directly from gradle as Exec task, like you can do from cli.
In gradle you can define the follow tasks (Note that I try it on windows but to do the same on linux as you ask simply you've to change the paths):
// define exec path
class SoapUITask extends Exec {
String soapUIExecutable = 'C:/some_path/SoapUI-5.2.1/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// execute SOAPUI
task executeSOAPUI(type: SoapUITask){
// simply pass the project path as argument,
// note that the extra " are needed
soapUIArgs = '"C:/location/of/project.xml"'
}
To run this task use gradle executeSOAPUI.
This task simply runs a SOAPUI project, however testrunner supports more parameters which you can pass to soapUIArgs string in executeSOAPUI task, take a look here.
Instead of this if you want to deal with more complex testing there is a gradle plugin to launch SOAPUI project, take a look on it here
Hope this helps,

Related

Cucumber Test execution for gradle project via command line using tags for cucumber feature files

I am looking to execute a cucumber test for a gradle project via command line using specific feature tags.
The command I am using: gradle test -DCucumber.options="-tags #tagname".
Command does execute the tags mentioned.
I have tried using gradle test -DCucumber.options="-tags #tagname" and also gradle test. I didn't find any difference in both the command.
gradle test -DCucumber.options="-tags #tagname" executes the Runtest.java and tags mentioned in this file, irrespective of what feature tags I pass via command line for example: tagname.
Runtest.java
#RunWith(Cucumber.class)
#CucumberOptions(features = "src\\test\\resources\\featurefiles", monochrome = true, plugin = {
"com.eis.listeners.ExtentCucumberFormatter:" }, glue = {
"com.adminconsole.stepdefs" },tags= {"#adminconsolelogin,#devicemanager,#certificatemanagement"} ,format = { "json:JsonReports/AdminConsole.json" })
So here I have mentioned three tags in the Runtest.java.
Now, instead of running all the tags, I wanna run a specific tag via command line.
Command: gradle test -DCucumber.options="-tags #adminconsolelogin", but -DCucumber.options="-tags #adminconsolelogin" part ain't working.
I am looking for a solution where we can run specific tags irrespective of what tag is mentioned in Runtest.java. More precisely pass tags dynamically via command line.
But -DCucumber.options="-tags #tagname" ain't working via command line.
Would appreciate if anyone can provide me with a correct command or strategy or code on how to do it. If the below command is wrong: gradle test -DCucumber.options="-tags #tagname" please correct me.
Update: For Cucumber 6 you need to provide the following statement:
test {
systemProperty "cucumber.filter.tags", System.getProperty("cucumber.filter.tags")
}
You have to bridge the system properties between the gradle JVM and the forked JVM for the tests for this to work. From issue #1346:
test {
systemProperty "cucumber.options", System.getProperty("cucumber.options")
}
Add that to your build.gradle and then you can do it on the command-line:
gradle test -Dcucumber.options="-tags #tagname"
You need to add this
test {
systemProperty "cucumber.options", System.getProperty("cucumber.options")
}
And CLI command will be
gradle test -Dcucumber.options="--tags #tagName"

How to create Karaf shell command in Gradle project

I'm trying to create own Karaf shell command and I'm willing to do this using Gradle because entire project is on Gradle.
The only relevant documentation I've found so far is here
http://karaf.apache.org/manual/latest/#_shell_commands
and it says
See [examples/karaf-command-example] to add your own shell commands.
Examples are created using MAVEN and there is absolutely no description about what magic is happening there and what should appear in resulting bundle so that I could reproduce it in Gradle.
Can someone tell how to achieve the same in Gradle project?
How Karaf identifies which commands are present in Bundle?
Over time I did not find how to make that same thing in gradle, but I came across the solution which gives same result - using OSGI Declarative Services.
More details here (look for osgi.command.scope):
http://blog.vogella.com/2016/09/26/configuring-osgi-declarative-services/
Here is sample code, which allows running command some:command with one optional string parameter.
package some.application;
import org.osgi.service.component.annotations.Component;
#Component(
service=SomeCommand.class,
property = {"osgi.command.scope=some", "osgi.command.function=command"}
)
public class SomeCommand {
public void command() {
System.out.println("SomeCommand: " + "<no args>");
}
public void command(String param) {
System.out.println("SomeCommand: " + param);
}
}

Build Gradle getProperties before running already made task

I’m trying to use a Java, Serenity-BDD project with gradle version 4.8+, but the application is not pulling the CLI arguments of -Denvironment and -Dservicebranches. I have these properties as blank values in my local.properties file, and they’re not getting assigned when my app runs.
./gradlew --build-cache build -Dwebdriver.remote.url=${SELENIUM_REMOTE_URL} -Denvironment=${ENVIRONMENT} -Dservicebranches=${SERVICE_BRANCHES} -Dtags=${TAGS}
I have a local.properties file with properties that are being successfully dependency injected into the project (through Serenity-Spring). I'm hoping that these CLI arguments will override these values:
servicebranches=
environment=local
But right now, anything specified in the CLI arguments are not being passed into the project. Either through DI, or through explicitly grabbing the environment variables in the build.gradle, which what I've tried hasn't been working.
Here's a few things which I have tried in the build.gradle:
//task integrationTests() {
// doFirst
// {
// def environment = System.getProperty('environment')
// def servicebranches = System.getProperty('servicebranches')
// }
// tasks.build.execute()
//}
//integrationTests.dependsOn(build)
//build.doFirst{
// systemProperties System.properties
// def environment = System.properties['environment']
// environment = environment //This actually flags with 'Silly assignment'
//}
build.doFirst{
def environment = System.getProperty('environment')
def servicebranches = System.getProperty('servicebranches')
}
The latest one seems to still be missing a step, because the program is still working, but the args are still not getting through. I've even tried -Denvironment=potato, and no errors have come up because I do not have a property or properties file named that.
I've also tried using the -P tag instead of -D tag, but that doesn't seem to be working either.
All I’m trying to do is use build.gradle to use System.getProperty(‘environment’) and System.getProperty(‘servicebranches’) before I use the already created ‘build’ task that comes with Serenity. How would I do this? Do I build a whole new task, where I use these getProperties, and then call the build task? Do I have to specify the assignment of these same named variables in the local.properties file?
-D is for system properties in Gradle. Try with -P instead (https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties)
I know this is a very old question but here's what I did to solve my problem, I got the idea from here: https://github.com/serenity-bdd/serenity-documentation/pull/120/files
Serenity was not pulling the environment from gradle to use EnvironmentSpecificProperties, it kept saying "undefined property for environment 'null" when I removed the default environment. I had to add this to my Gradle file:
test {
systemProperty 'environment', System.properties['environment']
}

How can I share build code script for all my gradle projects (not just subprojects)

I want to have this code snippet
test {
testLogging.showStandardStreams = true
}
Shared for all my gradle projects. Is that possible? Preferrably something I add to ~/.gradle/common.gradle or similar.
Probably the best way to inject build logic into existing build scripts without touching them is using init scripts. So you can create a script like testlogging.gradle that looks like this:
allprojects {
tasks.withType(Test) {
testLogging.showStandardStreams = true
}
}
As you can see I use tasks.withType(Test) instead of test here to reference the test task by type. That has some benefits:
this script works also for builds with no task with name test. This could likely happen (e.g. in multiproject builds)
this script would also apply for any other tasks in your build that are of type Test. Some projects use integTest etc.
To auto apply this script on your machine, you can put it in the folder ~/.gradle/init.d. Gradle considers every .gradle file in there as init script and applies them to each build.
To learn more details about init scripts check the according chapter in the gradle userguide.

I want to run multiple SOAPUI project xmls in Gradle script

I want to run multiple soapui projects in Gradle script. The SOAPUI project files are kept is following location:
d:/soapui/projects/path/a.xml, b.xml etc
Will be there any Gradle script that it will enter into the above mentioned location and execute the each project one by one using testrunner.bat
As #RaGe comments you can use the gradle SOAPUI plugin. However if you're looking for a more custom way you can proceed as follows.
You can generate a task on Gradle to execute testrunner to run your SOAPUI projects. Then you can create dynamically one task for each project you've in a directory path, and using .depends you can make that all these dynamic generated tasks are called when you call the specific task.
Your build.gradle could be something like:
// task to execute testrunner
class SoapUITask extends Exec {
String soapUIExecutable = '/SOAPUI_HOME/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// empty task wich has depends to execute the
// ohter tasks
task executeSOAPUI(){
}
// get the path where are your projects
def projectsDir = new File(project.properties['soapuiProjectsPath'])
// create tasks dynamically for each project file
projectsDir.eachFile{ file ->
if(file.name.contains('.xml')){
// create the tasks
task "executeSOAPUI${file.name}"(type: SoapUITask){
println "execute project ${file.name}"
soapUIArgs = ' "' + file.getAbsolutePath() +'"'
}
// make the depends to avoid invoke each task one by one
executeSOAPUI.dependsOn "executeSOAPUI${file.name}"
}
}
To invoke this you can do it using the follow command:
gradle executeSOAPUI -PsoapuiProjectsPath=d:/soapui/projects/path/
Note that -P is used to pass the parameter for projects dir.
Recently I wrote an answer on how to write gradle task to run SOAPUI which can be also util, if you want check more details here.
Hope this helps,

Resources