
io.github.carousell.testrails.CreateRunMojo Maven / Gradle / Ivy
package io.github.carousell.testrails;
import com.codepine.api.testrail.TestRail;
import com.codepine.api.testrail.model.Plan.Entry;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/** Mojo for creating a Testrail run */
@Mojo(name = "createrun")
public class CreateRunMojo extends AbstractMojo {
private static final Logger LOG = LoggerFactory.getLogger(CreateRunMojo.class);
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
@Parameter(defaultValue = "${project.basedir}/src/test/resources/features")
private String featuresSourceDirectory;
@Parameter(required = true, readonly = true)
private String url;
@Parameter(required = true, readonly = true)
private int projectId;
@Parameter(required = true, readonly = true)
private int suiteId;
@Parameter(required = true, readonly = true)
private int planId;
@Parameter(required = true, readonly = true)
private String username;
@Parameter(required = true, readonly = true)
private String password;
@Parameter(defaultValue = "generated by testrail-maven-plugin")
private String testRunName;
@Parameter(property = "tags")
private String[] tags;
private FeatureParser featureParser = new FeatureParser();
public void execute() throws MojoExecutionException, MojoFailureException {
LOG.info("Get parameters from command...");
LOG.info("Project Id : {}", projectId);
LOG.info("Suite Id : {}", suiteId);
LOG.info("Plan Id : {}", planId);
LOG.info("Test Run Name : {}", testRunName);
LOG.info("Tags : {}", tags);
LOG.info("Start to Parse Case Ids from Feature Files...");
featureParser.parseFeatures(featuresSourceDirectory, tags);
List caseIdList = featureParser.getCaseIdList().size() != 0
? featureParser.getCaseIdList() : new ArrayList(){{add(1);}};
LOG.info("These Test Case ID will be added into TestRun : {}", caseIdList);
LOG.info("Create a TestRun Name {} with case ids under Plan Id {} on TestRail",
testRunName, planId);
TestRail testRail =
TestRail.builder(url, username, password).applicationName("playground").build();
Entry entry = testRail
.plans()
.addEntry(planId, new Entry().setSuiteId(suiteId)
.setName(testRunName)
.setIncludeAll(false)
.setCaseIds(caseIdList))
.execute();
int runId = entry.getRuns().get(0).getId();
LOG.info("Setting entryId {} as Maven property", entry.getId());
project.getProperties().put("entryId", entry.getId());
LOG.info("Setting testRunId {} as Maven property", runId);
project.getProperties().put("testRunId", Integer.toString(runId));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy