Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestNG Practitest integration implementation #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions api.v2/java.v2/JAVA_INTEGRATION_SAMPLE.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand Down Expand Up @@ -32,7 +32,6 @@
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.3.1" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:4.1.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.3.1" level="project" />
Expand All @@ -42,8 +41,10 @@
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.3.1" level="project" />
<orderEntry type="library" name="Maven: com.codeborne:phantomjsdriver:1.4.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:htmlunit-driver:2.24" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.7.1" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.5" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.9.1" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.9" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.9.1" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.13.0" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.24" level="project" />
<orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
<orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
Expand All @@ -69,5 +70,19 @@
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.10.2" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.2" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.2" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-java8:1.2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-java:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-testng:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-core:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-html:0.2.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-picocontainer:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-jvm-deps:1.0.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:gherkin:2.12.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.picocontainer:picocontainer:2.15" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.testng:testng:6.11" level="project" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.64" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
</component>
</module>
51 changes: 51 additions & 0 deletions api.v2/java.v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>JAVA_INTEGRATION_SAMPLE</groupId>
<artifactId>JAVA_INTEGRATION_SAMPLE</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>


<dependencies>
Expand All @@ -30,6 +42,45 @@
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.listeners;

public class CucumberJVMListenerForPractiTest {

//TODO: implement Cucumber Listener
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.listeners;

public class JUnitListenerForPractiTest {

//TODO: implement Junit Listener
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.listeners;

import com.practitest.api.example.PractiTestWriter;
import com.practitest.integration.ExtractTests;
import com.webdriver.example.Utils.Log;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import java.util.List;

public class TestNGListenerForPractiTest implements ITestListener {

protected Integer instanceID = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just one instanceID? There should be one instance for every test in the test set



@Override
public void onTestStart(ITestResult result) {
}

@Override
public void onTestSuccess(ITestResult result) {
PractiTestWriter.submitResults(instanceID, 0);
}

@Override
public void onTestFailure(ITestResult result) {
PractiTestWriter.submitResults(instanceID, 1);
}

@Override
public void onTestSkipped(ITestResult result) {
}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}

@Override
public void onStart(ITestContext context) {
Integer existingTestID = PractiTestWriter.getSetID();
if (existingTestID == 0)
{
List<Integer> testIDs = ExtractTests.extractAllTestIds(context);
//Create test run for all tests in current execution
Integer setID = PractiTestWriter.createNewSet(testIDs);
//Create new instance
this.instanceID = PractiTestWriter.createNewInstance(setID, testIDs);
}
else
{
Log.info("Using existing TestSEtID: "+existingTestID.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the testset exists (and going to be reused), you still have to synchronize the test in that testset. For example, a new test might be added, or some test might be removed. You should retrieve the current list of instances for the existing testset, add/remove instances as needed, and then create the runs and upload results

}

}


@Override
public void onFinish(ITestContext context) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,125 @@

public class PractiTestAPI {

/**
* Reads project.properties file for projectID
*/
private final static String projectID = System.getProperty("PROJECT_ID");

/**
*
* @param id
* @return
*/
public static Response sendGetSteps(String id)
{
return RequestFactory.doGet("com/v2/projects/4650/steps.json?test-ids=" +id);
return RequestFactory.doGet("/v2/projects/"+projectID+"/steps.json?test-ids=" +id);
}

/**
*
* @param body
*/
public static void sendCreateRun(String body)
{
RequestFactory.doPost("com/v2/projects/4650/runs.json", body).prettyPrint();
RequestFactory.doPost("/v2/projects/"+projectID+"/runs.json", body);
}

public static void sendCreateRun(int instanceID, List<StepModel> step)
/**
*
* @param instanceID
* @param step
* @return
*/
public static Response sendCreateRun(int instanceID, List<StepModel> step)
{
Data data = new Data();
data.setType("instances");
data.setAttributes(new Attributes(instanceID));
data.setAttributes(new Attributes(instanceID, 0));
data.setSteps(new Steps(step));
RequestFactory.doPost("com/v2/projects/4650/runs.json", new RunsModel(data)).prettyPrint();
return RequestFactory.doPost("/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id");
}

/**
*
* @param instanceID
* @return
*/
public static Response sendCreateRun(int instanceID)
{
Data data = new Data();
data.setType("instances");
data.setAttributes(new Attributes(instanceID, 0));
return RequestFactory.doPost("/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id");
}

/**
*
* @param instanceID
* @return
*/
public static Response sendSubmitResult(int instanceID, int exitCode)
{
Data data = new Data();
data.setType("instances");
data.setAttributes(new Attributes(instanceID, exitCode));
return RequestFactory.doPost("/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id");
}

/**
*
* @param body
*/
public static void sendCreateInstance(String body)
{
RequestFactory.doPost("com/v2/projects/4650/instances.json", body).prettyPrint();
RequestFactory.doPost("/v2/projects/"+projectID+"/instances.json", body).prettyPrint();
}

public static void sendCreateInstance(int setID, int testID)
/**
*
* @param setID
* @param testID
* @return
*/
public static Response sendCreateInstance(int setID, int testID)
{
com.practitest.api.model.instance.Data data = new com.practitest.api.model.instance.Data();
data.setAttributes(new com.practitest.api.model.instance.Attributes(setID, testID));

RequestFactory.doPost("com/v2/projects/4650/instances.json", new InstanceModel(data)).prettyPrint();
return RequestFactory.doPost("/v2/projects/"+projectID+"/instances.json", new InstanceModel(data));
}

/**
*
* @param body
* @return
*/
public static Response sendCreateTestSet(String body)
{
return RequestFactory.doPost("/v2/projects/"+projectID+"/sets.json", body);
}

public static void sendCreateTestSet(String body)
/**
*
* @return
*/
public static Response sendGetTestSet()
{
RequestFactory.doPost("com/v2/projects/4650/sets.json", body).prettyPrint();
return RequestFactory.doGet("/v2/projects/"+projectID+"sets.json");
}

public static void sendCreateTestSet(String name, List<Integer> testIDs)
/**
*
* @param name
* @param testIDs
* @return
*/
public static Response sendCreateTestSet(String name, List<Integer> testIDs)
{
com.practitest.api.model.sets.Data data = new com.practitest.api.model.sets.Data();
data.setInstances(new Instances(testIDs));
data.setAttributes(new com.practitest.api.model.sets.Attributes(name));
RequestFactory.doPost("com/v2/projects/4650/sets.json", new SetsModel(data)).prettyPrint();
return RequestFactory.doPost("/v2/projects/"+projectID+"/sets.json", new SetsModel(data));
}


Expand Down
Loading